You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by TahitianGabriel <gl...@piti.pf> on 2009/12/01 23:01:56 UTC

Re: Servlet container authentication in Wicket

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