KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > security > user > xml > XMLUserStore


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * XMLUserStore.java
20  *
21  * The class responsible for retrieving the XML user information.
22  */

23
24 // package path
25
package com.rift.coad.lib.security.user.xml;
26
27 // java imports
28
import java.util.Map JavaDoc;
29 import java.util.HashMap JavaDoc;
30
31 // coadunation imports
32
import com.rift.coad.lib.security.login.AuthTypes;
33 import com.rift.coad.lib.security.login.LoginException;
34 import com.rift.coad.lib.security.login.LoginHandler;
35 import com.rift.coad.lib.security.user.UserStoreConnector;
36 import com.rift.coad.lib.security.user.UserException;
37 import com.rift.coad.lib.security.UserSession;
38
39 /**
40  * The class responsible for retrieving the XML user information.
41  *
42  * @author Brett Chaldecott
43  */

44 public class XMLUserStore implements UserStoreConnector {
45     
46     // the list of users
47
private Map JavaDoc users = null;
48     
49     /**
50      * Creates a new instance of XMLUserStore
51      */

52     public XMLUserStore() throws UserException {
53         users = new HashMap JavaDoc();
54         XMLUserParser userParser = new XMLUserParser(users);
55     }
56     
57     
58     /**
59      * This method returns the name of the user store.
60      *
61      * @return The string containing the name of the user store.
62      */

63     public String JavaDoc getName() {
64         return "XMLUserStore";
65     }
66     
67     
68     /**
69      * This method returns the user information for the given username. Note:
70      * this method must not throw an exception if the user is not found, it must
71      * instead return null.
72      *
73      *
74      * @return The name of the user to retrieve information for.
75      * @return User The user object for the given username.
76      * @exception UserException
77      */

78     public UserSession getUserInfo(String JavaDoc username) throws UserException {
79         UserData userData = (UserData)users.get(username);
80         if (userData == null) {
81             return null;
82         }
83         return userData.getUser();
84     }
85     
86     
87     /**
88      * This method returns true if the login manager can handle the requested
89      * authentication type.
90      *
91      * @return TRUE if it can FALSE if not.
92      * @param type The type of auth to check.
93      */

94     public boolean handleAuthType(String JavaDoc type) {
95         return AuthTypes.PASSWORD.equals(type);
96     }
97     
98     
99     /**
100      * This method returns the login handler for the given auth type.
101      *
102      * @return The login handler that can handle the given auth type.
103      * @param type The type of login.
104      * @exception LoginException
105      */

106     public LoginHandler getLoginHandler(String JavaDoc type) throws LoginException {
107         return new XMLLoginHandler(users);
108     }
109 }
110
Popular Tags