Java Code Examples for org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer

The following examples show how to use org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer. 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
public AuthorizationServerConfigurer authorizationServerConfigurer() {
	return new AuthorizationServerConfigurerAdapter() {
		@Override
		public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
			clients.inMemory()
			       .withClient("browserclient")
			       .secret(passwordEncoder.encode("browserclient12345678"))
			       .scopes("account", "message", "email")
			       .resourceIds("resource")
			       .authorizedGrantTypes("implicit")
			       .redirectUris("http://localhost:8082/hello.html");
		}
		
		@Override
		public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
		    oauthServer.checkTokenAccess("isAuthenticated()");    
		}

		@Override
		public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
			endpoints.authenticationManager(webSecurityConfigurerAdapter.authenticationManagerBean())
			         .userDetailsService(webSecurityConfigurerAdapter.userDetailsServiceBean());
		}			
	};
}
 
Example 2
Source Project: oauth-boot   Source File: OAuth2AuthorizationServerConfig.java    License: MIT License 6 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {

    endpoints
            // token 存储方式
            .tokenStore(tokenStore)
            .authenticationManager(authenticationManager)
            // 不配置会导致token无法刷新
            .userDetailsService(userDetailsService)
            .allowedTokenEndpointRequestMethods(HttpMethod.POST,HttpMethod.GET);

    // 判断当前是否使用jwt
    if(!(tokenStore instanceof RedisTokenStore) && this.converter!=null){
        endpoints.accessTokenConverter(converter);
    }


    // 处理 ExceptionTranslationFilter 抛出的异常
    endpoints.exceptionTranslator(bootWebResponseExceptionTranslator);

    endpoints.pathMapping("/oauth/confirm_access","/custom/confirm_access");
}
 
Example 3
Source Project: spring-auth-example   Source File: OAuth2Config.java    License: MIT License 6 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints)
    throws Exception {
  endpoints.tokenStore(tokenStore())
      .tokenEnhancer(jwtTokenEnhancer())
      .authenticationManager(authenticationManager)
      .userDetailsService(userDetailsService);

  List<TokenGranter> tokenGranters = new ArrayList<>();
  tokenGranters
      .add(new CustomResourceOwnerPasswordTokenGranter(authenticationManager,
          endpoints.getTokenServices(), endpoints.getClientDetailsService(),
          endpoints.getOAuth2RequestFactory()));
  tokenGranters.add(new RefreshTokenGranter(endpoints.getTokenServices(),
      endpoints.getClientDetailsService(),
      endpoints.getOAuth2RequestFactory()));
  endpoints.tokenGranter(new CompositeTokenGranter(tokenGranters));
}
 
Example 4
Source Project: lion   Source File: AuthorizationServerConfig.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {

    // 配置tokenServices参数
    DefaultTokenServices tokenServices = new DefaultTokenServices();
    tokenServices.setTokenStore(tokenStore());
    /**
     * jwt 无状态方式
     */
    //tokenServices.setTokenEnhancer(jwtAccessTokenConverter());
    tokenServices.setSupportRefreshToken(true);
    tokenServices.setClientDetailsService(clientDetails());
    // 设置access_token有效时长12小时,默认12小时
    tokenServices.setAccessTokenValiditySeconds(60 * 60 * 12);
    // 设置refresh_token有效时长7天,默认30天
    tokenServices.setRefreshTokenValiditySeconds(60 * 60 * 24 * 7);

    endpoints
            .userDetailsService(userDetailsService)
            .authenticationManager(authenticationManager)
            .tokenServices(tokenServices)
            // 自定义认证异常处理类
            .exceptionTranslator(webResponseExceptionTranslator());
}
 
