wicket-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From TahitianGabriel <glan...@piti.pf>
Subject Re: Servlet container authentication in Wicket
Date Tue, 01 Dec 2009 22:01:56 GMT

Here's what I use with wicket 1.3/1.4 and Tomcat using LDAP realm.
I use AuthenticatedWebApplication and AuthenticatedWebSession.

public class MySession extends AuthenticatedWebSession {
    /** Name. */
    private final String userName;
    /** Roles. */
    private final Roles roles;

    public MySession(final Request varRequest) {
        super(varRequest);

        roles = new Roles();

        //authentification from container (tomcat)
        HttpServletRequest servletRequest = ((WebRequestCycle)
RequestCycle.get()).getWebRequest()
                .getHttpServletRequest();
        Principal principal = servletRequest.getUserPrincipal();

        if (principal == null) { //user not authentificated by tomcat!
            //handle error as you want!
            userName = null;
            return;
        } else {
            // username
            userName = principal.getName();

            // get the roles you need
            if (servletRequest.isUserInRole("yourRole1")) {
                roles.add("yourRole1");
            }
            if (servletRequest.isUserInRole("yourRole2")) {
                roles.add("yourRole2");
            }
            ...
            
            //simulate signin
            signIn("ok", "ok");
        }
    }

    public final boolean authenticate(final String varUsername, final String
varPassword) {
        return userName != null;
    }

    public final Roles getRoles() {
        if (isSignedIn()) {
            return roles;
        }
        return null;
    }

    public final String getUserName() {
        return userName;
    }

}


The "MySignIngPage.html" contains <script
type="text/javascript">window.location="/"</script>



Gabriel.



Philipp Daumke-2 wrote:
> 
> Hi,
> 
> I had a look at that specification but it doesn't give any more hints 
> how to use it. Does somebody have any more working examples? Or is there 
> a tutorial how to connect wicket to the local LDAP?
> 
> 

-- 
View this message in context: http://old.nabble.com/Servlet-container-authentication-in-Wicket-tp21780995p26599795.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Mime
View raw message