    001    package org.apache.turbine.services.security.passive;
    002
    003
    004    /*
    005     * Licensed to the Apache Software Foundation (ASF) under one
    006     * or more contributor license agreements.  See the NOTICE file
    007     * distributed with this work for additional information
    008     * regarding copyright ownership.  The ASF licenses this file
    009     * to you under the Apache License, Version 2.0 (the
    010     * "License"); you may not use this file except in compliance
    011     * with the License.  You may obtain a copy of the License at
    012     *
    013     *   http://www.apache.org/licenses/LICENSE-2.0
    014     *
    015     * Unless required by applicable law or agreed to in writing,
    016     * software distributed under the License is distributed on an
    017     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    018     * KIND, either express or implied.  See the License for the
    019     * specific language governing permissions and limitations
    020     * under the License.
    021     */
    022
    023
    024    import java.util.List;
    025
    026    import org.apache.commons.configuration.Configuration;
    027
    028    import org.apache.turbine.om.security.User;
    029    import org.apache.turbine.services.security.UserManager;
    030    import org.apache.turbine.util.security.DataBackendException;
    031    import org.apache.turbine.util.security.EntityExistsException;
    032    import org.apache.turbine.util.security.PasswordMismatchException;
    033    import org.apache.turbine.util.security.UnknownEntityException;
    034
    035    /**
    036     * Void user manager can be used where no data storage is needed
    037     * by the application.
    038     * It's methods don't provide any useful functionality  except throwing
    039     * DataBackendExceptions. Security service will be still able to create
    040     * anonymous User objects when this UserManager is used.
    041     *
    042     * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
    043     * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
    044     * @version $Id: PassiveUserManager.java 1096130 2011-04-23 10:37:19Z ludwig $
    045     */
    046    public class PassiveUserManager implements UserManager
    047    {
    048        /**
    049         * Initializes the UserManager
    050         *
    051         * @param conf A Configuration object to init this Manager
    052         */
    053        public void init(Configuration conf)
    054        {
    055            // GNDN
    056        }
    057
    058        /**
    059         * Check whether a specified user's account exists.
    060         *
    061         * The login name is used for looking up the account.
    062         *
    063         * @param user The user to be checked.
    064         * @return true if the specified account exists
    065         * @throws DataBackendException if there was an error accessing the data backend.
    066         */
    067        public boolean accountExists(User user)
    068                throws DataBackendException
    069        {
    070            throw new DataBackendException("PassiveUserManager knows no users");
    071        }
    072
    073        /**
    074         * Check whether a specified user's account exists.
    075         *
    076         * The login name is used for looking up the account.
    077         *
    078         * @param userName The name of the user to be checked.
    079         * @return true if the specified account exists
    080         * @throws DataBackendException if there was an error accessing the data backend.
    081         */
    082        public boolean accountExists(String userName)
    083                throws DataBackendException
    084        {
    085            throw new DataBackendException("PassiveUserManager knows no users");
    086        }
    087
    088        /**
    089         * Retrieve a user from persistent storage using username as the
    090         * key.
    091         *
    092         * @param username the name of the user.
    093         * @return an User object.
    094         * @exception UnknownEntityException if the user's record does not
    095         *            exist in the database.
    096         * @exception DataBackendException if there is a problem accessing the
    097         *            storage.
    098         */
    099        public User retrieve(String username)
    100                throws UnknownEntityException, DataBackendException
    101        {
    102            throw new DataBackendException("PassiveUserManager knows no users");
    103        }
    104
    105        /**
    106         * Retrieve a set of users that meet the specified criteria.
    107         *
    108         * As the keys for the criteria, you should use the constants that
    109         * are defined in {@link User} interface, plus the names
    110         * of the custom attributes you added to your user representation
    111         * in the data storage. Use verbatim names of the attributes -
    112         * without table name prefix in case of DB implementation.
    113         *
    114         * @param criteria The criteria of selection.
    115         * @return a List of users meeting the criteria.
    116         * @throws DataBackendException if there is a problem accessing the
    117         *         storage.
    118         * @deprecated Use <a href="#retrieveList">retrieveList</a> instead.
    119         */
    120        public User[] retrieve(Object criteria)
    121                throws DataBackendException
    122        {
    123            throw new DataBackendException("PassiveUserManager knows no users");
    124        }
    125
    126        /**
    127         * Retrieve a set of users that meet the specified criteria.
    128         *
    129         * As the keys for the criteria, you should use the constants that
    130         * are defined in {@link User} interface, plus the names
    131         * of the custom attributes you added to your user representation
    132         * in the data storage. Use verbatim names of the attributes -
    133         * without table name prefix in case of DB implementation.
    134         *
    135         * @param criteria The criteria of selection.
    136         * @return a List of users meeting the criteria.
    137         * @throws DataBackendException if there is a problem accessing the
    138         *         storage.
    139         */
    140        public List retrieveList(Object criteria)
    141                throws DataBackendException
    142        {
    143            throw new DataBackendException("PassiveUserManager knows no users");
    144        }
    145
    146        /**
    147         * Retrieve a user from persistent storage using username as the
    148         * key, and authenticate the user. The implementation may chose
    149         * to authenticate to the server as the user whose data is being
    150         * retrieved.
    151         *
    152         * @param username the name of the user.
    153         * @param password the user supplied password.
    154         * @return an User object.
    155         * @exception PasswordMismatchException if the supplied password was
    156         *            incorrect.
    157         * @exception UnknownEntityException if the user's record does not
    158         *            exist in the database.
    159         * @exception DataBackendException if there is a problem accessing the
    160         *            storage.
    161         */
    162        public User retrieve(String username, String password)
    163                throws PasswordMismatchException, UnknownEntityException,
    164                DataBackendException
    165        {
    166            throw new DataBackendException("PassiveUserManager knows no users");
    167        }
    168
    169        /**
    170         * Save an User object to persistent storage. User's record is
    171         * required to exist in the storage.
    172         *
    173         * @param user an User object to store.
    174         * @exception UnknownEntityException if the user's record does not
    175         *            exist in the database.
    176         * @exception DataBackendException if there is a problem accessing the
    177         *            storage.
    178         */
    179        public void store(User user)
    180                throws UnknownEntityException, DataBackendException
    181        {
    182            throw new DataBackendException("PassiveUserManager does not support saving user data");
    183        }
    184
    185        /**
    186         * Saves User data when the session is unbound. The user account is required
    187         * to exist in the storage.
    188         *
    189         * LastLogin, AccessCounter, persistent pull tools, and any data stored
    190         * in the permData hashtable that is not mapped to a column will be saved.
    191         *
    192         * @exception UnknownEntityException if the user's account does not
    193         *            exist in the database.
    194         * @exception DataBackendException if there is a problem accessing the
    195         *            storage.
    196         */
    197        public void saveOnSessionUnbind(User user)
    198                throws UnknownEntityException, DataBackendException
    199        {
    200            throw new DataBackendException("PassiveUserManager does not support saving user data");
    201        }
    202
    203        /**
    204         * Authenticate an User with the specified password. If authentication
    205         * is successful the method returns nothing. If there are any problems,
    206         * exception was thrown.
    207         *
    208         * @param user an User object to authenticate.
    209         * @param password the user supplied password.
    210         * @exception PasswordMismatchException if the supplied password was
    211         *            incorrect.
    212         * @exception UnknownEntityException if the user's record does not
    213         *            exist in the database.
    214         * @exception DataBackendException if there is a problem accessing the
    215         *            storage.
    216         */
    217        public void authenticate(User user, String password)
    218                throws PasswordMismatchException, UnknownEntityException,
    219                DataBackendException
    220        {
    221            throw new DataBackendException("PassiveUserManager knows no users");
    222        }
    223
    224        /**
    225         * Creates new user account with specified attributes.
    226         *
    227         * @param user the object describing account to be created.
    228         * @param initialPassword The password to use for the object creation
    229         *
    230         * @throws DataBackendException if there was an error accessing the data backend.
    231         * @throws EntityExistsException if the user account already exists.
    232         */
    233        public void createAccount(User user, String initialPassword)
    234                throws EntityExistsException, DataBackendException
    235        {
    236            throw new DataBackendException("PassiveUserManager does not support"
    237                    + " creating accounts");
    238        }
    239
    240        /**
    241         * Removes an user account from the system.
    242         *
    243         * @param user the object describing the account to be removed.
    244         * @throws DataBackendException if there was an error accessing the data backend.
    245         * @throws UnknownEntityException if the user account is not present.
    246         */
    247        public void removeAccount(User user)
    248                throws UnknownEntityException, DataBackendException
    249        {
    250            throw new DataBackendException("PassiveUserManager does not support removing accounts");
    251        }
    252
    253        /**
    254         * Change the password for an User.
    255         *
    256         * @param user an User to change password for.
    257         * @param oldPassword the current password supplied by the user.
    258         * @param newPassword the current password requested by the user.
    259         * @exception PasswordMismatchException if the supplied password was
    260         *            incorrect.
    261         * @exception UnknownEntityException if the user's record does not
    262         *            exist in the database.
    263         * @exception DataBackendException if there is a problem accessing the
    264         *            storage.
    265         */
    266        public void changePassword(User user, String oldPassword,
    267                                   String newPassword)
    268                throws PasswordMismatchException, UnknownEntityException,
    269                DataBackendException
    270        {
    271            throw new DataBackendException("PassiveUserManager does not support setting passwords");
    272        }
    273
    274        /**
    275         * Forcibly sets new password for an User.
    276         *
    277         * This is supposed by the administrator to change the forgotten or
    278         * compromised passwords. Certain implementatations of this feature
    279         * would require administrative level access to the authenticating
    280         * server / program.
    281         *
    282         * @param user an User to change password for.
    283         * @param password the new password.
    284         * @exception UnknownEntityException if the user's record does not
    285         *            exist in the database.
    286         * @exception DataBackendException if there is a problem accessing the
    287         *            storage.
    288         */
    289        public void forcePassword(User user, String password)
    290                throws UnknownEntityException, DataBackendException
    291        {
    292            throw new DataBackendException("PassiveUserManager does not support setting passwords");
    293        }
    294    }