Java Code Examples for org.springframework.security.oauth2.provider.token.store.JwtTokenStore

The following examples show how to use org.springframework.security.oauth2.provider.token.store.JwtTokenStore. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
@Bean
public TokenStore tokenStore() {
    if (properties.getEnableJwt()) {
        return new JwtTokenStore(jwtAccessTokenConverter());
    } else {
        RedisTokenStore redisTokenStore = new RedisTokenStore(redisConnectionFactory);
        // 解决每次生成的 token都一样的问题
        redisTokenStore.setAuthenticationKeyGenerator(oAuth2Authentication -> UUID.randomUUID().toString());
        return redisTokenStore;
    }
}
 
Example 2
Source Project: cloud-service   Source File: AuthorizationServerConfig.java    License: MIT License 5 votes vote down vote up
/**
 * 令牌存储
 */
@Bean
public TokenStore tokenStore() {
    if (storeWithJwt) {
        return new JwtTokenStore(accessTokenConverter());
    }
    RedisTokenStore redisTokenStore = new RedisTokenStore(redisConnectionFactory);
    // 解决同一username每次登陆access_token都相同的问题
    redisTokenStore.setAuthenticationKeyGenerator(new RandomAuthenticationKeyGenerator());

    return redisTokenStore;
}
 
Example 3
Source Project: open-cloud   Source File: OpenHelper.java    License: MIT License 5 votes vote down vote up
/**
 * 构建资源服务器JwtToken服务类
 *
 * @param properties
 * @return
 */
public static ResourceServerTokenServices buildJwtTokenServices(OpenCommonProperties properties) throws Exception {
    // 使用自定义系统用户凭证转换器
    DefaultAccessTokenConverter accessTokenConverter = buildAccessTokenConverter();
    OpenJwtTokenService tokenServices = new OpenJwtTokenService();
    // 这里的签名key 保持和认证中心一致
    JwtAccessTokenConverter converter = buildJwtTokenEnhancer(properties);
    JwtTokenStore jwtTokenStore = new JwtTokenStore(converter);
    tokenServices.setTokenStore(jwtTokenStore);
    tokenServices.setJwtAccessTokenConverter(converter);
    tokenServices.setDefaultAccessTokenConverter(accessTokenConverter);
    log.info("buildJwtTokenServices[{}]", tokenServices);
    return tokenServices;
}
 
Example 4
Source Project: Spring-5.0-By-Example   Source File: OAuthTokenConfiguration.java    License: MIT License 5 votes vote down vote up
@Bean
public JwtTokenStore tokenStore() throws Exception {
  JwtAccessTokenConverter enhancer = new JwtAccessTokenConverter();
  enhancer.setSigningKey(privateKey);
  enhancer.setVerifierKey(publicKey);
  enhancer.afterPropertiesSet();
  return new JwtTokenStore(enhancer);
}
 
Example 5
@Bean
public TokenStore tokenStore() {
	if (this.jwtEnabled) {
		return new JwtTokenStore(accessTokenConverter());
	} else {
		return new InMemoryTokenStore();
	}
}
 
Example 6
@Bean
public TokenStore tokenStore() {
	if (this.jwtEnabled) {
		return new JwtTokenStore(accessTokenConverter());
	} else {
		return new InMemoryTokenStore();
	}
}
 
Example 7
@Bean
public TokenStore tokenStore() {
	if (this.jwtEnabled) {
		return new JwtTokenStore(accessTokenConverter());
	} else {
		return new InMemoryTokenStore();
	}
}
 
Example 8
@Test
public void configureWhenKeyStoreIsProvidedThenExposesJwtTokenStore() {
	this.contextRunner.withPropertyValues(
			"security.oauth2.authorization.jwt.key-store=classpath:"
					+ "org/springframework/boot/autoconfigure/security/oauth2/authserver/keystore.jks",
			"security.oauth2.authorization.jwt.key-store-password=changeme",
			"security.oauth2.authorization.jwt.key-alias=jwt").run(context -> {
				assertThat(context.getBeansOfType(TokenStore.class)).hasSize(1);
				assertThat(context.getBean(TokenStore.class)).isInstanceOf(JwtTokenStore.class);
			});
}
 
