mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-23 07:45:49 +00:00
Arreglos con los login y el authority
This commit is contained in:
parent
a041e31a50
commit
9de23998b9
6 changed files with 49 additions and 56 deletions
|
@ -36,11 +36,8 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
|||
|
||||
http.authorizeRequests().antMatchers("/resources/**", "/webjars/**", "/h2-console/**").permitAll()
|
||||
.antMatchers(HttpMethod.GET, "/", "/oups").permitAll()
|
||||
.antMatchers("/users/new").permitAll()
|
||||
.antMatchers("/usuarios/new").permitAll()
|
||||
.antMatchers("/offers/**").permitAll()
|
||||
.antMatchers("/admin/**").hasAnyAuthority("admin")
|
||||
.antMatchers("/owners/**").hasAnyAuthority("owner", "admin")
|
||||
.antMatchers("/clients/new").permitAll()
|
||||
.antMatchers("/offers/**").hasAnyAuthority("admin")
|
||||
.antMatchers("/vets/**").authenticated().anyRequest().denyAll()
|
||||
.and().formLogin()
|
||||
/* .loginPage("/login") */
|
||||
|
|
|
@ -6,5 +6,10 @@ import javax.persistence.Table;
|
|||
@Entity
|
||||
@Table(name = "administrators")
|
||||
public class Administrator extends User{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import javax.validation.constraints.NotEmpty;
|
|||
|
||||
@Entity
|
||||
@Table(name = "clients")
|
||||
public class Client extends User {
|
||||
public class Client extends BaseEntity{
|
||||
|
||||
@NotEmpty
|
||||
private String email;
|
||||
|
|
|
@ -1,56 +1,18 @@
|
|||
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.JoinColumn;
|
||||
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")
|
||||
@MappedSuperclass
|
||||
public class User{
|
||||
public class User extends BaseEntity{
|
||||
|
||||
@Id
|
||||
private String username;
|
||||
|
||||
@NotBlank
|
||||
private String password;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
boolean enabled;
|
||||
|
||||
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
// public Set<Authorities> getAuthority() {
|
||||
// return authorities;
|
||||
// }
|
||||
//
|
||||
// public void setAuthorities(Set<Authorities> authorities) {
|
||||
// this.authorities = authorities;
|
||||
// }
|
||||
@OneToOne
|
||||
@JoinColumn(name = "username")
|
||||
private Usuario usuario;
|
||||
}
|
||||
|
|
|
@ -5,12 +5,39 @@ import java.util.Set;
|
|||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
@Entity
|
||||
@Table(name = "users")
|
||||
public class Usuario extends User{
|
||||
public class Usuario {
|
||||
|
||||
@Id
|
||||
private String username;
|
||||
|
||||
@NotBlank
|
||||
private String password;
|
||||
|
||||
boolean enabled;
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
|
||||
private Set<Authorities> authorities;
|
||||
|
|
|
@ -19,6 +19,8 @@ INSERT INTO nu_offers(start, end, code, type, client_id, gold, discount_gold, si
|
|||
--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');
|
||||
INSERT INTO users(username,password,enabled) VALUES ('cliente','cliente',TRUE);
|
||||
INSERT INTO authorities(id,username,authority) VALUES (1,'cliente','client');
|
||||
|
||||
INSERT INTO clients(email, address, timetable,telephone,description,code,food) VALUES ('cliente@hotmail.com','Calle Tahona nº5','12:00-23:00','954876351','Descripcion','codigo','variado');
|
||||
--INSERT INTO authorities(id,username,authority) VALUES (31,'cliente','client');
|
Loading…
Reference in a new issue