diff options
author | st782s <statta@research.att.com> | 2018-11-20 07:31:32 -0500 |
---|---|---|
committer | st782s <statta@research.att.com> | 2018-11-20 07:31:32 -0500 |
commit | 7246eabfd23d6cadc9f658f666df62b93f30ed70 (patch) | |
tree | f60963a0eb52e3bf645491afa5c6ed9477dc28c7 /ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPIProxy.java | |
parent | ace477c7097f4dc48498916ba2e024a81513ed93 (diff) |
CADI Integration
Issue-ID: PORTAL-474
System to system authorization using CADI
Change-Id: I76487f8155a36fca8283669fe5e28ec7d5aec91d
Signed-off-by: st782s <statta@research.att.com>
Diffstat (limited to 'ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPIProxy.java')
-rw-r--r-- | ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPIProxy.java | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPIProxy.java b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPIProxy.java index 1ce03146..71f66168 100644 --- a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPIProxy.java +++ b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPIProxy.java @@ -43,8 +43,13 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.StringWriter; +import java.util.Arrays; +import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.TreeSet; +import java.util.stream.Collectors; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; @@ -60,6 +65,7 @@ import org.onap.portalsdk.core.onboarding.rest.RestWebServiceClient; import org.onap.portalsdk.core.onboarding.util.PortalApiConstants; import org.onap.portalsdk.core.onboarding.util.PortalApiProperties; import org.onap.portalsdk.core.restful.domain.EcompRole; +import org.onap.portalsdk.core.restful.domain.EcompRoleFunction; import org.onap.portalsdk.core.restful.domain.EcompUser; import org.owasp.esapi.ESAPI; @@ -146,6 +152,8 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer response.getWriter().write(buildJsonResponse(false, "Misconfigured - no instance of service class")); return; } + + String requestUri = request.getRequestURI(); String responseJson = ""; String storeAnalyticsContextPath = "/storeAnalytics"; @@ -217,6 +225,7 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer writeAndFlush(response, APPLICATION_JSON, buildJsonResponse(false, "Not authorized")); return; } + try { String requestBody = readRequestBody(request); @@ -264,6 +273,9 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer if (requestUri.endsWith(PortalApiConstants.API_PREFIX + "/user")) { try { EcompUser user = mapper.readValue(requestBody, EcompUser.class); + logger.debug("doPost: create user requestbody: "+ requestBody); + Set<EcompRole> userEcompRoles = getEcompRolesOfUser(user); + user.setRoles(userEcompRoles); pushUser(user); if (logger.isDebugEnabled()) logger.debug("doPost: pushUser: success"); @@ -280,6 +292,9 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer String loginId = requestUri.substring(requestUri.lastIndexOf('/') + 1); try { EcompUser user = mapper.readValue(requestBody, EcompUser.class); + logger.debug("doPost: update user requestbody: "+ requestBody); + Set<EcompRole> userEcompRoles = getEcompRolesOfUser(user); + user.setRoles(userEcompRoles); editUser(loginId, user); if (logger.isDebugEnabled()) logger.debug("doPost: editUser: success"); @@ -342,6 +357,7 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer buildJsonResponse(false, "Misconfigured - no instance of service class")); return; } + String requestUri = request.getRequestURI(); String contentType = APPLICATION_JSON; @@ -413,7 +429,6 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer writeAndFlush(response, APPLICATION_JSON, buildJsonResponse(false, "Not authorized")); return; } - String responseJson = null; try { // Ignore any request body in a GET. @@ -683,4 +698,45 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer return portalRestApiServiceImpl.getCredentials(); } + private Set<EcompRole> getEcompRolesOfUser(EcompUser user) throws JsonProcessingException + { + + Set<EcompRole> userEcompRoles = new TreeSet<>(); + Set<EcompRole> ecompRoles = user.getRoles(); + for (EcompRole role : ecompRoles) { + Set roleFunctions = role.getRoleFunctions(); + Iterator<EcompRoleFunction> roleIter = roleFunctions.iterator(); + ObjectMapper mapper = new ObjectMapper(); + Set<EcompRoleFunction> EcompRoleFunctions = new TreeSet<>(); + while (roleIter.hasNext()) { + String str = mapper.writeValueAsString(roleIter.next()); + + String str1 = str.substring(1, str.length() - 1); + Map<String, String> result = Arrays.stream(str1.split(",")).map(s -> s.split(":")) + .collect(Collectors.toMap(a -> a[0], // key + a -> a[1] // value + )); + + EcompRoleFunction roleFunction = new EcompRoleFunction(); + for (Map.Entry<String, String> set : result.entrySet()) { + String key = set.getKey().replaceAll("\"", " ").trim(); + if (!key.isEmpty() && key.equalsIgnoreCase("action")) { + roleFunction.setAction(set.getValue().replaceAll("\"", " ").trim()); + } else if (!key.isEmpty() && key.equalsIgnoreCase("type")) { + roleFunction.setType(set.getValue().replaceAll("\"", " ").trim()); + + } else if (!key.isEmpty() && key.equalsIgnoreCase("code")) { + roleFunction.setCode(set.getValue().replaceAll("\"", " ").trim()); + + } else if (!key.isEmpty() && key.equalsIgnoreCase("name")) { + roleFunction.setName(set.getValue().replaceAll("\"", " ").trim()); + } + } + EcompRoleFunctions.add(roleFunction); + } + role.setRoleFunctions(EcompRoleFunctions); + userEcompRoles.add(role); + } + return userEcompRoles; + } } |