Coloquei o SpringSecurity pra fucionar, tento acessar uma pagina e ele me direciona para a pagina de login. Até ae OK, quando eu tento efetuar o login ele nao faz nada, nao trava, nao da erro, nao avança, nao volta. kkkkkkkk queria saber como ele direcionar para a pagina de logado…
estrutura das pastas
webcontent
-jsp
–login.xhtml
–sucesso.xhtml
–erro.xhtml
–privado
—principal.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<b:beans xmlns="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:b="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.xsd">
<http auto-config="true" >
<!-- Don't set any role restrictions on login.jsp -->
<intercept-url pattern="/jsp/login.xhtml" access="IS_AUTHENTICATED_ANONYMOUSLY" />
<!-- Restrict access to ALL other pages -->
<intercept-url pattern="/jsp/privado/*.xhtml" access="ROLE_USER" />
<!-- Set the login page and what to do if login fails -->
<form-login login-page="/jsp/login.xhtml"
authentication-failure-url="/jsp/login.xhtml?login_error=1" default-target-url="/jsp/sucesso.xhtml"
login-processing-url="/j_spring_security_check"
/>
</http>
<authentication-manager>
<authentication-provider>
<jdbc-user-service data-source-ref="dataSource"
users-by-username-query="SELECT login as username, senha as password, 'true' as enable FROM usuario WHERE login = ?"
authorities-by-username-query="SELECT u.login as username, n.nome as authority FROM usuario u, usuarionivel n WHERE u.nivel_id = n.id AND u.login = ?" />
</authentication-provider>
</authentication-manager>
<b:bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<b:property name="url"
value="jdbc:mysql://localhost:3306/decom" />
<b:property name="driverClassName" value="com.mysql.jdbc.Driver" />
<b:property name="username" value="rootx" />
<b:property name="password" value="root" />
</b:bean>
</b:beans>
login.xhtml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
</h:head>
<h:body style="font-family: sans-serif; font-size: 11px; ">
<center>
<p:dialog widgetVar="login" width="230" height="160" dynamic="true"
resizable="false" style="margin: 0;" header="DECOM - SISViagem"
visible="true" showEffect="fade" maximizable="false" closable="false"
id="dialogLogin">
<br />
<br />
<form action="j_spring_security_check" method="post">
<h:panelGrid columns="2">
<h:outputText value="Login:"></h:outputText>
<p:inputText id="j_username"></p:inputText>
<h:outputText value="Senha:"></h:outputText>
<p:password id="j_password"></p:password>
<h:column></h:column>
<p:commandButton value="Entrar" action="#{usuarioController.login}"></p:commandButton>
</h:panelGrid>
</form>
</p:dialog>
</center>
</h:body>
</html>
usuarioController
package br.com.Decom.ManergerBeam;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import br.com.Decom.Model.Usuario;
@SessionScoped
@ManagedBean
public class UsuarioController implements Serializable {
private static final long serialVersionUID = 1L;
private Usuario usuario = new Usuario();
//DAO<Usuario> daoUsDao = new DAO<Usuario>(Usuario.class);
//private String login;
//private String senha;
public UsuarioController() {
System.out.println("teset");
usuario = new Usuario();
SecurityContext context = SecurityContextHolder.getContext();
if (context instanceof SecurityContext){
Authentication authentication = context.getAuthentication();
if (authentication instanceof Authentication){
usuario.setNome(((User)authentication.getPrincipal()).getUsername());
System.out.println("Nome: " + usuario.getNome());
}
}
}
public void login(){
System.out.println("teste");
}
}
