Skip to main content

Custom login module

1 reply [Last post]
Anonymous

Hi.

I wrote this custom login module with jaas.

public class CustomLoginModule<br />
    implements LoginModule {<br />
    private User user;<br />
    private Set roles = new HashSet();</p>
<p>    protected Subject subject;<br />
    protected CallbackHandler callbackHandler;<br />
    protected Map sharedState;</p>
<p>    public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options) {<br />
        this.subject = subject;<br />
        this.callbackHandler = callbackHandler;<br />
        this.sharedState = sharedState;<br />
    }</p>
<p>    public boolean login()<br />
        throws LoginException {<br />
        user = new User("xflyer");<br />
        roles.add(new Role("ADMIN"));</p>
<p>        sharedState.put("javax.security.auth.principal", user);<br />
        sharedState.put("javax.security.auth.roles", roles);</p>
<p>        return true;<br />
    }</p>
<p>    public boolean commit()<br />
        throws LoginException {<br />
        if (user != null && !subject.getPrincipals().contains(user)) {<br />
            subject.getPrincipals().add(user);<br />
        }</p>
<p>		for (Role role: roles) {<br />
			if (!subject.getPrincipals().contains(role)) {<br />
				subject.getPrincipals().add(role);<br />
			}<br />
		}</p>
<p>        return true;<br />
    }</p>
<p>    public boolean abort()<br />
        throws LoginException {<br />
        this.subject = null;<br />
        this.callbackHandler = null;<br />
        this.sharedState = null;<br />
        this.roles = new HashSet();</p>
<p>        return true;<br />
    }</p>
<p>    public boolean logout()<br />
        throws LoginException {<br />
        subject.getPrincipals().removeAll(roles);<br />
        subject.getPrincipals().remove(user);</p>
<p>        return true;<br />
    }<br />
}

After I put this lines into my login.config:

sampleRealm {<br />
       myapp.security.SampleLoginModule required;<br />
};

But I can't authenticate with any user. How I can configure custom login module into glassfish?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Anonymous

Hi. someone can help?