funcionaaaaa

This commit is contained in:
Abraham 2021-03-23 19:13:46 +01:00
parent 5b924de49d
commit e67d404669
7 changed files with 66 additions and 27 deletions

View file

@ -1,7 +1,6 @@
package org.springframework.cheapy.model;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@ -12,21 +11,26 @@ import javax.validation.constraints.Size;
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)
private String authority;
// public User getUsername() {
// return usern;
// }
//
// public void setUser(User user) {
// this.usern = user;
// }
public Usuario getUser() {
return user;
}
public void setUser(Usuario usern) {
this.user = usern;
}
public String getAuthority() {
return authority;
}
@ -35,4 +39,9 @@ public class Authorities extends BaseEntity{
this.authority = authority;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
}

View file

@ -28,8 +28,7 @@ public class User{
boolean enabled;
//@OneToMany(cascade = CascadeType.ALL, mappedBy = "usern")
//Set<Authorities> authorities;
public String getUsername() {
return username;

View 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;
}
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -21,7 +21,7 @@ import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
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.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

View file

@ -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 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');