KickJava   Java API By Example, From Geeks To Geeks.

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


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  * ClassLogin, authentication based on 'class', using <security>/classauthentication.xml or ClassAuthenticationWrapper.
20  *
21  * @author Michiel Meeuwissen
22  * @version $Id: ClassLogin.java,v 1.5 2005/12/29 20:43:16 michiel Exp $
23  * @since MMBase-1.8
24  */

25
26 public class ClassLogin extends ContextLoginModule {
27     private static final Logger log = Logging.getLoggerInstance(ClassLogin.class);
28
29     public ContextUserContext login(Map JavaDoc userLoginInfo, Object JavaDoc[] userParameters) throws org.mmbase.security.SecurityException {
30
31         org.mmbase.security.classsecurity.ClassAuthentication.Login li = org.mmbase.security.classsecurity.ClassAuthentication.classCheck("class");
32         if (li == null) {
33             throw new SecurityException JavaDoc("Class authentication failed '" + userLoginInfo + "' (class not authorized)");
34         }
35         // get username
36
String JavaDoc userName = (String JavaDoc) li.getMap().get("username");
37         String JavaDoc reqRank = (String JavaDoc) li.getMap().get("rank");
38         if(userName == null && reqRank == null) throw new org.mmbase.security.SecurityException("expected the property 'username' and/or 'rank' with login");
39
40         if ("anonymous".equals(reqRank) && userName == null) {
41             return getValidUserContext("anonymous", Rank.ANONYMOUS);
42         }
43
44         org.w3c.dom.Element JavaDoc node = getAccount(userName, null, reqRank);
45         if(node == null) {
46             log.info("No user with name '" + userName + "' and rank '" + reqRank + "'");
47             return null;
48         }
49         userName = node.getAttribute("name");
50
51         Rank rank= getRank(userName, null);
52         if(rank == null) {
53             log.warn( "expected a rank for user with name '" + userName + "', canceling a valid login due to the fact that the rank attribute was not set");
54             return null;
55
56         }
57         return getValidUserContext(userName, rank);
58     }
59 }
60
Popular Tags