org.springframework.security.oauth2.provider.token.ResourceServerTokenServices Java Examples
The following examples show how to use
org.springframework.security.oauth2.provider.token.ResourceServerTokenServices.
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
Source File: SysUtil.java From spring-microservice-exam with MIT License | 6 votes |
/** * 获取当前登录的租户code * * @return String */ private static String getCurrentUserTenantCode() { String tenantCode = ""; try { ResourceServerTokenServices resourceServerTokenServices = SpringContextHolder.getApplicationContext().getBean(ResourceServerTokenServices.class); Object details = SecurityContextHolder.getContext().getAuthentication().getDetails(); if (details instanceof OAuth2AuthenticationDetails) { OAuth2AuthenticationDetails oAuth2AuthenticationDetails = (OAuth2AuthenticationDetails) details; OAuth2AccessToken oAuth2AccessToken = resourceServerTokenServices.readAccessToken(oAuth2AuthenticationDetails.getTokenValue()); Object tenantObj = oAuth2AccessToken.getAdditionalInformation().get(SecurityConstant.TENANT_CODE); tenantCode = tenantObj == null ? "" : tenantObj.toString(); } else if (details instanceof WebAuthenticationDetails) { // 未认证 Object requestObj = RequestContextHolder.getRequestAttributes(); if (requestObj != null) { HttpServletRequest request = ((ServletRequestAttributes) requestObj).getRequest(); tenantCode = request.getParameter(SecurityConstant.TENANT_CODE); } } } catch (Exception e) { log.error(e.getMessage(), e); } return tenantCode; }
Example #2
Source File: AuthenticationTest.java From nakadi with MIT License | 6 votes |
@Bean public ResourceServerTokenServices mockResourceTokenServices() { final ResourceServerTokenServices tokenServices = mock(ResourceServerTokenServices.class); when(tokenServices.loadAuthentication(any())).thenAnswer(invocation -> { final UsernamePasswordAuthenticationToken user = new UsernamePasswordAuthenticationToken("user", "N/A", AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER")); final String token = (String) invocation.getArguments()[0]; final Set<String> scopes = ImmutableSet.copyOf(scopesForTokens.get(token)); final Map<String, Object> details = new HashMap<>(); details.put("realm", realms.get(token)); user.setDetails(details); final OAuth2Request request = new OAuth2Request(null, null, null, true, scopes, null, null, null, null); return new OAuth2Authentication(request, user); }); return tokenServices; }
Example #3
Source File: ResourceServerTokenServicesConfiguration.java From spring-security-oauth2-boot with Apache License 2.0 | 6 votes |
@Bean @ConditionalOnMissingBean(ResourceServerTokenServices.class) public RemoteTokenServices remoteTokenServices() { RemoteTokenServices services = new RemoteTokenServices(); services.setCheckTokenEndpointUrl(this.resource.getTokenInfoUri()); services.setClientId(this.resource.getClientId()); services.setClientSecret(this.resource.getClientSecret()); return services; }
Example #4
Source File: ResourceServerTokenServicesConfiguration.java From spring-security-oauth2-boot with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnMissingBean(ResourceServerTokenServices.class) public DefaultTokenServices jwtTokenServices(TokenStore jwtTokenStore) { DefaultTokenServices services = new DefaultTokenServices(); services.setTokenStore(jwtTokenStore); return services; }
Example #5
Source File: AuthenticationConfig.java From nakadi with MIT License | 5 votes |
@Bean @Primary public ResourceServerTokenServices zalandoResourceTokenServices( @Qualifier("remote") final TokenInfoResourceServerTokenServices remoteTokenInfo, @Qualifier("local") final TokenInfoResourceServerTokenServices localTokenInfo, final MetricRegistry metricRegistry, final FeatureToggleService featureToggleService) { return new NakadiResourceServerTokenServices( metricRegistry, localTokenInfo, remoteTokenInfo, featureToggleService); }
Example #6
Source File: SecurityConfig.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Bean public OAuth2AuthenticationManager oAuth2AuthenticationManager( DefaultClientDetailsService defaultClientDetailsService ) { OAuth2AuthenticationManager oa2Manager = new OAuth2AuthenticationManager(); oa2Manager.setTokenServices( (ResourceServerTokenServices) tokenServices()); oa2Manager.setClientDetailsService( defaultClientDetailsService ); return oa2Manager; }
Example #7
Source File: OAuthConfiguration.java From pazuzu-registry with MIT License | 5 votes |
@Bean public ResourceServerTokenServices customResourceTokenServices() { return new TokenInfoResourceServerTokenServices("pazuzu-registry", new ClientIdAuthorityGrantingAuthenticationExtractor(registryProperties.getAdmins(), Roles.ADMIN), ExecutorWrappers .wrap(new DefaultTokenInfoRequestExecutor( accessTokensBeanProperties.getTokenInfoUri().toString()))); }
Example #8
Source File: SsoSecurityConfigurer.java From spring-security-oauth2-boot with Apache License 2.0 | 5 votes |
private OAuth2ClientAuthenticationProcessingFilter oauth2SsoFilter(OAuth2SsoProperties sso) { OAuth2RestOperations restTemplate = this.applicationContext.getBean(UserInfoRestTemplateFactory.class) .getUserInfoRestTemplate(); ResourceServerTokenServices tokenServices = this.applicationContext.getBean(ResourceServerTokenServices.class); OAuth2ClientAuthenticationProcessingFilter filter = new OAuth2ClientAuthenticationProcessingFilter( sso.getLoginPath()); filter.setRestTemplate(restTemplate); filter.setTokenServices(tokenServices); filter.setApplicationEventPublisher(this.applicationContext); return filter; }
Example #9
Source File: ResourceServerTokenServicesConfiguration.java From spring-security-oauth2-boot with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnMissingBean(ResourceServerTokenServices.class) public DefaultTokenServices jwtTokenServices(TokenStore jwtTokenStore) { DefaultTokenServices services = new DefaultTokenServices(); services.setTokenStore(jwtTokenStore); return services; }
Example #10
Source File: ResourceServerTokenServicesConfiguration.java From spring-security-oauth2-boot with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnMissingBean(ResourceServerTokenServices.class) public DefaultTokenServices jwkTokenServices(TokenStore jwkTokenStore) { DefaultTokenServices services = new DefaultTokenServices(); services.setTokenStore(jwkTokenStore); return services; }
Example #11
Source File: ResourceServerTokenServicesConfiguration.java From spring-security-oauth2-boot with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnMissingBean(ResourceServerTokenServices.class) public UserInfoTokenServices userInfoTokenServices() { UserInfoTokenServices services = new UserInfoTokenServices(this.sso.getUserInfoUri(), this.sso.getClientId()); services.setRestTemplate(this.restTemplate); services.setTokenType(this.sso.getTokenType()); if (this.authoritiesExtractor != null) { services.setAuthoritiesExtractor(this.authoritiesExtractor); } if (this.principalExtractor != null) { services.setPrincipalExtractor(this.principalExtractor); } return services; }
Example #12
Source File: ResourceServerTokenServicesConfiguration.java From spring-security-oauth2-boot with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnMissingBean({ ConnectionFactoryLocator.class, ResourceServerTokenServices.class }) public UserInfoTokenServices userInfoTokenServices() { UserInfoTokenServices services = new UserInfoTokenServices(this.sso.getUserInfoUri(), this.sso.getClientId()); services.setTokenType(this.sso.getTokenType()); services.setRestTemplate(this.restTemplate); if (this.authoritiesExtractor != null) { services.setAuthoritiesExtractor(this.authoritiesExtractor); } if (this.principalExtractor != null) { services.setPrincipalExtractor(this.principalExtractor); } return services; }
Example #13
Source File: ResourceServerConfiguration.java From microservices-oauth with Apache License 2.0 | 5 votes |
@Bean public ResourceServerTokenServices tokenService() { RemoteTokenServices tokenServices = new RemoteTokenServices(); tokenServices.setClientId("adminapp"); tokenServices.setClientSecret("password"); tokenServices.setCheckTokenEndpointUrl(authEndpoint + "/uaa/oauth/check_token"); return tokenServices; }
Example #14
Source File: OpenHelper.java From open-cloud with MIT License | 5 votes |
/** * 构建资源服务器RedisToken服务类 * * @return */ public static ResourceServerTokenServices buildRedisTokenServices(RedisConnectionFactory redisConnectionFactory) throws Exception { OpenRedisTokenService tokenServices = new OpenRedisTokenService(); // 这里的签名key 保持和认证中心一致 RedisTokenStore redisTokenStore = new RedisTokenStore(redisConnectionFactory); tokenServices.setTokenStore(redisTokenStore); log.info("buildRedisTokenServices[{}]", tokenServices); return tokenServices; }
Example #15
Source File: OpenHelper.java From open-cloud with MIT License | 5 votes |
/** * 构建资源服务器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 #16
Source File: RestApiSecurityConfig.java From camunda-bpm-identity-keycloak with Apache License 2.0 | 4 votes |
/** * Creates JWKS based TokenServices. * @return DefaultTokenServices */ public ResourceServerTokenServices tokenServices() { DefaultTokenServices defaultTokenServices = new DefaultTokenServices(); defaultTokenServices.setTokenStore(tokenStore()); return defaultTokenServices; }
Example #17
Source File: CoreServiceApplication.java From DAFramework with MIT License | 4 votes |
@Bean public ResourceServerTokenServices tokenServices() { return new CustomUserInfoTokenServices(sso.getUserInfoUri(), sso.getClientId()); }
Example #18
Source File: AccountApplication.java From microservice-skeleton with MIT License | 4 votes |
@Bean public ResourceServerTokenServices tokenServices() { return new CustomUserInfoTokenServices(sso.getUserInfoUri(), sso.getClientId()); }
Example #19
Source File: Oauth2AuthenticationInterceptor.java From grpc-spring-security-demo with MIT License | 4 votes |
@Autowired public Oauth2AuthenticationInterceptor(ResourceServerTokenServices tokenServices) { this.tokenServices = tokenServices; }
Example #20
Source File: App.java From template-spring-boot-oauth2-wso2-is with Apache License 2.0 | 4 votes |
@Bean @Primary public ResourceServerTokenServices myUserInfoTokenServices() { return new AppUserInfoTokenServices(sso.getUserInfoUri(), sso.getClientId()); }
Example #21
Source File: ResourceServerTokenServicesConfiguration.java From spring-security-oauth2-boot with Apache License 2.0 | 4 votes |
@Bean @ConditionalOnBean(ConnectionFactoryLocator.class) @ConditionalOnMissingBean(ResourceServerTokenServices.class) public SpringSocialTokenServices socialTokenServices() { return new SpringSocialTokenServices(this.connectionFactory, this.sso.getClientId()); }
Example #22
Source File: MeController.java From osiam with MIT License | 4 votes |
@Autowired public MeController(ResourceServerTokenServices resourceServerTokenServices, SCIMUserProvisioning userProvisioning) { this.resourceServerTokenServices = resourceServerTokenServices; this.userProvisioning = userProvisioning; }
Example #23
Source File: OAuth2Configuration.java From fullstop with Apache License 2.0 | 4 votes |
@Bean public ResourceServerTokenServices customResourceTokenServices() { // return new TokenInfoResourceServerTokenServices(tokenInfoUri, "what_here"); return new BearerNoneTokenInfoResourceServerTokenServices(tokenInfoUri); }