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

The following examples show how to use org.springframework.security.oauth2.provider.token.store.KeyStoreKeyFactory. 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 check out the related API usage on the sidebar.
Example 1
@Bean
@ConditionalOnMissingBean(JwtAccessTokenConverter.class)
public JwtAccessTokenConverter accessTokenConverter() {
	Assert.notNull(this.resource.getJwt().getKeyStore(), "keyStore cannot be null");
	Assert.notNull(this.resource.getJwt().getKeyStorePassword(), "keyStorePassword cannot be null");
	Assert.notNull(this.resource.getJwt().getKeyAlias(), "keyAlias cannot be null");

	JwtAccessTokenConverter converter = new JwtAccessTokenConverter();

	Resource keyStore = this.context.getResource(this.resource.getJwt().getKeyStore());
	char[] keyStorePassword = this.resource.getJwt().getKeyStorePassword().toCharArray();
	KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory(keyStore, keyStorePassword);

	String keyAlias = this.resource.getJwt().getKeyAlias();
	char[] keyPassword = Optional.ofNullable(this.resource.getJwt().getKeyPassword()).map(String::toCharArray)
			.orElse(keyStorePassword);
	converter.setKeyPair(keyStoreKeyFactory.getKeyPair(keyAlias, keyPassword));

	return converter;
}
 
Example 2
@Bean
@ConditionalOnMissingBean(JwtAccessTokenConverter.class)
public JwtAccessTokenConverter accessTokenConverter() {
	Assert.notNull(this.authorization.getJwt().getKeyStore(), "keyStore cannot be null");
	Assert.notNull(this.authorization.getJwt().getKeyStorePassword(), "keyStorePassword cannot be null");
	Assert.notNull(this.authorization.getJwt().getKeyAlias(), "keyAlias cannot be null");

	JwtAccessTokenConverter converter = new JwtAccessTokenConverter();

	Resource keyStore = this.context.getResource(this.authorization.getJwt().getKeyStore());
	char[] keyStorePassword = this.authorization.getJwt().getKeyStorePassword().toCharArray();
	KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory(keyStore, keyStorePassword);

	String keyAlias = this.authorization.getJwt().getKeyAlias();
	char[] keyPassword = Optional.ofNullable(this.authorization.getJwt().getKeyPassword())
			.map(String::toCharArray).orElse(keyStorePassword);
	converter.setKeyPair(keyStoreKeyFactory.getKeyPair(keyAlias, keyPassword));

	return converter;
}
 
Example 3
/**
 * 配置AccessToken加密方式
 */
@Bean
public JwtAccessTokenConverter jwtAccessTokenConverter(CustomUserAuthenticationConverter customUserAuthenticationConverter) {
	JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
	KeyPair keyPair = new KeyStoreKeyFactory(
			keyProperties.getKeyStore().getLocation(),
			keyProperties.getKeyStore().getSecret().toCharArray()).getKeyPair(
			keyProperties.getKeyStore().getAlias(),
			keyProperties.getKeyStore().getPassword().toCharArray());
	converter.setKeyPair(keyPair);
	//配置自定义的CustomUserAuthenticationConverter
	DefaultAccessTokenConverter accessTokenConverter = (DefaultAccessTokenConverter) converter.getAccessTokenConverter();
	accessTokenConverter.setUserTokenConverter(customUserAuthenticationConverter);
	return converter;
}
 
Example 4
@Bean
    public JwtAccessTokenConverter accessTokenConverter() {
        final JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
//    converter.setSigningKey("123");
        KeyStoreKeyFactory keyStoreKeyFactory =
                new KeyStoreKeyFactory(new ClassPathResource("mytest.jks"), "mypass".toCharArray());
        converter.setKeyPair(keyStoreKeyFactory.getKeyPair("mytest"));
        converter.setAccessTokenConverter(new CustomerAccessTokenConverter());
        return converter;
    }
 
Example 5
Source Project: microservices-platform   Source File: AuthJwtTokenStore.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public JwtAccessTokenConverter jwtAccessTokenConverter() {
    final JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
    KeyPair keyPair = new KeyStoreKeyFactory
            (keyProperties.getKeyStore().getLocation(), keyProperties.getKeyStore().getSecret().toCharArray())
            .getKeyPair(keyProperties.getKeyStore().getAlias());
    converter.setKeyPair(keyPair);
    DefaultAccessTokenConverter tokenConverter = (DefaultAccessTokenConverter)converter.getAccessTokenConverter();
    tokenConverter.setUserTokenConverter(new CustomUserAuthenticationConverter());
    return converter;
}
 
Example 6
/**
 * 令牌转换器,(非)对称密钥加密
 *
 * @return JwtAccessTokenConverter
 */
@Bean
public JwtAccessTokenConverter jwtAccessTokenConverter() {
    JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
    //  对称密钥加密
    //  converter.setSigningKey("oauth2");
    //  非对称密钥加密
    KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory(
            new ClassPathResource("oauth2.jks"), "123456".toCharArray());
    converter.setKeyPair(keyStoreKeyFactory.getKeyPair("oauth2"));
    return converter;
}
 
