Skip to content

Commit

Permalink
[WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
bseber authored and derTobsch committed May 16, 2024
1 parent 10f184b commit da9295f
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.lang.NonNull;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import java.security.Principal;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
Expand All @@ -33,9 +35,10 @@ public void postHandle(@NonNull HttpServletRequest request, @NonNull HttpServlet

if (modelAndView != null && navigationHeaderVisible(modelAndView)) {

final Principal userPrincipal = request.getUserPrincipal();
final SecurityContext securityContext = SecurityContextHolder.getContext();
final Authentication authentication = securityContext.getAuthentication();

if (userPrincipal instanceof OAuth2AuthenticationToken token) {
if (authentication instanceof OAuth2AuthenticationToken token) {
final List<SecurityRole> roles = token.getAuthorities()
.stream()
.map(SecurityRole::fromAuthority)
Expand Down

0 comments on commit da9295f

Please sign in to comment.