Java Code Examples for org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer#authenticationManager()

The following examples show how to use org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer#authenticationManager() . 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 vote down vote up
@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: AuthorizationServerConfiguration.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
     * 用来配置授权(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 3
Source File: Oauth2AuthorizationServerConfig.java    From spring-security-oauth2-demo with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
    endpoints.authenticationManager(this.authenticationManager);
    // 自定义 请求 路径
    // endpoints.pathMapping("/oauth/token", "/my/token")
    //        .pathMapping("", "");
}
 
Example 4
Source File: AuthServerConfig.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@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 vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints)
        throws Exception {
    // adding authenticationManager because we are supporting password grant
    // type
    endpoints.authenticationManager(authenticationManager);
}
 
Example 6
Source File: AuthServerConfig.java    From Mastering-Spring-Cloud with MIT License 4 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    endpoints.authenticationManager(authenticationManager);
}
 
Example 7
Source File: SecurityApp.java    From Mastering-Microservices-with-Java-9-Second-Edition with MIT License 4 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpointsConfigurer) throws Exception {
    endpointsConfigurer.authenticationManager(authenticationManager);
}
 
Example 8
Source File: OAuth2SecurityConfiguration.java    From mobilecloud-15 with Apache License 2.0 4 votes vote down vote up
/**
 * This method tells our AuthorizationServerConfigurerAdapter to use the delegated AuthenticationManager
 * to process authentication requests.
 */
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints)
		throws Exception {
	endpoints.authenticationManager(authenticationManager);
}
 
Example 9
Source File: SecurityApp.java    From Microservices-Building-Scalable-Software with MIT License 4 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpointsConfigurer) throws Exception {
    endpointsConfigurer.authenticationManager(authenticationManager);
}
 
Example 10
Source File: OAuth2AuthorizationServer.java    From OAuth-2.0-Cookbook with MIT License 4 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints)
        throws Exception {
    endpoints.authenticationManager(authenticationManager);
}
 
Example 11
Source File: OAuth2AuthorizationServer.java    From OAuth-2.0-Cookbook with MIT License 4 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    endpoints.authenticationManager(authenticationManager);
}
 
Example 12
Source File: AuthServiceApplication.java    From building-microservices with Apache License 2.0 4 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    endpoints.authenticationManager(this.authenticationManager);
}
 
Example 13
Source File: AuthorizationServerConfig.java    From cloud-project with Apache License 2.0 4 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    endpoints.authenticationManager(this.authenticationManager);
    endpoints.accessTokenConverter(accessTokenConverter());
    endpoints.tokenStore(tokenStore());
}
 
Example 14
Source File: PolymerAuthConfig.java    From spring-polymer-demo with Artistic License 2.0 4 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
  endpoints.authenticationManager(authenticationManager);
}
 
Example 15
Source File: OAuth2Config.java    From auth-server with Apache License 2.0 4 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer configurer) throws Exception {
  configurer.authenticationManager(authenticationManager);
  configurer.userDetailsService(userService);
  configurer.tokenStore(tokenStore);
}
 
Example 16
Source File: OAuth2AuthorizationServer.java    From oauth2lab with MIT License 4 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints)
        throws Exception {
    endpoints.authenticationManager(authenticationManager);
}
 
Example 17
Source File: SecurityApp.java    From Mastering-Microservices-with-Java with MIT License 4 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpointsConfigurer) throws Exception {
    endpointsConfigurer.authenticationManager(authenticationManager);
}
 
Example 18
Source File: OAuth2AuthorizationServerConfigurer.java    From Spring-Boot-2.0-Projects with MIT License 4 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    endpoints.authenticationManager(authenticationManagerBean);
}
 
Example 19
Source File: AuthorizationServerConfig.java    From Spring with Apache License 2.0 4 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
	endpoints.authenticationManager(authManager);
}
 
Example 20
Source File: Oauth2AuthorizationServerConfig.java    From spring-security-oauth2-demo with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
    endpoints.authenticationManager(this.authenticationManager);
    endpoints.tokenGranter(tokenGranter(endpoints));
}