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