mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-23 15:55:49 +00:00
Merge pull request #20 from cheapy-ispp/005-iniciosesion
005 iniciosesion
This commit is contained in:
commit
a10a0c2476
9 changed files with 114 additions and 58 deletions
|
@ -58,7 +58,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
|||
public void configure(final AuthenticationManagerBuilder auth) throws Exception {
|
||||
auth.jdbcAuthentication().dataSource(this.dataSource)
|
||||
//[login de admin,owner y vet] .usersByUsernameQuery("select username,password,enabled " + "from users " + "where username = ?")
|
||||
.usersByUsernameQuery("select nombre_usuario,contra,enabled from usuarios where nombre_usuario=?").authoritiesByUsernameQuery("select username, authority " + "from authorities " + "where username = ?") //[login de tallerespaco]
|
||||
.usersByUsernameQuery("select username, password, enabled from users where username=?").authoritiesByUsernameQuery("select username, authority " + "from authorities " + "where username = ?") //[login de tallerespaco]
|
||||
.passwordEncoder(this.passwordEncoder());
|
||||
|
||||
}
|
||||
|
|
|
@ -1,26 +1,36 @@
|
|||
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;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
@Entity
|
||||
@Table(name = "authorities")
|
||||
public class Authorities {
|
||||
public class Authorities extends BaseEntity{
|
||||
|
||||
@Id
|
||||
String username;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
String authority;
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "username")
|
||||
private Usuario user;
|
||||
|
||||
@Size(min = 3, max = 50)
|
||||
private String authority;
|
||||
|
||||
public Usuario getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(String username) {
|
||||
this.username = username;
|
||||
|
||||
public void setUser(Usuario usern) {
|
||||
this.user = usern;
|
||||
}
|
||||
|
||||
|
||||
public String getAuthority() {
|
||||
return authority;
|
||||
}
|
||||
|
@ -29,4 +39,9 @@ public class Authorities {
|
|||
this.authority = authority;
|
||||
}
|
||||
|
||||
public static long getSerialversionuid() {
|
||||
return serialVersionUID;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -11,7 +11,10 @@ import javax.validation.constraints.NotEmpty;
|
|||
@Entity
|
||||
@Table(name = "clients")
|
||||
public class Client extends User {
|
||||
|
||||
|
||||
@NotEmpty
|
||||
private String email;
|
||||
|
||||
@NotEmpty
|
||||
private String address;
|
||||
|
||||
|
@ -42,7 +45,15 @@ public class Client extends User {
|
|||
|
||||
@OneToMany
|
||||
private Set<TimeOffer> timeOffers;
|
||||
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
|
|
@ -1,30 +1,34 @@
|
|||
package org.springframework.cheapy.model;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
|
||||
@Entity
|
||||
@Table(name = "users")
|
||||
public class User extends BaseEntity {
|
||||
|
||||
@NotBlank
|
||||
String username;
|
||||
|
||||
@NotBlank
|
||||
String password;
|
||||
|
||||
@Email
|
||||
@NotBlank
|
||||
String email;
|
||||
//@Entity
|
||||
//@Table(name = "users")
|
||||
@MappedSuperclass
|
||||
public class User{
|
||||
|
||||
@Id
|
||||
private String username;
|
||||
|
||||
@NotBlank
|
||||
private String password;
|
||||
|
||||
boolean enabled;
|
||||
|
||||
|
||||
@OneToOne
|
||||
Authorities authority;
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
|
@ -42,19 +46,11 @@ public class User extends BaseEntity {
|
|||
this.password = password;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public Authorities getAuthority() {
|
||||
return authority;
|
||||
}
|
||||
|
||||
public void setAuthority(Authorities authority) {
|
||||
this.authority = authority;
|
||||
}
|
||||
// public Set<Authorities> getAuthority() {
|
||||
// return authorities;
|
||||
// }
|
||||
//
|
||||
// public void setAuthorities(Set<Authorities> authorities) {
|
||||
// this.authorities = authorities;
|
||||
// }
|
||||
}
|
||||
|
|
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.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;
|
||||
|
|
|
@ -12,4 +12,11 @@ INSERT INTO owners VALUES (10, 'Carlos', 'Estaban', '2335 Independence La.', 'Wa
|
|||
|
||||
INSERT INTO food_offers(start, end, code, type, client_id, food, discount, units) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'jkhlljk', 'active', null, 'macarrones', '15%', 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 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