本文整理汇总了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;
}