001: /*
002: * CoadunationLib: The coaduntion implementation library.
003: * Copyright (C) 2006 Rift IT Contracting
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
018: *
019: * XMLUserStore.java
020: *
021: * The class responsible for retrieving the XML user information.
022: */
023:
024: // package path
025: package com.rift.coad.lib.security.user.xml;
026:
027: // java imports
028: import java.util.Map;
029: import java.util.HashMap;
030:
031: // coadunation imports
032: import com.rift.coad.lib.security.login.AuthTypes;
033: import com.rift.coad.lib.security.login.LoginException;
034: import com.rift.coad.lib.security.login.LoginHandler;
035: import com.rift.coad.lib.security.user.UserStoreConnector;
036: import com.rift.coad.lib.security.user.UserException;
037: import com.rift.coad.lib.security.UserSession;
038:
039: /**
040: * The class responsible for retrieving the XML user information.
041: *
042: * @author Brett Chaldecott
043: */
044: public class XMLUserStore implements UserStoreConnector {
045:
046: // the list of users
047: private Map users = null;
048:
049: /**
050: * Creates a new instance of XMLUserStore
051: */
052: public XMLUserStore() throws UserException {
053: users = new HashMap();
054: XMLUserParser userParser = new XMLUserParser(users);
055: }
056:
057: /**
058: * This method returns the name of the user store.
059: *
060: * @return The string containing the name of the user store.
061: */
062: public String getName() {
063: return "XMLUserStore";
064: }
065:
066: /**
067: * This method returns the user information for the given username. Note:
068: * this method must not throw an exception if the user is not found, it must
069: * instead return null.
070: *
071: *
072: * @return The name of the user to retrieve information for.
073: * @return User The user object for the given username.
074: * @exception UserException
075: */
076: public UserSession getUserInfo(String username)
077: throws UserException {
078: UserData userData = (UserData) users.get(username);
079: if (userData == null) {
080: return null;
081: }
082: return userData.getUser();
083: }
084:
085: /**
086: * This method returns true if the login manager can handle the requested
087: * authentication type.
088: *
089: * @return TRUE if it can FALSE if not.
090: * @param type The type of auth to check.
091: */
092: public boolean handleAuthType(String type) {
093: return AuthTypes.PASSWORD.equals(type);
094: }
095:
096: /**
097: * This method returns the login handler for the given auth type.
098: *
099: * @return The login handler that can handle the given auth type.
100: * @param type The type of login.
101: * @exception LoginException
102: */
103: public LoginHandler getLoginHandler(String type)
104: throws LoginException {
105: return new XMLLoginHandler(users);
106: }
107: }
|