From d378c37fbd1ecec7b43394926f1ca32a695e07de Mon Sep 17 00:00:00 2001 From: vasraz Date: Mon, 22 Mar 2021 15:33:06 +0000 Subject: Reformat openecomp-be Signed-off-by: Vasyl Razinkov Issue-ID: SDC-3449 Change-Id: I13e02322f8e00820cc5a1d85752caaeda9bf10d1 --- .../server/filters/RestrictionAccessFilter.java | 63 ++++++++++------------ 1 file changed, 27 insertions(+), 36 deletions(-) (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/java/org/openecomp/server/filters/RestrictionAccessFilter.java') diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/java/org/openecomp/server/filters/RestrictionAccessFilter.java b/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/java/org/openecomp/server/filters/RestrictionAccessFilter.java index 61a74500ca..19b5e52cf8 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/java/org/openecomp/server/filters/RestrictionAccessFilter.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/java/org/openecomp/server/filters/RestrictionAccessFilter.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,25 +17,23 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.server.filters; import com.fasterxml.jackson.databind.ObjectMapper; -import org.onap.sdc.tosca.services.YamlUtil; -import org.openecomp.sdc.securityutil.ISessionValidationFilterConfiguration; -import org.openecomp.sdc.securityutil.filters.SessionValidationFilter; -import org.openecomp.server.configuration.CookieConfig; -import org.openecomp.sdc.logging.api.Logger; -import org.openecomp.sdc.logging.api.LoggerFactory; -import org.openecomp.sdcrests.item.rest.services.catalog.notification.EntryNotConfiguredException; - -import javax.servlet.http.Cookie; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.List; import java.util.Map; import java.util.Objects; +import javax.servlet.http.Cookie; +import org.onap.sdc.tosca.services.YamlUtil; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.openecomp.sdc.securityutil.ISessionValidationFilterConfiguration; +import org.openecomp.sdc.securityutil.filters.SessionValidationFilter; +import org.openecomp.sdcrests.item.rest.services.catalog.notification.EntryNotConfiguredException; +import org.openecomp.server.configuration.CookieConfig; public class RestrictionAccessFilter extends SessionValidationFilter { @@ -43,7 +41,23 @@ public class RestrictionAccessFilter extends SessionValidationFilter { private static final String CONFIG_FILE_PROPERTY = "configuration.yaml"; private static final String CONFIG_SECTION = "authCookie"; + @Override + public ISessionValidationFilterConfiguration getFilterConfiguration() { + return Configuration.getInstance(); + } + + @Override + protected Cookie addRoleToCookie(Cookie cookie) { + return cookie; + } + + @Override + protected boolean isRoleValid(Cookie cookie) { + return true; + } + private static class Configuration implements ISessionValidationFilterConfiguration { + private static Configuration instance; private String securityKey; private long maxSessionTimeOut; @@ -55,13 +69,10 @@ public class RestrictionAccessFilter extends SessionValidationFilter { private String cookiePath; private boolean isCookieHttpOnly; - private Configuration() { try { - String file = Objects.requireNonNull(System.getProperty(CONFIG_FILE_PROPERTY), - "Config file location must be specified via system property " + CONFIG_FILE_PROPERTY); - + "Config file location must be specified via system property " + CONFIG_FILE_PROPERTY); Object config = getAuthenticationConfiguration(file); ObjectMapper mapper = new ObjectMapper(); CookieConfig cookieConfig = mapper.convertValue(config, CookieConfig.class); @@ -74,11 +85,9 @@ public class RestrictionAccessFilter extends SessionValidationFilter { this.cookieDomain = cookieConfig.getDomain(); this.cookiePath = cookieConfig.getPath(); this.isCookieHttpOnly = cookieConfig.isHttpOnly(); - } catch (Exception e) { LOGGER.warn("Failed to load configuration. ", e); } - } public static Configuration getInstance() { @@ -89,18 +98,15 @@ public class RestrictionAccessFilter extends SessionValidationFilter { } private static Object getAuthenticationConfiguration(String file) throws IOException { - Map configuration = Objects.requireNonNull(readConfigurationFile(file), "Configuration cannot be empty"); Object authenticationConfig = configuration.get(CONFIG_SECTION); if (authenticationConfig == null) { throw new EntryNotConfiguredException(CONFIG_SECTION + " section"); } - return authenticationConfig; } private static Map readConfigurationFile(String file) throws IOException { - try (InputStream fileInput = new FileInputStream(file)) { YamlUtil yamlUtil = new YamlUtil(); return yamlUtil.yamlToMap(fileInput); @@ -152,19 +158,4 @@ public class RestrictionAccessFilter extends SessionValidationFilter { return excludedUrls; } } - - @Override - public ISessionValidationFilterConfiguration getFilterConfiguration() { - return Configuration.getInstance(); - } - - @Override - protected Cookie addRoleToCookie(Cookie cookie) { - return cookie; - } - - @Override - protected boolean isRoleValid(Cookie cookie) { - return true; - } } -- cgit 1.2.3-korg