BortalCertificateLoginModule.java 1.06 KB
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);
	}
}