Skip to content

Commit 8c14dff

Browse files
committed
[breaking] sessions - Returning 404 on GET /sessions/current when no session is defined on current request
1 parent 46f8b58 commit 8c14dff

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

‎restx-security-basic/src/main/java/restx/security/SessionResource.java‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,15 @@ public Session authenticate(Map session) {
6161
}
6262

6363
@GET("/sessions/current")
64-
public Session currentSession() {
65-
String sessionKey = RestxSession.current().get(String.class, Session.SESSION_DEF_KEY).get();
66-
RestxPrincipal principal = RestxSession.current().getPrincipal().get();
64+
public Optional<Session> currentSession() {
65+
Optional<String> sessionKey = RestxSession.current().get(String.class, Session.SESSION_DEF_KEY);
66+
Optional<? extends RestxPrincipal> principal = RestxSession.current().getPrincipal();
6767

68-
return new Session(sessionKey, principal);
68+
if(!sessionKey.isPresent() || !principal.isPresent()) {
69+
return Optional.absent();
70+
}
71+
72+
return Optional.of(new Session(sessionKey.get(), principal.get()));
6973
}
7074

7175
@PermitAll

0 commit comments

Comments
 (0)