Example 7
Source Project: cubeai   Source File: UaaConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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() {
    JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
    KeyPair keyPair = new KeyStoreKeyFactory(
         new ClassPathResource(uaaProperties.getKeyStore().getName()), uaaProperties.getKeyStore().getPassword().toCharArray())
         .getKeyPair(uaaProperties.getKeyStore().getAlias());
    converter.setKeyPair(keyPair);
    return converter;
}
 
Example 8
/**
 * 配置AccessToken加密方式
 */
@Bean
public JwtAccessTokenConverter jwtAccessTokenConverter(CustomUserAuthenticationConverter customUserAuthenticationConverter) {
	JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
	KeyPair keyPair = new KeyStoreKeyFactory(
			keyProperties.getKeyStore().getLocation(),
			keyProperties.getKeyStore().getSecret().toCharArray()).getKeyPair(
			keyProperties.getKeyStore().getAlias(),
			keyProperties.getKeyStore().getPassword().toCharArray());
	converter.setKeyPair(keyPair);
	//配置自定义的CustomUserAuthenticationConverter
	DefaultAccessTokenConverter accessTokenConverter = (DefaultAccessTokenConverter) converter.getAccessTokenConverter();
	accessTokenConverter.setUserTokenConverter(customUserAuthenticationConverter);
	return converter;
}
 
Example 9
Source Project: Taroco   Source File: JwtTokenConfigration.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * JWT Token 生成转换器(加密方式以及加密的Token中存放哪些信息)
 *
 * @return
 */
@Bean
public JwtAccessTokenConverter jwtAccessTokenConverter() {
    final JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
    KeyPair keyPair = new KeyStoreKeyFactory
            (oauth2Properties.getKeyStore().getLocation(), oauth2Properties.getKeyStore().getSecret().toCharArray())
            .getKeyPair(oauth2Properties.getKeyStore().getAlias());
    converter.setKeyPair(keyPair);
    converter.setAccessTokenConverter(new CustomerAccessTokenConverter());
    return converter;
}
 
Example 10
@Bean
public JwtAccessTokenConverter jwtAccessTokenConverter() {
	JwtAccessTokenConverter converter = new CustomTokenEnhancer();
	converter.setKeyPair(
			new KeyStoreKeyFactory(new ClassPathResource("jwt.jks"), "password".toCharArray()).getKeyPair("jwt"));
	return converter;
}
 
Example 11
Source Project: spring-cloud-gray   Source File: OAuth2Config.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This bean generates an token enhancer, which manages the exchange between JWT acces tokens and Authentication
 * in both direction.
 *
 * @return an access token converter configured with the authorization server's public/private keys
 */
@Bean
public JwtAccessTokenConverter jwtAccessTokenConverter() {
    JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
    KeyPair keyPair = new KeyStoreKeyFactory(
            new ClassPathResource("keystore.jks"), "password".toCharArray())
            .getKeyPair("selfsigned");
    converter.setKeyPair(keyPair);
    return converter;
}
 
Example 12
Source Project: spring-cloud-gray   Source File: JWTOauth2Test.java    License: Apache License 2.0 5 votes vote down vote up
public JwtAccessTokenConverter jwtAccessTokenConverter() {
    JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
    KeyPair keyPair = new KeyStoreKeyFactory(
            new ClassPathResource("keystore.jks"), "password".toCharArray())
            .getKeyPair("selfsigned");
    converter.setKeyPair(keyPair);
    return converter;
}
 
Example 13
Source Project: spring-auth-example   Source File: OAuth2Config.java    License: MIT License 5 votes vote down vote up
@Bean
protected JwtAccessTokenConverter jwtTokenEnhancer() {
  KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory(
      new ClassPathResource("jwt.jks"), "mySecretKey".toCharArray());
  JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
  converter.setKeyPair(keyStoreKeyFactory.getKeyPair("jwt"));
  return converter;
}
 
Example 14
@Bean
public JwtAccessTokenConverter accessTokenConverter() {
    JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
    KeyStoreKeyFactory keyStoreKeyFactory =
            new KeyStoreKeyFactory(
                    new ClassPathResource("mykeys.jks"),
                    "mypass".toCharArray());
    converter.setKeyPair(keyStoreKeyFactory.getKeyPair("mykeys"));
    return converter;
}
 
Example 15
Source Project: java-microservice   Source File: JwtServerConfiguration.java    License: MIT License 5 votes vote down vote up
@Bean
protected JwtAccessTokenConverter jwtTokenEnhancer() {
    KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory(
            new ClassPathResource("jwt.jks"), 
            ENC_PASSWORD.toCharArray()
    );
    JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
    converter.setKeyPair(keyStoreKeyFactory.getKeyPair("jwt"));
    return converter;
}
 
Example 16
@Bean
public JwtAccessTokenConverter jwtAccessTokenConverter() {
	JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
	//Keypair is the alias name -> anilkeystore.jks / password / anila
	KeyPair keyPair = new KeyStoreKeyFactory(new ClassPathResource("anilkeystore.jks"), "password".toCharArray())
			.getKeyPair("anila");
	converter.setKeyPair(keyPair);
	return converter;
}
 