Example 9
@Bean
public TokenStore tokenStore() {
	if (this.jwtEnabled) {
		return new JwtTokenStore(accessTokenConverter());
	} else {
		return new InMemoryTokenStore();
	}
}
 
Example 10
@Bean
public TokenStore tokenStore() {
	if (this.jwtEnabled) {
		return new JwtTokenStore(accessTokenConverter());
	} else {
		return new InMemoryTokenStore();
	}
}
 
Example 11
@Bean
public TokenStore tokenStore() {
	if (this.jwtEnabled) {
		return new JwtTokenStore(accessTokenConverter());
	} else {
		return new InMemoryTokenStore();
	}
}
 
Example 12
@Bean
public TokenStore tokenStore() {
	if (this.jwtEnabled) {
		return new JwtTokenStore(accessTokenConverter());
	} else {
		return new InMemoryTokenStore();
	}
}
 
Example 13
@Bean
public JwtTokenStore tokenStore() throws Exception {
  JwtAccessTokenConverter enhancer = new JwtAccessTokenConverter();
  enhancer.setSigningKey(privateKey);
  enhancer.setVerifierKey(publicKey);
  enhancer.afterPropertiesSet();
  return new JwtTokenStore(enhancer);
}
 
Example 14
@Bean
public JwtTokenStore tokenStore() throws Exception {
  JwtAccessTokenConverter enhancer = new JwtAccessTokenConverter();
  enhancer.setSigningKey(privateKey);
  enhancer.setVerifierKey(publicKey);
  enhancer.afterPropertiesSet();
  return new JwtTokenStore(enhancer);
}
 
Example 15
@Bean
public JwtTokenStore tokenStore() throws Exception {
  JwtAccessTokenConverter enhancer = new JwtAccessTokenConverter();
  enhancer.setSigningKey(privateKey);
  enhancer.setVerifierKey(publicKey);
  enhancer.afterPropertiesSet();
  return new JwtTokenStore(enhancer);
}
 
Example 16
@Bean
public JwtTokenStore tokenStore() throws Exception {
  JwtAccessTokenConverter enhancer = new JwtAccessTokenConverter();
  enhancer.setSigningKey(privateKey);
  enhancer.setVerifierKey(publicKey);
  enhancer.afterPropertiesSet();
  return new JwtTokenStore(enhancer);
}
 
Example 17
Source Project: Spring-5.0-By-Example   Source File: OAuthTokenConfiguration.java    License: MIT License 5 votes vote down vote up
@Bean
public JwtTokenStore tokenStore() throws Exception {
  JwtAccessTokenConverter enhancer = new JwtAccessTokenConverter();
  enhancer.setSigningKey(privateKey);
  enhancer.setVerifierKey(publicKey);
  enhancer.afterPropertiesSet();
  return new JwtTokenStore(enhancer);
}
 
Example 18
@Bean
public JwtTokenStore tokenStore() throws Exception {
  JwtAccessTokenConverter enhancer = new JwtAccessTokenConverter();
  enhancer.setSigningKey(privateKey);
  enhancer.setVerifierKey(publicKey);
  enhancer.afterPropertiesSet();
  return new JwtTokenStore(enhancer);
}
 
Example 19
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
    endpoints
            .tokenStore(new JwtTokenStore(jwtAccessTokenConverter))
            .authenticationManager(authenticationManager)
            .accessTokenConverter(jwtAccessTokenConverter);
}
 
