use of org.springframework.security.oauth2.provider.token.AccessTokenConverter in project mots by motech-implementations.
the class TokenConfiguration method tokenServices.
/**
* Set-up CustomTokenServices with tokenStore().
* @return token services
*/
@Bean
@Primary
public CustomTokenServices tokenServices() {
TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
tokenEnhancerChain.setTokenEnhancers(Arrays.asList(tokenEnhancer(), accessTokenConverter()));
CustomTokenServices customTokenServices = new CustomTokenServices();
customTokenServices.setTokenStore(tokenStore());
customTokenServices.setTokenEnhancer(tokenEnhancerChain);
customTokenServices.setClientDetailsService(clientDetailsService);
customTokenServices.setSupportRefreshToken(true);
customTokenServices.setAccessTokenValiditySeconds(tokenValiditySeconds);
customTokenServices.setRefreshTokenValiditySeconds(tokenValiditySeconds * 2);
customTokenServices.setReuseRefreshToken(false);
return customTokenServices;
}
use of org.springframework.security.oauth2.provider.token.AccessTokenConverter in project spring-security-oauth2-google by skate056.
the class GoogleTokenServicesTest method shouldLoadAuthenticationAndTransformValuesToStandardValues.
@Test
public void shouldLoadAuthenticationAndTransformValuesToStandardValues() throws Exception {
Map<String, String> body = new HashMap<>();
body.put("issued_to", "blh");
body.put("user_id", "user@domain.google.com");
body.put("email", "user@domain.google.com");
given(response.getBody()).willReturn(body);
given(restTemplate.exchange(anyString(), any(HttpMethod.class), any(HttpEntity.class), any(ParameterizedTypeReference.class))).willReturn(response);
given(accessTokenConverter.extractAuthentication(body)).willReturn(mockAuthentication);
googleTokenServices.setRestTemplate(restTemplate);
googleTokenServices.setCheckTokenEndpointUrl("//");
googleTokenServices.setAccessTokenConverter(accessTokenConverter);
OAuth2Authentication authentication = googleTokenServices.loadAuthentication(null);
assertThat(authentication, is(mockAuthentication));
verify(accessTokenConverter).extractAuthentication(mapCapture.capture());
Map<String, String> value = mapCapture.getValue();
assertThat(value.get("user_name"), notNullValue());
assertThat(value.get("user_name"), is("user@domain.google.com"));
assertThat(value.get("user_id"), notNullValue());
assertThat(value.get("user_id"), is("user@domain.google.com"));
assertThat(value.get("client_id"), notNullValue());
assertThat(value.get("client_id"), is("blh"));
assertThat(value.get("issued_to"), notNullValue());
assertThat(value.get("issued_to"), is("blh"));
}
use of org.springframework.security.oauth2.provider.token.AccessTokenConverter in project new-cloud by xie-summer.
the class ResourceServerConfiguration method accessTokenConverter.
@Bean
public JwtAccessTokenConverter accessTokenConverter() {
JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
Resource resource = new ClassPathResource("public.txt");
String publicKey = null;
try {
publicKey = inputStream2String(resource.getInputStream());
} catch (final IOException e) {
throw new RuntimeException(e);
}
converter.setVerifierKey(publicKey);
converter.setAccessTokenConverter(new CustomerAccessTokenConverter());
return converter;
}
use of org.springframework.security.oauth2.provider.token.AccessTokenConverter in project openlmis-stockmanagement by OpenLMIS.
the class ResourceServerSecurityConfiguration method accessTokenConverter.
/**
* AccessTokenConverter bean initializer.
*/
@Bean
public AccessTokenConverter accessTokenConverter() {
DefaultAccessTokenConverter defaultAccessTokenConverter = new DefaultAccessTokenConverter();
defaultAccessTokenConverter.setUserTokenConverter(new CustomUserAuthenticationConverter());
return defaultAccessTokenConverter;
}
use of org.springframework.security.oauth2.provider.token.AccessTokenConverter in project theskeleton by codenergic.
the class SecurityConfig method accessTokenConverter.
/**
* Token converter and enhancer
* @return
*/
@Bean
public JwtAccessTokenConverter accessTokenConverter(@Value("${security.jwt.signing-key:}") String signingKey, ResourceLoader resourceLoader) throws IOException {
DefaultAccessTokenConverter accessTokenConverter = new DefaultAccessTokenConverter();
accessTokenConverter.setUserTokenConverter(new UserAccessTokenAuthenticationConverter());
JwtAccessTokenConverter jwtAccessTokenConverter = new JwtAccessTokenConverter();
jwtAccessTokenConverter.setAccessTokenConverter(accessTokenConverter);
if (StringUtils.isBlank(signingKey))
return jwtAccessTokenConverter;
if (ResourceUtils.isUrl(signingKey)) {
Resource signingKeyResource = resourceLoader.getResource(signingKey);
signingKey = IOUtils.toString(signingKeyResource.getURI(), StandardCharsets.UTF_8);
}
jwtAccessTokenConverter.setSigningKey(signingKey);
jwtAccessTokenConverter.setVerifierKey(signingKey);
return jwtAccessTokenConverter;
}
Aggregations