mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-23 07:45:49 +00:00
Arreglo de fallos en el despliegue
This commit is contained in:
parent
91a0c235c1
commit
ce05bea9c0
6 changed files with 29 additions and 10 deletions
|
@ -0,0 +1,10 @@
|
||||||
|
package org.springframework.cheapy.model;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "administrators")
|
||||||
|
public class Administrator extends User{
|
||||||
|
|
||||||
|
}
|
|
@ -12,7 +12,15 @@ public class Authorities {
|
||||||
String username;
|
String username;
|
||||||
|
|
||||||
String authority;
|
String authority;
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUser(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
public String getAuthority() {
|
public String getAuthority() {
|
||||||
return authority;
|
return authority;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
package org.springframework.cheapy.model;
|
package org.springframework.cheapy.model;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.MappedSuperclass;
|
import javax.persistence.MappedSuperclass;
|
||||||
import javax.persistence.OneToOne;
|
import javax.persistence.OneToOne;
|
||||||
|
import javax.persistence.Table;
|
||||||
import javax.validation.constraints.Email;
|
import javax.validation.constraints.Email;
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
|
|
||||||
|
|
||||||
@MappedSuperclass
|
@Entity
|
||||||
|
@Table(name = "users")
|
||||||
public class User extends BaseEntity {
|
public class User extends BaseEntity {
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
|
|
|
@ -5,9 +5,6 @@ import org.springframework.cheapy.model.Authorities;
|
||||||
import org.springframework.cheapy.model.User;
|
import org.springframework.cheapy.model.User;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public interface AuthoritiesRepository extends CrudRepository<Authorities, Integer>{
|
public interface AuthoritiesRepository extends CrudRepository<Authorities, Integer>{
|
||||||
|
|
||||||
Authorities findByUser(User user);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class AuthoritiesService {
|
public class AuthoritiesService {
|
||||||
|
/*
|
||||||
private AuthoritiesRepository authoritiesRepository;
|
private AuthoritiesRepository authoritiesRepository;
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ public class AuthoritiesService {
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Authorities findAuthoritiyByUser(User user) {
|
public Authorities findAuthoritiyByUser(User user) {
|
||||||
return this.authoritiesRepository.findByUser(user);
|
return this.authoritiesRepository.findByUser(user.getUsername());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@ -59,7 +59,7 @@ public class AuthoritiesService {
|
||||||
Authorities authority = new Authorities();
|
Authorities authority = new Authorities();
|
||||||
Optional<User> user = userService.findUser(username);
|
Optional<User> user = userService.findUser(username);
|
||||||
if(user.isPresent()) {
|
if(user.isPresent()) {
|
||||||
authority.setUser(user.get());
|
authority.setUser(user.get().getUsername());
|
||||||
authority.setAuthority(role);
|
authority.setAuthority(role);
|
||||||
//user.get().getAuthorities().add(authority);
|
//user.get().getAuthorities().add(authority);
|
||||||
authoritiesRepository.save(authority);
|
authoritiesRepository.save(authority);
|
||||||
|
@ -67,5 +67,5 @@ public class AuthoritiesService {
|
||||||
throw new DataAccessException("User '"+username+"' not found!") {};
|
throw new DataAccessException("User '"+username+"' not found!") {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class UserService {
|
public class UserService {
|
||||||
|
/*
|
||||||
private UserRepository userRepository;
|
private UserRepository userRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -60,4 +60,5 @@ public class UserService {
|
||||||
String currentPrincipalName = authentication.getName(); //Obtiene el nombre del ususario actual
|
String currentPrincipalName = authentication.getName(); //Obtiene el nombre del ususario actual
|
||||||
return this.userRepository.findByUsername(currentPrincipalName); //Obtiene el usuario con ese nombre
|
return this.userRepository.findByUsername(currentPrincipalName); //Obtiene el usuario con ese nombre
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue