[Users | Trunk]: Add communityMap boolean on mapType. Registered Service: Security level hint

This commit is contained in:
Konstantinos Triantafyllou 2021-01-28 14:40:31 +00:00
parent c7e62e2734
commit 4ef435f514
4 changed files with 57 additions and 22 deletions

View File

@ -120,8 +120,12 @@ public class RegistryService {
@Consumes(MediaType.APPLICATION_JSON)
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
public Response createRole(@RequestBody Role role) {
calls.createRole(role);
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse("Role has been created").toString()).type(MediaType.APPLICATION_JSON).build();
if(calls.getCouId(role.getName()) == null) {
calls.createRole(role);
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse("Role has been created").toString()).type(MediaType.APPLICATION_JSON).build();
} else {
return Response.status(HttpStatus.CONFLICT.value()).entity(jsonUtils.createResponse("Role has already existed").toString()).type(MediaType.APPLICATION_JSON).build();
}
}
/**
@ -162,7 +166,7 @@ public class RegistryService {
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN, " +
"@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
public Response inviteMember(@PathParam("type") String type, @PathParam("id") String id, @RequestBody String body) {
Integer couId = calls.getCouId(type, id);
Integer couId = calls.getCouId(type, id, false);
if (couId != null) {
JsonObject details = new JsonParser().parse(body).getAsJsonObject();
JsonObject email = details.get("email").getAsJsonObject();
@ -224,7 +228,7 @@ public class RegistryService {
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN, " +
"@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
public Response cancelMemberInvitations(@PathParam("type") String type, @PathParam("id") String id, @PathParam("email") String email) {
Integer couId = calls.getCouId(type, id);
Integer couId = calls.getCouId(type, id, false);
if (couId != null) {
verificationUtils.deleteMemberVerifications(email, type, id);
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse("Invitations have been deleted").toString()).type(MediaType.APPLICATION_JSON).build();
@ -360,7 +364,7 @@ public class RegistryService {
if (coPersonId != null) {
if (coPersonId.equals(calls.getCoPersonIdByIdentifier())) {
if (verification.getVerificationCode().equals(code)) {
Integer couId = calls.getCouId(verification.getType(), verification.getEntity());
Integer couId = calls.getCouId(verification.getType(), verification.getEntity(), false);
if (couId != null) {
Integer role = calls.getRoleId(coPersonId, couId);
calls.assignMemberRole(coPersonId, couId, role);
@ -429,7 +433,7 @@ public class RegistryService {
id, @PathParam("email") String email) {
Integer coPersonId = calls.getCoPersonIdByEmail(email);
if (coPersonId != null) {
Integer couId = calls.getCouId(type, id);
Integer couId = calls.getCouId(type, id, false);
Integer role = null;
if(couId != null) {
role = calls.getRoleId(coPersonId, couId);
@ -461,7 +465,7 @@ public class RegistryService {
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN," +
"@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
public Response getMembers(@PathParam("type") String type, @PathParam("id") String id) {
Integer couId = calls.getCouId(type, id);
Integer couId = calls.getCouId(type, id,false);
if(couId != null) {
JsonArray members = calls.getUserNamesByCouId(couId, false);
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(members).toString()).type(MediaType.APPLICATION_JSON).build();
@ -479,7 +483,7 @@ public class RegistryService {
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN," +
"@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
public Response getMembersEmail(@PathParam("type") String type, @PathParam("id") String id) {
Integer couId = calls.getCouId(type, id);
Integer couId = calls.getCouId(type, id, false);
if(couId != null) {
JsonArray members = calls.getUserEmailByCouId(couId, false);
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(members).toString()).type(MediaType.APPLICATION_JSON).build();
@ -495,7 +499,7 @@ public class RegistryService {
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getMembersCount(@PathParam("type") String type, @PathParam("id") String id) {
Integer couId = calls.getCouId(type, id);
Integer couId = calls.getCouId(type, id, false);
int count = 0;
if(couId != null) {
count = calls.getUserNamesByCouId(couId, false).size();

View File

@ -6,12 +6,13 @@ import org.springframework.stereotype.Component;
public class AuthorizationService {
public final String PORTAL_ADMIN = "PORTAL_ADMINISTRATOR";
public final String ANONYMOUS_USER = "ROLE_ANONYMOUS";
public final String REGISTERED_USER = "REGISTERED_USER";
private String mapType(String type) {
private String mapType(String type, boolean communityMap) {
if(type.equals("organization")) {
type = "institution";
}
if(type.equals("ri")) {
} else if(type.equals("ri") && communityMap) {
type = "community";
}
return type;
@ -22,7 +23,7 @@ public class AuthorizationService {
*
* */
public String curator(String type) {
return "CURATOR_" + mapType(type).toUpperCase();
return "CURATOR_" + mapType(type, true).toUpperCase();
}
/**
@ -31,19 +32,19 @@ public class AuthorizationService {
* Id = EE, EGI, etc
* */
public String manager(String type, String id) {
return mapType(type).toUpperCase() + "_" + id.toUpperCase() + "_MANAGER";
return mapType(type, true).toUpperCase() + "_" + id.toUpperCase() + "_MANAGER";
}
/**
* Type = FUNDER | COMMUNITY | INSTITUTION | PROJECT
* Type = FUNDER | COMMUNITY | RI | INSTITUTION | PROJECT
*
* Id = EE, EGI, etc
* */
public String member(String type, String id) {
return mapType(type).toUpperCase() + "_" + id.toUpperCase();
return mapType(type, false).toUpperCase() + "_" + id.toUpperCase();
}
public boolean isCommunity(String type) {
return mapType(type).equals("community");
return mapType(type, false).equals("community");
}
}

