をゼロに私がSecurityContextがを返すためのSpring Beanを設定している:私はこのBeanを使用する場合春のセキュリティは、次のように認証リターンが
<bean id="securityContext" class="org.springframework.security.context.SecurityContextHolder"
factory-method="getContext">
</bean>
認証オブジェクトがnullを返します。
Authentication authentication = securityContext.getAuthentication();
GrantedAuthority[] authorities = authentication.getAuthorities();
上記の2行目はNPEを引き起こします。これは期待通りに次のコードは、当局に返すよう、私には奇妙に思える:
GrantedAuthority[] authorities =
SecurityContextHolder.getContext().getAuthentication().getAuthorities();
は基本的に私は私のコードをよりテスト可能にするために)SecurityContextHolder.getContext(への静的呼び出しを排除しようとしています。
これを解決する方法についてのご意見はありますか? Springで返されたSecurityContextが、自分のコード内からの静的呼び出しが行える間に権限を返すことができないのはなぜですか?
FYI私はStruts 2アクション内からコードを実行しています。
私はこれに同意し、フレームワークと戦わないでください。 – JamesC
それは良い問題の説明ですが、解決策ではありません。 – msangel