Boa tarde, galera
Estou tentando implementar Spring Security 3 na minha aplicação, com JTA.
estou usando:
Servidor: Glassfish 3.1
Spring Security: 3.0.5
Hibernate: 4.1
JSF: 2.1.x
Erro do log ao tentar logar no sistema:
[code]Advertência: #{loginBean.login}: java.lang.NullPointerException
javax.faces.FacesException: #{loginBean.login}: java.lang.NullPointerException
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
Caused by: javax.faces.el.EvaluationException: java.lang.NullPointerException
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
… 60 more
Caused by: java.lang.NullPointerException
at br.com.testspring.bean.LoginBean.login(LoginBean.java:22)[/code]
persistence.xml :
[code]<?xml version="1.0" encoding="UTF-8"?>
<persistence-unit name="primary" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/segDS</jta-data-source>
<properties>
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.SunOneJtaPlatform" />
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="true" />
</properties>
</persistence-unit>
[/code]
Separei a configuração do spring em 2 duas partes
db.xml
[code]context:annotation-config/
<context:component-scan base-package=“br.com.testSpring”/>
jdbc/segDS<tx:annotation-driven transaction-manager=“transactionManager”/>
<tx:jta-transaction-manager />
[/code]
applicationContext-security.xml
[code]
<http use-expressions="true" auto-config="true" >
<intercept-url pattern="/pages/**" access="isAuthenticated()" />
<intercept-url pattern="/**" access="permitAll" />
<form-login login-page="/login.xhtml" authentication-failure-url="/login.xhtml" />
<access-denied-handler error-page="/semPermissao.xhtml" />
</http>
<beans:bean id="userDetailsService" class="br.com.testspring.service.UserDetailsServiceImpl" />
<authentication-manager alias="authenticationManager">
<authentication-provider user-service-ref="userDetailsService" />
</authentication-manager>
</beans:beans>
[/code]
LoginBean
[code]@ManagedBean
@RequestScoped
public class LoginBean {
@ManagedProperty(value = “#{authenticationService}”)
private AuthenticationService authenticationService;
private String userName;
private String password;
public String login() {
boolean success = authenticationService.login(userName, password); // o problema parece estar aqui pelo log
if (!success) {
FacesMessage facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, "", "Login ou senha inv�lidos");
FacesContext.getCurrentInstance().addMessage(null, facesMessage);
return "falhaLogin";
}
return "sucessoLogin";
}
[/code]
Classe AuthenticationService
[code]@Component
public class AuthenticationService {
@Autowired
@Qualifier(“authenticationManager”)
private AuthenticationManager authenticationManager;
public boolean login(String username, String password) {
try {
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password);
Authentication authenticate = authenticationManager.authenticate(token);
if (authenticate.isAuthenticated()) {
SecurityContextHolder.getContext().setAuthentication(authenticate);
return true;
}
}
catch (AuthenticationException e) {}
return false;
}
[/code]
Alguém me ajuda?