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的新手,请原谅我的无知:-) –