Example 5
@Bean
public AuthorizationServerConfigurer authorizationServerConfigurer() {
	return new AuthorizationServerConfigurerAdapter() {
		@Override
		public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
			clients.inMemory()
			       .withClient("authcodeclient")
			       .secret(passwordEncoder.encode("authcodeclient12345678"))
			       .scopes("account", "message", "email")
			       .resourceIds("resource")
			       .authorizedGrantTypes("authorization_code", "refresh_token")
			       .redirectUris("http://localhost:8082/HELLO");
		}
		
		@Override
		public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
		    oauthServer.checkTokenAccess("isAuthenticated()");    
		}

		@Override
		public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
			endpoints.authenticationManager(webSecurityConfigurerAdapter.authenticationManagerBean())
			         .userDetailsService(webSecurityConfigurerAdapter.userDetailsServiceBean());
		}			
	};
}
 
Example 6
Source Project: java-tutorial   Source File: AuthorizationServerConfig.java    License: MIT License 6 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    endpoints.tokenStore(jdbcTokenStore)
            .authenticationManager(authenticationManager)
            .userDetailsService(userDetailsService);

    if (jwtAccessTokenConverter != null && jwtTokenEnhancer != null) {
        TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
        ArrayList enhancerList = new ArrayList();
        enhancerList.add(jwtTokenEnhancer);
        enhancerList.add(jwtAccessTokenConverter);
        tokenEnhancerChain.setTokenEnhancers(enhancerList);
        endpoints.tokenEnhancer(tokenEnhancerChain)
                .accessTokenConverter(jwtAccessTokenConverter);
    }
    // 配置TokenServices参数
    endpoints.tokenServices(defaultTokenServices());
}
 
Example 7
Source Project: osiam   Source File: OAuth2AuthorizationServerConfig.java    License: MIT License 5 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    endpoints.userApprovalHandler(userApprovalHandler)
            .requestFactory(oAuth2RequestFactory())
            .authorizationCodeServices(authorizationCodeServices())
            .tokenServices(tokenServices())
            .tokenEnhancer(osiamTokenEnhancer())
            .tokenGranter(tokenGranter());
}
 
Example 8
Source Project: SpringCloud   Source File: AuthorizationServerConfig.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 配置自定义的granter,手机号验证码登陆
 *
 * @param endpoints
 * @return
 * @auth joe_chen
 */
public TokenGranter tokenGranter(final AuthorizationServerEndpointsConfigurer endpoints) {
    List<TokenGranter> granters = Lists.newArrayList(endpoints.getTokenGranter());
    granters.add(new MobileTokenGranter(
            authenticationManager,
            endpoints.getTokenServices(),
            endpoints.getClientDetailsService(),
            endpoints.getOAuth2RequestFactory()));
    return new CompositeTokenGranter(granters);
}
 
Example 9
/**
 * Configuration and Integration of Spring Security to Complete User Validity Authentication
 *
 * @param endpoints AuthorizationServerEndpointsConfigurer
 * @throws Exception 异常信息
 */
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    endpoints
            .authenticationManager(authenticationManager)
            .tokenStore(tokenStore)
            // ApiBoot custom token granter
            .tokenGranter(tokenGranter())
            .accessTokenConverter(accessTokenConverter);
}
 
Example 10
Source Project: microservice-skeleton   Source File: InMemoryOAuth2Config.java    License: MIT License 5 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    endpoints
            .tokenStore(this.tokenStore)
            .authenticationManager(authenticationManager)
            .userDetailsService(userDetailsService);
}
 
Example 11
Source Project: OAuth-2.0-Cookbook   Source File: OAuthConfiguration.java    License: MIT License 5 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    DefaultOAuth2RequestFactory factory =
        new DefaultOAuth2RequestFactory(clientDetailsService);
    factory.setCheckUserScopes(true);

    endpoints
        .requestFactory(factory);
}
 
