mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-25 00:25:50 +00:00
Sigue sin ser funcional
This commit is contained in:
parent
d574a048e3
commit
2339891ff0
6 changed files with 134 additions and 54 deletions
|
@ -7,14 +7,11 @@ import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "authorities")
|
@Table(name = "authorities")
|
||||||
public class Authorities extends BaseEntity{
|
public class Authorities {
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
@NotNull
|
//@NotNull
|
||||||
|
@Id
|
||||||
String username;
|
String username;
|
||||||
|
|
||||||
String authority;
|
String authority;
|
||||||
|
@ -31,34 +28,41 @@ public class Authorities extends BaseEntity{
|
||||||
public void setAuthority(String authority) {
|
public void setAuthority(String authority) {
|
||||||
this.authority = authority;
|
this.authority = authority;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + ((authority == null) ? 0 : authority.hashCode());
|
||||||
|
result = prime * result + ((username == null) ? 0 : username.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
Authorities other = (Authorities) obj;
|
||||||
|
if (authority == null) {
|
||||||
|
if (other.authority != null)
|
||||||
|
return false;
|
||||||
|
} else if (!authority.equals(other.authority))
|
||||||
|
return false;
|
||||||
|
if (username == null) {
|
||||||
|
if (other.username != null)
|
||||||
|
return false;
|
||||||
|
} else if (!username.equals(other.username))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Authorities [username=" + username + ", authority=" + authority + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// @ManyToOne
|
|
||||||
// @JoinColumn(name = "username")
|
|
||||||
// private Usuario user;
|
|
||||||
//
|
|
||||||
// @Size(min = 3, max = 50)
|
|
||||||
// private String authority;
|
|
||||||
//
|
|
||||||
// public Usuario getUser() {
|
|
||||||
// return user;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void setUser(Usuario usern) {
|
|
||||||
// this.user = usern;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public String getAuthority() {
|
|
||||||
// return authority;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void setAuthority(String authority) {
|
|
||||||
// this.authority = authority;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public static long getSerialversionuid() {
|
|
||||||
// return serialVersionUID;
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,14 +11,11 @@ import net.bytebuddy.implementation.bind.annotation.Default;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "users")
|
@Table(name = "users")
|
||||||
public class User extends BaseEntity{
|
public class User {
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
|
@Id
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String username;
|
private String username;
|
||||||
|
|
||||||
|
@ -52,4 +49,47 @@ public class User extends BaseEntity{
|
||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + ((enabled == null) ? 0 : enabled.hashCode());
|
||||||
|
result = prime * result + ((password == null) ? 0 : password.hashCode());
|
||||||
|
result = prime * result + ((username == null) ? 0 : username.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
User other = (User) obj;
|
||||||
|
if (enabled == null) {
|
||||||
|
if (other.enabled != null)
|
||||||
|
return false;
|
||||||
|
} else if (!enabled.equals(other.enabled))
|
||||||
|
return false;
|
||||||
|
if (password == null) {
|
||||||
|
if (other.password != null)
|
||||||
|
return false;
|
||||||
|
} else if (!password.equals(other.password))
|
||||||
|
return false;
|
||||||
|
if (username == null) {
|
||||||
|
if (other.username != null)
|
||||||
|
return false;
|
||||||
|
} else if (!username.equals(other.username))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "User [username=" + username + ", password=" + password + ", enabled=" + enabled + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
package org.springframework.cheapy.repository;
|
package org.springframework.cheapy.repository;
|
||||||
|
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
import org.springframework.data.repository.Repository;
|
import org.springframework.data.repository.Repository;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cheapy.model.Authorities;
|
import org.springframework.cheapy.model.Authorities;
|
||||||
|
import org.springframework.dao.DataAccessException;
|
||||||
|
|
||||||
public interface AuthoritiesRepository extends Repository<Authorities, Integer>{
|
public interface AuthoritiesRepository extends CrudRepository<Authorities, Integer>{
|
||||||
|
|
||||||
@Autowired
|
// @Autowired
|
||||||
void save(Authorities authorities);
|
// void save(Authorities authorities);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,14 @@ public class AuthoritiesService {
|
||||||
public void saveAuthorities(Authorities authorities) throws DataAccessException {
|
public void saveAuthorities(Authorities authorities) throws DataAccessException {
|
||||||
authoritiesRepository.save(authorities);
|
authoritiesRepository.save(authorities);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void saveAuthorities(String username, String role) throws DataAccessException {
|
||||||
|
Authorities authority = new Authorities();
|
||||||
|
authority.setUsername(username);
|
||||||
|
authority.setAuthority(role);
|
||||||
|
authoritiesRepository.save(authority);
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
@Transactional
|
@Transactional
|
||||||
public void saveAuthorities(String username, String role) throws DataAccessException {
|
public void saveAuthorities(String username, String role) throws DataAccessException {
|
||||||
|
|
|
@ -31,9 +31,13 @@ public class SingUpController {
|
||||||
|
|
||||||
//private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm";
|
//private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
private final ClientService clientService;
|
private final ClientService clientService;
|
||||||
|
@Autowired
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
|
@Autowired
|
||||||
private final UsuarioService usuarioService;
|
private final UsuarioService usuarioService;
|
||||||
|
@Autowired
|
||||||
private final AuthoritiesService authoritiesService;
|
private final AuthoritiesService authoritiesService;
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,9 +80,12 @@ public class SingUpController {
|
||||||
return "singup/singUpUser";
|
return "singup/singUpUser";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.userService.saveUser(user);
|
//auth.setId(1);
|
||||||
|
//this.authoritiesService.saveAuthorities(auth);
|
||||||
this.usuarioService.saveUsuario(usuario);
|
this.usuarioService.saveUsuario(usuario);
|
||||||
this.authoritiesService.saveAuthorities(auth);
|
this.userService.saveUser(user);
|
||||||
|
this.authoritiesService.saveAuthorities(usuario.getUsuar().getUsername(), "usuario");
|
||||||
|
|
||||||
return "redirect:/";
|
return "redirect:/";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,20 +9,36 @@ INSERT INTO owners VALUES (8, 'Maria', 'Escobito', '345 Maple St.', 'Madison', '
|
||||||
INSERT INTO owners VALUES (9, 'David', 'Schroeder', '2749 Blackhawk Trail', 'Madison', '6085559435');
|
INSERT INTO owners VALUES (9, 'David', 'Schroeder', '2749 Blackhawk Trail', 'Madison', '6085559435');
|
||||||
INSERT INTO owners VALUES (10, 'Carlos', 'Estaban', '2335 Independence La.', 'Waunakee', '6085555487');
|
INSERT INTO owners VALUES (10, 'Carlos', 'Estaban', '2335 Independence La.', 'Waunakee', '6085555487');
|
||||||
|
|
||||||
INSERT INTO users (dtype,id,username,password,enabled) VALUES ('User',1,'admin','admin', TRUE );
|
--INSERT INTO users (dtype,id,username,password,enabled) VALUES ('User',1,'admin','admin', TRUE );
|
||||||
INSERT INTO authorities (id,username,authority) VALUES (1,'admin','admin');
|
--INSERT INTO authorities (id,username,authority) VALUES (1,'admin','admin');
|
||||||
|
|
||||||
INSERT INTO users (dtype,id,username,password,enabled) VALUES ('User',2,'manoli','manoli', TRUE );
|
--INSERT INTO users (dtype,id,username,password,enabled) VALUES ('User',2,'manoli','manoli', TRUE );
|
||||||
INSERT INTO authorities (id,username,authority) VALUES (2,'manoli','client');
|
--INSERT INTO authorities (id,username,authority) VALUES (2,'manoli','client');
|
||||||
INSERT INTO users (dtype,id,username,password,enabled) VALUES ('User',3,'david','david', TRUE );
|
--INSERT INTO users (dtype,id,username,password,enabled) VALUES ('User',3,'david','david', TRUE );
|
||||||
INSERT INTO authorities (id,username,authority) VALUES (3,'david','client');
|
--INSERT INTO authorities (id,username,authority) VALUES (3,'david','client');
|
||||||
|
--
|
||||||
|
--INSERT INTO users (dtype,id,username,password,enabled) VALUES ('User',4,'paco','paco', TRUE );
|
||||||
|
--INSERT INTO authorities (id,username,authority) VALUES (4,'paco','usuario');
|
||||||
|
--INSERT INTO users (dtype,id,username,password,enabled) VALUES ('User',5,'lolo','lolo', TRUE );
|
||||||
|
--INSERT INTO authorities (id,username,authority) VALUES (5,'lolo','usuario');
|
||||||
|
--INSERT INTO users (dtype,id,username,password,enabled) VALUES ('User',6,'pepe','pepe', TRUE );
|
||||||
|
--INSERT INTO authorities (id,username,authority) VALUES (6,'pepe','usuario');
|
||||||
|
|
||||||
|
INSERT INTO users (dtype,username,password,enabled) VALUES ('User','admin','admin', TRUE );
|
||||||
|
INSERT INTO authorities (username,authority) VALUES ('admin','admin');
|
||||||
|
|
||||||
|
INSERT INTO users (dtype,username,password,enabled) VALUES ('User','manoli','manoli', TRUE );
|
||||||
|
INSERT INTO authorities (username,authority) VALUES ('manoli','client');
|
||||||
|
INSERT INTO users (dtype,username,password,enabled) VALUES ('User','david','david', TRUE );
|
||||||
|
INSERT INTO authorities (username,authority) VALUES ('david','client');
|
||||||
|
|
||||||
|
INSERT INTO users (dtype,username,password,enabled) VALUES ('User','paco','paco', TRUE );
|
||||||
|
INSERT INTO authorities (username,authority) VALUES ('paco','usuario');
|
||||||
|
INSERT INTO users (dtype,username,password,enabled) VALUES ('User','lolo','lolo', TRUE );
|
||||||
|
INSERT INTO authorities (username,authority) VALUES ('lolo','usuario');
|
||||||
|
INSERT INTO users (dtype,username,password,enabled) VALUES ('User','pepe','pepe', TRUE );
|
||||||
|
INSERT INTO authorities (username,authority) VALUES ('pepe','usuario');
|
||||||
|
|
||||||
INSERT INTO users (dtype,id,username,password,enabled) VALUES ('User',4,'paco','paco', TRUE );
|
|
||||||
INSERT INTO authorities (id,username,authority) VALUES (4,'paco','usuario');
|
|
||||||
INSERT INTO users (dtype,id,username,password,enabled) VALUES ('User',5,'lolo','lolo', TRUE );
|
|
||||||
INSERT INTO authorities (id,username,authority) VALUES (5,'lolo','usuario');
|
|
||||||
INSERT INTO users (dtype,id,username,password,enabled) VALUES ('User',6,'pepe','pepe', TRUE );
|
|
||||||
INSERT INTO authorities (id,username,authority) VALUES (6,'pepe','usuario');
|
|
||||||
|
|
||||||
INSERT INTO usuarios (id, nombre, apellidos, direccion, municipio, email, username) VALUES (1, 'admin', 'admin', 'C/admin', 'carmona', 'admin@gmail.com','admin');
|
INSERT INTO usuarios (id, nombre, apellidos, direccion, municipio, email, username) VALUES (1, 'admin', 'admin', 'C/admin', 'carmona', 'admin@gmail.com','admin');
|
||||||
INSERT INTO usuarios (id, nombre, apellidos, direccion, municipio, email, username) VALUES (2, 'Paco', 'Naranjo', 'C/Esperanza', 'sevilla', 'Paco@gmail.com','paco');
|
INSERT INTO usuarios (id, nombre, apellidos, direccion, municipio, email, username) VALUES (2, 'Paco', 'Naranjo', 'C/Esperanza', 'sevilla', 'Paco@gmail.com','paco');
|
||||||
|
|
Loading…
Reference in a new issue