Search in sources :

Example 1 with OAuth2AuthorizationService

use of org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService in project spring-authorization-server by spring-projects.

the class OAuth2TokenEndpointConfigurer method createDefaultAuthenticationProviders.

private <B extends HttpSecurityBuilder<B>> List<AuthenticationProvider> createDefaultAuthenticationProviders(B builder) {
    List<AuthenticationProvider> authenticationProviders = new ArrayList<>();
    OAuth2AuthorizationService authorizationService = OAuth2ConfigurerUtils.getAuthorizationService(builder);
    OAuth2TokenGenerator<? extends OAuth2Token> tokenGenerator = OAuth2ConfigurerUtils.getTokenGenerator(builder);
    OAuth2AuthorizationCodeAuthenticationProvider authorizationCodeAuthenticationProvider = new OAuth2AuthorizationCodeAuthenticationProvider(authorizationService, tokenGenerator);
    authenticationProviders.add(authorizationCodeAuthenticationProvider);
    OAuth2RefreshTokenAuthenticationProvider refreshTokenAuthenticationProvider = new OAuth2RefreshTokenAuthenticationProvider(authorizationService, tokenGenerator);
    authenticationProviders.add(refreshTokenAuthenticationProvider);
    OAuth2ClientCredentialsAuthenticationProvider clientCredentialsAuthenticationProvider = new OAuth2ClientCredentialsAuthenticationProvider(authorizationService, tokenGenerator);
    authenticationProviders.add(clientCredentialsAuthenticationProvider);
    return authenticationProviders;
}
Also used : OAuth2AuthorizationCodeAuthenticationProvider(org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeAuthenticationProvider) OAuth2ClientCredentialsAuthenticationProvider(org.springframework.security.oauth2.server.authorization.authentication.OAuth2ClientCredentialsAuthenticationProvider) OAuth2AuthorizationService(org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService) AuthenticationProvider(org.springframework.security.authentication.AuthenticationProvider) OAuth2RefreshTokenAuthenticationProvider(org.springframework.security.oauth2.server.authorization.authentication.OAuth2RefreshTokenAuthenticationProvider) OAuth2AuthorizationCodeAuthenticationProvider(org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeAuthenticationProvider) OAuth2ClientCredentialsAuthenticationProvider(org.springframework.security.oauth2.server.authorization.authentication.OAuth2ClientCredentialsAuthenticationProvider) ArrayList(java.util.ArrayList) OAuth2RefreshTokenAuthenticationProvider(org.springframework.security.oauth2.server.authorization.authentication.OAuth2RefreshTokenAuthenticationProvider)

Example 2 with OAuth2AuthorizationService

use of org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService in project platform-base by SummerWindL.

the class AuthorizationConfig method authorizationService.

/**
 * 保存授权信息,授权服务器给我们颁发来token,那我们肯定需要保存吧,由这个服务来保存
 */
@Bean
public OAuth2AuthorizationService authorizationService(JdbcTemplate jdbcTemplate, RegisteredClientRepository registeredClientRepository) {
    JdbcOAuth2AuthorizationService authorizationService = new JdbcOAuth2AuthorizationService(jdbcTemplate, registeredClientRepository);
    class CustomOAuth2AuthorizationRowMapper extends JdbcOAuth2AuthorizationService.OAuth2AuthorizationRowMapper {

        public CustomOAuth2AuthorizationRowMapper(RegisteredClientRepository registeredClientRepository) {
            super(registeredClientRepository);
            getObjectMapper().configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
            this.setLobHandler(new DefaultLobHandler());
        }
    }
    CustomOAuth2AuthorizationRowMapper oAuth2AuthorizationRowMapper = new CustomOAuth2AuthorizationRowMapper(registeredClientRepository);
    authorizationService.setAuthorizationRowMapper(oAuth2AuthorizationRowMapper);
    return authorizationService;
}
Also used : RegisteredClientRepository(org.springframework.security.oauth2.server.authorization.client.RegisteredClientRepository) JdbcRegisteredClientRepository(org.springframework.security.oauth2.server.authorization.client.JdbcRegisteredClientRepository) DefaultLobHandler(org.springframework.jdbc.support.lob.DefaultLobHandler) Bean(org.springframework.context.annotation.Bean)

Example 3 with OAuth2AuthorizationService

use of org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService in project ordinaryroad by 1962247851.

the class AuthorizationServerConfig method authorizationService.

