本文整理匯總了Java中org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter類的典型用法代碼示例。如果您正苦於以下問題:Java JwtAccessTokenConverter類的具體用法?Java JwtAccessTokenConverter怎麽用?Java JwtAccessTokenConverter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JwtAccessTokenConverter類屬於org.springframework.security.oauth2.provider.token.store包,在下文中一共展示了JwtAccessTokenConverter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: jwtAccessTokenConverter
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; //導入依賴的package包/類
/**
* This bean generates an token enhancer, which manages the exchange between JWT acces tokens and Authentication
* in both directions.
*
* @return an access token converter configured with the authorization server's public/private keys
*/
@Bean
public JwtAccessTokenConverter jwtAccessTokenConverter()
throws IOException, KeyStoreException, CertificateException,
NoSuchAlgorithmException, UnrecoverableKeyException {
DomainJwtAccessTokenConverter converter = new DomainJwtAccessTokenConverter();
InputStream stream = new ClassPathResource(Constants.KEYSTORE_FILE).getInputStream();
KeyStore store = KeyStore.getInstance(Constants.KEYSTOPE_TYPE);
store.load(stream, "password".toCharArray());
PrivateKey privateKey = (PrivateKey)store.getKey("selfsigned", "password".toCharArray());
PublicKey publicKey = getKeyFromConfigServer(keyUriRestTemplate);
KeyPair keyPair = new KeyPair(publicKey, privateKey);
converter.setKeyPair(keyPair);
return converter;
}
示例2: setup
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; //導入依賴的package包/類
@Before
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
JwtAccessTokenConverter converter = new DomainJwtAccessTokenConverter();
KeyPair keyPair = new KeyStoreKeyFactory(
new ClassPathResource(KEYSTORE_PATH), KEYSTORE_PSWRD.toCharArray())
.getKeyPair(KEYSTORE_ALIAS);
converter.setKeyPair(keyPair);
converter.afterPropertiesSet();
tokenStore = new JwtTokenStore(converter);
tokenServices = new DomainTokenServices();
tokenServices.setTokenStore(tokenStore);
tokenServices.setTokenEnhancer(converter);
tokenServices.setTenantPropertiesService(tenantPropertiesService);
when(tenantPropertiesService.getTenantProps()).thenReturn(tenantProperties);
when(tenantProperties.getSecurity()).thenReturn(security);
}
示例3: jwtTokenEnhancer
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; //導入依賴的package包/類
@Bean
public JwtAccessTokenConverter jwtTokenEnhancer() {
JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
String keyValue = this.resource.getJwt().getKeyValue();
if (!StringUtils.hasText(keyValue)) {
keyValue = getKeyFromServer();
}
if (StringUtils.hasText(keyValue) && !keyValue.startsWith("-----BEGIN")) {
converter.setSigningKey(keyValue);
}
if (keyValue != null) {
converter.setVerifierKey(keyValue);
}
if (!CollectionUtils.isEmpty(this.configurers)) {
AnnotationAwareOrderComparator.sort(this.configurers);
for (JwtAccessTokenConverterConfigurer configurer : this.configurers) {
configurer.configure(converter);
}
}
return converter;
}
開發者ID:spring-projects,項目名稱:spring-security-oauth2-boot,代碼行數:22,代碼來源:ResourceServerTokenServicesConfiguration.java
示例4: jwtTokenEnhancer
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; //導入依賴的package包/類
@Bean
protected JwtAccessTokenConverter jwtTokenEnhancer() {
JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
Resource resource = new ClassPathResource("public.cert");
String publicKey = null;
try {
publicKey = new String(FileCopyUtils.copyToByteArray(resource.getInputStream()));
} catch (IOException e) {
throw new RuntimeException(e);
}
converter.setVerifierKey(publicKey);
return converter;
}
示例5: accessTokenConverter
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; //導入依賴的package包/類
@Bean
public JwtAccessTokenConverter accessTokenConverter() {
JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
try {
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
keyGen.initialize(1024, random);
KeyPair keyPair = keyGen.generateKeyPair();
converter.setKeyPair(keyPair);
} catch (Exception e) {
throw new RuntimeException(e);
}
return converter;
}
示例6: accessTokenConverter
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; //導入依賴的package包/類
/**
* Jwt資源令牌轉換器
* @return accessTokenConverter
*/
@Bean
public JwtAccessTokenConverter accessTokenConverter(){
return new JwtAccessTokenConverter(){
/**
* 重寫增強token的方法
* @param accessToken 資源令牌
* @param authentication 認證
* @return 增強的OAuth2AccessToken對象
*/
@Override
public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
String userName = authentication.getUserAuthentication().getName();
User user = (User) authentication.getUserAuthentication().getPrincipal();
Map<String,Object> infoMap = new HashMap<>();
infoMap.put("userName",userName);
infoMap.put("roles",user.getAuthorities());
((DefaultOAuth2AccessToken)accessToken).setAdditionalInformation(infoMap);
return super.enhance(accessToken, authentication);
}
};
}
示例7: jwtTokenStore
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; //導入依賴的package包/類
/**
* @return The {@link JwtTokenStore} verifies access tokens and extract
* authentication and authorities from it.
*/
@Bean
public JwtTokenStore jwtTokenStore() {
final DefaultAccessTokenConverter accessTokenConverter = new DefaultAccessTokenConverter();
accessTokenConverter.setUserTokenConverter(userPrincipalInfoTokenServices());
final JwtAccessTokenConverter jwtTokenEnhancer = new JwtAccessTokenConverter();
jwtTokenEnhancer.setAccessTokenConverter(accessTokenConverter);
jwtTokenEnhancer.setSigningKey(uaaClientResources.getResource().getJwt().getKeyValue());
jwtTokenEnhancer.setVerifierKey(uaaClientResources.getResource().getJwt().getKeyValue());
try {
jwtTokenEnhancer.afterPropertiesSet();
} catch (final Exception e) {
throw Throwables.propagate(e);
}
return new JwtTokenStore(jwtTokenEnhancer);
}
示例8: accessTokenConverter
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; //導入依賴的package包/類
@Bean
public JwtAccessTokenConverter accessTokenConverter() {
final JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
converter.setSigningKey("123");
converter.setJwtClaimsSetVerifier(jwtClaimsSetVerifier());
return converter;
}
示例9: accessTokenConverter
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; //導入依賴的package包/類
@Bean
public JwtAccessTokenConverter accessTokenConverter() {
final JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
converter.setAccessTokenConverter(customAccessTokenConverter);
// converter.setSigningKey("123");
final Resource resource = new ClassPathResource("public.txt");
String publicKey = null;
try {
publicKey = IOUtils.toString(resource.getInputStream());
} catch (final IOException e) {
throw new RuntimeException(e);
}
converter.setVerifierKey(publicKey);
return converter;
}
示例10: accessTokenConverter
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; //導入依賴的package包/類
@Bean
public JwtAccessTokenConverter accessTokenConverter() {
final JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
converter.setSigningKey("123");
converter.setJwtClaimsSetVerifier(jwtClaimsSetVerifier());
// final Resource resource = new ClassPathResource("public.txt");
// String publicKey = null;
// try {
// publicKey = IOUtils.toString(resource.getInputStream());
// } catch (final IOException e) {
// throw new RuntimeException(e);
// }
// converter.setVerifierKey(publicKey);
return converter;
}
示例11: jwtTokenEnhancer
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; //導入依賴的package包/類
@Bean
public JwtAccessTokenConverter jwtTokenEnhancer() {
JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
String keyValue = this.resource.getJwt().getKeyValue();
if (!StringUtils.hasText(keyValue)) {
try {
keyValue = getKeyFromServer();
}
catch (ResourceAccessException ex) {
logger.warn("Failed to fetch token key (you may need to refresh "
+ "when the auth server is back)");
}
}
if (StringUtils.hasText(keyValue) && !keyValue.startsWith("-----BEGIN")) {
converter.setSigningKey(keyValue);
}
if (keyValue != null) {
converter.setVerifierKey(keyValue);
}
AnnotationAwareOrderComparator.sort(this.configurers);
for (JwtAccessTokenConverterConfigurer configurer : this.configurers) {
configurer.configure(converter);
}
return converter;
}
示例12: jwtAccessTokenConverterIsConfiguredWhenKeyUriIsProvided
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; //導入依賴的package包/類
@Test
public void jwtAccessTokenConverterIsConfiguredWhenKeyUriIsProvided() {
TestPropertyValues
.of("security.oauth2.resource.jwt.key-uri=http://localhost:12345/banana")
.applyTo(this.environment);
this.context = new SpringApplicationBuilder(ResourceConfiguration.class,
JwtAccessTokenConverterRestTemplateCustomizerConfiguration.class)
.environment(this.environment).web(WebApplicationType.NONE).run();
assertThat(this.context.getBeansOfType(JwtAccessTokenConverter.class)).hasSize(1);
}
開發者ID:spring-projects,項目名稱:spring-security-oauth2-boot,代碼行數:11,代碼來源:ResourceServerTokenServicesConfigurationTests.java
示例13: jwtAccessTokenConverter
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; //導入依賴的package包/類
@Bean
public JwtAccessTokenConverter jwtAccessTokenConverter(
@Qualifier("loadBalancedRestTemplate") RestTemplate keyUriRestTemplate) throws CertificateException {
JwtAccessTokenConverter converter = new DomainJwtAccessTokenConverter();
converter.setVerifierKey(getKeyFromAuthorizationServer(keyUriRestTemplate));
return converter;
}
示例14: jwtTokenEnhancer
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; //導入依賴的package包/類
@Bean
public JwtAccessTokenConverter jwtTokenEnhancer() {
JwtAccessTokenConverter jwtAccessTokenConverter = new JwtAccessTokenConverter();
KeyPair keyPair = new KeyStoreKeyFactory(
new ClassPathResource("keystore.jks"), "secret".toCharArray())
.getKeyPair("test");
jwtAccessTokenConverter.setKeyPair(keyPair);
DefaultAccessTokenConverter defaultAccessTokenConverter = new DefaultAccessTokenConverter();
defaultAccessTokenConverter.setUserTokenConverter(userAuthenticationConverter());
jwtAccessTokenConverter.setAccessTokenConverter(defaultAccessTokenConverter);
return jwtAccessTokenConverter;
}
示例15: jwtAccessTokenConverter
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; //導入依賴的package包/類
@Bean
public JwtAccessTokenConverter jwtAccessTokenConverter(
@Qualifier("loadBalancedRestTemplate") RestTemplate keyUriRestTemplate) throws CertificateException {
DomainJwtAccessTokenConverter converter = new DomainJwtAccessTokenConverter();
converter.setVerifierKey(getKeyFromConfigServer(keyUriRestTemplate));
return converter;
}