Java Code Examples for org.springframework.security.oauth2.common.DefaultOAuth2AccessToken#setScope()
The following examples show how to use
org.springframework.security.oauth2.common.DefaultOAuth2AccessToken#setScope() .
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: CustomAccessTokenConverter.java From microservices-oauth with Apache License 2.0 | 6 votes |
public OAuth2AccessToken extractAccessToken(String value, Map<String, ?> map) { DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken(value); Map<String, Object> info = new HashMap<String, Object>(map); info.remove(EXP); info.remove(AUD); info.remove(CLIENT_ID); info.remove(SCOPE); if (map.containsKey(EXP)) token.setExpiration(new Date((Long) map.get(EXP) * 1000L)); if (map.containsKey(JTI)) info.put(JTI, map.get(JTI)); token.setScope(extractScope(map)); token.setAdditionalInformation(info); return token; }
Example 2
Source File: CustomAccessTokenConverter.java From spring-boot-2-oauth2-resource-jwt with MIT License | 6 votes |
public OAuth2AccessToken extractAccessToken(String value, Map<String, ?> map) { DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken(value); Map<String, Object> info = new HashMap<String, Object>(map); info.remove(EXP); info.remove(AUD); info.remove(CLIENT_ID); info.remove(SCOPE); if (map.containsKey(EXP)) token.setExpiration(new Date((Long) map.get(EXP) * 1000L)); if (map.containsKey(JTI)) info.put(JTI, map.get(JTI)); token.setScope(extractScope(map)); token.setAdditionalInformation(info); return token; }
Example 3
Source File: YamiTokenServices.java From mall4j with GNU Affero General Public License v3.0 | 5 votes |
private OAuth2AccessToken createAccessToken(OAuth2Authentication authentication, OAuth2RefreshToken refreshToken) { DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken(UUID.randomUUID().toString()); int validitySeconds = getAccessTokenValiditySeconds(authentication.getOAuth2Request()); if (validitySeconds > 0) { token.setExpiration(new Date(System.currentTimeMillis() + (validitySeconds * 1000L))); } token.setRefreshToken(refreshToken); token.setScope(authentication.getOAuth2Request().getScope()); return accessTokenEnhancer != null ? accessTokenEnhancer.enhance(token, authentication) : token; }
Example 4
Source File: CustomTokenServicesTest.java From multiapps-controller with Apache License 2.0 | 5 votes |
private OAuth2AccessToken buildToken(String tokenString, Date expiration, Map<String, Object> additionalTokenProperties) { DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken(tokenString); token.setExpiration(expiration); token.setScope(Collections.singleton(DEFAULT_SCOPE)); token.setAdditionalInformation(additionalTokenProperties); return token; }
Example 5
Source File: AuthorizationCheckerTest.java From multiapps-controller with Apache License 2.0 | 5 votes |
private void setUpMocks(boolean hasPermissions, boolean hasAccess, Exception e) { DefaultOAuth2AccessToken accessToken = new DefaultOAuth2AccessToken("testTokenValue"); accessToken.setScope(new HashSet<>()); CloudOrganization organization = ImmutableCloudOrganization.builder() .name(ORG) .build(); CloudSpace space = ImmutableCloudSpace.builder() .name(SPACE) .organization(organization) .build(); ClientHelper clientHelper = Mockito.mock(ClientHelper.class); if (hasAccess) { when(client.getSpace(ORG, SPACE, false)).thenReturn(space); when(clientHelper.computeTarget(SPACE_ID)).thenReturn(new CloudTarget(ORG, SPACE)); } else { when(clientHelper.computeTarget(SPACE_ID)).thenReturn(null); } when(authorizationChecker.getClientHelper(client)).thenReturn(clientHelper); userInfo = new UserInfo(USER_ID.toString(), USERNAME, accessToken); List<UUID> spaceDevelopersList = new ArrayList<>(); if (hasPermissions) { spaceDevelopersList.add(USER_ID); } if (e == null) { when(client.getSpaceDevelopers(ORG, SPACE)).thenReturn(spaceDevelopersList); when(client.getSpaceDevelopers(UUID.fromString(SPACE_ID))).thenReturn(spaceDevelopersList); } else { when(client.getSpaceDevelopers(ORG, SPACE)).thenThrow(e); when(client.getSpaceDevelopers(UUID.fromString(SPACE_ID))).thenThrow(e); } when(clientProvider.getControllerClient(userInfo.getName())).thenReturn(client); when(applicationConfiguration.getFssCacheUpdateTimeoutMinutes()).thenReturn(ApplicationConfiguration.DEFAULT_SPACE_DEVELOPER_CACHE_TIME_IN_SECONDS); }
Example 6
Source File: TokenFactory.java From multiapps-controller with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public OAuth2AccessToken createToken(String tokenString, Map<String, Object> tokenInfo) { List<String> scope = (List<String>) tokenInfo.get(SCOPE); Number exp = (Number) tokenInfo.get(EXP); if (scope == null || exp == null) { return null; } DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken(tokenString); token.setExpiration(new Date(exp.longValue() * 1000)); token.setScope(new HashSet<>(scope)); token.setAdditionalInformation(tokenInfo); return token; }
Example 7
Source File: OAuth2AccessTokenBuilder.java From spring-security-mongo with MIT License | 5 votes |
public OAuth2AccessToken build() { final DefaultOAuth2AccessToken oAuth2AccessToken = new DefaultOAuth2AccessToken(token); oAuth2AccessToken.setExpiration(convertToDateFrom(expiration)); oAuth2AccessToken.setRefreshToken(oAuth2RefreshToken); oAuth2AccessToken.setScope(scope); oAuth2AccessToken.setAdditionalInformation(additionalInformation); return oAuth2AccessToken; }