diff options
author | Jesse Morgan <jesse@jesterpm.net> | 2014-03-31 22:35:43 -0700 |
---|---|---|
committer | Jesse Morgan <jesse@jesterpm.net> | 2014-03-31 22:35:43 -0700 |
commit | 38c12cf70ef4714a7fc508f7fbaf44487ea971b7 (patch) | |
tree | 59d29b82f65952653f789615db1003b431be607a /src/com/p4square/session/SessionCreatingAuthenticator.java | |
parent | cfb2c5ef6582e51ae9cfdfff35e12b5b7fdc24fb (diff) |
Locking down restlet library version.
While trying to fix this issue, I also moved FMFacade into this package
and fixed a couple bugs that snuck into the last commit.
Diffstat (limited to 'src/com/p4square/session/SessionCreatingAuthenticator.java')
-rw-r--r-- | src/com/p4square/session/SessionCreatingAuthenticator.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/com/p4square/session/SessionCreatingAuthenticator.java b/src/com/p4square/session/SessionCreatingAuthenticator.java new file mode 100644 index 0000000..3ec14b4 --- /dev/null +++ b/src/com/p4square/session/SessionCreatingAuthenticator.java @@ -0,0 +1,46 @@ +/* + * Copyright 2013 Jesse Morgan + */ + +package com.p4square.session; + +import org.apache.log4j.Logger; + +import org.restlet.Context; +import org.restlet.Request; +import org.restlet.Response; +import org.restlet.security.Authenticator; +import org.restlet.security.User; + +/** + * Authenticator which creates a Session for the request and adds a cookie + * to the response. + * + * The Request MUST be Authenticated and MUST have a User object associated. + * + * @author Jesse Morgan <jesse@jesterpm.net> + */ +public class SessionCreatingAuthenticator extends Authenticator { + private static final Logger LOG = Logger.getLogger(SessionCreatingAuthenticator.class); + + public SessionCreatingAuthenticator(Context context) { + super(context, true); + } + + protected boolean authenticate(Request request, Response response) { + if (Sessions.getInstance().get(request) != null) { + return true; + } + + User user = request.getClientInfo().getUser(); + + if (request.getClientInfo().isAuthenticated() && user != null) { + Sessions.getInstance().create(request, response); + LOG.debug(response); + return true; + } + + return false; + } + +} |