@Override public OAuth2Authentication readAuthentication(OAuth2AccessToken token) { return readAuthentication(token.getValue()); }
@Override public OAuth2Authentication readAuthenticationForRefreshToken(OAuth2RefreshToken token) { return readAuthentication(token.getValue()); }
private void remove(String token) { if (approvalStore != null) { OAuth2Authentication auth = readAuthentication(token); String clientId = auth.getOAuth2Request().getClientId(); Authentication user = auth.getUserAuthentication(); if (user != null) { Collection<Approval> approvals = new ArrayList<Approval>(); for (String scope : auth.getOAuth2Request().getScope()) { approvals.add(new Approval(user.getName(), clientId, scope, new Date(), ApprovalStatus.APPROVED)); } approvalStore.revokeApprovals(approvals); } } } }
@Override public OAuth2RefreshToken readRefreshToken(String tokenValue) { OAuth2AccessToken encodedRefreshToken = convertAccessToken(tokenValue); OAuth2RefreshToken refreshToken = createRefreshToken(encodedRefreshToken); if (approvalStore != null) { OAuth2Authentication authentication = readAuthentication(tokenValue); if (authentication.getUserAuthentication() != null) { String userId = authentication.getUserAuthentication().getName(); String clientId = authentication.getOAuth2Request().getClientId(); Collection<Approval> approvals = approvalStore.getApprovals(userId, clientId); Collection<String> approvedScopes = new HashSet<String>(); for (Approval approval : approvals) { if (approval.isApproved()) { approvedScopes.add(approval.getScope()); } } if (!approvedScopes.containsAll(authentication.getOAuth2Request().getScope())) { return null; } } } return refreshToken; }
@Override public OAuth2Authentication readAuthentication(OAuth2AccessToken token) { return readAuthentication(token.getValue()); }
@Override public OAuth2Authentication readAuthenticationForRefreshToken(OAuth2RefreshToken token) { return readAuthentication(token.getValue()); }
private void doSomething(RequestContext requestContext) { HttpServletRequest request = requestContext.getRequest(); String requestURI = request.getRequestURI(); if (OPTIONS.equalsIgnoreCase(request.getMethod()) || requestURI.contains(AUTH_PATH)) { return; } List<Route> routeMaps = routeLocator.getRoutes(); if (!routeMaps.stream().anyMatch(x -> PatternMatchUtils.simpleMatch(x.getPath(), requestURI) )) { return; } String token = StringUtils.substringAfter(request.getHeader(HttpHeaders.AUTHORIZATION), BEARER_TOKEN_TYPE); if (!StringUtils.isEmpty(token)) { String authHeader = BEARER_TOKEN_TYPE + token; // 传递给后续微服务 requestContext.addZuulRequestHeader(CoreHeaderInterceptor.HEADER_LABEL, authHeader); log.info("authHeader={} ", authHeader); OAuth2Authentication authentication = jwtTokenStore.readAuthentication(token); SecurityContextHolder.getContext().setAuthentication(authentication); } Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); log.info("authentication=" + authentication); }
private void remove(String token) { if (approvalStore != null) { OAuth2Authentication auth = readAuthentication(token); String clientId = auth.getOAuth2Request().getClientId(); Authentication user = auth.getUserAuthentication(); if (user != null) { Collection<Approval> approvals = new ArrayList<Approval>(); for (String scope : auth.getOAuth2Request().getScope()) { approvals.add(new Approval(user.getName(), clientId, scope, new Date(), ApprovalStatus.APPROVED)); } approvalStore.revokeApprovals(approvals); } } } }
@Override public OAuth2RefreshToken readRefreshToken(String tokenValue) { OAuth2AccessToken encodedRefreshToken = convertAccessToken(tokenValue); OAuth2RefreshToken refreshToken = createRefreshToken(encodedRefreshToken); if (approvalStore != null) { OAuth2Authentication authentication = readAuthentication(tokenValue); if (authentication.getUserAuthentication() != null) { String userId = authentication.getUserAuthentication().getName(); String clientId = authentication.getOAuth2Request().getClientId(); Collection<Approval> approvals = approvalStore.getApprovals(userId, clientId); Collection<String> approvedScopes = new HashSet<String>(); for (Approval approval : approvals) { if (approval.isApproved()) { approvedScopes.add(approval.getScope()); } } if (!approvedScopes.containsAll(authentication.getOAuth2Request().getScope())) { return null; } } } return refreshToken; }
Principal principal = jwtTokenStore.readAuthentication(token).getUserAuthentication(); if(principal == null && !StompCommand.DISCONNECT.equals(accessor.getCommand())) { return message;