私は基本的なSpringBootアプリケーションを持っています。 Spring Initializer、組み込みTomcat、Thymeleafテンプレートエンジン、およびパッケージを実行可能なJARファイルとして使用しています。SpringBootアプリケーションで@RolesAllowedを使用している例外
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
...
}
companyServiceが挿入され、nullではありません。
@Configuration
@EnableGlobalMethodSecurity(jsr250Enabled=true, securedEnabled=true, prePostEnabled=true)
私はアプリケーションを持っているコントローラに到達しようとすると、私はこの
@ModelAttribute("companies")
@RolesAllowed({"ROLE_ADMIN"})
public Iterable<Company> companies(){
return companyService.findAll();
}
ようanotatedコントローラのメソッドを持つ:@RolesAllowed
を削除すると、私のapplicationConfigに
@Autowired
CompanyService companyService;
正常に動作します情報なしの例外:
<div th:utext="'Failed URL: ' + ${url}" th:remove="tag">${url}</div>
<div th:utext="'Exception: ' + ${message}" th:remove="tag">${message}</div>
<div th:utext="'Exception: ' + ${trace}" th:remove="tag">${trace}</div>
<!--
Failed URL: null
Exception: No message available
Exception: null
-->
コントローラに到達する前に、私は、ユーザー
System.out.println("Authorities -> " +
SecurityContextHolder.getContext().getAuthentication().getAuthorities())
の役割を確認し、これが結果である:
Authorities -> [Authority [authority=ROLE_BASIC], Authority [authority=ROLE_ADMIN]]
同じ結果使用:
@ModelAttribute("companies")
@Secured("ADMIN")
public Iterable<Company> companies(){
return companyService.findAll();
}
又は@Secured("ROLE_ADMIN")
:
42410 [http-nio-8080-exec-7] DEBUG o.s.s.access.vote.AffirmativeBased - Voter: org.sp[email protected]65eab2b2, returned: 1
42410 [http-nio-8080-exec-7] DEBUG o.s.s.w.a.i.FilterSecurityInterceptor - Authorization successful
42410 [http-nio-8080-exec-7] DEBUG o.s.s.w.a.i.FilterSecurityInterceptor - RunAsManager did not change Authentication object
42410 [http-nio-8080-exec-7] DEBUG o.s.security.web.FilterChainProxy - /company/list reached end of additional filter chain; proceeding with original chain
42411 [http-nio-8080-exec-7] DEBUG o.s.s.w.a.ExceptionTranslationFilter - Chain processed normally
42411 [http-nio-8080-exec-7] DEBUG o.s.s.w.c.SecurityContextPersistenceFilter - SecurityContextHolder now cleared, as request processing completed
42411 [http-nio-8080-exec-7] DEBUG o.a.c.c.C.[Tomcat].[localhost] - Processing ErrorPage[errorCode=0, location=/error
企業()私が得たあなたが@Securedを削除する際に呼び出され、デバッグ
AffirmativeBased
さ:スイッチ(結果){ 場合AccessDecisionVoter.ACCESS_GRANTED: リターンを。 logger.debug( "Authorization successful");
ログにスタックトレースはありませんか? – dur
いいえ、ログにスタックトレースはありません –
あなたのアプリはユーザー認証を要求していますか?セキュリティ保護されたURLにアクセスすると、ブラウザはユーザー/パスワードを要求しますか? – aaguilera