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 9245021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:10:18+00:00 2026-06-18T09:10:18+00:00

The problem is, when i go the the login page, type an username/password to

  • 0

The problem is, when i go the the login page, type an username/password to login I get an error even if i wrote them correctly (I checked my database and the entries exist).
I know i should of used a Logger but i’m still learning the Spring Framework with Hibernate.

EDIT :
1.first part of the test i entered an empty username/password(and it works for empty/empty). For the second part i used one that should work.
2.Other DAOs work correctly with Hibernate (e.g. they retrieve the data correctly and i have no problem with them)

The console output looks like this:

-----------------------------------
User Service INVOKED
User Service-- searching for User:
DAO-- Searching for:
Hibernate: select this_.id as id9_0_, this_.accountName as accountN2_9_0_, this_.password as password9_0_, this_.secGrade as secGrade9_0_, this_.userEmail as userEmail9_0_, this_.userName as userName9_0_ from USER this_ where this_.accountName=?
DAO-- End search
DAO--Not found
User Service-- UserProxyImpl instantiated
User Service-- NOT FOUND,
null
true //<-- Error returned to the controller
-----------------------------------
User Service INVOKED
User Service-- searching for User:admin
DAO-- Searching for:admin
Hibernate: select this_.id as id9_0_, this_.accountName as accountN2_9_0_, this_.password as password9_0_, this_.secGrade as secGrade9_0_, this_.userEmail as userEmail9_0_, this_.userName as userName9_0_ from USER this_ where this_.accountName=?
UserService-- Error in retrieving user
// It stops here and i don't understand why
true // still, returns error to the controller.

Is this a session timeout problem?

Method from the Login Controller:

@RequestMapping(value = "/login", method = RequestMethod.GET)
    public String Login(@RequestParam(value="error", required=false) boolean error,ModelMap model) {

        if (error == true) {
            model.put("error", "You have entered an invalid username or password!");
        } else {
            model.put("error", "");
        }
        System.out.println(error);
        return "login";     

    }

The User Entity:

@Entity
@Table(name = "USER")
public class User implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = -1963505165125499005L;


    private long id;
    private int secGrade;

    private String userName;
    private String accountName;
    private String password;
    private String userEmail;

    public User(String name,
                String user_name,
                String password,
                String email,
                int secGrade){
        this.userName = name;
        this.accountName = user_name;
        this.password = password;
        this.userEmail = email;
        this.secGrade = secGrade;
    }

    @Id
    @GeneratedValue
    public long getId() {
        return id;
    }
    public void setId(long id) {
        this.id = id;
    }
    public int getSecGrade() {
        return secGrade;
    }
    public void setSecGrade(int secGrade) {
        this.secGrade = secGrade;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getAccountName() {
        return accountName;
    }

    public void setAccountName(String accountName) {
        this.accountName = accountName;
    }

    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }

    public String getUserEmail() {
        return userEmail;
    }

    public void setUserEmail(String userEmail) {
        this.userEmail = userEmail;
    }

}

Proxy class used for handling DB Entity:

public class UserProxyImpl implements UserProxy {

    private int secGrade;   
    private String name;
    private String user_name;
    private String password;
    private String email;

    public UserProxyImpl() { }

    public UserProxyImpl(User usr){
        if( usr != null){
            System.out.println("USER PROXY--- constru from "+usr.getAccountName());
            this.secGrade = usr.getSecGrade();
            this.name = usr.getUserName();
            this.user_name = usr.getAccountName();
            this.password = usr.getPassword();
            this.email = usr.getUserEmail();
        }
    }
+ GETTERS/SETTERS
}

Methods from the UserServiceImpl, which create the User obj and adds Authorities:

@Override
        public UserDetails loadUserByUsername(String username) 
                throws UsernameNotFoundException,DataAccessException {
                // Declare a null Spring User
                UserDetails user = null;
                System.out.println("-----------------------------------");
                System.out.println("User Service INVOKED");


            try {
                System.out.println("User Service-- searching for User:"+username);
               // Search database for a user that matches the specified username
                UserProxyImpl dbUser = new UserProxyImpl(userDAO.searchDB(username));
                System.out.println("User Service-- UserProxyImpl instantiated");
                if(dbUser.getName() != null){
                    System.out.println("User Service-- FOUND,"+username);
                }
                else{
                    System.out.println("User Service-- NOT FOUND,"+username);
                }

               // Populate the Spring User object with details from the dbUser
               // getAuthorities() will translate the access level to the correct role type
                System.out.println(dbUser.getName());
                user = new User(
                        dbUser.getUser_name(),
                        dbUser.getPassword().toLowerCase(),
                        true,
                        true,
                        true,
                        true,
                        getAuthorities(new Integer(dbUser.getSecGrade()))
                        );
                System.out.println(user.toString());
              } catch (Exception e) {
               System.out.println("UserService-- Error in retrieving user");
               throw new UsernameNotFoundException("Error in retrieving user");
              }

              // Return user to Spring for processing.

              return user;
             }


         @Override
        public Collection<GrantedAuthority> getAuthorities(Integer access) {
               // Create a list of grants for this user
               List<GrantedAuthority> authList = new ArrayList<GrantedAuthority>(2);

               // All users are granted with ROLE_USER access

               authList.add(new GrantedAuthorityImpl("ROLE_USER"));

               // Check if this user has admin access
               // We interpret Integer(3) as an admin user
               if ( access.compareTo(3) == 0) {

                    authList.add(new GrantedAuthorityImpl("ROLE_ADMIN"));

               }
               else if ( access.compareTo(2) == 0) {                

                   authList.add(new GrantedAuthorityImpl("ROLE_MOD"));
               }

               // Return list of granted authorities
               return authList;
               }