Example 20
Source Project: spring-cloud-gray   Source File: JWTOauth2Test.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void test(){
    JwtTokenStore jwtTokenStore = tokenStore();
    String accessToken = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHQiOnsiYSI6IkEiLCJiIjoiQiJ9LCJ1c2VyX25hbWUiOiJzYWxlc29uIiwic2NvcGUiOlsib3BlbmlkIl0sImV4cCI6MTUzNjkwOTU3NCwiYXV0aG9yaXRpZXMiOlsiUk9MRV9BRE1JTiJdLCJqdGkiOiJmMWZmM2UxZS1mYWYxLTRiNmEtODU0Yi1lMWUxZTg1NWIyMDgiLCJjbGllbnRfaWQiOiJqaWFkYW8ifQ.htL5nJu3ZuLhYqTh936-W_Kj4J4FGzjR064TP3YvTSqUkRdlNajJdm6h1wtSEykuvREOt-i5I72EhmmfTV0xjkcgBVrRXP6YcUNTIhEjuEy6upnd8yJhldFtUQwlUOIsXiMfdXa9nI-8ZeGr13JJESOOuvij3dRPILlxpW9mcE52hNSwCfcAh7yNA4KmuBDfsAgyaTe_qZcmnRPzQl_6P3ZrYgK8iTzKY-1LjGeqZ3vGAygP0-ppvQHAHyGp1MTePj3STywz9N05WStLA_Tav1NQksezAneTp4Im33pbuAWnz0e8FslQGYQ9YOfZgrwY9DEh_ARV2aFfpnwx_HRFeQ";
    log.info("accessToken: {}", accessToken);
    OAuth2AccessToken oAuth2AccessToken = jwtTokenStore.readAccessToken(accessToken);
    log.info("oAuth2AccessToken.additionalInformation: {}", oAuth2AccessToken.getAdditionalInformation());
}
 
Example 21
@Test
public void jwtTokenStoreShouldBeConditionalOnMissingBean() throws Exception {
	TestPropertyValues.of("security.oauth2.resource.jwt.keyValue=" + PUBLIC_KEY).applyTo(this.environment);
	this.context = new SpringApplicationBuilder(JwtTokenStoreConfiguration.class, ResourceConfiguration.class)
			.environment(this.environment).web(WebApplicationType.NONE).run();
	assertThat(this.context.getBeansOfType(JwtTokenStore.class)).hasSize(1);
}
 
Example 22
Source Project: Spring-5.0-By-Example   Source File: OAuthTokenConfiguration.java    License: MIT License 5 votes vote down vote up
@Bean
public JwtTokenStore tokenStore() throws Exception {
  JwtAccessTokenConverter enhancer = new JwtAccessTokenConverter();
  enhancer.setSigningKey(privateKey);
  enhancer.setVerifierKey(publicKey);
  enhancer.afterPropertiesSet();
  return new JwtTokenStore(enhancer);
}
 
Example 23
@Bean
public TokenStore tokenStore() {
    return new JwtTokenStore(jwtAccessTokenConverter());
}
 
Example 24
@Bean
public TokenStore tokenStore() {
    return new JwtTokenStore(jwtAccessTokenConverter());
}
 
Example 25
@Bean
public TokenStore tokenStore() {
    return new JwtTokenStore(this.accessTokenConverter());
}
 
Example 26
@Bean
@Autowired
public TokenStore tokenStore(JwtAccessTokenConverter jwtAccessTokenConverter) {
	return new JwtTokenStore(jwtAccessTokenConverter);
}
 
Example 27
Source Project: authmore-framework   Source File: AuthServerConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
    public TokenStore tokenStore() {
        return new JwtTokenStore(accessTokenConverter());
//        return new RedisTokenStore(redisConnectionFactory);
    }
 
Example 28
Source Project: gemini   Source File: OAuth2AuthorizationServerConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public TokenStore tokenStore() {
    return new JwtTokenStore(accessTokenConverter()); // For JWT. Use in-memory, jdbc, or other if not JWT
}
 
Example 29
Source Project: spring-boot-demo   Source File: OAuth2ResourceServerConfig.java    License: MIT License 4 votes vote down vote up
@Bean
public TokenStore tokenStore() {
  return new JwtTokenStore(accessTokenConverter());
}
 
Example 30
@Bean
public TokenStore tokenStore() {
    return new JwtTokenStore(accessTokenConverter());
}