Skip to content
Snippets Groups Projects
Commit 2bb6e3a9 authored by OZGCloud's avatar OZGCloud
Browse files

fix user Service - no NPE if SecureContext is missing

parent 125287b9
No related branches found
No related tags found
No related merge requests found
...@@ -36,12 +36,13 @@ public class CurrentUserService { ...@@ -36,12 +36,13 @@ public class CurrentUserService {
} }
} }
public Optional<Authentication> getAuthentication() { public Optional<Authentication> findAuthentication() {
return findTrustedAuthentication(); return findTrustedAuthentication();
} }
Optional<Authentication> findTrustedAuthentication() { Optional<Authentication> findTrustedAuthentication() {
return Optional.ofNullable(SecurityContextHolder.getContext().getAuthentication()) return Optional.ofNullable(SecurityContextHolder.getContext())
.map(context -> context.getAuthentication())
.filter(auth -> !trustResolver.isAnonymous(auth)) .filter(auth -> !trustResolver.isAnonymous(auth))
.filter(Authentication::isAuthenticated); .filter(Authentication::isAuthenticated);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment