org.springframework.security.oauth2.provider.CompositeTokenGranter Java Examples

The following examples show how to use org.springframework.security.oauth2.provider.CompositeTokenGranter. 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: OAuth2Config.java    From spring-auth-example with 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 #2
Source File: OAuth2AuthorizationServerConfig.java    From osiam with MIT License 6 votes vote down vote up
@Bean
public TokenGranter tokenGranter() throws Exception {
    return new CompositeTokenGranter(Arrays.asList(new TokenGranter[]{
            new ClientCredentialsTokenGranter(
                    tokenServices(), osiamClientDetailsService, oAuth2RequestFactory()
            ),
            new OsiamResourceOwnerPasswordTokenGranter(
                    authenticationManager, tokenServices(), osiamClientDetailsService, oAuth2RequestFactory()
            ),
            new RefreshTokenGranter(
                    tokenServices(), osiamClientDetailsService, oAuth2RequestFactory()
            ),
            new LessStrictRedirectUriAuthorizationCodeTokenGranter(
                    tokenServices(), authorizationCodeServices(), osiamClientDetailsService, oAuth2RequestFactory()
            )
    }));
}
 
Example #3
Source File: AuthorizationServerConfiguration.java    From cola with MIT License 5 votes vote down vote up
/**
 * 配置Token授权方式
 *
 * @param endpoints
 */
private void configGranters(AuthorizationServerEndpointsConfigurer endpoints) {
	if (tokenGranters != null) {
		CompositeTokenGranter compositeTokenGranter = (CompositeTokenGranter) endpoints.getTokenGranter();
		tokenGranters.forEach(compositeTokenGranter::addTokenGranter);
	}
}
 
Example #4
Source File: OAuth2Configuration.java    From oauth2lab with MIT License 5 votes vote down vote up
@Bean
public TokenGranter tokenGranter() {

    DefaultOAuth2RequestFactory requestFactory = new DefaultOAuth2RequestFactory(clientDetailsService());

    AuthorizationCodeServices codeServices = authorizationCodeServices();

    AuthorizationServerTokenServices tokenServices = tokenServices();
    List<TokenGranter> tokenGranters = Arrays.asList(
            new AuthorizationCodeTokenGranter(tokenServices, codeServices, clientDetailsService(), requestFactory),
            new ResourceOwnerPasswordTokenGranter(authenticationManager, tokenServices, clientDetailsService(), requestFactory),
            new ImplicitTokenGranter(tokenServices, clientDetailsService(), requestFactory));

    return new CompositeTokenGranter(tokenGranters);
}
 
Example #5
Source File: OAuth2SecurityConfiguration.java    From spring-cloud-shop with MIT License 5 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    endpoints
            .exceptionTranslator(webResponseExceptionTranslator)
            .authenticationManager(authenticationManager)
            .authorizationCodeServices(authorizationCodeServices)
            .tokenStore(tokenStore())
            .userDetailsService(userServiceImpl)
            .tokenGranter(new CompositeTokenGranter(getTokenGranters(endpoints.getAuthorizationCodeServices(), endpoints.getTokenServices(), endpoints.getClientDetailsService(), endpoints.getOAuth2RequestFactory())))
            .allowedTokenEndpointRequestMethods(HttpMethod.GET, HttpMethod.POST);
}
 
Example #6
Source File: OAuth2Configuration.java    From OAuth-2.0-Cookbook with MIT License 5 votes vote down vote up
@Bean
public TokenGranter tokenGranter() {

    DefaultOAuth2RequestFactory requestFactory = new DefaultOAuth2RequestFactory(clientDetailsService());

    AuthorizationCodeServices codeServices = authorizationCodeServices();

    AuthorizationServerTokenServices tokenServices = tokenServices();
    List<TokenGranter> tokenGranters = Arrays.asList(
            new CustomAuthCodeTokenGranter(tokenServices, codeServices, clientDetailsService(), requestFactory),
            new ResourceOwnerPasswordTokenGranter(authenticationManager, tokenServices, clientDetailsService(), requestFactory),
            new ImplicitTokenGranter(tokenServices, clientDetailsService(), requestFactory));

    return new CompositeTokenGranter(tokenGranters);
}
 
Example #7
Source File: AuthorizationServerConfig.java    From SpringCloud with 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 #8
Source File: Oauth2AuthorizationServerConfig.java    From spring-security-oauth2-demo with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 重点
 * 先获取已经有的五种授权,然后添加我们自己的进去
 *
 * @param endpoints AuthorizationServerEndpointsConfigurer
 * @return TokenGranter
 */
private TokenGranter tokenGranter(final AuthorizationServerEndpointsConfigurer endpoints) {
    List<TokenGranter> granters = new ArrayList<>(Collections.singletonList(endpoints.getTokenGranter()));
    granters.add(new SmsTokenGranter(endpoints.getTokenServices(), endpoints.getClientDetailsService(),
            endpoints.getOAuth2RequestFactory(), userDetailsService));
    return new CompositeTokenGranter(granters);
}
 
Example #9
Source File: AuthorizationConfig.java    From springcloud-oauth2 with MIT License votes vote down vote up
/**
     * 创建grant_type列表
     * @param endpoints
     * @return
     */
    private TokenGranter tokenGranter(AuthorizationServerEndpointsConfigurer endpoints) {
        List<TokenGranter> list = new ArrayList<>();
        // 这里配置密码模式、刷新token模式、自定义手机号验证码模式、授权码模式、简化模式
        list.add(new ResourceOwnerPasswordTokenGranter(authenticationManager, endpoints.getTokenServices(), endpoints.getClientDetailsService(), endpoints.getOAuth2RequestFactory()));
        list.add(new RefreshTokenGranter(endpoints.getTokenServices(), endpoints.getClientDetailsService(), endpoints.getOAuth2RequestFactory()));
        list.add(new MobileCodeTokenGranter(authenticationManager,endpoints.getTokenServices(), endpoints.getClientDetailsService(), endpoints.getOAuth2RequestFactory()));
        list.add(new AuthorizationCodeTokenGranter(endpoints.getTokenServices(),endpoints.getAuthorizationCodeServices(), endpoints.getClientDetailsService(), endpoints.getOAuth2RequestFactory()));
        list.add(new ImplicitTokenGranter(endpoints.getTokenServices(),endpoints.getClientDetailsService(),endpoints.getOAuth2RequestFactory()));
        return new CompositeTokenGranter(list);
    }