User authentication in java using Mysql database and Framework spring boot

0

Good afternoon. I am developing a web application using the spring boot framework, hibernate and jpa with the mysql database. I have a question about the authentication of this user because until the moment I only save this user in the database but how do I authenticate it and know if the data in the database is the same as the user is typing in the form? well .. I will show here the only part of the backend because the doubt is all in the backend. this is the part where I used hibernate.

/**
 Classe de persistência de dados ao banco mysql
 */

package com.web.Models;

import java.io.Serializable;

import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; import javax.validation.constraints.NotNull;

@Entity @Table (name="login") public class Login implements Serializable {

private static final long serialVersionUID = -7123394242940032066L;

@Id
@GeneratedValue(strategy= GenerationType.AUTO)
private long id;

@NotNull
@Column(name = "usuario")
private String usuario;

@NotNull
@Column(name = "senha")
private String senha;


public Login() {

}
public Login(String usuario, String senha, long id) {
    this.usuario = usuario;
    this.senha = senha;
    this.id = id;
}


public long getId() {
    return id;
}
public void setId(long id) {
    this.id = id;
}
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;
}

}

here the repository

package com.web.Repository;

import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository;

import com.web.Models.Login;

@Repository public interface LoginRepository extends CrudRepository {

}

package com.web.Controller;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody;

import com.web.Models.Login; import com.web.Repository.LoginRepository; import com.web.Util.Log;

import ch.qos.logback.classic.Logger;

@Controller public class LoginController {     @Autowired     private LoginRepository repository;

@RequestMapping(value="/cadastrarUsuario", method=RequestMethod.GET)
public String form() {
    return "addUser/cadastrarLogin";
}
@RequestMapping(value="/cadastrarUsuario", method=RequestMethod.POST)
public String form(Login login) {
    repository.save(login);
    return "redirect:/cadastrarUsuario";
}


@RequestMapping(value="/validarUsuario", method=RequestMethod.GET)
public String validform() {
    return "validUsuario/validarLogin";
}

Because only the part of the controller that I can not validate this user, I did not create a service class for reasons of faculty only with repository, controller and model, who can help me?

>
}
    
asked by anonymous 07.11.2017 / 15:20

0 answers