View File

@ -29,11 +29,10 @@ public class RegistryCalls {
public JsonUtils jsonUtils;
private String mapType(String type) {
private String mapType(String type, boolean communityMap) {
if(type.equals("organization")) {
type = "institution";
}
if(type.equals("ri")) {
} else if(type.equals("ri") && communityMap) {
type = "community";
}
return type;
@ -107,6 +106,23 @@ public class RegistryCalls {
return (response != null) ? response.getAsJsonObject().get("Cous").getAsJsonArray() : new JsonArray();
}
/**
* 4. Get a couId by name
*
* @param name
* @return
*/
public Integer getCouId(String name) {
JsonArray cous = getCous();
Integer couId = null;
for (JsonElement cou : cous) {
if (cou.getAsJsonObject().get("Name").getAsString().equals(name)) {
couId = cou.getAsJsonObject().get("Id").getAsInt();
}
}
return couId;
}
/**
* 4. Get a couId by type.id
*
@ -115,10 +131,22 @@ public class RegistryCalls {
* @return
*/
public Integer getCouId(String type, String id) {
return getCouId(type, id, true);
}
/**
* 4. Get a couId by type.id without mapping type
*
* @param type
* @param id
* @return
*/
public Integer getCouId(String type, String id, boolean communityMap) {
JsonArray cous = getCous();
Integer couId = null;
for (JsonElement cou : cous) {
if (cou.getAsJsonObject().get("Name").getAsString().equals(mapType(type) + "." + id)) {
if (cou.getAsJsonObject().get("Name").getAsString().equals(mapType(type, communityMap) + "." + id)) {
couId = cou.getAsJsonObject().get("Id").getAsInt();
}
}

View File

@ -88,7 +88,7 @@
</div>
<div class="uk-margin-medium-top">
<label class="uk-form-label uk-text-bold">Security level</label>
<div class="uk-margin">Security level hint</div>
<div id="security-hint" class="uk-margin"></div>
<div class="uk-margin-small-top">
<span class="uk-margin-small-right">
<input id="basic" class="uk-radio uk-margin-small-right" type="radio"
@ -220,8 +220,10 @@
function checkRadio() {
var securityLevel = $('input[type=radio][name=security_level]:checked').val();
if(securityLevel === 'basic') {
$("#security-hint").html('Basic Security level hint');
$("#public-key").hide();
} else {
$("#security-hint").html('Advanced Security level hint');
var keyType = $('input[type=radio][name=key_type]:checked').val();
$("#public-key").show();
if (keyType === 'uri') {