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