Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8854843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:58:39+00:00 2026-06-14T13:58:39+00:00

For the past days I’ve been trying like crazy to create a custom login

  • 0

For the past days I’ve been trying like crazy to create a custom login page using spring security, but I did not find a working example nor figured it out by myself how to validate the form using spring, and believe me, I tried eveything, every example related I could possibly found on google.

The form loads ok, everythins is in place, all I need is to get Spring Security to authenticate the credentials against a database when I click the “Login” button.

Let me explain by breaking it into parts.

So, I have a login form:

<h:form>
 <p:panelGrid columns="2">

    <p:outputLabel for="j_username" value="Usuário:"/>
    <p:inputText id="j_username"
                 title="Preencha com o seu usuário (login)."
                 required="true"
                 requiredMessage="O campo usuário é obrigatório."
                 value="#{loginBean.usuario}"/>

     <p:outputLabel for="j_password" value="Senha:"/>
     <p:password id="j_password"
                 title="Preencha com a sua senha."
                 required="true"
                 requiredMessage="O campo senha é obrigatório."
                 value="#{loginBean.senha}"/>

      <p:inputText type="hidden"/>

      <p:panelGrid columns="2" styleClass="customPanelgridTable">
       <p:outputLabel for="_spring_security_remember_me" value="Lembrar senha? "/>
         <p:selectBooleanCheckbox id="_spring_security_remember_me"
                                  value="#{loginBean.lembrar_me}"/>
      </p:panelGrid>

      <f:facet name="footer">
        <p:commandButton value="Entrar"
                         actionListener="#{loginBean.doLogin}"/>
      </f:facet>
 </p:panelGrid>
</h:form>

And I need the method “doLogin” to validate the credentials using Spring Security.

My LoginBean:

@Named
@SessionScoped
public class LoginBean implements Serializable {

private static final long serialVersionUID = 1L;

private String usuario, senha;
private boolean lembrar_me = false;

public String getUsuario() {
    return usuario;
}

public void setUsuario(String usuario) {
    this.usuario = usuario;
}

public String getSenha() {
    return senha;
}

public void setSenha(String senha) {
    this.senha = senha;
}

public boolean isLembrar_me() {
    return lembrar_me;
}

public void setLembrar_me(boolean lembrar_me) {
    this.lembrar_me = lembrar_me;
}

public void doLogin() {
  //Spring validation...
}

}

How can I do that?

applicationContext.xml

<http security="none" pattern="/javax.faces.resource/**" />
<http security="none" pattern="/static/**"/>
<http auto-config="true" use-expressions="true"
                  access-denied-page="/public/login.xhtml">

    <intercept-url pattern="/public/**" access="permitAll"/>
    <intercept-url pattern="/secure/**" access="hasRole('ROLE_USER')"/>
    <intercept-url pattern="/login.xhtml" access="permitAll"/>
    <intercept-url pattern="/**" access="hasRole('ROLE_USER')"/>
    <form-login login-page="/public/login.xhtml"
                authentication-failure-url="/public/login.xhtml?erro=true"
                default-target-url="/secure/secure.xhtml"/>

</http>

<beans:bean id="dataSource" 
            class="org.springframework.jdbc.datasource.DriverManagerDataSource" >

    <beans:property name="url" value="jdbc:mysql://localhost:3306/gde" />
    <beans:property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <beans:property name="username" value="root" />
    <beans:property name="password" value="" />
</beans:bean>

<authentication-manager>
    <authentication-provider>

        <user-service>
            <user name="teste" password="teste" authorities="ROLE_USER"/> 
        </user-service>

        <jdbc-user-service data-source-ref="dataSource"
                           users-by-username-query="SELECT USUARIO as username, ISATIVO as enabled FROM usuario WHERE USUARIO=?"

                           authorities-by-username-query="SELECT USUARIO as username, AUTORIZACOES as authority FROM usuario_tipo_usuario WHERE USUARIO=?"
        />
    </authentication-provider>
</authentication-manager>

Any help is much appreciated, I’m stuck with this for days!!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:58:40+00:00Added an answer on June 14, 2026 at 1:58 pm

    Since you want the nifty ajax features of primefaces, you can not use the UsernamePasswordAuthenticationFilter provided by spring security. Try invoking the AuthenticationManager directly, then (The Authentication Manager and the Namespace explains how you can obtain a reference to it).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Over the past few days I have been trying to create/run a project in
I've been the past days trying to test my first in-app purchse iphone application.
For the past few days I have been trying to play any sound over
I have been trying for the past two days now to implement Admob ads
I have been searching for the past through days, trying to figure out how
Over the past few days, I have been trying to find an answer to
for the past four days I am trying to understand the dijkstra's algorithm. But
For the past several days I've been trying to send confirmation emails from my
For the past few days, I've been receiving the same error when trying to
I've been troubleshooting for the past few days trying to install distribute so I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.