[jboss-user] [JBoss Portal] - custom authentication

vinguye2 do-not-reply at jboss.com
Thu Nov 1 15:51:49 EDT 2007


Hi,
Has anyone figured out a simple solution to customize authentication for JBoss Portal?  I've searched the forum, but there seems to be no definitive answer.  Would be nice if a solution was posted in the docs or Wiki by the JBoss team.

Basically, I'd like to authenticate users against my own db.  But as a start, I created a custom LoginModule and placed it in login-config.xml.  The code is below, which I got by following this post:
http://jboss.org/index.html?module=bb&op=viewtopic&t=118988

I can successfully login with any username/password, but I still see the "Login" link at the top right of the page after I login.  I am beginning to assume there is something in the original org.jboss.portal.identity.auth.IdentityLoginModule code that is specific to JBP that normal login module implementors aren't aware of.  But I don't have access to the IdentifyLoginModule's source code.

Any help is appreciated!

public class MyLoginModule extends AbstractServerLoginModule
{
    private String username = null;
    private Principal identity;
    private Object password;

    @Override
    protected Principal getIdentity()
    {
        System.out.println("getIdentity(): " + identity);
        return identity;
    }

    @Override
    protected Group[] getRoleSets() throws LoginException
    {
        System.out.println("getRoleSets()");
        Group rolesGroup = new SimpleGroup("Roles");
        rolesGroup.addMember(new SimplePrincipal("Authenticated"));
        rolesGroup.addMember(new SimplePrincipal("Admin"));
        rolesGroup.addMember(new SimplePrincipal("Users"));
        rolesGroup.addMember(identity);
        return new Group[] {rolesGroup};
    }

    public boolean login()
    throws LoginException
    {
        NameCallback nameCallback = new NameCallback("Enter username");
        PasswordCallback pwdCallback = new PasswordCallback("Enter password", false);
        try
        {
            callbackHandler.handle(new Callback[] {nameCallback, pwdCallback});
            username = nameCallback.getName();
            password = new String(pwdCallback.getPassword());
            identity = new SimplePrincipal(username);
            loginOk = true;

            System.out.println("Username: " + username + ", password: " + password + ", Identity: " + identity);
            return true;
        }
        catch (UnsupportedCallbackException exc)
        {
            LoginException le = new LoginException("Internal error!");
            le.initCause(exc);
            throw le;
        }
        catch (IOException exc)
        {
            LoginException le = new LoginException("Internal error!");
            le.initCause(exc);
            throw le;
        }
    }
}


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4101068#4101068

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4101068



More information about the jboss-user mailing list