Обработка Brute Force Attack в java spring rest api безопасности с реализацией oauth2 - PullRequest
0 голосов
/ 20 ноября 2018

Я использую Java Spring Security для моего REST API, используя неявную реализацию oauth2.Однако так же, как в безопасности Java Spring для MVC, я не могу найти / реализовать пользовательскую faultHandler для конфигурации безопасности REST API для реализации логики для обработки попыток входа в систему.Подскажите, пожалуйста, как мне реализовать то же самое?

@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled=true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
.....
@Override
    protected void configure(HttpSecurity http) throws Exception {
         http
         .csrf().disable()
         .authorizeRequests()
            .antMatchers("/api/**").permitAll()
            .antMatchers("/rest/**").permitAll()
            .antMatchers("/secureapi/**").authenticated()
         .and()
         .formLogin() //New added need to check
         .and()
         .exceptionHandling().authenticationEntryPoint(getBasicAuthEntryPoint())
         .and()
         .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
    }
}

Сервер авторизации:

@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
.....
    @Override
    public void configure(ClientDetailsServiceConfigurer configurer) throws Exception {
    configurer
        .inMemory()
        .withClient(CLIENT_ID)
        .secret(CLIENT_SECRET)
        .authorizedGrantTypes(GRANT_TYPE, AUTHORIZATION_CODE, REFRESH_TOKEN, IMPLICIT )
        .scopes(SCOPE_READ, SCOPE_WRITE, TRUST)
        .accessTokenValiditySeconds(ACCESS_TOKEN_VALIDITY_SECONDS)
        .refreshTokenValiditySeconds(REFRESH_TOKEN_VALIDITY_SECONDS);
    }

    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
        endpoints.tokenStore(tokenStore).authenticationManager(authenticationManager).tokenEnhancer(CustomTokenEnhancer);
    }

    @Override
        public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
            oauthServer.realm(REALM+"/client");
        }
    }
}

Сервер ресурсов:

@EnableResourceServer
public class ResourceServerConfig extends ResourceServerConfigurerAdapter {

    private static final String RESOURCE_ID = "resource_id";

    @Override
    public void configure(ResourceServerSecurityConfigurer resources) {
        resources.resourceId(RESOURCE_ID).stateless(false);
    }

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.
                anonymous().disable()
                .authorizeRequests()
                        .antMatchers("/secureapi/**").authenticated()
                .and().exceptionHandling()
                        .accessDeniedHandler(new OAuth2AccessDeniedHandler());
    }

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...