001package org.apache.turbine.om.security;
002
003import java.util.Date;
004
005/*
006 * Licensed to the Apache Software Foundation (ASF) under one
007 * or more contributor license agreements.  See the NOTICE file
008 * distributed with this work for additional information
009 * regarding copyright ownership.  The ASF licenses this file
010 * to you under the Apache License, Version 2.0 (the
011 * "License"); you may not use this file except in compliance
012 * with the License.  You may obtain a copy of the License at
013 *
014 *   http://www.apache.org/licenses/LICENSE-2.0
015 *
016 * Unless required by applicable law or agreed to in writing,
017 * software distributed under the License is distributed on an
018 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
019 * KIND, either express or implied.  See the License for the
020 * specific language governing permissions and limitations
021 * under the License.
022 */
023
024import java.util.Map;
025
026import javax.servlet.http.HttpSessionBindingListener;
027
028import org.apache.fulcrum.security.model.turbine.entity.TurbineUser;
029
030/**
031 * This interface represents functionality that all users of the
032 * Turbine system require.
033 *
034 * @author <a href="mailto:frank.kim@clearink.com">Frank Y. Kim</a>
035 * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
036 * @author <a href="mailto:jon@collab.net">Jon S. Stevens</a>
037 * @author <a href="mailto:cberry@gluecode.com">Craig D. Berry</a>
038 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
039 * @version $Id$
040 */
041public interface User
042    extends HttpSessionBindingListener, TurbineUserDelegate, TurbineUser
043{
044    /** The 'perm storage' key name for the create_date field. */
045    String CREATE_DATE = "CREATE_DATE";
046
047    /** The 'perm storage' key name for the last_login field. */
048    String LAST_LOGIN = "LAST_LOGIN";
049
050    /** The 'perm storage' key for the confirm_value field. */
051    String CONFIRM_VALUE = "CONFIRM_VALUE";
052
053    /** This is the value that is stored in the database for confirmed users */
054    String CONFIRM_DATA = "CONFIRMED";
055
056    /** The 'perm storage' key name for the access counter. */
057    String ACCESS_COUNTER = "_access_counter";
058
059    /** The 'temp storage' key name for the session access counter */
060    String SESSION_ACCESS_COUNTER = "_session_access_counter";
061
062    /** The 'temp storage' key name for the 'has logged in' flag */
063    String HAS_LOGGED_IN = "_has_logged_in";
064
065    /** The session key for the User object. */
066    String SESSION_KEY = "turbine.user";
067
068    /**
069     * Gets the access counter for a user from perm storage.
070     *
071     * @return The access counter for the user.
072     */
073    int getAccessCounter();
074
075    /**
076     * Gets the access counter for a user during a session.
077     *
078     * @return The access counter for the user for the session.
079     */
080    int getAccessCounterForSession();
081
082    /**
083     * Gets the last access date for this User. This is the last time
084     * that the user object was referenced.
085     *
086     * @return A Java Date with the last access date for the user.
087     */
088    Date getLastAccessDate();
089
090    /**
091     * Gets the create date for this User.  This is the time at which
092     * the user object was created.
093     *
094     * @return A Java Date with the date of creation for the user.
095     */
096    Date getCreateDate();
097
098    /**
099     * Returns the user's last login date.
100     *
101     * @return A Java Date with the last login date for the user.
102     */
103    Date getLastLogin();
104
105    /**
106     * Get an object from permanent storage.
107     *
108     * @param name The object's name.
109     * @return An Object with the given name.
110     */
111    Object getPerm(String name);
112
113    /**
114     * Get an object from permanent storage; return default if value
115     * is null.
116     *
117     * @param name The object's name.
118     * @param def A default value to return.
119     * @return An Object with the given name.
120     */
121    Object getPerm(String name, Object def);
122
123    /**
124     * This should only be used in the case where we want to save the
125     * data to the database.
126     *
127     * @return A Map.
128     */
129    Map<String, Object> getPermStorage();
130
131    /**
132     * This should only be used in the case where we want to save the
133     * data to the database.
134     *
135     * @return A Map.
136     */
137    Map<String, Object> getTempStorage();
138
139    /**
140     * Get an object from temporary storage.
141     *
142     * @param name The object's name.
143     * @return An Object with the given name.
144     */
145    Object getTemp(String name);
146
147    /**
148     * Get an object from temporary storage; return default if value
149     * is null.
150     *
151     * @param name The object's name.
152     * @param def A default value to return.
153     * @return An Object with the given name.
154     */
155    Object getTemp(String name, Object def);
156
157    /**
158     * This sets whether or not someone has logged in.  hasLoggedIn()
159     * returns this value.
160     *
161     * @param value Whether someone has logged in or not.
162     */
163    void setHasLoggedIn(Boolean value);
164
165    /**
166     * The user is considered logged in if they have not timed out.
167     *
168     * @return True if the user has logged in.
169     */
170    boolean hasLoggedIn();
171
172    /**
173     * Increments the permanent hit counter for the user.
174     */
175    void incrementAccessCounter();
176
177    /**
178     * Increments the session hit counter for the user.
179     */
180    void incrementAccessCounterForSession();
181
182    /**
183     * Remove an object from temporary storage and return the object.
184     *
185     * @param name The name of the object to remove.
186     * @return An Object.
187     */
188    Object removeTemp(String name);
189
190    /**
191     * Sets the access counter for a user, saved in perm storage.
192     *
193     * @param cnt The new count.
194     */
195    void setAccessCounter(int cnt);
196
197    /**
198     * Sets the session access counter for a user, saved in temp
199     * storage.
200     *
201     * @param cnt The new count.
202     */
203    void setAccessCounterForSession(int cnt);
204
205    /**
206     * Sets the last access date for this User. This is the last time
207     * that the user object was referenced.
208     */
209    void setLastAccessDate();
210
211    /**
212     * Set last login date/time.
213     *
214     * @param lastLogin The last login date.
215     */
216    void setLastLogin(Date lastLogin);
217
218    /**
219     * Put an object into permanent storage.
220     *
221     * @param name The object's name.
222     * @param value The object.
223     */
224    void setPerm(String name,
225                 Object value);
226
227    /**
228     * This should only be used in the case where we want to save the
229     * data to the database.
230     *
231     * @param storage A Map.
232     */
233    void setPermStorage(Map<String, Object> storage);
234
235    /**
236     * This should only be used in the case where we want to save the
237     * data to the database.
238     *
239     * @param storage A Map.
240     */
241    void setTempStorage(Map<String, Object> storage);
242
243    /**
244     * Put an object into temporary storage.
245     *
246     * @param name The object's name.
247     * @param value The object.
248     */
249    void setTemp(String name, Object value);
250
251    /**
252     * Sets the creation date for this user.
253     *
254     * @param date Creation date
255     */
256    void setCreateDate(Date date);
257
258    /**
259     * This method reports whether or not the user has been confirmed
260     * in the system by checking the TurbineUserPeer.CONFIRM_VALUE
261     * column to see if it is equal to CONFIRM_DATA.
262     *
263     * @return True if the user has been confirmed.
264     */
265    boolean isConfirmed();
266
267    /**
268     * Sets the confirmation value.
269     *
270     * @param value The confirmation key value.
271     */
272    void setConfirmed(String value);
273
274    /**
275     * Gets the confirmation value.
276     *
277     * @return The confirmed value
278     */
279    String getConfirmed();
280
281    /**
282     * Updates the last login date in the database.
283     *
284     * @throws Exception A generic exception.
285     */
286
287    void updateLastLogin()
288        throws Exception;
289}