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 {
|
public void configure(final AuthenticationManagerBuilder auth) throws Exception {
|
||||||
auth.jdbcAuthentication().dataSource(this.dataSource)
|
auth.jdbcAuthentication().dataSource(this.dataSource)
|
||||||
//[login de admin,owner y vet] .usersByUsernameQuery("select username,password,enabled " + "from users " + "where username = ?")
|
//[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());
|
.passwordEncoder(this.passwordEncoder());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +1,36 @@
|
||||||
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.ManyToOne;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "authorities")
|
@Table(name = "authorities")
|
||||||
public class Authorities {
|
public class Authorities extends BaseEntity{
|
||||||
|
|
||||||
@Id
|
|
||||||
String username;
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
String authority;
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "username")
|
||||||
public String getUsername() {
|
private Usuario user;
|
||||||
return username;
|
|
||||||
|
@Size(min = 3, max = 50)
|
||||||
|
private String authority;
|
||||||
|
|
||||||
|
public Usuario getUser() {
|
||||||
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUser(String username) {
|
public void setUser(Usuario usern) {
|
||||||
this.username = username;
|
this.user = usern;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAuthority() {
|
public String getAuthority() {
|
||||||
return authority;
|
return authority;
|
||||||
}
|
}
|
||||||
|
@ -29,4 +39,9 @@ public class Authorities {
|
||||||
this.authority = authority;
|
this.authority = authority;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static long getSerialversionuid() {
|
||||||
|
return serialVersionUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,10 @@ import javax.validation.constraints.NotEmpty;
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "clients")
|
@Table(name = "clients")
|
||||||
public class Client extends User {
|
public class Client extends User {
|
||||||
|
|
||||||
|
@NotEmpty
|
||||||
|
private String email;
|
||||||
|
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
private String address;
|
private String address;
|
||||||
|
|
||||||
|
@ -42,7 +45,15 @@ public class Client extends User {
|
||||||
|
|
||||||
@OneToMany
|
@OneToMany
|
||||||
private Set<TimeOffer> timeOffers;
|
private Set<TimeOffer> timeOffers;
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
public String getAddress() {
|
public String getAddress() {
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +1,34 @@
|
||||||
package org.springframework.cheapy.model;
|
package org.springframework.cheapy.model;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.persistence.CascadeType;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.MappedSuperclass;
|
import javax.persistence.MappedSuperclass;
|
||||||
|
import javax.persistence.OneToMany;
|
||||||
import javax.persistence.OneToOne;
|
import javax.persistence.OneToOne;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
import javax.validation.constraints.Email;
|
import javax.validation.constraints.Email;
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
|
||||||
@Entity
|
//@Entity
|
||||||
@Table(name = "users")
|
//@Table(name = "users")
|
||||||
public class User extends BaseEntity {
|
@MappedSuperclass
|
||||||
|
public class User{
|
||||||
@NotBlank
|
|
||||||
String username;
|
@Id
|
||||||
|
private String username;
|
||||||
@NotBlank
|
|
||||||
String password;
|
@NotBlank
|
||||||
|
private String password;
|
||||||
@Email
|
|
||||||
@NotBlank
|
boolean enabled;
|
||||||
String email;
|
|
||||||
|
|
||||||
@OneToOne
|
|
||||||
Authorities authority;
|
|
||||||
|
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
return username;
|
return username;
|
||||||
|
@ -42,19 +46,11 @@ public class User extends BaseEntity {
|
||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEmail() {
|
// public Set<Authorities> getAuthority() {
|
||||||
return email;
|
// return authorities;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void setEmail(String email) {
|
// public void setAuthorities(Set<Authorities> authorities) {
|
||||||
this.email = email;
|
// this.authorities = authorities;
|
||||||
}
|
// }
|
||||||
|
|
||||||
public Authorities getAuthority() {
|
|
||||||
return authority;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAuthority(Authorities authority) {
|
|
||||||
this.authority = authority;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
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;
|
||||||
|
|
|
@ -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 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