Example 17
@Bean
public JwtAccessTokenConverter accessTokenConverter() {
    JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
    KeyStoreKeyFactory keyFactory =
            new KeyStoreKeyFactory(new ClassPathResource("private.jks"), "storepass".toCharArray());
    converter.setKeyPair(keyFactory.getKeyPair("jwtserver", "keypass".toCharArray()));
    converter.setVerifierKey(publicKey);
    return converter;
}
 
Example 18
@Bean
public JwtAccessTokenConverter jwtAccessTokenConverter() {
    JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
    KeyPair keyPair = new KeyStoreKeyFactory(
            new ClassPathResource(keystore),
            keyStorePass.toCharArray()
    ).getKeyPair(keyPairAlias);

    converter.setKeyPair(keyPair);
    return converter;
}
 
Example 19
@Bean
public JwtAccessTokenConverter jwtAccessTokenConverter() {
    JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
    KeyPair keyPair = new KeyStoreKeyFactory(
            new ClassPathResource("keys/jwtConverterStore.jks"),
            keyStorePass.toCharArray()
    ).getKeyPair(keyPairAlias);

    converter.setKeyPair(keyPair);
    return converter;
}
 
Example 20
Source Project: micro-ecommerce   Source File: AuthserverApplication.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public JwtAccessTokenConverter jwtAccessTokenConverter() {
	JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
	KeyPair keyPair = new KeyStoreKeyFactory(new ClassPathResource("keystore.jks"), "foobar".toCharArray())
			.getKeyPair("test");
	converter.setKeyPair(keyPair);
	return converter;
}
 
Example 21
Source Project: spring-boot-oauth2-jwt   Source File: OAuth2Configuration.java    License: MIT License 5 votes vote down vote up
@Bean
protected JwtAccessTokenConverter jwtAccessTokenConverter() {
	JwtAccessTokenConverter converter = new CustomTokenEnhancer();
	converter.setKeyPair(
			new KeyStoreKeyFactory(new ClassPathResource("jwt.jks"), "password".toCharArray()).getKeyPair("jwt"));
	return converter;
}
 
Example 22
Source Project: tutorials   Source File: AuthServerConfigurer.java    License: MIT License 5 votes vote down vote up
@Bean
public JwtAccessTokenConverter jwtAccessTokenConverter() {
    KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory(
        keystore, keystorePassword.toCharArray());
    KeyPair keyPair = keyStoreKeyFactory.getKeyPair(
        keyAlias, keyPassword.toCharArray());
    JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
    converter.setKeyPair(keyPair);
    return converter;
}
 
Example 23
Source Project: tutorials   Source File: UaaConfiguration.java    License: MIT License 5 votes vote down vote up
/**
 * 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() {
    JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
    KeyPair keyPair = new KeyStoreKeyFactory(
         new ClassPathResource(uaaProperties.getKeyStore().getName()), uaaProperties.getKeyStore().getPassword().toCharArray())
         .getKeyPair(uaaProperties.getKeyStore().getAlias());
    converter.setKeyPair(keyPair);
    return converter;
}
 
Example 24
/**
 * 生成KeyPair
 * @return KeyPair
 */
@Bean
public KeyPair keyPair() {
	KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory(keyProperties.getKeyStore().getLocation(), keyProperties.getKeyStore().getPassword().toCharArray());
	return keyStoreKeyFactory.getKeyPair(keyProperties.getKeyStore().getAlias());
}
 
Example 25
Source Project: syhthems-platform   Source File: AuthorizationServerConfig.java    License: MIT License 4 votes vote down vote up
@Bean
public KeyPair keyPair() {
    KeyStoreKeyFactory keyStoreKeyFactory =
            new KeyStoreKeyFactory(new ClassPathResource("syhthems.jks"), "syhthems-sunriseydy".toCharArray());
    return keyStoreKeyFactory.getKeyPair("syhthems");
}
 
Example 26
@Bean
public KeyPair keyPair() {
    ClassPathResource ksFile = new ClassPathResource(KEY_STORE_FILE);
    KeyStoreKeyFactory ksFactory = new KeyStoreKeyFactory(ksFile, KEY_STORE_PASSWORD.toCharArray());
    return ksFactory.getKeyPair(KEY_ALIAS);
}
 
Example 27
Source Project: platform   Source File: SecurityConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public KeyPair keyPair() {
    KeyStoreKeyFactory keyStoreKeyFactory =
            new KeyStoreKeyFactory(new ClassPathResource("jwt/jwt.jks"), "jwttest".toCharArray());
    return keyStoreKeyFactory.getKeyPair("jwttest");
}
 
Example 28
Source Project: spring-boot-demo   Source File: Oauth2AuthorizationTokenConfig.java    License: MIT License 2 votes vote down vote up
/**
 * 密钥  keyPair.
 * 可用于生成 jwt / jwk.
 *
 * @return keyPair
 */
@Bean
public KeyPair keyPair() {
    KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory(new ClassPathResource("oauth2.jks"), "123456".toCharArray());
    return keyStoreKeyFactory.getKeyPair("oauth2");
}