BortalCertificateLoginModule.java
950 Bytes
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
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();
if (next.startsWith("CN=")) {
String cn = next.substring(3);
log("Committing user auth: " + cn);
commitUserAuthentication(new String[] { cn });
return;
}
}
throw new LoginException("No CN found.");
}
private void log(String s) {
System.out.println("BortalCertificateLoginModule: " + s);
}
}