summaryrefslogtreecommitdiff
path: root/src/com/p4square/session/SessionCheckingAuthenticator.java
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2014-03-31 22:35:43 -0700
committerJesse Morgan <jesse@jesterpm.net>2014-03-31 22:35:43 -0700
commit38c12cf70ef4714a7fc508f7fbaf44487ea971b7 (patch)
tree59d29b82f65952653f789615db1003b431be607a /src/com/p4square/session/SessionCheckingAuthenticator.java
parentcfb2c5ef6582e51ae9cfdfff35e12b5b7fdc24fb (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/SessionCheckingAuthenticator.java')
-rw-r--r--src/com/p4square/session/SessionCheckingAuthenticator.java39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/com/p4square/session/SessionCheckingAuthenticator.java b/src/com/p4square/session/SessionCheckingAuthenticator.java
new file mode 100644
index 0000000..489d6a0
--- /dev/null
+++ b/src/com/p4square/session/SessionCheckingAuthenticator.java
@@ -0,0 +1,39 @@
+/*
+ * 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;
+
+/**
+ * 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) {
+ LOG.debug("Found session for user " + s.getUser());
+ request.getClientInfo().setUser(s.getUser());
+ return true;
+
+ } else {
+ return false;
+ }
+ }
+
+}