DAO class method used for retrieving an object from the DB:

public User searchDB(String username){

        User u = (User)this.getSessionFactory().getCurrentSession()
                    .createCriteria(User.class)
                    .add(Restrictions.eq("accountName",username))
                    .uniqueResult();
        System.out.println("DAO-- End search");
        if(u != null){
            System.out.println("DAO-- Found:"+u.getUserName());
            return u;
        }
        else{
            System.out.println("DAO--Not found");
            return null;
        }

    }

Spring Security config. XML:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans 
    xmlns="http://www.springframework.org/schema/security"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
                        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                        http://www.springframework.org/schema/security 
                        http://www.springframework.org/schema/security/spring-security-3.1.xsd">


 <http auto-config = 'true' use-expressions="true" access-denied-page="/denied" >

    <intercept-url pattern = "/home/" access="permitAll"/>
    <intercept-url pattern = "/home/login" access="permitAll"/>
    <intercept-url pattern = "/home/jobs" access="permitAll"/>
    <intercept-url pattern = "/home/info" access="permitAll"/>
    <intercept-url pattern = "/home/common" access="hasRole('ROLE_USER')"/>
    <intercept-url pattern = "/home/desk" access="hasRole('ROLE_MOD')"/>
    <intercept-url pattern = "/home/admin" access="hasRole('ROLE_ADMIN')"/>
    <form-login login-page="/login"
                default-target-url="/home"
                authentication-failure-url="/home/login?error=true"/>
    <logout logout-success-url="/home" />               
 </http> 

 <authentication-manager alias="authenticationManager">
    <authentication-provider ref="authenticationProvider"/>
</authentication-manager>

<beans:bean id="authenticationProvider" class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
    <beans:property name="userDetailsService" ref="UserServiceImpl"/>
</beans:bean>


 <!-- Use a Md5 encoder  -->
 <beans:bean class="org.springframework.security.authentication.encoding.Md5PasswordEncoder" id="passwordEncoder"/>

 <!-- A custom service where Spring will retrieve users and their corresponding access levels  -->
 <beans:bean id="UserServiceImpl" class="com.x.interview_management.service.impl.UserServiceImpl"/>

</beans:beans>

Login.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>${error}</h1>
    <sec:authorize access="!isAuthenticated()">
    <div id = "login" style="text-align:center;">

                <h3 style="text-align:center">Login with Username and Password</h3>

                    <form action='/InterviewManagement/j_spring_security_check' method='POST'>
                    <table>
                    <tr>
                        <td>Username:</td>
                        <td><input type='text' name='j_username' value=''><td/>
                    <tr/>
                    <tr>
                        <td>Password:</td>
                        <td><input type='password' name='j_password'/><td/>
                    <tr/>

                    <tr>
                        <td><input name="submit" type="submit"/></td>
                        <td><input name="reset" type="reset"/></td>
                    </tr>
                    </table>
                    </form>

    </div>
    </sec:authorize>    
    <a href="/InterviewManagement/home/">return home</a>
</body>
</html>

Sorry about the code layout, it’s my first time posting on StackExchange.

  • 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-18T09:10:20+00:00Added an answer on June 18, 2026 at 9:10 am

    The problem was i had no default constructor for the User class.

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

Sidebar

Related Questions

I am having a problem with inserting a username and password in a login
My code in javascript file: $(#login).click(function(){ username=$(#user_name).val(); password=$(#password).val(); $.ajax({ type: POST, url: login.php, data:
I have a problem on my site's login page in IE7 browser. One of
I'm having a problem with a simple html login page I made, where when
I have wordpress a site with a customized login page, the problem is when
Ok simple question. I have a JSF application, containing a login page. The problem
The problem is that on a login page, after an incorrect entry is submitted,
my problem is after i successfully log in,it is not redirect to page that
http://www.linkmanagementgroup.com/ My problem is that i've got the log in on the Front Page
The problem I am encountering is that for my login form I have to

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.