mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-24 16:15:49 +00:00
funcionaaaaa
This commit is contained in:
parent
5b924de49d
commit
e67d404669
7 changed files with 66 additions and 27 deletions
|
@ -1,7 +1,6 @@
|
||||||
package org.springframework.cheapy.model;
|
package org.springframework.cheapy.model;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
|
||||||
import javax.persistence.JoinColumn;
|
import javax.persistence.JoinColumn;
|
||||||
import javax.persistence.ManyToOne;
|
import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
@ -12,21 +11,26 @@ import javax.validation.constraints.Size;
|
||||||
public class Authorities extends BaseEntity{
|
public class Authorities extends BaseEntity{
|
||||||
|
|
||||||
|
|
||||||
//@ManyToOne
|
/**
|
||||||
//@JoinColumn(name = "username")
|
*
|
||||||
//private User usern;
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "username")
|
||||||
|
private Usuario user;
|
||||||
|
|
||||||
@Size(min = 3, max = 50)
|
@Size(min = 3, max = 50)
|
||||||
private String authority;
|
private String authority;
|
||||||
|
|
||||||
// public User getUsername() {
|
public Usuario getUser() {
|
||||||
// return usern;
|
return user;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// public void setUser(User user) {
|
public void setUser(Usuario usern) {
|
||||||
// this.usern = user;
|
this.user = usern;
|
||||||
// }
|
}
|
||||||
|
|
||||||
public String getAuthority() {
|
public String getAuthority() {
|
||||||
return authority;
|
return authority;
|
||||||
}
|
}
|
||||||
|
@ -35,4 +39,9 @@ public class Authorities extends BaseEntity{
|
||||||
this.authority = authority;
|
this.authority = authority;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static long getSerialversionuid() {
|
||||||
|
return serialVersionUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,7 @@ public class User{
|
||||||
|
|
||||||
boolean enabled;
|
boolean enabled;
|
||||||
|
|
||||||
//@OneToMany(cascade = CascadeType.ALL, mappedBy = "usern")
|
|
||||||
//Set<Authorities> authorities;
|
|
||||||
|
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
return username;
|
return username;
|
||||||
|
|
26
src/main/java/org/springframework/cheapy/model/Usuario.java
Normal file
26
src/main/java/org/springframework/cheapy/model/Usuario.java
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
package org.springframework.cheapy.model;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.persistence.CascadeType;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.OneToMany;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "users")
|
||||||
|
public class Usuario extends User{
|
||||||
|
|
||||||
|
@OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
|
||||||
|
private Set<Authorities> authorities;
|
||||||
|
|
||||||
|
public Set<Authorities> getAuthorities() {
|
||||||
|
return authorities;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAuthorities(Set<Authorities> authorities) {
|
||||||
|
this.authorities = authorities;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,11 +0,0 @@
|
||||||
|
|
||||||
package org.springframework.cheapy.repository;
|
|
||||||
|
|
||||||
import org.springframework.data.repository.CrudRepository;
|
|
||||||
import org.springframework.cheapy.model.User;
|
|
||||||
|
|
||||||
public interface UserRepository extends CrudRepository<User, String> {
|
|
||||||
|
|
||||||
User findByUsername(String currentPrincipalName);
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
|
||||||
|
package org.springframework.cheapy.repository;
|
||||||
|
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
import org.springframework.cheapy.model.User;
|
||||||
|
import org.springframework.cheapy.model.Usuario;
|
||||||
|
|
||||||
|
public interface UsuarioRepository extends CrudRepository<Usuario, String> {
|
||||||
|
|
||||||
|
Usuario findByUsername(String currentPrincipalName);
|
||||||
|
|
||||||
|
}
|
|
@ -21,7 +21,7 @@ import java.util.Optional;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.cheapy.model.User;
|
import org.springframework.cheapy.model.User;
|
||||||
import org.springframework.cheapy.repository.UserRepository;
|
import org.springframework.cheapy.repository.UsuarioRepository;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
|
@ -14,5 +14,9 @@ INSERT INTO food_offers(start, end, code, type, client_id, food, discount, units
|
||||||
|
|
||||||
INSERT INTO time_offers(start, end, code, type, client_id, init, finish, discount) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'jkhlljk', 'active', null, '12:00:00', '13:00:00', '10%');
|
INSERT INTO time_offers(start, end, code, type, client_id, init, finish, discount) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'jkhlljk', 'active', null, '12:00:00', '13:00:00', '10%');
|
||||||
|
|
||||||
|
--insert into usuarios(username, password, enabled) values ('admin3', 'admin', true);
|
||||||
|
--insert into authorities(id ,usuario, authority) values (42,'admin3', 'admin');
|
||||||
|
|
||||||
|
INSERT INTO users(username,password,enabled) VALUES ('admin1','4dm1n',TRUE);
|
||||||
|
INSERT INTO authorities(id,username,authority) VALUES (1,'admin1','admin');
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue