2016-12-18 8 views
0

PreInvocationAuthorizationAdviceを導入して、独自の認可メカニズムをSpringに実装しようとしています。私のPreInvocationAuthorizationAdvice.beforeがなぜ呼び出されていないのですか?

マイたSecurityContext:

マイSecurityAdapter:

@Configuration 
@EnableWebSecurity 
public class SecurityAdapter extends WebSecurityConfigurerAdapter 
{ 
    @Override 
    protected void configure(HttpSecurity http) 
     throws Exception 
    { 
     http 
      .authorizeRequests() 
      .anyRequest().permitAll(); 
     http 
      .csrf() 
       .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()); 
    } 
} 

そして、私はすべての要求を許可しています。この時点では、最終的MyPreInvocationAdvice

public class MyPreInvocationAdvice implements PreInvocationAuthorizationAdvice 
{ 
    public MyPreInvocationAdvice() 
    { 
    } 

    @Override 
    public boolean before(Authentication authentication, MethodInvocation methodInvocation, PreInvocationAttribute preInvocationAttribute) 
    { 
     return true; 
    } 
} 

ここに私のコードです。しかし、問題は、私が要求するときにbeforeメソッドが全く呼び出されないということです。誰かが私が間違っている場所を教えてもらえますか?

答えて

0

私は自分自身で答えを見つけたので、将来私は自分自身でそれを参照することができます。

コントローラには@PreAuthorize("")の注釈を付ける必要があります。文字列の値は、後で自分で使用したくない場合(それを使用するコードになりますので、使用しない場合は破棄してください)、問題ありません。

@RestController 
@PreAuthorize("") 
public class Controller 
{ 
} 
関連する問題