Java Code Examples for org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer#tokenEnhancer()
The following examples show how to use
org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer#tokenEnhancer() .
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: AuthorizationServerConfig.java From cloud-service with MIT License | 6 votes |
@Override public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { endpoints.authenticationManager(this.authenticationManager); endpoints.tokenStore(tokenStore()); // 授权码模式下,code存储 // endpoints.authorizationCodeServices(new JdbcAuthorizationCodeServices(dataSource)); endpoints.authorizationCodeServices(redisAuthorizationCodeServices); if (storeWithJwt) { endpoints.accessTokenConverter(accessTokenConverter()); } else { // 2019.07.13 将当前用户信息追加到登陆后返回数据里 endpoints.tokenEnhancer((accessToken, authentication) -> { addLoginUserInfo(accessToken, authentication); return accessToken; }); } }
Example 2
Source File: AuthorizationServerConfig.java From microservices-platform with Apache License 2.0 | 6 votes |
/** * 配置身份认证器,配置认证方式,TokenStore,TokenGranter,OAuth2RequestFactory * @param endpoints */ @Override public void configure(AuthorizationServerEndpointsConfigurer endpoints) { if (jwtAccessTokenConverter != null) { if (tokenEnhancer != null) { TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain(); tokenEnhancerChain.setTokenEnhancers( Arrays.asList(tokenEnhancer, jwtAccessTokenConverter)); endpoints.tokenEnhancer(tokenEnhancerChain); } else { endpoints.accessTokenConverter(jwtAccessTokenConverter); } } endpoints.tokenStore(tokenStore) .authenticationManager(authenticationManager) .userDetailsService(userDetailsService) .authorizationCodeServices(authorizationCodeServices) .exceptionTranslator(webResponseExceptionTranslator); }
Example 3
Source File: AuthorizationServerConfiguration.java From spring-boot-demo with MIT License | 5 votes |
/** * 用来配置授权(authorization)以及令牌(token)的访问端点和令牌服务(token services) * * @param endpoints * @throws Exception */ @Override public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { // 配置tokenStore // endpoints.authenticationManager(authenticationManager).tokenStore(tokenStore()) // .accessTokenConverter(accessTokenConverter()).userDetailsService(userDetailsService); //指定认证管理器 endpoints.authenticationManager(authenticationManager); //指定token存储位置 endpoints.tokenStore(tokenStore()); endpoints.accessTokenConverter(accessTokenConverter()); endpoints.userDetailsService(userDetailsService); //自定义token生成方式 TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain(); tokenEnhancerChain.setTokenEnhancers(Arrays.asList(customerEnhancer(), accessTokenConverter())); endpoints.tokenEnhancer(tokenEnhancerChain); // 配置TokenServices参数 DefaultTokenServices tokenServices = (DefaultTokenServices) endpoints.getDefaultAuthorizationServerTokenServices(); tokenServices.setTokenStore(endpoints.getTokenStore()); tokenServices.setSupportRefreshToken(true); tokenServices.setClientDetailsService(endpoints.getClientDetailsService()); tokenServices.setTokenEnhancer(endpoints.getTokenEnhancer()); tokenServices.setAccessTokenValiditySeconds((int) TimeUnit.DAYS.toSeconds(1));//一天 endpoints.tokenServices(tokenServices); }
Example 4
Source File: AuthServerConfig.java From spring-cloud-skipper with Apache License 2.0 | 5 votes |
@Override public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { super.configure(endpoints); endpoints.authenticationManager(authenticationManagerBean); endpoints.tokenStore(tokenStore()); endpoints.tokenEnhancer(new TokenEnhancer() { @Override public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) { if (authentication.getPrincipal() instanceof User) { final User user = (User) authentication.getPrincipal(); final Set<String> scopes = new HashSet<String>(); for (GrantedAuthority authority : user.getAuthorities()) { final String role = authority.getAuthority(); if (role.startsWith("ROLE_")) { scopes.add(role.substring(5).toLowerCase()); } else { scopes.add(role.toLowerCase()); } } ((DefaultOAuth2AccessToken) accessToken).setScope(scopes); } return accessToken; } }); }
Example 5
Source File: OAuth2AuthorizationServer.java From OAuth-2.0-Cookbook with MIT License | 5 votes |
@Override public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { TokenEnhancerChain chain = new TokenEnhancerChain(); chain.setTokenEnhancers(Arrays.asList( new PoPTokenEnhancer(), accessTokenConverter(), new CleanTokenEnhancer())); endpoints .tokenEnhancer(chain); }
Example 6
Source File: AuthServerConfig.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
@Override public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { super.configure(endpoints); endpoints.authenticationManager(authenticationManagerBean); endpoints.tokenStore(tokenStore()); endpoints.tokenEnhancer(new TokenEnhancer() { @Override public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) { if (authentication.getPrincipal() instanceof User) { final User user = (User) authentication.getPrincipal(); final Set<String> scopes = new HashSet<String>(); for (GrantedAuthority authority : user.getAuthorities()) { final String role = authority.getAuthority(); if (role.startsWith("ROLE_")) { scopes.add(role.substring(5).toLowerCase()); } else { scopes.add(role.toLowerCase()); } } ((DefaultOAuth2AccessToken) accessToken).setScope(scopes); } return accessToken; } }); }
Example 7
Source File: AuthorizationServerConfiguration.java From onetwo with Apache License 2.0 | 5 votes |
@Override public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { if(tokenStore!=null){ endpoints.tokenStore(tokenStore); } endpoints.tokenEnhancer(tokenEnhancerChain()); this.oauth2Properties.getAuthorizationServer().getPathMappings().forEach((defPath, customPath) -> { endpoints.pathMapping(defPath, customPath); }); }