From e0cb4605302b9d04981158ff190b677ed40188f2 Mon Sep 17 00:00:00 2001 From: peremunoz Date: Wed, 13 Mar 2024 17:31:56 +0100 Subject: [PATCH] Add role to shelter volunteer --- .../eps/softarch/demo/domain/ShelterVolunteer.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/cat/udl/eps/softarch/demo/domain/ShelterVolunteer.java b/src/main/java/cat/udl/eps/softarch/demo/domain/ShelterVolunteer.java index 4656676b..60f8949a 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/domain/ShelterVolunteer.java +++ b/src/main/java/cat/udl/eps/softarch/demo/domain/ShelterVolunteer.java @@ -1,10 +1,17 @@ package cat.udl.eps.softarch.demo.domain; import com.fasterxml.jackson.annotation.JsonIdentityReference; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import jakarta.persistence.ElementCollection; import jakarta.persistence.Entity; import jakarta.persistence.ManyToOne; import lombok.Data; import lombok.EqualsAndHashCode; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.AuthorityUtils; + +import java.util.Collection; @EqualsAndHashCode(callSuper = true) @Data @@ -13,4 +20,11 @@ public class ShelterVolunteer extends User { @JsonIdentityReference(alwaysAsId = true) @ManyToOne private Shelter userShelter; + + @Override + @JsonValue(value = false) + @JsonProperty(access = JsonProperty.Access.READ_ONLY) + public Collection getAuthorities(){ + return AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_SHELTER_VOLUNTEER"); + } }