diff options
Diffstat (limited to 'openecomp-be/lib')
4 files changed, 101 insertions, 58 deletions
diff --git a/openecomp-be/lib/openecomp-common-lib/pom.xml b/openecomp-be/lib/openecomp-common-lib/pom.xml index 96218d396e..87f0482b80 100644 --- a/openecomp-be/lib/openecomp-common-lib/pom.xml +++ b/openecomp-be/lib/openecomp-common-lib/pom.xml @@ -48,6 +48,11 @@ <groupId>org.apache.commons</groupId> <artifactId>commons-text</artifactId> </dependency> + <dependency> + <groupId>com.amdocs.zusammen</groupId> + <artifactId>zusammen-datatypes</artifactId> + <version>${zusammen.version}</version> + </dependency> </dependencies> </project> diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java index 0bf8796910..61fae7d15f 100644 --- a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java +++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java @@ -39,6 +39,11 @@ public enum Messages { PERMISSIONS_ERROR("Permissions Error. The user does not have permission to perform this action."), PERMISSIONS_OWNER_ERROR("Permissions Error. Only one owner is allowed."), + ENTITY_NOT_FOUND("Incorrect item/version details provided."), + SUB_ENTITY_NOT_FOUND("Incorrect sub entity details provided."), + FAILED_TO_SYNC("Non existing version cannot be synced."), + FAILED_TO_PUBLISH_OUT_OF_SYNC("Publish is not allowed since the version status is Out of sync"), + DELETE_VSP_ERROR("VSP has been certified and cannot be deleted."), DELETE_VLM_ERROR("VLM has been certified and cannot be deleted."), diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/util/UniqueValueUtil.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/util/UniqueValueUtil.java index 86c3d64d59..0ba7228cce 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/util/UniqueValueUtil.java +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/util/UniqueValueUtil.java @@ -16,6 +16,9 @@ package org.openecomp.core.util; +import java.util.Optional; + +import org.apache.commons.lang3.ArrayUtils; import org.openecomp.core.dao.UniqueValueDao; import org.openecomp.core.dao.types.UniqueValueEntity; import org.openecomp.core.utilities.CommonMethods; @@ -23,8 +26,6 @@ import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.common.errors.ErrorCategory; import org.openecomp.sdc.common.errors.ErrorCode; -import java.util.Optional; - public class UniqueValueUtil { private static final String UNIQUE_VALUE_VIOLATION = "UNIQUE_VALUE_VIOLATION"; @@ -44,10 +45,16 @@ public class UniqueValueUtil { * @param uniqueCombination the unique combination */ public void createUniqueValue(String type, String... uniqueCombination) { - formatValue(uniqueCombination).ifPresent(formattedValue -> { - validateUniqueValue(type, formattedValue, uniqueCombination); - uniqueValueDao.create(new UniqueValueEntity(type, formattedValue)); - }); + String originalEntityName = null; + if (ArrayUtils.isNotEmpty(uniqueCombination)) { + originalEntityName = uniqueCombination[uniqueCombination.length - 1]; + } + + Optional<String> formattedValue = formatValue(uniqueCombination); + if (formattedValue.isPresent()) { + validateUniqueValue(type, formattedValue.get(), originalEntityName); + uniqueValueDao.create(new UniqueValueEntity(type, formattedValue.get())); + } } /** @@ -85,8 +92,15 @@ public class UniqueValueUtil { * @param uniqueCombination the unique combination */ public void validateUniqueValue(String type, String... uniqueCombination) { - formatValue(uniqueCombination) - .ifPresent(formattedValue -> validateUniqueValue(type, formattedValue, uniqueCombination)); + String originalEntityName = null; + if (ArrayUtils.isNotEmpty(uniqueCombination)) { + originalEntityName = uniqueCombination[uniqueCombination.length - 1]; + } + + Optional<String> formattedValue = formatValue(uniqueCombination); + if (formattedValue.isPresent()) { + validateUniqueValue(type, formattedValue.get(), originalEntityName); + } } /** @@ -100,14 +114,13 @@ public class UniqueValueUtil { .orElse(false); } - private void validateUniqueValue(String type, String formattedValue, - String... uniqueCombination) { + private void validateUniqueValue(String type, String formattedValue, String originalEntityName) { if (isUniqueValueOccupied(type, formattedValue)) { throw new CoreException(new ErrorCode.ErrorCodeBuilder() .withCategory(ErrorCategory.APPLICATION) .withId(UNIQUE_VALUE_VIOLATION) .withMessage(String - .format(UNIQUE_VALUE_VIOLATION_MSG, type, getValueWithoutContext(uniqueCombination))) + .format(UNIQUE_VALUE_VIOLATION_MSG, type, originalEntityName)) .build()); } } diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/servlet/PermissionsFilter.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/servlet/PermissionsFilter.java index baafb4a9eb..30472d6e80 100644 --- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/servlet/PermissionsFilter.java +++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/servlet/PermissionsFilter.java @@ -16,9 +16,7 @@ package org.openecomp.sdc.itempermissions.servlet; -import org.openecomp.sdc.itempermissions.PermissionsServices; -import org.openecomp.sdc.itempermissions.PermissionsServicesFactory; - +import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; @@ -28,70 +26,92 @@ import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.ws.rs.HttpMethod; -import java.io.IOException; +import javax.ws.rs.core.Response; + +import org.codehaus.jackson.map.ObjectMapper; +import org.openecomp.sdc.common.errors.ErrorCode; +import org.openecomp.sdc.common.errors.ErrorCodeAndMessage; +import org.openecomp.sdc.common.errors.Messages; +import org.openecomp.sdc.itempermissions.PermissionsServices; +import org.openecomp.sdc.itempermissions.PermissionsServicesFactory; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; /** * Created by ayalaben on 6/27/2017. */ public class PermissionsFilter implements Filter { - private final PermissionsServices permissionsServices; - private static final String IRRELEVANT_REQUEST = "Irrelevant_Request"; - private static final String EDIT_ITEM = "Edit_Item"; + private static final Logger LOGGER = LoggerFactory.getLogger(PermissionsFilter.class); + private final PermissionsServices permissionsServices; + private static final String IRRELEVANT_REQUEST = "Irrelevant_Request"; + private static final String EDIT_ITEM = "Edit_Item"; - public PermissionsFilter() { - this.permissionsServices = PermissionsServicesFactory.getInstance().createInterface(); - } + public PermissionsFilter() { + this.permissionsServices = PermissionsServicesFactory.getInstance().createInterface(); + } - @Override - public void init(FilterConfig filterConfig) { - // required by servlet API - } + @Override + public void init(FilterConfig filterConfig) { + // required by servlet API + } - @Override - public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, - FilterChain filterChain) throws IOException, ServletException { + @Override + public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) + throws IOException, ServletException { - if ((servletRequest instanceof HttpServletRequest) && - isIrrelevant((HttpServletRequest) servletRequest, servletResponse)) { - return; + if ((servletRequest instanceof HttpServletRequest) + && isRelevant((HttpServletRequest) servletRequest, servletResponse)) { + filterChain.doFilter(servletRequest, servletResponse); + } } - filterChain.doFilter(servletRequest, servletResponse); - } + private boolean isRelevant(HttpServletRequest servletRequest, ServletResponse servletResponse) throws IOException { + String method = servletRequest.getMethod(); + if (method.equals(HttpMethod.POST) || method.equals(HttpMethod.PUT) || method.equals(HttpMethod.DELETE)) { - private boolean isIrrelevant(HttpServletRequest servletRequest, ServletResponse servletResponse) throws IOException { + String userId = servletRequest.getHeader("USER_ID"); + String itemId = parseItemIdFromPath(servletRequest.getPathInfo()); + if (!itemId.equals(IRRELEVANT_REQUEST) && !permissionsServices.isAllowed(itemId, userId, EDIT_ITEM)) { + ((HttpServletResponse) servletResponse).setStatus(HttpServletResponse.SC_FORBIDDEN); + servletResponse.getWriter().print(buildResponse(Response.Status.FORBIDDEN, + Messages.PERMISSIONS_ERROR.getErrorMessage(), + Messages.PERMISSIONS_ERROR.name())); + return false; + } + } - String method = servletRequest.getMethod(); - if (method.equals(HttpMethod.POST) || method.equals(HttpMethod.PUT) || method.equals(HttpMethod.DELETE)) { - - String userId = servletRequest.getHeader("USER_ID"); - String itemId = parseItemIdFromPath(servletRequest.getPathInfo()); + return true; + } - if (!itemId.equals(IRRELEVANT_REQUEST) && !permissionsServices.isAllowed(itemId,userId,EDIT_ITEM)) { - ((HttpServletResponse) servletResponse).setStatus(HttpServletResponse.SC_FORBIDDEN); - servletResponse.getWriter().print("Permissions Error. The user does not have " + - "permission to perform" + - " this action."); - return true; + private String parseItemIdFromPath(String pathInfo) { + String[] tokens = pathInfo.split("/"); + if (tokens.length < 4) { + return IRRELEVANT_REQUEST; + } else { + return tokens[3]; } } - return false; - } + @Override + public void destroy() { + // required by serlvet API + } - private String parseItemIdFromPath(String pathInfo) { - String[] tokens = pathInfo.split("/"); - if (tokens.length < 4) { - return IRRELEVANT_REQUEST; - } else { - return tokens[3]; + private String buildResponse(Response.Status status, String message, String id) { + ErrorCode errorCode = new ErrorCode.ErrorCodeBuilder() + .withId(id) + .withMessage(message).build(); + return objectToJsonString(new ErrorCodeAndMessage(status, errorCode)); } - } - @Override - public void destroy() { - // required by serlvet API - } + private String objectToJsonString(Object obj) { + try { + return new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(obj); + } catch (Exception e) { + LOGGER.error(e.getMessage(), e); + return "An internal error has occurred. Please contact support."; + } + } } |