blob: 3ec14b4c05c78151535c2489ede4d859ca921770 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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;
}
}
|