1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.michaelo.tomcat.realm;
17
18 import java.security.Principal;
19
20 import org.apache.catalina.realm.RealmBase;
21 import org.apache.juli.logging.Log;
22 import org.apache.juli.logging.LogFactory;
23 import org.apache.tomcat.util.res.StringManager;
24 import org.ietf.jgss.GSSContext;
25 import org.ietf.jgss.GSSName;
26
27
28
29
30
31
32
33 public abstract class ActiveDirectoryRealmBase extends RealmBase {
34
35 protected final Log logger = LogFactory.getLog(getClass());
36 protected final StringManager sm = StringManager.getManager(getClass());
37
38
39
40
41
42 @Override
43 protected String getPassword(String username) {
44 throw new UnsupportedOperationException(
45 "getPassword(String) is not supported by this realm");
46 }
47
48
49
50
51
52 @Override
53 protected Principal getPrincipal(String username) {
54 throw new UnsupportedOperationException(
55 "getPrincipal(String) is not supported by this realm");
56 }
57
58 @Override
59 protected boolean hasRoleInternal(Principal principal, String role) {
60 if (!(principal instanceof ActiveDirectoryPrincipal))
61 return false;
62
63 ActiveDirectoryPrincipal adp = (ActiveDirectoryPrincipal) principal;
64 return adp.hasRole(role);
65 }
66
67 @Override
68 public String[] getRoles(Principal principal) {
69 if (principal instanceof ActiveDirectoryPrincipal) {
70 return ((ActiveDirectoryPrincipal) principal).getRoles();
71 }
72
73 String className = principal.getClass().getName();
74 throw new IllegalStateException(sm.getString("activeDirectoryRealmBase.cannotGetRoles",
75 principal.getName(), className));
76 }
77
78 }