Permalink
Browse files

sessions - Introduced new CurrentSessionResolver component providing …

…an extension point for retrieving current Session returned on GET /sessions/current
  • Loading branch information...
fcamblor committed Aug 21, 2017
1 parent 8c14dff commit 99acd3d3c581c61abdd966d4ddafc8b39da115aa
@@ -0,0 +1,18 @@
package restx.security;
import com.google.common.base.Optional;
import restx.factory.Component;
@Component
public class CurrentSessionResolver {
public Optional<Session> resolveCurrentSession(){
Optional<String> sessionKey = RestxSession.current().get(String.class, Session.SESSION_DEF_KEY);
Optional<? extends RestxPrincipal> principal = RestxSession.current().getPrincipal();
if(!sessionKey.isPresent() || !principal.isPresent()) {
return Optional.absent();
}
return Optional.of(new Session(sessionKey.get(), principal.get()));
}
}
@@ -20,11 +20,15 @@
private final BasicPrincipalAuthenticator authenticator;
private final UUIDGenerator uuidGenerator;
private SessionInvalider sessionInvalider;
private CurrentSessionResolver currentSessionResolver;
public SessionResource(BasicPrincipalAuthenticator authenticator, UUIDGenerator uuidGenerator, SessionInvalider sessionInvalider) {
public SessionResource(
BasicPrincipalAuthenticator authenticator, UUIDGenerator uuidGenerator,
SessionInvalider sessionInvalider, CurrentSessionResolver currentSessionResolver) {
this.authenticator = authenticator;
this.uuidGenerator = uuidGenerator;
this.sessionInvalider = sessionInvalider;
this.currentSessionResolver = currentSessionResolver;
}
@@ -62,14 +66,7 @@ public Session authenticate(Map session) {
@GET("/sessions/current")
public Optional<Session> currentSession() {
Optional<String> sessionKey = RestxSession.current().get(String.class, Session.SESSION_DEF_KEY);
Optional<? extends RestxPrincipal> principal = RestxSession.current().getPrincipal();
if(!sessionKey.isPresent() || !principal.isPresent()) {
return Optional.absent();
}
return Optional.of(new Session(sessionKey.get(), principal.get()));
return currentSessionResolver.resolveCurrentSession();
}
@PermitAll

0 comments on commit 99acd3d

Please sign in to comment.