mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-22 15:25:49 +00:00
add Privilege
This commit is contained in:
parent
8f21109239
commit
3d1868225a
5 changed files with 48 additions and 11 deletions
|
@ -60,12 +60,13 @@ class PetController extends WebSocketSender {
|
|||
|
||||
@ModelAttribute("owner")
|
||||
public OwnerDTO findOwner(@PathVariable("ownerId") int ownerId) {
|
||||
return this.ownerService.findById(ownerId);
|
||||
OwnerDTO ownerDTO = ownerService.findById(ownerId);
|
||||
return ownerDTO;
|
||||
}
|
||||
|
||||
@InitBinder("owner")
|
||||
public void initOwnerBinder(WebDataBinder dataBinder) {
|
||||
dataBinder.setDisallowedFields(CommonAttribute.OWNER_ID);
|
||||
// dataBinder.setDisallowedFields(CommonAttribute.OWNER_ID);
|
||||
}
|
||||
|
||||
@InitBinder("pet")
|
||||
|
@ -125,7 +126,7 @@ class PetController extends WebSocketSender {
|
|||
return CommonView.PET_CREATE_OR_UPDATE;
|
||||
}
|
||||
else {
|
||||
pet.setOwner(owner);
|
||||
owner.addPet(pet);
|
||||
this.petService.save(pet);
|
||||
sendSuccessMessage(CommonWebSocket.PET_UPDATED);
|
||||
return CommonView.OWNER_OWNERS_ID_R;
|
||||
|
|
|
@ -59,8 +59,7 @@ public class UserController extends WebSocketSender {
|
|||
|
||||
@InitBinder("user")
|
||||
public void setAllowedFields(WebDataBinder dataBinder) {
|
||||
// dataBinder.setDisallowedFields(CommonAttribute.USER_ID,"roles");
|
||||
|
||||
dataBinder.setDisallowedFields(CommonAttribute.USER_ID,"roles");
|
||||
}
|
||||
|
||||
Map<String, String> oauth2AuthenticationUrls = new HashMap<>();
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package org.springframework.samples.petclinic.model.common;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
@Entity
|
||||
public class Privilege {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
@ManyToMany(mappedBy = "privileges")
|
||||
private Set<Role> roles;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Set<Role> getRoles() {
|
||||
return roles;
|
||||
}
|
||||
|
||||
public void setRoles(Set<Role> roles) {
|
||||
this.roles = roles;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,5 @@
|
|||
package org.springframework.samples.petclinic.model.common;
|
||||
|
||||
import org.springframework.beans.support.MutableSortDefinition;
|
||||
import org.springframework.beans.support.PropertyComparator;
|
||||
import org.springframework.samples.petclinic.common.CommonError;
|
||||
import org.springframework.samples.petclinic.common.CommonParameter;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
|
@ -12,7 +10,6 @@ import javax.persistence.*;
|
|||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import javax.validation.constraints.Size;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
|
||||
|
@ -21,7 +18,7 @@ import java.util.*;
|
|||
*
|
||||
* @author Paul-Emmanuel DOS SANTOS FACAO
|
||||
*/
|
||||
@Entity(name = "User")
|
||||
@Entity
|
||||
@Table(name = "users")
|
||||
public class User extends Person implements Serializable, UserDetails {
|
||||
|
||||
|
|
|
@ -123,9 +123,7 @@ public class PetService implements BaseService<Pet, PetDTO> {
|
|||
@Override
|
||||
public PetDTO save(PetDTO petDTO) {
|
||||
Pet pet = dtoToEntity(petDTO);
|
||||
Owner owner = pet.getOwner();
|
||||
pet = petRepository.save(pet);
|
||||
pet.setOwner(owner);
|
||||
|
||||
return entityToDTO(pet);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue