Java Code Examples for org.springframework.security.oauth2.common.OAuth2AccessToken#getAdditionalInformation()
The following examples show how to use
org.springframework.security.oauth2.common.OAuth2AccessToken#getAdditionalInformation() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserInfoHeaderFilter.java From Taroco with Apache License 2.0 | 6 votes |
@Override public Object run() { RequestContext ctx = RequestContext.getCurrentContext(); HttpServletRequest request = ctx.getRequest(); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication != null) { RequestContext requestContext = RequestContext.getCurrentContext(); requestContext.addZuulRequestHeader(SecurityConstants.USER_HEADER, authentication.getName()); requestContext.addZuulRequestHeader(SecurityConstants.USER_ROLE_HEADER, CollUtil.join(authentication.getAuthorities(), ",")); String tokenValue = extractToken(request); if (!StringUtils.isEmpty(tokenValue)) { OAuth2AccessToken accessToken = tokenStore.readAccessToken(tokenValue); if (accessToken != null && !CollectionUtils.isEmpty(accessToken.getAdditionalInformation())) { Map<String, Object> information = accessToken.getAdditionalInformation(); requestContext.addZuulRequestHeader(SecurityConstants.HEADER_LABEL, information.get(SecurityConstants.HEADER_LABEL) + ""); requestContext.addZuulRequestHeader(SecurityConstants.USER_PERMISSION_HEADER, information.get(SecurityConstants.USER_PERMISSION_HEADER) + ""); } } } return null; }
Example 2
Source File: OAuth2ClientTokenSevices.java From OAuth-2.0-Cookbook with MIT License | 5 votes |
@Override public void saveAccessToken(OAuth2ProtectedResourceDetails resource, Authentication authentication, OAuth2AccessToken accessToken) { ClientUser clientUser = getClientUser(authentication); clientUser.accessToken = accessToken.getValue(); clientUser.expirationTime = accessToken.getExpiration().getTime(); clientUser.additionalInformation = accessToken.getAdditionalInformation(); users.put(clientUser.username, clientUser); }
Example 3
Source File: JweTokenEnhancer.java From OAuth-2.0-Cookbook with MIT License | 5 votes |
@Override public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) { DefaultOAuth2AccessToken result = new DefaultOAuth2AccessToken(accessToken); Map<String, Object> info = new LinkedHashMap<>(accessToken.getAdditionalInformation()); String tokenId = result.getValue(); if (!info.containsKey(TOKEN_ID)) { info.put(TOKEN_ID, tokenId); } result.setAdditionalInformation(info); result.setValue(encode(result, authentication)); return result; }
Example 4
Source File: JweTokenEnhancer.java From OAuth-2.0-Cookbook with MIT License | 5 votes |
@Override public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) { DefaultOAuth2AccessToken result = new DefaultOAuth2AccessToken(accessToken); Map<String, Object> info = new LinkedHashMap<>(accessToken.getAdditionalInformation()); String tokenId = result.getValue(); if (!info.containsKey(TOKEN_ID)) { info.put(TOKEN_ID, tokenId); } result.setAdditionalInformation(info); result.setValue(encode(result, authentication)); return result; }
Example 5
Source File: UserController.java From spring-security-oauth with MIT License | 5 votes |
@PreAuthorize("#oauth2.hasScope('read')") @RequestMapping(method = RequestMethod.GET, value = "/users/extra") @ResponseBody public Map<String, Object> getExtraInfo(OAuth2Authentication auth) { final OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) auth.getDetails(); final OAuth2AccessToken accessToken = tokenStore.readAccessToken(details.getTokenValue()); System.out.println(accessToken); return accessToken.getAdditionalInformation(); }
Example 6
Source File: TokenProperties.java From multiapps-controller with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") private static <T> T getTokenProperty(OAuth2AccessToken token, String key) { Map<String, Object> additionalInformation = token.getAdditionalInformation(); return (T) additionalInformation.get(key); }
Example 7
Source File: TokenFactoryTest.java From multiapps-controller with Apache License 2.0 | 4 votes |
private static void validateTokenAdditionalInfo(OAuth2AccessToken token, Map<String, Object> tokenInfo) { Map<String, Object> tokenAdditionalInformation = token.getAdditionalInformation(); assertEquals(tokenInfo, tokenAdditionalInformation); }
Example 8
Source File: OAuth2Configuration.java From spring-boot-oauth2-jwt with MIT License | 4 votes |
@Override public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) { User user = (User) authentication.getPrincipal(); Map<String, Object> info = new LinkedHashMap<String, Object>(accessToken.getAdditionalInformation()); info.put("email", user.getEmail()); DefaultOAuth2AccessToken customAccessToken = new DefaultOAuth2AccessToken(accessToken); // Get the authorities from the user Set<GrantedAuthority> authoritiesSet = new HashSet<>(authentication.getAuthorities()); // Generate String array String[] authorities = new String[authoritiesSet.size()]; int i = 0; for (GrantedAuthority authority : authoritiesSet) authorities[i++] = authority.getAuthority(); info.put("authorities", authorities); customAccessToken.setAdditionalInformation(info); return super.enhance(customAccessToken, authentication); }
Example 9
Source File: OAuth2Configuration.java From spring-boot-2-oauth2-authorization-jwt with MIT License | 3 votes |
@Override public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) { User user = (User) authentication.getPrincipal(); Map<String, Object> info = new LinkedHashMap<String, Object>(accessToken.getAdditionalInformation()); info.put("email", user.getEmail()); DefaultOAuth2AccessToken customAccessToken = new DefaultOAuth2AccessToken(accessToken); customAccessToken.setAdditionalInformation(info); return super.enhance(customAccessToken, authentication); }
Example 10
Source File: OAuth2Configuration.java From microservices-oauth with Apache License 2.0 | 3 votes |
@Override public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) { User user = (User) authentication.getPrincipal(); Map<String, Object> info = new LinkedHashMap<String, Object>(accessToken.getAdditionalInformation()); info.put("email", user.getEmail()); DefaultOAuth2AccessToken customAccessToken = new DefaultOAuth2AccessToken(accessToken); customAccessToken.setAdditionalInformation(info); return super.enhance(customAccessToken, authentication); }