FileDocCategorySizeDatePackage
SimpleLoginModule.javaAPI DocExample3633Mon Jan 15 13:05:10 GMT 2001javasec.samples.ch15

SimpleLoginModule

public class SimpleLoginModule extends Object implements LoginModule

Fields Summary
private Subject
subject
private CallbackHandler
callbackHandler
private SimplePrincipal
principal
private boolean
debug
private String
userName
private boolean
succeeded
private boolean
commitSucceeded
Constructors Summary
Methods Summary
public booleanabort()

        if (debug)
            System.err.println("SimpleLoginModule: Abort");

        if (succeeded == false)
            // We failed, and so did someone else, so just clean up
    	    return false;
        else if (succeeded == true && commitSucceeded == true) {
            // Our login succeeded, but another required module failed
            // We must remove our principal and clean up
            logout();
        } else  {
            // Our commit failed, even though login succeeded
            // The rest of our internal state should already
            // have been cleaned up
            succeeded = false;
        }
        return true;
    
public booleancommit()

        if (debug)
            System.err.println("SimpleLoginModule: Commit");

        if (!succeeded) {
            // We didn't authenticate the user, but someone else did.
            // Clean up our state, but don't add our principal to
            // the subject
            userName = null;
            return false;
        }

        principal = new SimplePrincipal(userName);
        // defaultUser might already be in the subject if another module
        // authenticated him.
        if (!subject.getPrincipals().contains(principal)) {
            subject.getPrincipals().add(principal);
        }

        // Clean up our internal state
        userName = null;
        commitSucceeded = true;
        return true;
    
public voidinitialize(javax.security.auth.Subject s, javax.security.auth.callback.CallbackHandler cb, java.util.Map sharedMap, java.util.Map options)


         
                               
 
        subject = s;
        callbackHandler = cb;

        // initialize any configured options
        debug = "true".equalsIgnoreCase((String)options.get("debug"));

        // We don