Search in sources :

Example 1 with CustomerAccessTokenConverter

use of com.framework.auth.config.support.CustomerAccessTokenConverter in project new-cloud by xie-summer.

the class OAuth2JWTAuthorizationConfig method jwtAccessTokenConverter.

/**
 * 使用JWT对称加密
 * @return
 */
// @Bean
// public JwtAccessTokenConverter jwtAccessTokenConverter() {
// JwtAccessTokenConverter jwtAccessTokenConverter = new JwtAccessTokenConverter();
// jwtAccessTokenConverter.setSigningKey(CommonConstant.SIGN_KEY);
// return jwtAccessTokenConverter;
// }
/**
 * 使用JWT不对称加密  ,认证中加密,资源服务器验签解密
 * @return
 */
@Bean
public JwtAccessTokenConverter jwtAccessTokenConverter() {
    final JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
    KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory(new ClassPathResource("mytest.jks"), "mypass".toCharArray());
    converter.setKeyPair(keyStoreKeyFactory.getKeyPair("mytest"));
    converter.setAccessTokenConverter(new CustomerAccessTokenConverter());
    return converter;
}
Also used : CustomerAccessTokenConverter(com.framework.auth.config.support.CustomerAccessTokenConverter) JwtAccessTokenConverter(org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter) ClassPathResource(org.springframework.core.io.ClassPathResource) KeyStoreKeyFactory(org.springframework.security.rsa.crypto.KeyStoreKeyFactory) Bean(org.springframework.context.annotation.Bean)

Example 2 with CustomerAccessTokenConverter

use of com.framework.auth.config.support.CustomerAccessTokenConverter 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;
}
Also used : CustomerAccessTokenConverter(com.framework.auth.config.support.CustomerAccessTokenConverter) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) JwtAccessTokenConverter(org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter) IOException(java.io.IOException) ClassPathResource(org.springframework.core.io.ClassPathResource) Bean(org.springframework.context.annotation.Bean)

Aggregations

CustomerAccessTokenConverter (com.framework.auth.config.support.CustomerAccessTokenConverter)2 Bean (org.springframework.context.annotation.Bean)2 ClassPathResource (org.springframework.core.io.ClassPathResource)2 JwtAccessTokenConverter (org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter)2 IOException (java.io.IOException)1 Resource (org.springframework.core.io.Resource)1 KeyStoreKeyFactory (org.springframework.security.rsa.crypto.KeyStoreKeyFactory)1