Example 12
/**
     * 用来配置授权(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 13
Source Project: spring-boot-demo   Source File: AuthorizationServerConfig.java    License: MIT License 5 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
    endpoints.tokenStore(tokenStore())
            .authenticationManager(authenticationManager)
            .allowedTokenEndpointRequestMethods(HttpMethod.GET, HttpMethod.POST)
    ;
}
 
Example 14
Source Project: OAuth-2.0-Cookbook   Source File: OAuth2AuthorizationServer.java    License: MIT License 5 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    endpoints.authenticationManager(authenticationManager)
        .tokenStore(jwtTokenStore())
        .tokenEnhancer(tokenEnhancer())
        .accessTokenConverter(accessTokenConverter());
}
 
Example 15
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {

    TokenEnhancerChain chain = new TokenEnhancerChain();
    chain.setTokenEnhancers(
            Arrays.asList(enhancer, accessTokenConverter()));

    endpoints
            .authenticationManager(authenticationManager)
            .tokenStore(jwtTokenStore())
            .tokenEnhancer(chain)
            .accessTokenConverter(accessTokenConverter());
}
 
Example 16
Source Project: tutorials   Source File: AuthServerConfigurer.java    License: MIT License 5 votes vote down vote up
@Override
public void configure(
    AuthorizationServerEndpointsConfigurer endpoints)
    throws Exception {
    endpoints
        .accessTokenConverter(jwtAccessTokenConverter())
        .userDetailsService(userDetailsService);
}
 
Example 17
Source Project: platform   Source File: AuthorizationServerConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
    endpoints.authenticationManager(this.authenticationManager);
    endpoints.tokenStore(tokenStore());
    endpoints.accessTokenConverter(accessTokenConverter());
    // 默认情况下,只有第一次请求到的Refresh Token可用,
    // 后续刷新后获取到的Refresh Token都无法使用的
    // 这里可以根据实际情况做选择
    endpoints.reuseRefreshTokens(false);
}
 
Example 18
Source Project: OAuth-2.0-Cookbook   Source File: OAuth2AuthorizationServer.java    License: MIT License 5 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints)
        throws Exception {
    //@formatter:off
    endpoints
        .authenticationManager(authenticationManager)
        .tokenStore(tokenStore());
    //@formatter:on
}
 
Example 19
Source Project: spring-cloud-study   Source File: OAuth2Config.java    License: Apache License 2.0 5 votes vote down vote up
@Override
    public void configure(final AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
        /**
         * 普通 jwt 模式
         */
//         endpoints.tokenStore(jwtTokenStore)
//                .accessTokenConverter(jwtAccessTokenConverter)
//                .userDetailsService(kiteUserDetailsService)
//                /**
//                 * 支持 password 模式
//                 */
//                .authenticationManager(authenticationManager);

        /**
         * jwt 增强模式
         */
        TokenEnhancerChain enhancerChain = new TokenEnhancerChain();
        List<TokenEnhancer> enhancerList = new ArrayList<>();
        enhancerList.add(jwtTokenEnhancer);
        enhancerList.add(jwtAccessTokenConverter);
        enhancerChain.setTokenEnhancers(enhancerList);
        endpoints.tokenStore(jwtTokenStore)
                .userDetailsService(kiteUserDetailsService)
                /**
                 * 支持 password 模式
                 */
                .authenticationManager(authenticationManager)
                .tokenEnhancer(enhancerChain)
                .accessTokenConverter(jwtAccessTokenConverter);

        /**
         * redis token 方式
         */
//        endpoints.authenticationManager(authenticationManager)
//                .tokenStore(redisTokenStore)
//                .userDetailsService(kiteUserDetailsService);

    }
 
