BortalCertificateLoginModule.java 950 Bytes
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);
	}
}