KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > security > implementation > context > PasswordLogin


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.security.implementation.context;
11
12 import org.mmbase.security.Rank;
13 import java.util.Map JavaDoc;
14
15 import org.mmbase.util.logging.Logger;
16 import org.mmbase.util.logging.Logging;
17
18 /**
19  * Class PasswordLogin
20  * @javadoc
21  *
22  * @author Eduard Witteveen
23  * @version $Id: PasswordLogin.java,v 1.8 2005/10/04 11:15:24 michiel Exp $
24  */

25
26 public class PasswordLogin extends ContextLoginModule {
27     private static Logger log = Logging.getLoggerInstance(PasswordLogin.class);
28
29     public ContextUserContext login(Map JavaDoc userLoginInfo, Object JavaDoc[] userParameters) throws org.mmbase.security.SecurityException {
30
31         // get userName
32
String JavaDoc userName = (String JavaDoc)userLoginInfo.get("username");
33         if(userName == null) throw new org.mmbase.security.SecurityException("expected the property 'username' with login");
34
35         // get password
36
String JavaDoc password = (String JavaDoc)userLoginInfo.get("password");
37         if(password == null) throw new org.mmbase.security.SecurityException("expected the property 'password' with login");
38
39         log.debug("request for user: '"+userName+"' with pass: '"+password+"'");
40
41         org.w3c.dom.Element JavaDoc node = getAccount(userName);
42         if(node == null) {
43             log.info("user with name:" + userName + " doesnt have a value for this module");
44             return null;
45         }
46         org.w3c.dom.Element JavaDoc identify = (org.w3c.dom.Element JavaDoc) node.getElementsByTagName("identify").item(0);
47         String JavaDoc configPassword = org.mmbase.util.xml.DocumentReader.getNodeTextValue(identify);
48         if(!configPassword.equals(password)) {
49             log.debug("user with name:" + userName + " used pass:" + password + " but needed :" + configPassword);
50             log.info("user with name:" + userName + " didnt give the right password");
51             return null;
52         }
53
54         Rank rank= getRank(userName);
55         if(rank == null) {
56             log.warn( "expected a rank for user with the name:" + userName + ", canceling a valid login due to the fact that the rank attribute wasnt set");
57             return null;
58
59         }
60         return getValidUserContext(userName, rank);
61     }
62 }
63
Popular Tags