Example 20
Source Project: spring-cloud-study   Source File: OAuth2Config.java    License: Apache License 2.0 5 votes vote down vote up
@Override
    public void configure(final AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
        /**
         * 普通 jwt 模式
         */
//         endpoints.tokenStore(jwtTokenStore)
//                .accessTokenConverter(jwtAccessTokenConverter)
//                .userDetailsService(kiteUserDetailsService)
//                /**
//                 * 支持 password 模式
//                 */
//                .authenticationManager(authenticationManager);

        /**
         * jwt 增强模式
         */
        TokenEnhancerChain enhancerChain = new TokenEnhancerChain();
        List<TokenEnhancer> enhancerList = new ArrayList<>();
        enhancerList.add(jwtTokenEnhancer);
        enhancerList.add(jwtAccessTokenConverter);
        enhancerChain.setTokenEnhancers(enhancerList);
        endpoints.tokenStore(jwtTokenStore)
                .userDetailsService(kiteUserDetailsService)
                /**
                 * 支持 password 模式
                 */
                .authenticationManager(authenticationManager)
                .tokenEnhancer(enhancerChain)
                .accessTokenConverter(jwtAccessTokenConverter);

        /**
         * redis token 方式
         */
//        endpoints.authenticationManager(authenticationManager)
//                .tokenStore(redisTokenStore)
//                .userDetailsService(kiteUserDetailsService);

    }
 
Example 21
/**
 * 配置TokenStore、Token增强、认证管理器以及异常处理
 *
 * @param endpoints endpoints
 */
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    endpoints
            .allowedTokenEndpointRequestMethods(HttpMethod.GET, HttpMethod.POST)
.authenticationManager(this.authenticationConfiguration.getAuthenticationManager())
            // 将token存储到redis
            .tokenStore(tokenStore())
            // token增强
            .tokenEnhancer(jwtTokenEnhancer())
            // 异常转换
            .exceptionTranslator(webResponseExceptionTranslator());
}
 
Example 22
Source Project: OAuth-2.0-Cookbook   Source File: OAuth2AuthorizationServer.java    License: 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 23
Source Project: JetfireCloud   Source File: AuthenticationServerConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
    //配置token的数据源、自定义的tokenServices等信息,配置身份认证器,配置认证方式,TokenStore,TokenGranter,OAuth2RequestFactory
    endpoints.tokenStore(tokenStore())
            .tokenEnhancer(tokenEnhancerChain())
            .authenticationManager(authenticationManager)
            .userDetailsService(userDetailsService);
}
 
Example 24
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    endpoints
            .authenticationManager(this.authenticationManager)
            .tokenServices(tokenServices())
            .tokenStore(tokenStore())
            .accessTokenConverter(accessTokenConverter());
}
 
Example 25
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    endpoints.tokenStore(tokenStore)
            .authorizationCodeServices(authorizationCodeServices)
            .userDetailsService(userDetailsService)
            .userApprovalHandler(userApprovalHandler())
            .authenticationManager(authenticationManager);
}
 
Example 26
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    endpoints.authenticationManager(authenticationManager);
    endpoints.tokenStore(tokenStore);
    endpoints.tokenGranter(tokenGranter);

    AuthorizationCodeServices codeServices = authorizationCodeServices;

    endpoints.authorizationCodeServices(codeServices);
}
 
Example 27
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    endpoints
            .authenticationManager(authenticationManager)
            .userDetailsService(userDetailsService)
            .tokenStore(tokenStore()).accessTokenConverter(jwtAccessTokenConverter()).tokenEnhancer(tokenEnhancerChain());
}
 
Example 28
Source Project: OAuth-2.0-Cookbook   Source File: OAuth2AuthorizationServer.java    License: MIT License 5 votes vote down vote up
@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 29
Source Project: Auth-service   Source File: OAuth2Config.java    License: MIT License 5 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    endpoints.authenticationManager(authenticationManager)
            .tokenStore(tokenStore(redisConnectionFactory))
            .tokenServices(authorizationServerTokenServices())
            .accessTokenConverter(accessTokenConverter())
            .exceptionTranslator(webResponseExceptionTranslator);
}
 
Example 30
@Override
  public void configure(final AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
final TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
tokenEnhancerChain.setTokenEnhancers(Arrays.asList(tokenEnhancer()));
endpoints.tokenStore(tokenStore())
		.tokenEnhancer(tokenEnhancerChain).authenticationManager(authenticationManager);
  }