2011-11-10 9 views
0

Spring SecurityとJSF 2.0の統合中に問題があります。保護されたページや他のすべての傍受はうまくいきますが、私のバッキングBeanを使ってユーザーにログインしようとすると、LoginBeanのManagedPropertyであるAuthenticationServiceがnullに見えます。私がSpring Security 3.7を使用していたときにうまくいきました.3.1.0に切り替わったので、問題が発生しました。ここではLoginBeanとAuthenticationServiceを囲んでいます(このインターフェイスを挿入するとNullPointerExceptionが発生しています)。JSFとSpring Securityの統合 - ManagedPropertyの問題

//LoginBean 
@ManagedProperty(value="#{authenticationService}") 
private AuthenticationService authenticationService; 

public String login() { 
    boolean success = authenticationService.login(name, password); 
    if(success) { 
     return "/faces/signed/home.xhtml?faces-redirect=true"; 
    } 
    else { 
     return "/faces/accessDenied.xhtml?faces-redirect=true"; 
    } 
} 

この

@Service("authenticationService") 
public class AuthenticationServiceImpl implements AuthenticationService { 

@Resource 
AuthenticationManager authenticationManager; 

@Override 
public boolean login(String username, String password) { 
    try{ 
     Authentication authenticate = 
       authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(
         username, password)); 
     if(authenticate.isAuthenticated()) { 
      SecurityContextHolder.getContext().setAuthentication(authenticate); 
      return true; 
     } 
    } 
    catch (AuthenticationException e) { 
     System.out.println("chyba"); 
    } 
    return false; 
} 

はところで、私は答えのために、このチュートリアル http://technology-for-human.blogspot.com/2011/01/jsf-2-with-spring-3-protection-with.htmlおかげで多くを使用しようとしましたAuthenticationServiceインターフェースとその実装

public interface AuthenticationService { 

    public boolean login(String username, String password); 

} 

実装です!

+0

春のセキュリティコンテキストファイルを投稿できますか? – davo

+0

@David M Kershaw:このファイルも含めて申し訳ありませんが、私の質問に関連しているかどうかはわかりませんでした。ここにそのhttp://www.mediafire.com/?7pbvvqzxkn527ux のリンクがありますが、コメントにファイルを封入する方法や長いテキストを貼り付ける方法はありますか?ファイル(ファイルが長すぎます)。私はStackOverflowの新機能ですので、私の無知を許してください:-) –

答えて

1

は、同様の問題があったが、あなたはこれがあなたがauthenticationServiceを注入することができます@Resource

を使用することができます。

@Resource(name = "authenticationService") 

private AuthenticationService authenticationService;