diff --git a/src/main/java/eu/dnetlib/dnetrolemanagement/controllers/AdminController.java b/src/main/java/eu/dnetlib/dnetrolemanagement/controllers/AdminController.java index 4d707e5..3d3cbfd 100644 --- a/src/main/java/eu/dnetlib/dnetrolemanagement/controllers/AdminController.java +++ b/src/main/java/eu/dnetlib/dnetrolemanagement/controllers/AdminController.java @@ -2,10 +2,9 @@ package eu.dnetlib.dnetrolemanagement.controllers; import com.google.gson.Gson; import com.google.gson.JsonArray; -import eu.dnetlib.dnetrolemanagement.dto.Response; -import eu.dnetlib.dnetrolemanagement.dto.User; +import eu.dnetlib.dnetrolemanagement.entities.Response; +import eu.dnetlib.dnetrolemanagement.entities.User; import eu.dnetlib.dnetrolemanagement.exception.UnprocessableException; -import eu.dnetlib.dnetrolemanagement.exception.ConflictException; import eu.dnetlib.dnetrolemanagement.exception.ResourceNotFoundException; import eu.dnetlib.dnetrolemanagement.services.RegistryService; import eu.dnetlib.dnetrolemanagement.utils.AuthoritiesUpdater; @@ -40,8 +39,8 @@ public class AdminController { * Get the user info of the managers of a type(Community, etc.) with id(ee, egi, etc.) */ @RequestMapping(value = "/{type}/{id}", method = RequestMethod.GET) - public ResponseEntity getInfos(@PathVariable("type") String type, @PathVariable("id") String id) { - Integer couId = registryService.getCouId(type, id); + public ResponseEntity getAll(@PathVariable("type") String type, @PathVariable("id") String id) { + Integer couId = registryService.getCouId(AuthoritiesUtils.memberRole(type, id)); if (couId != null) { JsonArray users = registryService.getUserIdByCouId(couId, true); JsonArray emails = registryService.getUserEmailByCouId(couId, true); @@ -55,18 +54,20 @@ public class AdminController { * Assign admin role to logged in user or user with @email */ @RequestMapping(value = "/{type}/{id}", method = RequestMethod.POST) - public ResponseEntity assignRole(@PathVariable("type") String type, @PathVariable("id") String id, @RequestParam(required = false) String email) { + public ResponseEntity assignRole(@PathVariable("type") String type, @PathVariable("id") String id, @RequestParam(required = false) String email, + @RequestParam(value = "force", defaultValue = "false") boolean force) { List coPersonIds = registryService.getCoPersonIdsByEmail(email); if (coPersonIds.size() > 0) { - Integer couId = registryService.getCouId(type, id); - if (couId != null) { + Integer temp = registryService.getCouId(AuthoritiesUtils.memberRole(type, id)); + if (temp != null || force) { + Integer couId = (temp != null)?temp:registryService.createRole(AuthoritiesUtils.memberRole(type, id), ""); AtomicBoolean assigned = new AtomicBoolean(false); coPersonIds.forEach(coPersonId -> { - if(assignRoleToAccount(coPersonId, couId, type, id)) { + if (assignRoleToAccount(coPersonId, couId, type, id, force)) { assigned.set(true); } }); - if(assigned.get()) { + if (assigned.get()) { return ResponseEntity.ok(new Response("Role has been assigned successfully")); } else { throw new UnprocessableException("User must be a member of this group and not already admin"); @@ -77,14 +78,20 @@ public class AdminController { throw new ResourceNotFoundException("User has not been found"); } - private boolean assignRoleToAccount(Integer coPersonId, Integer couId, String type, String id) { + private boolean assignRoleToAccount(Integer coPersonId, Integer couId, String type, String id, boolean force) { String identifier = registryService.getIdentifierByCoPersonId(coPersonId); Integer role = registryService.getRoleId(coPersonId, couId); - if (role != null) { + if (role != null || force) { + if(role == null) { + registryService.assignMemberRole(coPersonId,couId, role); + } if (registryService.getUserAdminGroup(coPersonId, couId) == null) { registryService.assignAdminRole(coPersonId, couId); authoritiesUpdater.update(identifier, old -> { HashSet authorities = new HashSet<>((Collection) old); + if(role == null) { + authorities.add(new SimpleGrantedAuthority(AuthoritiesUtils.member(type, id))); + } authorities.add(new SimpleGrantedAuthority(AuthoritiesUtils.manager(type, id))); return authorities; }); @@ -102,7 +109,7 @@ public class AdminController { public ResponseEntity removeRole(@PathVariable("type") String type, @PathVariable("id") String id, @RequestParam(required = false) String email) { List coPersonIds = registryService.getCoPersonIdsByEmail(email); if (coPersonIds.size() > 0) { - Integer couId = registryService.getCouId(type, id); + Integer couId = registryService.getCouId(AuthoritiesUtils.memberRole(type, id)); if (couId != null) { coPersonIds.forEach(coPersonId -> { registryService.removeAdminRole(coPersonId, couId); @@ -121,12 +128,12 @@ public class AdminController { } - /** + /* *//** * Get the names of the managers of a type(Community, etc.) with id(ee, egi, etc.) - */ + *//* @RequestMapping(value = "/{type}/{id}/name", method = RequestMethod.GET) public ResponseEntity getNames(@PathVariable("type") String type, @PathVariable("id") String id) { - Integer couId = registryService.getCouId(type, id); + Integer couId = registryService.getCouId(AuthoritiesUtils.memberRole(type, id)); if (couId != null) { JsonArray users = registryService.getUserNamesByCouId(couId, true); return ResponseEntity.ok(gson.fromJson(users, User[].class)); @@ -135,12 +142,12 @@ public class AdminController { } - /** + *//** * Get the Identifiers of the managers of a type(Community, etc.) with id(ee, egi, etc.) - */ + *//* @RequestMapping(value = "/{type}/{id}/id", method = RequestMethod.GET) public ResponseEntity getIds(@PathVariable("type") String type, @PathVariable("id") String id) { - Integer couId = registryService.getCouId(type, id); + Integer couId = registryService.getCouId(AuthoritiesUtils.memberRole(type, id)); if (couId != null) { JsonArray users = registryService.getUserIdByCouId(couId, true); return ResponseEntity.ok(gson.fromJson(users, User[].class)); @@ -148,18 +155,18 @@ public class AdminController { throw new ResourceNotFoundException("Role has not been found"); } - /** + *//** * Get the emails of the managers of a type(Community, etc.) with id(ee, egi, etc.) - */ + *//* @RequestMapping(value = "/{type}/{id}/email", method = RequestMethod.GET) public ResponseEntity getEmails(@PathVariable("type") String type, @PathVariable("id") String id) { - Integer couId = registryService.getCouId(type, id); + Integer couId = registryService.getCouId(AuthoritiesUtils.memberRole(type, id)); if (couId != null) { JsonArray users = registryService.getUserEmailByCouId(couId, true); return ResponseEntity.ok(gson.fromJson(users, User[].class)); } throw new ResourceNotFoundException("Role has not been found"); - } + }*/ } diff --git a/src/main/java/eu/dnetlib/dnetrolemanagement/controllers/CuratorController.java b/src/main/java/eu/dnetlib/dnetrolemanagement/controllers/CuratorController.java new file mode 100644 index 0000000..202fa46 --- /dev/null +++ b/src/main/java/eu/dnetlib/dnetrolemanagement/controllers/CuratorController.java @@ -0,0 +1,123 @@ +package eu.dnetlib.dnetrolemanagement.controllers; + +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import eu.dnetlib.dnetrolemanagement.entities.Response; +import eu.dnetlib.dnetrolemanagement.entities.Role; +import eu.dnetlib.dnetrolemanagement.entities.User; +import eu.dnetlib.dnetrolemanagement.exception.ConflictException; +import eu.dnetlib.dnetrolemanagement.exception.ResourceNotFoundException; +import eu.dnetlib.dnetrolemanagement.exception.UnprocessableException; +import eu.dnetlib.dnetrolemanagement.services.RegistryService; +import eu.dnetlib.dnetrolemanagement.utils.AuthoritiesUpdater; +import eu.dnetlib.dnetrolemanagement.utils.AuthoritiesUtils; +import eu.dnetlib.dnetrolemanagement.utils.JsonUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.web.bind.annotation.*; + +import java.util.Collection; +import java.util.HashSet; +import java.util.List; + +@RestController +@RequestMapping("/curator") +public class CuratorController { + + private final RegistryService registryService; + private final AuthoritiesUpdater authoritiesUpdater; + private final Gson gson; + + @Autowired + public CuratorController(RegistryService registryService, AuthoritiesUpdater authoritiesUpdater) { + this.registryService = registryService; + this.authoritiesUpdater = authoritiesUpdater; + this.gson = new Gson(); + } + + /** + * Create a new role (only for admins) + */ + @RequestMapping(value = "/create", method = RequestMethod.POST) + public ResponseEntity createRole(@RequestBody Role role) { + if (registryService.getCouId(role.getName()) == null) { + if (registryService.createRole(role.getName(), role.getDescription()) != null) { + return ResponseEntity.ok(new Response("Role has been created successfully")); + } else { + throw new UnprocessableException("Role creation failed. Try again later"); + } + } else { + throw new ConflictException("This role already exists"); + } + } + + /** + * Get the user info of the curators of a type(Community, etc.) + */ + @RequestMapping(value = "/{type}", method = RequestMethod.GET) + public ResponseEntity getAll(@PathVariable("type") String type) { + Integer couId = registryService.getCouId(AuthoritiesUtils.curatorRole(type)); + if (couId != null) { + JsonArray users = registryService.getUserIdByCouId(couId, false); + JsonArray emails = registryService.getUserEmailByCouId(couId, false); + JsonArray names = registryService.getUserNamesByCouId(couId, false); + return ResponseEntity.ok(JsonUtils.mergeUserInfo(users, emails, names, gson)); + } + throw new ResourceNotFoundException("Role has not been found"); + } + + /** + * Assign curator role to logged in user or user with @email + */ + @RequestMapping(value = "/{type}", method = RequestMethod.POST) + public ResponseEntity assignRole(@PathVariable("type") String type, @RequestParam(required = false) String email, + @RequestParam(value = "force", defaultValue = "false") boolean force) { + List coPersonIds = registryService.getCoPersonIdsByEmail(email); + if (coPersonIds.size() > 0) { + Integer temp = registryService.getCouId(AuthoritiesUtils.curatorRole(type).toLowerCase()); + if (temp != null || force) { + Integer couId = (temp != null)?temp:registryService.createRole(AuthoritiesUtils.curatorRole(type), ""); + coPersonIds.forEach(coPersonId -> { + String identifier = registryService.getIdentifierByCoPersonId(coPersonId); + Integer role = registryService.getRoleId(coPersonId, couId); + registryService.assignMemberRole(coPersonId, couId, role); + authoritiesUpdater.update(identifier, old -> { + HashSet authorities = new HashSet<>((Collection) old); + authorities.add(new SimpleGrantedAuthority(AuthoritiesUtils.curator(type))); + return authorities; + }); + }); + return ResponseEntity.ok(new Response("Role has been assigned successfully")); + } + throw new ResourceNotFoundException("Role has not been found"); + } + throw new ResourceNotFoundException("User has not been found"); + } + + /** + * Remove curator role from logged in user or user with @email + */ + @RequestMapping(value = "/{type}", method = RequestMethod.DELETE) + public ResponseEntity removeRole(@PathVariable("type") String type, @RequestParam(required = false) String email) { + List coPersonIds = registryService.getCoPersonIdsByEmail(email); + if (coPersonIds.size() > 0) { + Integer couId = registryService.getCouId(AuthoritiesUtils.curatorRole(type).toLowerCase()); + if (couId != null) { + coPersonIds.forEach(coPersonId -> { + String identifier = registryService.getIdentifierByCoPersonId(coPersonId); + Integer role = registryService.getRoleId(coPersonId, couId); + registryService.removeMemberRole(coPersonId, couId, role); + authoritiesUpdater.update(identifier, old -> { + HashSet authorities = new HashSet<>((Collection) old); + authorities.remove(new SimpleGrantedAuthority(AuthoritiesUtils.curator(type))); + return authorities; + }); + }); + return ResponseEntity.ok(new Response("Role has been revoked successfully")); + } + throw new ResourceNotFoundException("Role has not been found"); + } + throw new ResourceNotFoundException("User has not been found"); + } +} diff --git a/src/main/java/eu/dnetlib/dnetrolemanagement/controllers/MemberController.java b/src/main/java/eu/dnetlib/dnetrolemanagement/controllers/MemberController.java index 4ee9e9e..130b63a 100644 --- a/src/main/java/eu/dnetlib/dnetrolemanagement/controllers/MemberController.java +++ b/src/main/java/eu/dnetlib/dnetrolemanagement/controllers/MemberController.java @@ -2,8 +2,10 @@ package eu.dnetlib.dnetrolemanagement.controllers; import com.google.gson.Gson; import com.google.gson.JsonArray; -import eu.dnetlib.dnetrolemanagement.dto.Response; -import eu.dnetlib.dnetrolemanagement.dto.User; +import eu.dnetlib.dnetrolemanagement.entities.Response; +import eu.dnetlib.dnetrolemanagement.entities.Role; +import eu.dnetlib.dnetrolemanagement.entities.User; +import eu.dnetlib.dnetrolemanagement.exception.ConflictException; import eu.dnetlib.dnetrolemanagement.exception.ResourceNotFoundException; import eu.dnetlib.dnetrolemanagement.exception.UnprocessableException; import eu.dnetlib.dnetrolemanagement.services.RegistryService; @@ -11,13 +13,12 @@ import eu.dnetlib.dnetrolemanagement.utils.AuthoritiesUpdater; import eu.dnetlib.dnetrolemanagement.utils.AuthoritiesUtils; import eu.dnetlib.dnetrolemanagement.utils.JsonUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.web.bind.annotation.*; import java.util.Collection; -import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.stream.Collectors; @@ -38,12 +39,13 @@ public class MemberController { } + /** * Get the user info of the members of a type(Community, etc.) with id(ee, egi, etc.) */ @RequestMapping(value = "/{type}/{id}", method = RequestMethod.GET) - public ResponseEntity getInfos(@PathVariable("type") String type, @PathVariable("id") String id) { - Integer couId = registryService.getCouId(type, id); + public ResponseEntity getAll(@PathVariable("type") String type, @PathVariable("id") String id) { + Integer couId = registryService.getCouId(AuthoritiesUtils.memberRole(type, id)); if (couId != null) { JsonArray users = registryService.getUserIdByCouId(couId, false); JsonArray emails = registryService.getUserEmailByCouId(couId, false); @@ -57,11 +59,13 @@ public class MemberController { * Assign member role to logged in user or user with @email */ @RequestMapping(value = "/{type}/{id}", method = RequestMethod.POST) - public ResponseEntity assignRole(@PathVariable("type") String type, @PathVariable("id") String id, @RequestParam(required = false) String email) { + public ResponseEntity assignRole(@PathVariable("type") String type, @PathVariable("id") String id, @RequestParam(required = false) String email, + @RequestParam(value = "force", defaultValue = "false") boolean force) { List coPersonIds = registryService.getCoPersonIdsByEmail(email); if (coPersonIds.size() > 0) { - Integer couId = registryService.getCouId(type, id); - if (couId != null) { + Integer temp = registryService.getCouId(AuthoritiesUtils.memberRole(type, id)); + if (temp != null || force) { + Integer couId = (temp != null)?temp:registryService.createRole(AuthoritiesUtils.memberRole(type, id), ""); coPersonIds.forEach(coPersonId -> { String identifier = registryService.getIdentifierByCoPersonId(coPersonId); Integer role = registryService.getRoleId(coPersonId, couId); @@ -83,26 +87,33 @@ public class MemberController { * Remove member role from logged in user or user with @email */ @RequestMapping(value = "/{type}/{id}", method = RequestMethod.DELETE) - public ResponseEntity removeRole(@PathVariable("type") String type, @PathVariable("id") String id, @RequestParam(required = false) String email) { + public ResponseEntity removeRole(@PathVariable("type") String type, @PathVariable("id") String id, @RequestParam(required = false) String email, + @RequestParam(value = "force", defaultValue = "false") boolean force) { List coPersonIds = registryService.getCoPersonIdsByEmail(email); if (coPersonIds.size() > 0) { - Integer couId = registryService.getCouId(type, id); + Integer couId = registryService.getCouId(AuthoritiesUtils.memberRole(type, id)); if (couId != null) { // If none of the accounts has admin role for this group remove member role - if (coPersonIds.stream().filter(coPersonId -> registryService.getUserAdminGroup(coPersonId, couId) != null).collect(Collectors.toList()).size() == 0) { + if (force || coPersonIds.stream().noneMatch(coPersonId -> registryService.getUserAdminGroup(coPersonId, couId) != null)) { coPersonIds.forEach(coPersonId -> { String identifier = registryService.getIdentifierByCoPersonId(coPersonId); Integer role = registryService.getRoleId(coPersonId, couId); + if(force) { + registryService.removeAdminRole(coPersonId, couId); + } registryService.removeMemberRole(coPersonId, couId, role); authoritiesUpdater.update(identifier, old -> { HashSet authorities = new HashSet<>((Collection) old); + if(force) { + authorities.remove(new SimpleGrantedAuthority(AuthoritiesUtils.manager(type, id))); + } authorities.remove(new SimpleGrantedAuthority(AuthoritiesUtils.member(type, id))); return authorities; }); }); return ResponseEntity.ok(new Response("Role has been revoked successfully")); } - throw new UnprocessableException("User is admin of this group, so you must remove admin role first instead of member role"); + throw new UnprocessableException("Remove admin role first"); } throw new ResourceNotFoundException("Role has not been found"); } @@ -110,12 +121,12 @@ public class MemberController { } - /** +/* *//** * Get the names of the members of a type(Community, etc.) with id(ee, egi, etc.) - */ + *//* @RequestMapping(value = "/{type}/{id}/name", method = RequestMethod.GET) public ResponseEntity getNames(@PathVariable("type") String type, @PathVariable("id") String id) { - Integer couId = registryService.getCouId(type, id); + Integer couId = registryService.getCouId(AuthoritiesUtils.memberRole(type, id)); if (couId != null) { JsonArray users = registryService.getUserNamesByCouId(couId, false); return ResponseEntity.ok(gson.fromJson(users, User[].class)); @@ -123,12 +134,12 @@ public class MemberController { throw new ResourceNotFoundException("Role has not been found"); } - /** + *//** * Get the Identifiers of the members of a type(Community, etc.) with id(ee, egi, etc.) - */ + *//* @RequestMapping(value = "/{type}/{id}/id", method = RequestMethod.GET) public ResponseEntity getIds(@PathVariable("type") String type, @PathVariable("id") String id) { - Integer couId = registryService.getCouId(type, id); + Integer couId = registryService.getCouId(AuthoritiesUtils.memberRole(type, id)); if (couId != null) { JsonArray users = registryService.getUserIdByCouId(couId, false); return ResponseEntity.ok(gson.fromJson(users, User[].class)); @@ -136,16 +147,16 @@ public class MemberController { throw new ResourceNotFoundException("Role has not been found"); } - /** + *//** * Get the emails of the members of a type(Community, etc.) with id(ee, egi, etc.) - */ + *//* @RequestMapping(value = "/{type}/{id}/email", method = RequestMethod.GET) public ResponseEntity getEmails(@PathVariable("type") String type, @PathVariable("id") String id) { - Integer couId = registryService.getCouId(type, id); + Integer couId = registryService.getCouId(AuthoritiesUtils.memberRole(type, id)); if (couId != null) { JsonArray users = registryService.getUserEmailByCouId(couId, false); return ResponseEntity.ok(gson.fromJson(users, User[].class)); } throw new ResourceNotFoundException("Role has not been found"); - } + }*/ } diff --git a/src/main/java/eu/dnetlib/dnetrolemanagement/dto/Response.java b/src/main/java/eu/dnetlib/dnetrolemanagement/entities/Response.java similarity index 85% rename from src/main/java/eu/dnetlib/dnetrolemanagement/dto/Response.java rename to src/main/java/eu/dnetlib/dnetrolemanagement/entities/Response.java index c5ebd51..77998f8 100644 --- a/src/main/java/eu/dnetlib/dnetrolemanagement/dto/Response.java +++ b/src/main/java/eu/dnetlib/dnetrolemanagement/entities/Response.java @@ -1,4 +1,4 @@ -package eu.dnetlib.dnetrolemanagement.dto; +package eu.dnetlib.dnetrolemanagement.entities; public class Response { diff --git a/src/main/java/eu/dnetlib/dnetrolemanagement/entities/Role.java b/src/main/java/eu/dnetlib/dnetrolemanagement/entities/Role.java new file mode 100644 index 0000000..b337d4b --- /dev/null +++ b/src/main/java/eu/dnetlib/dnetrolemanagement/entities/Role.java @@ -0,0 +1,29 @@ +package eu.dnetlib.dnetrolemanagement.entities; + +public class Role { + String name; + String description; + + public Role() {} + + public Role(String name, String description) { + this.name = name; + this.description = description; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/src/main/java/eu/dnetlib/dnetrolemanagement/dto/User.java b/src/main/java/eu/dnetlib/dnetrolemanagement/entities/User.java similarity index 93% rename from src/main/java/eu/dnetlib/dnetrolemanagement/dto/User.java rename to src/main/java/eu/dnetlib/dnetrolemanagement/entities/User.java index 3fb4386..8ee91f7 100644 --- a/src/main/java/eu/dnetlib/dnetrolemanagement/dto/User.java +++ b/src/main/java/eu/dnetlib/dnetrolemanagement/entities/User.java @@ -1,4 +1,4 @@ -package eu.dnetlib.dnetrolemanagement.dto; +package eu.dnetlib.dnetrolemanagement.entities; public class User { diff --git a/src/main/java/eu/dnetlib/dnetrolemanagement/services/RegistryService.java b/src/main/java/eu/dnetlib/dnetrolemanagement/services/RegistryService.java index 60026e1..aa8460c 100644 --- a/src/main/java/eu/dnetlib/dnetrolemanagement/services/RegistryService.java +++ b/src/main/java/eu/dnetlib/dnetrolemanagement/services/RegistryService.java @@ -128,17 +128,6 @@ public class RegistryService { return null; } - /** - * 4.2 Get a couId by type.id with/without mapping type - * - * @param type - * @param id - * @return - */ - public Integer getCouId(String type, String id) { - return getCouId(type + "." + id); - } - /** * 5. Get User non admin roles */ diff --git a/src/main/java/eu/dnetlib/dnetrolemanagement/utils/AuthoritiesUtils.java b/src/main/java/eu/dnetlib/dnetrolemanagement/utils/AuthoritiesUtils.java index 05aa33c..593c587 100644 --- a/src/main/java/eu/dnetlib/dnetrolemanagement/utils/AuthoritiesUtils.java +++ b/src/main/java/eu/dnetlib/dnetrolemanagement/utils/AuthoritiesUtils.java @@ -7,33 +7,40 @@ import org.springframework.security.core.context.SecurityContextHolder; public class AuthoritiesUtils { /** - * Type = FUNDER | COMMUNITY | INSTITUTION | PROJECT - * - * */ + * Type = FUNDER | COMMUNITY | INSTITUTION | PROJECT etc. + */ public static String curator(String type) { return "CURATOR_" + type.toUpperCase(); } + public static String curatorRole(String type) { + return "Curator - " + Character.toString(type.charAt(0)).toUpperCase() + type.substring(1); + } + /** - * Type = FUNDER | COMMUNITY | INSTITUTION | PROJECT - * + * Type = FUNDER | COMMUNITY | INSTITUTION | PROJECT etc. + *

* Id = EE, EGI, etc - * */ + */ public static String manager(String type, String id) { return type.toUpperCase() + "_" + id.toUpperCase() + "_MANAGER"; } /** - * Type = FUNDER | COMMUNITY | RI | INSTITUTION | PROJECT - * + * Type = FUNDER | COMMUNITY | RI | INSTITUTION | PROJECT etc. + *

* Id = EE, EGI, etc - * */ + */ public static String member(String type, String id) { return type.toUpperCase() + "_" + id.toUpperCase(); } + public static String memberRole(String type, String id) { + return type + "." + id; + } + public static String getAaiId() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - return authentication instanceof OIDCAuthenticationToken ? ((OIDCAuthenticationToken)authentication).getSub() : null; + return authentication instanceof OIDCAuthenticationToken ? ((OIDCAuthenticationToken) authentication).getSub() : null; } } diff --git a/src/main/java/eu/dnetlib/dnetrolemanagement/utils/JsonUtils.java b/src/main/java/eu/dnetlib/dnetrolemanagement/utils/JsonUtils.java index 1003e65..aa320d8 100644 --- a/src/main/java/eu/dnetlib/dnetrolemanagement/utils/JsonUtils.java +++ b/src/main/java/eu/dnetlib/dnetrolemanagement/utils/JsonUtils.java @@ -5,7 +5,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import eu.dnetlib.dnetrolemanagement.config.properties.RegistryProperties; -import eu.dnetlib.dnetrolemanagement.dto.User; +import eu.dnetlib.dnetrolemanagement.entities.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component;