users@glassfish.java.net

Custom login module

From: <glassfish_at_javadesktop.org>
Date: Thu, 24 Sep 2009 10:03:23 PDT

Hi.

I wrote this custom login module with jaas.

[code]public class CustomLoginModule
    implements LoginModule {
    private User user;
    private Set roles = new HashSet();

    protected Subject subject;
    protected CallbackHandler callbackHandler;
    protected Map sharedState;

    public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options) {
        this.subject = subject;
        this.callbackHandler = callbackHandler;
        this.sharedState = sharedState;
    }

    public boolean login()
        throws LoginException {
        user = new User("xflyer");
        roles.add(new Role("ADMIN"));

        sharedState.put("javax.security.auth.principal", user);
        sharedState.put("javax.security.auth.roles", roles);

        return true;
    }

    public boolean commit()
        throws LoginException {
        if (user != null && !subject.getPrincipals().contains(user)) {
            subject.getPrincipals().add(user);
        }
                
                for (Role role: roles) {
                        if (!subject.getPrincipals().contains(role)) {
                                subject.getPrincipals().add(role);
                        }
                }

        return true;
    }

    public boolean abort()
        throws LoginException {
        this.subject = null;
        this.callbackHandler = null;
        this.sharedState = null;
        this.roles = new HashSet();

        return true;
    }

    public boolean logout()
        throws LoginException {
        subject.getPrincipals().removeAll(roles);
        subject.getPrincipals().remove(user);
                
        return true;
    }
}[/code]

After I put this lines into my login.config:

[code]sampleRealm {
       myapp.security.SampleLoginModule required;
};[/code]

But I can't authenticate with any user. How I can configure custom login module into glassfish?
[Message sent by forum member 'xflyer' (otavio_at_otavio.com.br)]

http://forums.java.net/jive/thread.jspa?messageID=365589