I'm new to spring boot. Trying to integrate with rest services and hibernate, where-in upon logging in with the correct credentials, getting the "Invalid password or username"

@Configuration
public class AppConfig {
@Bean
public userDao userRepository() {
    System.out.println("repo from bean");
    return new userDaoImpl();
}

@Bean
public userService userService() {
    System.out.println("ser from bean");
    return new userServiceImpl();
}

@SuppressWarnings("deprecation")
@Bean
public HibernateJpaSessionFactoryBean sessionFactory(){
    System.out.println("seesion factory from bean");
    return new HibernateJpaSessionFactoryBean();
}}
@Service
public class userServiceImpl implements userService {
    @Autowired
    private userDao userDao;

    public void setUserDao(userDao userDao) {
        this.userDao = userDao;
    }

    @Transactional
    public Users validateUser(String Username, String password) {
        return userDao.validateUser(Username, password);
    }}

@Repository
    public class userDaoImpl extends SpringBeanAutowiringSupport implements userDao {

    private static final Logger logger = LoggerFactory.getLogger(userDaoImpl.class);
    @Autowired
    private SessionFactory sessionFactory;

    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

      public Users validateUser(String Username, String password) {

         Criteria criteria = this.sessionFactory.getCurrentSession().createCriteria(Users.class);
        if (!StringUtils.isEmpty(Username)) {
            criteria.add(Restrictions.eq("username", Username));
        }
        if (!StringUtils.isEmpty(password)) {
            criteria.add(Restrictions.eq("password", password));
        }
        @SuppressWarnings("unchecked")
        List<Users> users = (List<Users>) criteria.list();
        if (!users.isEmpty()) {
            return users.get(0);
        }
        return null;
     }}

application.properties

spring.datasource.url= jdbc:postgresql://localhost:5432/myusers
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect  spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
    hibernate.show_sql=true
hibernate.hbm2ddl.auto=update
entitymanager.packagesToScan=com// com is my base package

@SpringBootApplication
@RestController
public class DemoApplication extends SpringBootServletInitializer {

public static void main(String[] args) {
    SpringApplication.run(DemoApplication.class, args);
}
 @Autowired
private userService userService;

 @RequestMapping(value="/loginProcess" , method=RequestMethod.POST)
public Response publishMessage2(@QueryParam("username") String username, @QueryParam("password") String password) {
    System.out.println("Hi " + username);
    String responseStr = "response to " + username;
    Users user = userService.validateUser(username, password);
    if (null != user) {
   System.out.println("WELCOME to the application " + user.getFirstname());
    } else {
        System.out.println("Username or Password is wrong!!");
    }
    return Response.status(200).entity(responseStr).build()
}   }

pom.xml

<?xml version = "1.0" encoding = "UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

      <modelVersion>4.0.0</modelVersion>
      <groupId>com.login</groupId>
      <artifactId>demo2</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <packaging>jar</packaging>
      <name>login_spring_boot</name>
      <description>login project for Spring Boot</description>
      <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.8.RELEASE</version>
     <relativePath />    
      </parent>
      <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <project.reporting.outputEncoding>UTF- 
   8</project.reporting.outputEncoding>
        <java.version>1.6</java.version>
      </properties>

      <dependencies>
        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-jersey</artifactId>
        </dependency>
        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-test</artifactId>
          <scope>test</scope>


        </dependency>
               <dependency> <groupId>org.springframework.boot</groupId> 
        <artifactId>spring-boot-starter-integration</artifactId> 
        </dependency>
        <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>jstl</artifactId>
        </dependency>
     <dependency>
          <groupId>org.postgresql</groupId>
          <artifactId>postgresql</artifactId>
          <scope>runtime</scope>
        </dependency>

        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId>
     <scope>runtime</scope> 
    </dependency>

        <dependency>
          <groupId>postgresql</groupId>
          <artifactId>postgresql</artifactId>
          <version>9.1-901.jdbc4</version>
        </dependency> 
     </dependencies>
    <build>
        <plugins>
          <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
          </plugin>
         </plugins>
      </build>
    </project>

When I call my rest service from postman( http://localhost:8080/loginProcess?username=abc&password=xyz) where abc and xyz are the valid credentials of a user,"Hi abc" and "Username or password is wrong!! " is printed.

0 Answers