BortalCertificateLoginModule.java
1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package fi.insomnia.bortal;
import java.util.StringTokenizer;
import javax.security.auth.login.LoginException;
import com.sun.appserv.security.AppservCertificateLoginModule;
public class BortalCertificateLoginModule extends AppservCertificateLoginModule {
@Override
protected void authenticateUser() throws LoginException {
// Get the distinguished name from the X500Principal.
String dname = getX500Principal().getName();
log("BortalCertificateLoginModule: " + dname);
StringTokenizer st = new StringTokenizer(dname, " \t\n\r\f,");
while (st.hasMoreTokens()) {
String next = st.nextToken(); // Set the appname:OU as the group.
// At this point, one has the application name and the DN of // the
// certificate. A suitable login decision can be made here.
if (next.startsWith("CN=")) {
commitUserAuthentication(new String[] { getAppName() + ":"
+ next.substring(3) });
return;
}
}
throw new LoginException("No OU found.");
}
private void log(String s) {
System.out.println("BortalCertificateLoginModule: " + s);
}
}