diff options
Diffstat (limited to 'src/com/p4square/grow/frontend/session/SessionCheckingAuthenticator.java')
-rw-r--r-- | src/com/p4square/grow/frontend/session/SessionCheckingAuthenticator.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/com/p4square/grow/frontend/session/SessionCheckingAuthenticator.java b/src/com/p4square/grow/frontend/session/SessionCheckingAuthenticator.java new file mode 100644 index 0000000..8382aff --- /dev/null +++ b/src/com/p4square/grow/frontend/session/SessionCheckingAuthenticator.java @@ -0,0 +1,38 @@ +/* + * Copyright 2013 Jesse Morgan + */ + +package com.p4square.grow.frontend.session; + +import org.apache.log4j.Logger; + +import org.restlet.Context; +import org.restlet.Request; +import org.restlet.Response; +import org.restlet.security.Authenticator; + +/** + * Authenticator which succeeds if a valid Session exists. + * + * @author Jesse Morgan <jesse@jesterpm.net> + */ +public class SessionCheckingAuthenticator extends Authenticator { + private static final Logger LOG = Logger.getLogger(SessionCheckingAuthenticator.class); + + public SessionCheckingAuthenticator(Context context, boolean optional) { + super(context, optional); + } + + protected boolean authenticate(Request request, Response response) { + Session s = Sessions.getInstance().get(request); + + if (s != null) { + request.getClientInfo().setUser(s.getUser()); + return true; + + } else { + return false; + } + } + +} |