2016-11-01 13 views
1

GET/POSTリクエストの前にクライアントはOPTIONSリクエストを行うため、この呼び出しを無視したままにしておきます。しかし、私がこの設定をすると、別のリクエスト(GET/POST)も無視されます(無視しないでください)。私はこの行を追加するとSpring Security OPTIONSリクエストを無視するだけのすべてのリクエストを無視する

.antMatchers(HttpMethod.OPTIONS); 

をすべての要求は無視されますが、GET/POSTは無視されてはなりません。

次は設定方法である:「ROLE_」:あなたのようにロール名に接頭文字列を設定している場合

@Override 
public void configure(WebSecurity web) throws Exception { 
    web.ignoring() 
     .antMatchers(HttpMethod.POST, "/login") 
     .antMatchers(HttpMethod.OPTIONS); 
} 

@Override 
protected void configure(HttpSecurity http) throws Exception { 
    http 
    .sessionManagement() 
    .sessionCreationPolicy(SessionCreationPolicy.STATELESS) 
    .and() 
    .authorizeRequests() 
     .anyRequest().authenticated() 
     .antMatchers(HttpMethod.OPTIONS).permitAll() 
     .antMatchers(HttpMethod.GET, "/login/authenticate").authenticated() 

     .antMatchers(HttpMethod.GET, "/credenciadas**").hasRole(PermissaoEnum.CONSULTAR_CREDENCIADA.getNomeInterno()) 
     .antMatchers(HttpMethod.POST, "/credenciadas/validar").hasRole(PermissaoEnum.CONSULTAR_CREDENCIADA.getNomeInterno()) 
     .antMatchers(HttpMethod.POST, "/credenciadas").hasRole(PermissaoEnum.INCLUIR_CREDENCIADA.getNomeInterno()) 
     .antMatchers(HttpMethod.POST, "/credenciadas/alterar").hasRole(PermissaoEnum.ALTERAR_CREDENCIADA.getNomeInterno()) 
     .antMatchers(HttpMethod.DELETE, "/credenciadas/").hasRole(PermissaoEnum.EXCLUIR_CREDENCIADA.getNomeInterno()) 

    .and() 
    .addFilterBefore(authenticationByTokenFilter(), UsernamePasswordAuthenticationFilter.class) 
    .exceptionHandling().authenticationEntryPoint(authenticationEntryPoint()) 
    .and() 
    .csrf().disable(); 
} 

答えて

1

あなたは確認してもらえますか?役割名が間違っている可能性があります。

関連する問題