Java Code Examples for org.springframework.security.oauth2.provider.TokenGranter

The following examples show how to use org.springframework.security.oauth2.provider.TokenGranter. 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
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 2
Source Project: osiam   Source File: OAuth2AuthorizationServerConfig.java    License: 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 Project: oauth2lab   Source File: OAuth2Configuration.java    License: 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 4
Source Project: spring-cloud-shop   Source File: OAuth2SecurityConfiguration.java    License: MIT License 5 votes vote down vote up
private List<TokenGranter> getTokenGranters(AuthorizationCodeServices authorizationCodeServices,
                                            AuthorizationServerTokenServices tokenServices,
                                            ClientDetailsService clientDetailsService,
                                            OAuth2RequestFactory requestFactory) {
    return Stream.of(
            new ClientCredentialsTokenGranter(tokenServices, clientDetailsService, requestFactory),
            new ResourceOwnerPasswordTokenGranter(authenticationManager, tokenServices, clientDetailsService, requestFactory),
            new PhonePasswordTokenGranter(authenticationManager, tokenServices, clientDetailsService, requestFactory),
            new AuthorizationCodeTokenGranter(tokenServices, authorizationCodeServices, clientDetailsService, requestFactory),
            new SmsTokenGranter(userServiceImpl, tokenServices, clientDetailsService, requestFactory))
            .collect(Collectors.toList());
}
 
Example 5
Source Project: OAuth-2.0-Cookbook   Source File: OAuth2Configuration.java    License: 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 6
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 7
/**
 * 重点
 * 先获取已经有的五种授权,然后添加我们自己的进去
 *
 * @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 8
Source Project: springcloud-oauth2   Source File: AuthorizationConfig.java    License: 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);
    }