當前位置: 首頁>>代碼示例>>Java>>正文


Java JwtAccessTokenConverter類代碼示例

本文整理匯總了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;
}
 
開發者ID:xm-online,項目名稱:xm-uaa,代碼行數:25,代碼來源:UaaConfiguration.java

示例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);
}
 
開發者ID:xm-online,項目名稱:xm-uaa,代碼行數:18,代碼來源:DomainTokenServicesUnitTest.java

示例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;
}
 
開發者ID:rhawan,項目名稱:microservices-tcc-alfa,代碼行數:14,代碼來源:JwtConfiguration.java

示例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;
}
 
開發者ID:PacktPublishing,項目名稱:OAuth-2.0-Cookbook,代碼行數:18,代碼來源:OAuth2AuthorizationServer.java

示例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);
        }
    };
}
 
開發者ID:lanshiqin,項目名稱:cloud-project,代碼行數:28,代碼來源:AuthorizationServerConfig.java

示例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);
}
 
開發者ID:eclipse,項目名稱:hawkbit-extensions,代碼行數:20,代碼來源:UaaOAuthAutoConfiguration.java

示例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;
}
 
開發者ID:Baeldung,項目名稱:spring-security-oauth,代碼行數:8,代碼來源:OAuth2ResourceServerConfig3.java

示例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;
}
 
開發者ID:Baeldung,項目名稱:spring-security-oauth,代碼行數:17,代碼來源:OAuth2ResourceServerConfigJwt.java

示例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;
}
 
開發者ID:Baeldung,項目名稱:spring-security-oauth,代碼行數:17,代碼來源:OAuth2ResourceServerConfig.java

示例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;
}
 
開發者ID:Nephilim84,項目名稱:contestparser,代碼行數:26,代碼來源:ResourceServerTokenServicesConfiguration.java

示例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;
}
 
開發者ID:xm-online,項目名稱:xm-ms-balance,代碼行數:9,代碼來源:MicroserviceSecurityConfiguration.java

示例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;
}
 
開發者ID:andifalk,項目名稱:spring-authorization-server,代碼行數:15,代碼來源:JwtConfiguration.java

示例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;
}
 
開發者ID:xm-online,項目名稱:xm-ms-dashboard,代碼行數:9,代碼來源:MicroserviceSecurityConfiguration.java


注:本文中的org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。