01: /*
02:
03: This software is OSI Certified Open Source Software.
04: OSI Certified is a certification mark of the Open Source Initiative.
05:
06: The license (Mozilla version 1.0) can be read at the MMBase site.
07: See http://www.MMBase.org/license
08:
09: */
10: package org.mmbase.security.implementation.basic;
11:
12: import java.util.Map;
13: import java.util.HashMap;
14:
15: import org.mmbase.security.Rank;
16:
17: /**
18: * Support for authentication method 'class' for 'basic' authentication.
19: *
20: * @author Michiel Meeuwissen
21: * @version $Id: ClassLoginModule.java,v 1.7 2008/01/10 14:12:24 michiel Exp $
22: * @since MMBase-1.8
23: */
24: public class ClassLoginModule implements LoginModule {
25:
26: private Map<String, String> ranks = new HashMap<String, String>();
27:
28: public void load(Map<String, Object> properties) {
29: for (Map.Entry<String, Object> entry : properties.entrySet()) {
30: if (entry.getValue() instanceof String) {
31: ranks.put(entry.getKey(), (String) entry.getValue());
32: }
33: }
34: }
35:
36: public boolean login(NameContext user,
37: Map<String, Object> loginInfo, Object[] parameters) {
38: org.mmbase.security.classsecurity.ClassAuthentication.Login li = org.mmbase.security.classsecurity.ClassAuthentication
39: .classCheck("class");
40: if (li == null) {
41: throw new SecurityException(
42: "Class authentication failed (class not authorized)");
43: }
44: String userName = li.getMap().get("username");
45:
46: String r = ranks.get(userName);
47: Rank rank = r == null ? Rank.BASICUSER : Rank.getRank(r);
48: user.setIdentifier(userName);
49: user.setRank(rank);
50: return true;
51: }
52: }
|