mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-23 15:55:49 +00:00
Merge pull request #19 from cheapy-issp/005-iniciosesion
005 iniciosesion
This commit is contained in:
commit
619f3e66e2
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{
|
||||
|
||||
}
|
|
@ -13,6 +13,14 @@ public class Authorities {
|
|||
|
||||
String authority;
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUser(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getAuthority() {
|
||||
return authority;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
package org.springframework.cheapy.model;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
|
||||
@MappedSuperclass
|
||||
@Entity
|
||||
@Table(name = "users")
|
||||
public class User extends BaseEntity {
|
||||
|
||||
@NotBlank
|
||||
|
|
|
@ -5,9 +5,6 @@ import org.springframework.cheapy.model.Authorities;
|
|||
import org.springframework.cheapy.model.User;
|
||||
|
||||
|
||||
|
||||
public interface AuthoritiesRepository extends CrudRepository<Authorities, Integer>{
|
||||
|
||||
Authorities findByUser(User user);
|
||||
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
*/
|
||||
@Service
|
||||
public class AuthoritiesService {
|
||||
|
||||
/*
|
||||
private AuthoritiesRepository authoritiesRepository;
|
||||
private UserService userService;
|
||||
|
||||
|
@ -46,7 +46,7 @@ public class AuthoritiesService {
|
|||
|
||||
@Transactional
|
||||
public Authorities findAuthoritiyByUser(User user) {
|
||||
return this.authoritiesRepository.findByUser(user);
|
||||
return this.authoritiesRepository.findByUser(user.getUsername());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
@ -59,7 +59,7 @@ public class AuthoritiesService {
|
|||
Authorities authority = new Authorities();
|
||||
Optional<User> user = userService.findUser(username);
|
||||
if(user.isPresent()) {
|
||||
authority.setUser(user.get());
|
||||
authority.setUser(user.get().getUsername());
|
||||
authority.setAuthority(role);
|
||||
//user.get().getAuthorities().add(authority);
|
||||
authoritiesRepository.save(authority);
|
||||
|
@ -67,5 +67,5 @@ public class AuthoritiesService {
|
|||
throw new DataAccessException("User '"+username+"' not found!") {};
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
|
||||
@Service
|
||||
public class UserService {
|
||||
|
||||
/*
|
||||
private UserRepository userRepository;
|
||||
|
||||
@Autowired
|
||||
|
@ -60,4 +60,5 @@ public class UserService {
|
|||
String currentPrincipalName = authentication.getName(); //Obtiene el nombre del ususario actual
|
||||
return this.userRepository.findByUsername(currentPrincipalName); //Obtiene el usuario con ese nombre
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue