    001package 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
    024import java.util.List;
    025
    026import org.apache.commons.configuration.Configuration;
    027import org.apache.fulcrum.security.acl.AccessControlList;
    028import org.apache.fulcrum.security.util.DataBackendException;
    029import org.apache.fulcrum.security.util.EntityExistsException;
    030import org.apache.fulcrum.security.util.PasswordMismatchException;
    031import org.apache.fulcrum.security.util.UnknownEntityException;
    032import org.apache.turbine.om.security.User;
    033import org.apache.turbine.services.security.UserManager;
    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 1773378 2016-12-09 13:19:59Z tv $
    045 */
    046public class PassiveUserManager implements UserManager
    047{
    048    /**
    049     * Initializes the UserManager
    050     *
    051     * @param conf A Configuration object to init this Manager
    052     */
    053    @Override
    054    public void init(Configuration conf)
    055    {
    056        // GNDN
    057    }
    058
    059    /**
    060     * Check whether a specified user's account exists.
    061     *
    062     * The login name is used for looking up the account.
    063     *
    064     * @param user The user to be checked.
    065     * @return true if the specified account exists
    066     * @throws DataBackendException if there was an error accessing the data backend.
    067     */
    068    @Override
    069    public boolean accountExists(User user)
    070            throws DataBackendException
    071    {
    072        throw new DataBackendException("PassiveUserManager knows no users");
    073    }
    074
    075    /**
    076     * Check whether a specified user's account exists.
    077     *
    078     * The login name is used for looking up the account.
    079     *
    080     * @param userName The name of the user to be checked.
    081     * @return true if the specified account exists
    082     * @throws DataBackendException if there was an error accessing the data backend.
    083     */
    084    @Override
    085    public boolean accountExists(String userName)
    086            throws DataBackendException
    087    {
    088        throw new DataBackendException("PassiveUserManager knows no users");
    089    }
    090
    091    /**
    092     * Retrieve a user from persistent storage using username as the
    093     * key.
    094     *
    095     * @param username the name of the user.
    096     * @return an User object.
    097     * @throws UnknownEntityException if the user's record does not
    098     *            exist in the database.
    099     * @throws DataBackendException if there is a problem accessing the
    100     *            storage.
    101     */
    102    @Override
    103    public <U extends User> U retrieve(String username)
    104            throws UnknownEntityException, DataBackendException
    105    {
    106        throw new DataBackendException("PassiveUserManager knows no users");
    107    }
    108
    109    /**
    110     * Retrieve a set of users that meet the specified criteria.
    111     *
    112     * As the keys for the criteria, you should use the constants that
    113     * are defined in {@link User} interface, plus the names
    114     * of the custom attributes you added to your user representation
    115     * in the data storage. Use verbatim names of the attributes -
    116     * without table name prefix in case of DB implementation.
    117     *
    118     * @param criteria The criteria of selection.
    119     * @return a List of users meeting the criteria.
    120     * @throws DataBackendException if there is a problem accessing the
    121     *         storage.
    122     */
    123    @Override
    124    public List<? extends User> retrieveList(Object criteria)
    125            throws DataBackendException
    126    {
    127        throw new DataBackendException("PassiveUserManager knows no users");
    128    }
    129
    130    /**
    131     * Retrieve a user from persistent storage using username as the
    132     * key, and authenticate the user. The implementation may chose
    133     * to authenticate to the server as the user whose data is being
    134     * retrieved.
    135     *
    136     * @param username the name of the user.
    137     * @param password the user supplied password.
    138     * @return an User object.
    139     * @throws PasswordMismatchException if the supplied password was
    140     *            incorrect.
    141     * @throws UnknownEntityException if the user's record does not
    142     *            exist in the database.
    143     * @throws DataBackendException if there is a problem accessing the
    144     *            storage.
    145     */
    146    @Override
    147    public <U extends User> U retrieve(String username, String password)
    148            throws PasswordMismatchException, UnknownEntityException,
    149            DataBackendException
    150    {
    151        throw new DataBackendException("PassiveUserManager knows no users");
    152    }
    153
    154    /**
    155     * Save an User object to persistent storage. User's record is
    156     * required to exist in the storage.
    157     *
    158     * @param user an User object to store.
    159     * @throws UnknownEntityException if the user's record does not
    160     *            exist in the database.
    161     * @throws DataBackendException if there is a problem accessing the
    162     *            storage.
    163     */
    164    @Override
    165    public void store(User user)
    166            throws UnknownEntityException, DataBackendException
    167    {
    168        throw new DataBackendException("PassiveUserManager does not support saving user data");
    169    }
    170
    171    /**
    172     * Saves User data when the session is unbound. The user account is required
    173     * to exist in the storage.
    174     *
    175     * LastLogin, AccessCounter, persistent pull tools, and any data stored
    176     * in the permData hashmap that is not mapped to a column will be saved.
    177     *
    178     * @throws UnknownEntityException if the user's account does not
    179     *            exist in the database.
    180     * @throws DataBackendException if there is a problem accessing the
    181     *            storage.
    182     */
    183    @Override
    184    public void saveOnSessionUnbind(User user)
    185            throws UnknownEntityException, DataBackendException
    186    {
    187        throw new DataBackendException("PassiveUserManager does not support saving user data");
    188    }
    189
    190    /**
    191     * Authenticate an User with the specified password. If authentication
    192     * is successful the method returns nothing. If there are any problems,
    193     * exception was thrown.
    194     *
    195     * @param user an User object to authenticate.
    196     * @param password the user supplied password.
    197     * @throws PasswordMismatchException if the supplied password was
    198     *            incorrect.
    199     * @throws UnknownEntityException if the user's record does not
    200     *            exist in the database.
    201     * @throws DataBackendException if there is a problem accessing the
    202     *            storage.
    203     */
    204    @Override
    205    public void authenticate(User user, String password)
    206            throws PasswordMismatchException, UnknownEntityException,
    207            DataBackendException
    208    {
    209        throw new DataBackendException("PassiveUserManager knows no users");
    210    }
    211
    212    /**
    213     * Creates new user account with specified attributes.
    214     *
    215     * @param user the object describing account to be created.
    216     * @param initialPassword The password to use for the object creation
    217     *
    218     * @throws DataBackendException if there was an error accessing the data backend.
    219     * @throws EntityExistsException if the user account already exists.
    220     */
    221    @Override
    222    public void createAccount(User user, String initialPassword)
    223            throws EntityExistsException, DataBackendException
    224    {
    225        throw new DataBackendException("PassiveUserManager does not support"
    226                + " creating accounts");
    227    }
    228
    229    /**
    230     * Removes an user account from the system.
    231     *
    232     * @param user the object describing the account to be removed.
    233     * @throws DataBackendException if there was an error accessing the data backend.
    234     * @throws UnknownEntityException if the user account is not present.
    235     */
    236    @Override
    237    public void removeAccount(User user)
    238            throws UnknownEntityException, DataBackendException
    239    {
    240        throw new DataBackendException("PassiveUserManager does not support removing accounts");
    241    }
    242
    243    /**
    244     * Change the password for an User.
    245     *
    246     * @param user an User to change password for.
    247     * @param oldPassword the current password supplied by the user.
    248     * @param newPassword the current password requested by the user.
    249     * @throws PasswordMismatchException if the supplied password was
    250     *            incorrect.
    251     * @throws UnknownEntityException if the user's record does not
    252     *            exist in the database.
    253     * @throws DataBackendException if there is a problem accessing the
    254     *            storage.
    255     */
    256    @Override
    257    public void changePassword(User user, String oldPassword,
    258                               String newPassword)
    259            throws PasswordMismatchException, UnknownEntityException,
    260            DataBackendException
    261    {
    262        throw new DataBackendException("PassiveUserManager does not support setting passwords");
    263    }
    264
    265    /**
    266     * Forcibly sets new password for an User.
    267     *
    268     * This is supposed by the administrator to change the forgotten or
    269     * compromised passwords. Certain implementations of this feature
    270     * would require administrative level access to the authenticating
    271     * server / program.
    272     *
    273     * @param user an User to change password for.
    274     * @param password the new password.
    275     * @throws UnknownEntityException if the user's record does not
    276     *            exist in the database.
    277     * @throws DataBackendException if there is a problem accessing the
    278     *            storage.
    279     */
    280    @Override
    281    public void forcePassword(User user, String password)
    282            throws UnknownEntityException, DataBackendException
    283    {
    284        throw new DataBackendException("PassiveUserManager does not support setting passwords");
    285    }
    286
    287    /**
    288     * Constructs an User object to represent an anonymous user of the
    289     * application.
    290     *
    291     * @return An anonymous Turbine User.
    292     * @throws UnknownEntityException
    293     *             if the anonymous User object couldn't be constructed.
    294     */
    295    @Override
    296    public <T extends User> T getAnonymousUser() throws UnknownEntityException
    297    {
    298        throw new UnknownEntityException("PassiveUserManager knows no users");
    299    }
    300
    301    /**
    302     * Checks whether a passed user object matches the anonymous user pattern
    303     * according to the configured user manager
    304     *
    305     * @param u a user object
    306     *
    307     * @return true if this is an anonymous user
    308     *
    309     */
    310    @Override
    311    public boolean isAnonymousUser(User u)
    312    {
    313        return true;
    314    }
    315
    316    /**
    317     * Construct a blank User object.
    318     *
    319     * This method calls getUserClass, and then creates a new object using the
    320     * default constructor.
    321     *
    322     * @return an object implementing User interface.
    323     * @throws DataBackendException
    324     *             if the object could not be instantiated.
    325     */
    326    @Override
    327    public <T extends User> T getUserInstance() throws DataBackendException
    328    {
    329        throw new DataBackendException("PassiveUserManager knows no users");
    330    }
    331
    332    /**
    333     * Construct a blank User object.
    334     *
    335     * This method calls getUserClass, and then creates a new object using the
    336     * default constructor.
    337     *
    338     * @param userName
    339     *            The name of the user.
    340     *
    341     * @return an object implementing User interface.
    342     * @throws DataBackendException
    343     *             if the object could not be instantiated.
    344     */
    345    @Override
    346    public <T extends User> T getUserInstance(String userName) throws DataBackendException
    347    {
    348        throw new DataBackendException("PassiveUserManager knows no users");
    349    }
    350
    351    /**
    352     * Return a Class object representing the system's chosen implementation of
    353     * of ACL interface.
    354     *
    355     * @return systems's chosen implementation of ACL interface.
    356     * @throws UnknownEntityException
    357     *             if the implementation of ACL interface could not be
    358     *             determined, or does not exist.
    359     */
    360    @Override
    361    public <T extends AccessControlList> T getACL(User user) throws UnknownEntityException
    362    {
    363        throw new UnknownEntityException("PassiveUserManager knows no users");
    364    }
    365}