私は@EnableGlobalMethodSecurity注釈を春に学ぼうとしています。ここで私のために働くように見えない例があります。@PreAuthorize( "isAuthenticated()")がリダイレクトされたサーバーを何回も返しました
この作品:のは、私がログインしているユーザ名すべてのページに、そのように示してグローバルコントローラがあるとしましょう:
@ControllerAdvice
public class GlobalController {
@ModelAttribute("username")
public String getCurrUser(Principal principal) {
if (principal != null) {
return principal.getName();
}
return null;
}
}
THIS doesntの仕事:今同じコントローラが、これをpreAuthorize注釈付き時刻。これにより、次のエラーメッセージが返されます。localhostがリダイレクトされました。
@ControllerAdvice
public class GlobalController {
@PreAuthorize("isAuthenticated()")
@ModelAttribute("username")
public String getCurrUser(Principal principal) {
return principal.getName();
}
}
マイSecurityConfigクラスは次のように注釈されている:
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled=true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
...
だから私は事前認証注釈と、このエラーメッセージを解決することができますどのように?
逆「@Preauthorizeと@modelattribute .... @ModelAttribute( "ユーザ名")@PreAuthorize( "にisAuthenticated()") パブリック文字列getCurrUser(主主){ –
はそれを試みたが、それはまだ同じエラーを返しますメッセージ:( –
ブールチェック= SecurityContextHolder.getContext()。getAuthentication()。isAuthenticated();これは第1のメソッドで試して、結果を教えてください? –