Announcement Announcement Module
Collapse
No announcement yet.
Beginner doubt - Overload login.xhtml Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Beginner doubt - Overload login.xhtml

    Hi,

    I am adding spring security in my project. When I use the default page spring security for to log, It works. But, when I use my page login.xhtml, it not works. Why?

    My web.xml
    Code:
      <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
          /WEB-INF/classes/applicationContext.xml
        </param-value>
      </context-param> 
      
      <listener>
        <listener-class>
          org.springframework.web.context.ContextLoaderListener
        </listener-class>
      </listener> 
      
      <!-- Configurações do SpringSecurity -->
      <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
      </filter>
      
      <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping>
      
      <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
      </filter-mapping>
    My Managed Bean:

    Code:
    @ManagedBean
    @RequestScoped
    public class LoginController implements Serializable
    {
    
      private String username;
      private String password;
    
      public String login() throws ServletException, IOException
      {
        ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
        HttpServletRequest request = ((HttpServletRequest) context.getRequest());
    
        ServletResponse resposnse = ((ServletResponse) context.getResponse());
        RequestDispatcher dispatcher = request.getRequestDispatcher("/j_spring_security_check");
        dispatcher.forward(request, resposnse);
        FacesContext.getCurrentInstance().responseComplete();
    
    
        return null;
      }
    
      public String getUsername()
      {
        return username;
      }
    
      public void setUsername(String username)
      {
        this.username = username;
      }
    
      public String getPassword()
      {
        return password;
      }
    
      public void setPassword(String password)
      {
        this.password = password;
      }
    my page

    Code:
      <ui:define name="centro"> 
        <h:form id="loginForm" prependId="false">
    
          <p:growl id="growl" showDetail="true" sticky="false" />  
    
          <h:panelGrid columns="3" cellpadding="2">
    
            <h:panelGrid columns="2" cellpadding="5">
              <h:outputText value="Login"/>
              <p:inputText id="j_username" required="true" value="#{loginController.username}"/>
    
              <h:outputText value="Senha"/>
              <p:password id="j_password" required="true" value="#{loginController.password}"/>  
    
              <p:commandButton id="saveButton" action="#{loginController.login}" value="Logar" update="@form" ajax="false"/> 
            </h:panelGrid>  
            <h:outputText value="Usuário ou senha incorretos!" rendered="#{param.erro}" style="color: darkred"/>
          </h:panelGrid> 
    
        </h:form>
      </ui:define>
    my context:
    Code:
      <sec:http pattern="/pages/public/login.xhtml*" security="none"/>
      <sec:http pattern="/javax.faces.resource/**" security="none"/>
      <sec:http pattern="/resources/**" security="none"/>
      
      <sec:http auto-config="true" use-expressions="true">
        
        <sec:intercept-url pattern="/**" access="hasRole('Cadastro')" />
        
        <sec:form-login login-page="/pages/public/login.xhtml"
                        authentication-failure-url="/pages/public/login.xhtml?erro=true" 
                        default-target-url='/pages/home.xhtml'/>
      </sec:http>
      
      <sec:authentication-manager>
        <sec:authentication-provider>
          <sec:jdbc-user-service 
            data-source-ref="dataSource"
            users-by-username-query = "query"
            authorities-by-username-query= "query"
     
          />
        </sec:authentication-provider>
      </sec:authentication-manager>
Working...
X