0
我在Spring Security和JSF 2.0集成期間遇到了一些問題。攔截受保護的頁面和其他一切工作正常,但是當我嘗試登錄用戶(通過我的支持bean)時,似乎我的LoginService的ManagedProperty屬性爲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";
}
}
這是的AuthenticationService接口及其實現
public interface AuthenticationService {
public boolean login(String username, String password);
}
實施
@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非常感謝您的答案!
你能發佈你的spring安全上下文文件嗎? – davo
@David M Kershaw:對不起,沒有附上這個文件,我不確定它是否與我的問題相關。順便說一句,這是http://www.mediafire.com/?7pbvvqzxkn527ux 的鏈接,我如何將文件附加到評論或粘貼長文本?它不允許我發送此評論與我的內容文件(文件太長)。我是StackOverflow的新手,請原諒我的無知:-) –