BortalCertificateLoginModule.java
1.09 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
40
41
42
43
44
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("OU=")) {
String ou = next.substring(3);
// E.g. TERMINAL/CASHIER, TERMINAL/CLIENT or TERMINAL/SELFHELP
String principal = "TERMINAL/" + ou.toUpperCase();
log("Committing user auth: " + principal);
commitUserAuthentication(new String[] { principal, "TERMINAL" });
return;
}
}
throw new LoginException("No CN found.");
}
private void log(String s) {
System.out.println("BortalCertificateLoginModule: " + s);
}
}