@Bean
public OAuth2AuthorizationService authorizationService(JdbcTemplate jdbcTemplate, RegisteredClientRepository registeredClientRepository) {
    JdbcOAuth2AuthorizationService jdbcOAuth2AuthorizationService = new JdbcOAuth2AuthorizationService(jdbcTemplate, registeredClientRepository);
    jdbcOAuth2AuthorizationService.setAuthorizationRowMapper(new CustomOAuth2AuthorizationRowMapper(registeredClientRepository));
    jdbcOAuth2AuthorizationService.setAuthorizationParametersMapper(new CustomOAuth2AuthorizationParametersMapper());
    return jdbcOAuth2AuthorizationService;
}
Also used : JdbcOAuth2AuthorizationService(org.springframework.security.oauth2.server.authorization.JdbcOAuth2AuthorizationService) Bean(org.springframework.context.annotation.Bean)

Example 4 with OAuth2AuthorizationService

use of org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService in project platform-base by SummerWindL.

the class AuthorizationConfig method authorizationService.

/**
 * 保存授权信息,授权服务器给我们颁发来token,那我们肯定需要保存吧,由这个服务来保存
 */
@Bean
public OAuth2AuthorizationService authorizationService(JdbcTemplate jdbcTemplate, RegisteredClientRepository registeredClientRepository) {
    JdbcOAuth2AuthorizationService authorizationService = new JdbcOAuth2AuthorizationService(jdbcTemplate, registeredClientRepository);
    class CustomOAuth2AuthorizationRowMapper extends JdbcOAuth2AuthorizationService.OAuth2AuthorizationRowMapper {

        public CustomOAuth2AuthorizationRowMapper(RegisteredClientRepository registeredClientRepository) {
            super(registeredClientRepository);
            getObjectMapper().configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
            this.setLobHandler(new DefaultLobHandler());
        }
    }
    CustomOAuth2AuthorizationRowMapper oAuth2AuthorizationRowMapper = new CustomOAuth2AuthorizationRowMapper(registeredClientRepository);
    authorizationService.setAuthorizationRowMapper(oAuth2AuthorizationRowMapper);
    return authorizationService;
}
Also used : RegisteredClientRepository(org.springframework.security.oauth2.server.authorization.client.RegisteredClientRepository) JdbcRegisteredClientRepository(org.springframework.security.oauth2.server.authorization.client.JdbcRegisteredClientRepository) DefaultLobHandler(org.springframework.jdbc.support.lob.DefaultLobHandler) Bean(org.springframework.context.annotation.Bean)

Example 5 with OAuth2AuthorizationService

use of org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService in project spring-authorization-server by spring-projects.

the class OAuth2ConfigurerUtils method getAuthorizationService.

static <B extends HttpSecurityBuilder<B>> OAuth2AuthorizationService getAuthorizationService(B builder) {
    OAuth2AuthorizationService authorizationService = builder.getSharedObject(OAuth2AuthorizationService.class);
    if (authorizationService == null) {
        authorizationService = getOptionalBean(builder, OAuth2AuthorizationService.class);
        if (authorizationService == null) {
            authorizationService = new InMemoryOAuth2AuthorizationService();
        }
        builder.setSharedObject(OAuth2AuthorizationService.class, authorizationService);
    }
    return authorizationService;
}
Also used : InMemoryOAuth2AuthorizationService(org.springframework.security.oauth2.server.authorization.InMemoryOAuth2AuthorizationService) InMemoryOAuth2AuthorizationService(org.springframework.security.oauth2.server.authorization.InMemoryOAuth2AuthorizationService) OAuth2AuthorizationService(org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService)

Aggregations

Bean (org.springframework.context.annotation.Bean)3 DefaultLobHandler (org.springframework.jdbc.support.lob.DefaultLobHandler)2 OAuth2AuthorizationService (org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService)2 JdbcRegisteredClientRepository (org.springframework.security.oauth2.server.authorization.client.JdbcRegisteredClientRepository)2 RegisteredClientRepository (org.springframework.security.oauth2.server.authorization.client.RegisteredClientRepository)2 ArrayList (java.util.ArrayList)1 AuthenticationProvider (org.springframework.security.authentication.AuthenticationProvider)1 InMemoryOAuth2AuthorizationService (org.springframework.security.oauth2.server.authorization.InMemoryOAuth2AuthorizationService)1 JdbcOAuth2AuthorizationService (org.springframework.security.oauth2.server.authorization.JdbcOAuth2AuthorizationService)1 OAuth2AuthorizationCodeAuthenticationProvider (org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeAuthenticationProvider)1 OAuth2ClientCredentialsAuthenticationProvider (org.springframework.security.oauth2.server.authorization.authentication.OAuth2ClientCredentialsAuthenticationProvider)1 OAuth2RefreshTokenAuthenticationProvider (org.springframework.security.oauth2.server.authorization.authentication.OAuth2RefreshTokenAuthenticationProvider)1