diff options
18 files changed, 1389 insertions, 525 deletions
diff --git a/BRMSGateway/src/main/java/org/onap/policy/brms/api/BrmsPush.java b/BRMSGateway/src/main/java/org/onap/policy/brms/api/BrmsPush.java index 716b8ec53..b8706bb9b 100644 --- a/BRMSGateway/src/main/java/org/onap/policy/brms/api/BrmsPush.java +++ b/BRMSGateway/src/main/java/org/onap/policy/brms/api/BrmsPush.java @@ -3,6 +3,7 @@ * ONAP Policy Engine * ================================================================================ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Modified Copyright (C) 2018 Samsung Electronics Co., Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -424,27 +425,9 @@ public class BrmsPush { } // Check User Specific values. if ("$controller:".equals(key)) { - try { - final PEDependency dependency = PolicyUtils.jsonStringToObject(value, PEDependency.class); - userControllerName = key.replaceFirst("$controller:", ""); - LOGGER.info("addRule: userControllerName - " + userControllerName + ", dependency: - " - + dependency); - addToGroup(userControllerName, dependency); - } catch (final Exception e) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error while resolving Controller: " + e); - } - + userControllerName = getUserControllerName(key, value); } else if ("$dependency$".equals(key) && value.startsWith("[") && value.endsWith("]")) { - value = value.substring(1, value.length() - 1).trim(); - final List<String> dependencyStrings = Arrays.asList(value.split(Pattern.quote("},{"))); - for (final String dependencyString : dependencyStrings) { - try { - userDependencies.add(PolicyUtils.jsonStringToObject(dependencyString, PEDependency.class)); - } catch (final Exception e) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error while resolving Dependencies: " - + e); - } - } + updateUserDependencies(userDependencies, value); } } if (userControllerName != null) { @@ -479,6 +462,35 @@ public class BrmsPush { } } + private String getUserControllerName(String key, String value) { + String userControllerName = null; + // Check User Specific values. + try { + final PEDependency dependency = PolicyUtils.jsonStringToObject(value, PEDependency.class); + userControllerName = key.replaceFirst("$controller:", ""); + LOGGER.info("addRule: userControllerName - " + userControllerName + ", dependency: - " + + dependency); + addToGroup(userControllerName, dependency); + } catch (final Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error while resolving Controller: " + e); + } + return userControllerName; + } + + private void updateUserDependencies(ArrayList<PEDependency> userDependencies, String value) { + //update the user dependencies supplied as parameter to this method + value = value.substring(1, value.length() - 1).trim(); + final List<String> dependencyStrings = Arrays.asList(value.split(Pattern.quote("},{"))); + for (final String dependencyString : dependencyStrings) { + try { + userDependencies.add(PolicyUtils.jsonStringToObject(dependencyString, PEDependency.class)); + } catch (final Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error while resolving Dependencies: " + + e); + } + } + } + private void syncGroupInfo() { // Sync DB to JMemory. final EntityTransaction et = em.getTransaction(); @@ -624,45 +636,49 @@ public class BrmsPush { try (JarFile jar = new JarFile(jarFileName)) { final Enumeration<?> enumEntries = jar.entries(); while (enumEntries.hasMoreElements()) { - final JarEntry jarEntry = (JarEntry) enumEntries.nextElement(); - File file = null; - final String fileName = jarEntry.getName().substring(jarEntry.getName().lastIndexOf("/") + 1); - if (jarEntry.getName().endsWith(".drl")) { - final String path = PROJECTSLOCATION + File.separator + artifactId + File.separator + "src" - + File.separator + "main" + File.separator + RESOURCES + File.separator + RULES; - new File(path).mkdirs(); - if (syncFlag && policyMap.containsKey(fileName.replace(".drl", ""))) { - file = new File(path + File.separator + fileName); - } else { - file = new File(path + File.separator + fileName); - } - } else if (jarEntry.getName().endsWith(POM_XML_FILE)) { - final String path = PROJECTSLOCATION + File.separator + artifactId; - new File(path).mkdirs(); - file = new File(path + File.separator + fileName); - } else if (jarEntry.getName().endsWith(KMODULE_XML_FILE)) { - final String path = PROJECTSLOCATION + File.separator + artifactId + File.separator + "src" - + File.separator + "main" + File.separator + RESOURCES + File.separator + META_INF; - new File(path).mkdirs(); - file = new File(path + File.separator + fileName); - } - if (file != null) { - try (InputStream is = jar.getInputStream(jarEntry); - FileOutputStream fos = new FileOutputStream(file)) { - while (is.available() > 0) { - fos.write(is.read()); - } - LOGGER.info(fileName + " Created.."); - } catch (final IOException e) { - LOGGER.info("exception Occured" + e); - } - } + parseJarContents(artifactId, jar, enumEntries); } } catch (final IOException e) { LOGGER.info("exception Occured" + e); } } + private void parseJarContents(String artifactId, JarFile jar, Enumeration<?> enumEntries) { + final JarEntry jarEntry = (JarEntry) enumEntries.nextElement(); + File file = null; + final String fileName = jarEntry.getName().substring(jarEntry.getName().lastIndexOf("/") + 1); + if (jarEntry.getName().endsWith(".drl")) { + final String path = PROJECTSLOCATION + File.separator + artifactId + File.separator + "src" + + File.separator + "main" + File.separator + RESOURCES + File.separator + RULES; + new File(path).mkdirs(); + if (syncFlag && policyMap.containsKey(fileName.replace(".drl", ""))) { + file = new File(path + File.separator + fileName); + } else { + file = new File(path + File.separator + fileName); + } + } else if (jarEntry.getName().endsWith(POM_XML_FILE)) { + final String path = PROJECTSLOCATION + File.separator + artifactId; + new File(path).mkdirs(); + file = new File(path + File.separator + fileName); + } else if (jarEntry.getName().endsWith(KMODULE_XML_FILE)) { + final String path = PROJECTSLOCATION + File.separator + artifactId + File.separator + "src" + + File.separator + "main" + File.separator + RESOURCES + File.separator + META_INF; + new File(path).mkdirs(); + file = new File(path + File.separator + fileName); + } + if (file != null) { + try (InputStream is = jar.getInputStream(jarEntry); + FileOutputStream fos = new FileOutputStream(file)) { + while (is.available() > 0) { + fos.write(is.read()); + } + LOGGER.info(fileName + " Created.."); + } catch (final IOException e) { + LOGGER.info("exception Occured" + e); + } + } + } + private NexusArtifact getLatestArtifactFromNexus(final String selectedName) { final List<NexusArtifact> artifacts = getArtifactFromNexus(selectedName, null); int bigNum = 0; @@ -771,41 +787,8 @@ public class BrmsPush { LOGGER.error("Error while starting Transaction " + e); } if (!modifiedGroups.isEmpty()) { - Boolean flag = false; - for (final Map.Entry<String, String> entry : modifiedGroups.entrySet()) { - InvocationResult result = null; - final String group = entry.getKey(); - try { - LOGGER.info("PushRules: ModifiedGroups, Key: " + group + ", Value: " + entry.getValue()); - final InvocationRequest request = new DefaultInvocationRequest(); - setVersion(group); - createPom(group); - request.setPomFile(new File( - PROJECTSLOCATION + File.separator + getArtifactId(group) + File.separator + POM_XML_FILE)); - request.setGoals(Arrays.asList(GOALS)); - final Invoker invoker = new DefaultInvoker(); - result = invoker.execute(request); - if (result.getExecutionException() != null) { - LOGGER.error(result.getExecutionException()); - } else if (result.getExitCode() != 0) { - LOGGER.error("Maven Invocation failure..!"); - } - } catch (final Exception e) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Maven Invocation issue for " - + getArtifactId(group) + e.getMessage(), e); - } - if (result != null && result.getExitCode() == 0) { - LOGGER.info("Build Completed..!"); - if (createFlag) { - addNotification(group, "create"); - } else { - addNotification(group, entry.getValue()); - } - flag = true; - } else { - throw new PolicyException(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Maven Invocation failure!"); - } - } + Boolean flag; + flag = buildAndGenerateJarFile(); if (flag) { sendNotification(controllers); } @@ -828,6 +811,45 @@ public class BrmsPush { getNameAndSetRemove(controllerName, name); } + private Boolean buildAndGenerateJarFile() throws PolicyException { + Boolean flag = false; + for (final Map.Entry<String, String> entry : modifiedGroups.entrySet()) { + InvocationResult result = null; + final String group = entry.getKey(); + try { + LOGGER.info("PushRules: ModifiedGroups, Key: " + group + ", Value: " + entry.getValue()); + final InvocationRequest request = new DefaultInvocationRequest(); + setVersion(group); + createPom(group); + request.setPomFile(new File( + PROJECTSLOCATION + File.separator + getArtifactId(group) + File.separator + POM_XML_FILE)); + request.setGoals(Arrays.asList(GOALS)); + final Invoker invoker = new DefaultInvoker(); + result = invoker.execute(request); + if (result.getExecutionException() != null) { + LOGGER.error(result.getExecutionException()); + } else if (result.getExitCode() != 0) { + LOGGER.error("Maven Invocation failure..!"); + } + } catch (final Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Maven Invocation issue for " + + getArtifactId(group) + e.getMessage(), e); + } + if (result != null && result.getExitCode() == 0) { + LOGGER.info("Build Completed..!"); + if (createFlag) { + addNotification(group, "create"); + } else { + addNotification(group, entry.getValue()); + } + flag = true; + } else { + throw new PolicyException(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Maven Invocation failure!"); + } + } + return flag; + } + private String getGroupName(final String name) { if (policyMap.containsKey(name)) { return policyMap.get(name); diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicy.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicy.java index 56c23ac2c..c8c540c34 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicy.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicy.java @@ -167,7 +167,9 @@ public class DecisionPolicy extends Policy { if(policyAdapter.getRuleProvider().equals(GUARD_YAML) || policyAdapter.getRuleProvider().equals(GUARD_BL_YAML)){ Map<String, String> yamlParams = new HashMap<>(); - yamlParams.put(DESCRIPTION, (policyAdapter.getPolicyDescription()!=null)? policyAdapter.getPolicyDescription(): "YAML Guard Policy"); + String blackListEntryType = policyAdapter.getBlackListEntryType() !=null ? policyAdapter.getBlackListEntryType(): "Use Manual Entry"; + String description = policyAdapter.getPolicyDescription() != null? policyAdapter.getPolicyDescription(): "YAML Guard Policy"; + yamlParams.put(DESCRIPTION, description + "@blEntry@" + blackListEntryType + "@blEntry@"); String fileName = policyAdapter.getNewFileName(); String name = fileName.substring(fileName.lastIndexOf('\\') + 1, fileName.length()); if ((name == null) || ("".equals(name))) { @@ -295,6 +297,16 @@ public class DecisionPolicy extends Policy { blackList.add(blackListString); } } + if(yamlParams.containsKey("appendBlackList")){ + String appendBlackListString = yamlParams.get("appendBlackList"); + List<String> appendBlackList = null; + if(appendBlackListString!=null && !appendBlackListString.trim().isEmpty()){ + appendBlackList = Arrays.asList(appendBlackListString.split(",")); + for(int i=0; i<appendBlackList.size();i++){ + blackList.remove(appendBlackList.get(i)); + } + } + } File templateFile; Path xacmlTemplatePath; ClassLoader classLoader = getClass().getClassLoader(); @@ -781,7 +793,7 @@ public class DecisionPolicy extends Policy { } public String getFunctionDefinitionId(String key){ - FunctionDefinition object = (FunctionDefinition) commonClassDao.getDataById(FunctionDefinition.class, "short_name", key); + FunctionDefinition object = (FunctionDefinition) commonClassDao.getDataById(FunctionDefinition.class, "shortname", key); if(object != null){ return object.getXacmlid(); } diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java index 6b980b98d..1b786ed6a 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java @@ -424,30 +424,6 @@ public class PolicyDBDao { return true; } - private void notifyOthers(long entityId,String entityType){ - notifyOthers(entityId,entityType,null); - } - - private void notifyOthers(long entityId, String entityType, String newGroupId){ - logger.debug("notifyOthers(long entityId, String entityType, long newGroupId) as notifyOthers("+entityId+","+entityType+","+newGroupId+") called"); - LinkedList<Thread> notifyThreads = new LinkedList<>(); - - //we're going to run notifications in parallel threads to speed things up - for(Object obj : otherServers){ - Thread newNotifyThread = new Thread(new NotifyOtherThread(obj, entityId, entityType, newGroupId)); - newNotifyThread.start(); - notifyThreads.add(newNotifyThread); - } - //we want to wait for all notifications to complete or timeout before we unlock the interface and allow more changes - for(Thread t : notifyThreads){ - try { - t.join(); - } catch (Exception e) { - logger.warn("Could not join a notifcation thread" + e); - } - } - } - private class NotifyOtherThread implements Runnable { public NotifyOtherThread(Object obj, long entityId, String entityType, String newGroupId){ this.obj = obj; @@ -2645,6 +2621,30 @@ public class PolicyDBDao { this.pdpId = pdp.getPdpKey(); } } + + private void notifyOthers(long entityId,String entityType){ + notifyOthers(entityId,entityType,null); + } + + private void notifyOthers(long entityId, String entityType, String newGroupId){ + logger.debug("notifyOthers(long entityId, String entityType, long newGroupId) as notifyOthers("+entityId+","+entityType+","+newGroupId+") called"); + LinkedList<Thread> notifyThreads = new LinkedList<>(); + + //we're going to run notifications in parallel threads to speed things up + for(Object obj : otherServers){ + Thread newNotifyThread = new Thread(new NotifyOtherThread(obj, entityId, entityType, newGroupId)); + newNotifyThread.start(); + notifyThreads.add(newNotifyThread); + } + //we want to wait for all notifications to complete or timeout before we unlock the interface and allow more changes + for(Thread t : notifyThreads){ + try { + t.join(); + } catch (Exception e) { + logger.warn("Could not join a notifcation thread" + e); + } + } + } } private PolicyDBDao(){ diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java index f7ef1a097..a6cda5e68 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-PAP-REST * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -416,6 +416,16 @@ public class PolicyCreation extends AbstractPolicyCreation{ String blackList = StringUtils.join(policyData.getYamlparams().getBlackList(), ","); attributeMap.put("blackList", blackList); } + if(DecisionPolicy.GUARD_BL_YAML.equals(policyData.getRuleProvider()) && "Use File Upload".equals(policyData.getBlackListEntryType())){ + if(policyData.getBlackListEntries() != null && !policyData.getBlackListEntries().isEmpty()){ + String blackList = StringUtils.join(policyData.getBlackListEntries(), ","); + attributeMap.put("blackList", blackList); + } + if(policyData.getAppendBlackListEntries() != null && !policyData.getAppendBlackListEntries().isEmpty()){ + String blackList = StringUtils.join(policyData.getAppendBlackListEntries(), ","); + attributeMap.put("appendBlackList", blackList); + } + } if(policyData.getYamlparams().getTargets()!=null){ String targets = StringUtils.join(policyData.getYamlparams().getTargets(),","); attributeMap.put("targets", targets); diff --git a/ONAP-PAP-REST/src/main/resources/Decision_GuardBLPolicyTemplate.xml b/ONAP-PAP-REST/src/main/resources/Decision_GuardBLPolicyTemplate.xml index 1ac292c3f..43d7a2349 100644 --- a/ONAP-PAP-REST/src/main/resources/Decision_GuardBLPolicyTemplate.xml +++ b/ONAP-PAP-REST/src/main/resources/Decision_GuardBLPolicyTemplate.xml @@ -122,7 +122,7 @@ <AdviceExpressions> <AdviceExpression AdviceId="GUARD_BL_YAML" AppliesTo="Deny"> <AttributeAssignmentExpression AttributeId="guard.response" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"> - <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">Denied!</AttributeValue> + <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">Denied By Blacklist</AttributeValue> </AttributeAssignmentExpression> </AdviceExpression> </AdviceExpressions> diff --git a/ONAP-PAP-REST/src/main/resources/Decision_GuardPolicyTemplate.xml b/ONAP-PAP-REST/src/main/resources/Decision_GuardPolicyTemplate.xml index 15465f3c0..809dc99fb 100644 --- a/ONAP-PAP-REST/src/main/resources/Decision_GuardPolicyTemplate.xml +++ b/ONAP-PAP-REST/src/main/resources/Decision_GuardPolicyTemplate.xml @@ -118,7 +118,7 @@ <AdviceExpressions> <AdviceExpression AdviceId="GUARD_YAML" AppliesTo="Deny"> <AttributeAssignmentExpression AttributeId="guard.response" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"> - <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">Denied!</AttributeValue> + <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">Denied By Guard</AttributeValue> </AttributeAssignmentExpression> </AdviceExpression> </AdviceExpressions> diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/PolicyRestAdapter.java b/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/PolicyRestAdapter.java index a9daf1732..e815fe2b9 100644 --- a/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/PolicyRestAdapter.java +++ b/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/PolicyRestAdapter.java @@ -127,6 +127,9 @@ public class PolicyRestAdapter { private String actionDictUrl = null; private String actionDictMethod = null; private YAMLParams yamlparams; + private List<String> blackListEntries; + private List<String> appendBlackListEntries; + private String blackListEntryType; //Rainy Day Decision private RainyDayParams rainyday; @@ -907,4 +910,22 @@ public class PolicyRestAdapter { public void setFaultDatas(ClosedLoopFaultTrapDatas faultDatas) { this.faultDatas = faultDatas; } + public List<String> getAppendBlackListEntries() { + return appendBlackListEntries; + } + public void setAppendBlackListEntries(List<String> appendBlackListEntries) { + this.appendBlackListEntries = appendBlackListEntries; + } + public List<String> getBlackListEntries() { + return blackListEntries; + } + public void setBlackListEntries(List<String> blackListEntries) { + this.blackListEntries = blackListEntries; + } + public String getBlackListEntryType() { + return blackListEntryType; + } + public void setBlackListEntryType(String blackListEntryType) { + this.blackListEntryType = blackListEntryType; + } } diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/ReturnBlackList.java b/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/ReturnBlackList.java new file mode 100644 index 000000000..6ecf1b5e4 --- /dev/null +++ b/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/ReturnBlackList.java @@ -0,0 +1,51 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP Policy Engine + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.rest.adapter; + +public class ReturnBlackList { + private boolean entryCheck; + private int actionValue; + private String entryValue; + + public boolean isEntryCheck() { + return entryCheck; + } + + public void setEntryCheck(boolean entryCheck) { + this.entryCheck = entryCheck; + } + + public int getActionValue() { + return actionValue; + } + + public void setActionValue(int actionValue) { + this.actionValue = actionValue; + } + + public String getEntryValue() { + return entryValue; + } + + public void setEntryValue(String entryValue) { + this.entryValue = entryValue; + } +} diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidation.java b/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidation.java index 50985b12d..0478f5f95 100644 --- a/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidation.java +++ b/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidation.java @@ -940,20 +940,25 @@ public class PolicyValidation { responseString.append("Guard Params <b>Time Units</b> is Required" + HTML_ITALICS_LNBREAK); valid = false; } - }else if("GUARD_BL_YAML".equals(policyData.getRuleProvider())){ - if(policyData.getYamlparams().getBlackList()==null || policyData.getYamlparams().getBlackList().isEmpty()){ - responseString.append(" Guard Params <b>BlackList</b> is Required " + HTML_ITALICS_LNBREAK); - valid = false; - }else{ - for(String blackList: policyData.getYamlparams().getBlackList()){ - if(blackList==null || !(SUCCESS.equals(PolicyUtils.policySpecialCharValidator(blackList)))){ - responseString.append(" Guard Params <b>BlackList</b> Should be valid String" + HTML_ITALICS_LNBREAK); - valid = false; - break; - } - } - } - } + } else if ("GUARD_BL_YAML".equals(policyData.getRuleProvider()) + && "Use Manual Entry".equals(policyData.getBlackListEntryType())) { + if (policyData.getYamlparams().getBlackList() == null + || policyData.getYamlparams().getBlackList().isEmpty()) { + responseString + .append(" Guard Params <b>BlackList</b> is Required " + HTML_ITALICS_LNBREAK); + valid = false; + } else { + for (String blackList : policyData.getYamlparams().getBlackList()) { + if (blackList == null + || !(SUCCESS.equals(PolicyUtils.policySpecialCharValidator(blackList)))) { + responseString.append(" Guard Params <b>BlackList</b> Should be valid String" + + HTML_ITALICS_LNBREAK); + valid = false; + break; + } + } + } + } } } } diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/adapter/ReturnBlackListTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/adapter/ReturnBlackListTest.java new file mode 100644 index 000000000..e8f6684b1 --- /dev/null +++ b/ONAP-REST/src/test/java/org/onap/policy/rest/adapter/ReturnBlackListTest.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP Policy Engine + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.rest.adapter; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class ReturnBlackListTest { + + @Test + public void testReturnBlackList() { + ReturnBlackList list = new ReturnBlackList(); + list.setActionValue(1); + list.setEntryCheck(true); + list.setEntryValue("Test"); + + assertTrue(1 == list.getActionValue()); + assertTrue(list.isEntryCheck()); + assertTrue("Test".equals(list.getEntryValue())); + } + +} diff --git a/POLICY-SDK-APP/pom.xml b/POLICY-SDK-APP/pom.xml index 7017017ce..1160a8f25 100644 --- a/POLICY-SDK-APP/pom.xml +++ b/POLICY-SDK-APP/pom.xml @@ -182,6 +182,11 @@ <artifactId>jackson-dataformat-xml</artifactId> <version>${jackson.version}</version> </dependency> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <version>2.8.0</version> + </dependency> <!-- Elastic Search --> <dependency> <groupId>org.elasticsearch</groupId> diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/ExportAndImportDecisionBlackListEntries.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/ExportAndImportDecisionBlackListEntries.java new file mode 100644 index 000000000..8a37e9ddc --- /dev/null +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/ExportAndImportDecisionBlackListEntries.java @@ -0,0 +1,380 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP Policy Engine + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.controller; + +import com.google.gson.Gson; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.nio.file.Files; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.apache.commons.compress.utils.IOUtils; +import org.apache.commons.fileupload.FileItem; +import org.apache.commons.fileupload.FileUploadException; +import org.apache.commons.fileupload.disk.DiskFileItemFactory; +import org.apache.commons.fileupload.servlet.ServletFileUpload; +import org.apache.poi.hssf.usermodel.HSSFRow; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.ss.usermodel.WorkbookFactory; +import org.json.JSONObject; +import org.onap.policy.common.logging.flexlogger.FlexLogger; +import org.onap.policy.common.logging.flexlogger.Logger; +import org.onap.policy.rest.adapter.PolicyRestAdapter; +import org.onap.policy.rest.adapter.ReturnBlackList; +import org.onap.policy.xacml.api.XACMLErrorConstants; +import org.onap.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.web.support.JsonMessage; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + + + +/** + * This class is used to import and export the black list entries which were used in the Decision Blacklist Guard YAML + * Policy. + * + */ +@Controller +@RequestMapping("/") +public class ExportAndImportDecisionBlackListEntries extends RestrictedBaseController { + + private static final Logger policyLogger = FlexLogger.getLogger(ExportAndImportDecisionBlackListEntries.class); + private static final String BLACKLISTENTRIESDATA = "blackListEntries"; + private static final String ACTION = "Action"; + private static final String BLACKLISTENTRY = "BlackListEntry"; + + /** + * This method is used to Export the Black List entries data from Decision BlackList Guard YAML Policy. So, user can + * update the file on adding or removing the entries, for updating the policies or using in other Environments. + * + * @param request the request contains the policy data. So, based on that we can populate and read and write the + * entries. + * @param response after reading and writing the blacklist list entries to file, the file is copied to tmp directory + * and making available to user to download from GUI. + * @throws IOException exception throws if anything goes wrong in the process. + */ + @RequestMapping(value = {"/policycreation/exportDecisionBlackListEntries"}, method = {RequestMethod.POST}) + public void exportBlackList(HttpServletRequest request, HttpServletResponse response) throws IOException { + try (HSSFWorkbook workBook = new HSSFWorkbook()) { + String requestData = request.getReader().lines().collect(Collectors.joining()); + JSONObject root = new JSONObject(requestData); + PolicyRestAdapter adapter = new Gson().fromJson(root.get("policyData").toString(), PolicyRestAdapter.class); + DecisionPolicyController controller = new DecisionPolicyController(); + controller.prePopulateDecisionPolicyData(adapter, null); + List<String> blackLists = adapter.getYamlparams().getBlackList(); + HSSFSheet sheet = workBook.createSheet("BlackList"); + HSSFRow headingRow = sheet.createRow(0); + headingRow.createCell(0).setCellValue("Action"); + headingRow.createCell(1).setCellValue("BlackListEntry"); + + short rowNo = 1; + for (Object object : blackLists) { + HSSFRow row = sheet.createRow(rowNo); + row.createCell(0).setCellValue(1); + row.createCell(1).setCellValue(object.toString()); + rowNo++; + } + + String tmpFile = System.getProperty("catalina.base") + File.separator + "webapps" + File.separator + "temp"; + + /* + * Export FileName is the combination of BlacList+Scope+PolicyName+Version+PolicyCreatedDate. + * + */ + + SimpleDateFormat parseFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date date = parseFormat.parse(root.get("date").toString().replaceAll("\"", "")); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss"); + String formatedDate = dateFormat.format(date); + + String fileName = "BlackList_Scope_" + adapter.getDomainDir() + "_Name_" + adapter.getPolicyName() + + "_Version_" + root.get("version").toString() + "_Date_" + formatedDate + ".xls"; + + String deleteCheckPath = tmpFile + File.separator + fileName; + File deleteCheck = new File(deleteCheckPath); + if (deleteCheck.exists() && deleteCheck.delete()) { + policyLogger.info("Deleted the file from system before exporting a new file."); + } + + File temPath = new File(tmpFile); + if (!temPath.exists()) { + temPath.mkdir(); + } + + String file = temPath + File.separator + fileName; + File filepath = new File(file); + FileOutputStream fos = new FileOutputStream(filepath); + workBook.write(fos); + fos.flush(); + + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String successMap = file.substring(file.lastIndexOf("webapps") + 8); + String responseString = new Gson().toJson(successMap); + JSONObject jsonResposne = new JSONObject("{data: " + responseString + "}"); + out.write(jsonResposne.toString()); + } catch (Exception e) { + policyLogger.error( + XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Exception Occured while Exporting BlackList Entries" , e); + } + } + + /** + * This method is used to import the BlackList excel file into the system. Which is used to create Decision + * Blacklist Guard YAML Policy. + * + * @param request the HTTP request contains file upload stream form GUI. + * @param response the response is send to the GUI after reading the file input stream. + * @throws FileUploadException throws fileUpload Exception. + * @throws IOException throws IO Exceptions. + */ + @RequestMapping(value = {"/policycreation/importBlackListForDecisionPolicy"}, method = {RequestMethod.POST}) + public void importBlackListFile(HttpServletRequest request, HttpServletResponse response) throws Exception { + List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); + List<String> errorLogs = new ArrayList<>(); + Gson mapper = new Gson(); + errorLogs.add("error"); + Map<String, Object> model = new HashMap<>(); + if (items.isEmpty()) { + errorLogs.add("The File doesn't have any content and it is invalid."); + model.put(BLACKLISTENTRIESDATA, errorLogs); + } else { + readItems(items, errorLogs, model); + } + JsonMessage msg = new JsonMessage(mapper.toJson(model)); + JSONObject jsonResposne = new JSONObject(msg); + response.getWriter().write(jsonResposne.toString()); + } + + /** + * This method is used to read the first item, as we expect only one entry in the file upload. + * + * @param items The file entries which were uploaded from GUI. + * @param errorLogs on adding all incorrect entries, we can let user know what need to fixed. + * @param model Map which stores key value (blacklist and append list data) + * @throws Exception throws exception if it is not .xls format + */ + private void readItems(List<FileItem> items, List<String> errorLogs, Map<String, Object> model) throws Exception { + Map<String, InputStream> files = new HashMap<>(); + + FileItem item = items.get(0); + files.put(item.getName(), item.getInputStream()); + File file = new File(item.getName()); + String fileName = file.getName(); + try (OutputStream outputStream = new FileOutputStream(file);) { + IOUtils.copy(item.getInputStream(), outputStream); + if (fileName.startsWith("BlackList") && fileName.endsWith(".xls")) { + readWorkBook(fileName, errorLogs, model); + } else { + errorLogs.add("The File Name should start with BlackList and must be .xls format."); + model.put(BLACKLISTENTRIESDATA, errorLogs); + } + } + Files.delete(file.toPath()); + } + + /** + * This method is used to read the workbook in xls file item. + * + * @param fileName fileName as input parameter + * @param errorLogs on adding all incorrect entries, we can let user know what need to fixed. + * @param model Map which stores key value (blacklist and append list data) + */ + private void readWorkBook(String fileName, List<String> errorLogs, Map<String, Object> model) { + Set<String> blackListEntries = new HashSet<>(); + Set<String> appendBlackListEntries = new HashSet<>(); + try (Workbook workbook = WorkbookFactory.create(new File(fileName))) { + Sheet datatypeSheet = workbook.getSheetAt(0); + Iterator<Row> rowIterator = datatypeSheet.iterator(); + readExcelRows(rowIterator, blackListEntries, appendBlackListEntries, errorLogs); + if (errorLogs.size() == 1) { + model.put(BLACKLISTENTRIESDATA, blackListEntries); + model.put("appendBlackListEntries", appendBlackListEntries); + } else { + model.put(BLACKLISTENTRIESDATA, errorLogs); + } + } catch (Exception e) { + String error = "Error Occured While Reading File. Please check the format of the file."; + errorLogs.add(error); + model.put(BLACKLISTENTRIESDATA, errorLogs); + policyLogger.error(error , e); + } + } + + /** + * This method is used to read all the rows from imported Excel sheet and set to respective objects. + * + * @param rowIterator Excel Sheet rows are passed as input parameters. + * @param blackListEntries the data is set to this object, which is going to be added. + * @param appendBlackListEntries the data is set to this object which is going to be removed. + * @param errorLogs on adding all incorrect entries, we can let user know what need to fixed. + */ + private void readExcelRows(Iterator<Row> rowIterator, Set<String> blackListEntries, + Set<String> appendBlackListEntries, List<String> errorLogs) { + while (rowIterator.hasNext()) { + Row currentRow = rowIterator.next(); + if (currentRow.getRowNum() == 0) { + continue; + } + Iterator<Cell> cellIterator = currentRow.cellIterator(); + readExcelCells(cellIterator, blackListEntries, appendBlackListEntries, errorLogs); + } + } + + /** + * This method is used to read all the cells in the row. + * + * @param cellIterator iterating the cells and will parse based on the cell type. + * @param blackListEntries the data is set to this object, which is going to be added. + * @param appendBlackListEntries the data is set to this object which is going to be removed. + * @param errorLogs on adding all incorrect entries, we can let user know what need to fixed. + */ + private void readExcelCells(Iterator<Cell> cellIterator, Set<String> blackListEntries, + Set<String> appendBlackListEntries, List<String> errorLogs) { + boolean actionCheck = false; + boolean blackListCheck = false; + String blEntry = ""; + int actionEntry = 0; + int lineNo = 1; + while (cellIterator.hasNext()) { + Cell cell = cellIterator.next(); + if (ACTION.equalsIgnoreCase(getCellHeaderName(cell))) { + ReturnBlackList returnList = readActionCell(cell, lineNo, errorLogs); + actionEntry = returnList.getActionValue(); + actionCheck = returnList.isEntryCheck(); + } + if (BLACKLISTENTRY.equalsIgnoreCase(getCellHeaderName(cell))) { + ReturnBlackList returnList = readBlackListCell(cell, lineNo, errorLogs); + blEntry = returnList.getEntryValue(); + blackListCheck = returnList.isEntryCheck(); + actionEntry = returnList.getActionValue(); + } + lineNo++; + } + if (actionCheck && blackListCheck) { + addBlackListEntries(actionEntry, blackListEntries, appendBlackListEntries, blEntry); + } + } + + /** + * This method is used to read the Action cell entry. + * + * @param cell reading the action entry cell. + * @param lineNo counts the number of the cell. + * @param errorLogs on adding all incorrect entries, we can let user know what need to fixed. + * @return returns the response on setting to ReturnBlackList class. + */ + private ReturnBlackList readActionCell(Cell cell, int lineNo, List<String> errorLogs) { + ReturnBlackList returnValues = new ReturnBlackList(); + String error = "Entry at row " + lineNo + " not added, the value in the " + ACTION + + "column is neither \"0\" nor \"1\""; + int actionEntry = 0; + try { + actionEntry = (int) cell.getNumericCellValue(); + returnValues.setEntryCheck(true); + if (actionEntry != 1 && actionEntry != 0) { + errorLogs.add(error); + } + } catch (Exception e) { + errorLogs.add(error); + policyLogger.error(error, e); + actionEntry = 0; + } + returnValues.setActionValue(actionEntry); + return returnValues; + } + + /** + * + * This method is used to read the BlackList cell entry. + * + * @param cell reading the blacklist entry cell. + * @param lineNo counts the number of the cell. + * @param errorLogs on adding all incorrect entries, we can let user know what need to fixed. + * @return returns the response on setting to ReturnBlackList class. + */ + private ReturnBlackList readBlackListCell(Cell cell, int lineNo, List<String> errorLogs) { + ReturnBlackList returnValues = new ReturnBlackList(); + String blEntry = ""; + try { + blEntry = cell.getStringCellValue(); + returnValues.setEntryCheck(true); + } catch (Exception e) { + String error = "Entry at row " + lineNo + " not added, the value in the " + BLACKLISTENTRY + + " column is not a valid string"; + errorLogs.add(error); + policyLogger.error(error, e); + returnValues.setActionValue(0); + } + returnValues.setEntryValue(blEntry); + return returnValues; + } + + /** + * This method is used to add the data to blacklist and append list after parsing each and every row. + * + * @param actionEntry it has the input to add or not and holds either 0 or 1. + * @param blackListEntries list to add blacklist entries based on action entry = 1. + * @param appendBlackListEntries list to add append list entries based on action entry = 0. + * @param blEntry the value added to both entries based on action entry. + */ + private void addBlackListEntries(int actionEntry, Set<String> blackListEntries, Set<String> appendBlackListEntries, + String blEntry) { + if (actionEntry == 1) { + blackListEntries.add(blEntry); + } else { + appendBlackListEntries.add(blEntry); + } + } + + /** + * This method is used to identify the header of the cell. + * + * @param cell Excel sheet cell is passed as input parameter. + * @return the column header name value + */ + private String getCellHeaderName(Cell cell) { + return cell.getSheet().getRow(0).getCell(cell.getColumnIndex()).getRichStringCellValue().toString(); + } +} diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/DecisionPolicyController.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/DecisionPolicyController.js index 5b2bdb2b2..f560f4d58 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/DecisionPolicyController.js +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/DecisionPolicyController.js @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP Policy Engine * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,14 +17,16 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -angular.module('abs').controller('decisionPolicyController', ['$scope', 'PolicyAppService', 'policyNavigator', 'modalService', '$modal', 'Notification', function ($scope, PolicyAppService, PolicyNavigator, modalService, $modal, Notification) { +angular.module('abs').controller('decisionPolicyController', ['$scope', 'PolicyAppService', 'policyNavigator', 'modalService', '$modal', 'Notification', '$http', function ($scope, PolicyAppService, PolicyNavigator, modalService, $modal, Notification, $http) { $("#dialog").hide(); $scope.policyNavigator; $scope.savebutton = true; $scope.refreshCheck = false; + $scope.disableOnCreate = false; if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){ + $scope.disableOnCreate = true; $scope.temp.policy = { policyType : "Decision" } @@ -45,7 +47,11 @@ angular.module('abs').controller('decisionPolicyController', ['$scope', 'PolicyA if($scope.temp.policy.ruleProvider==undefined){ $scope.temp.policy.ruleProvider="Custom"; } - + + if($scope.temp.policy.blackListEntryType==undefined){ + $scope.temp.policy.blackListEntryType="Use Manual Entry"; + } + PolicyAppService.getData('getDictionary/get_OnapNameDataByName').then(function (data) { var j = data; $scope.data = JSON.parse(j.data); @@ -216,9 +222,15 @@ angular.module('abs').controller('decisionPolicyController', ['$scope', 'PolicyA $scope.temp.policy.ruleAlgorithmschoices = []; } }else if($scope.temp.policy.ruleProvider=="GUARD_BL_YAML"){ - if($scope.temp.policy.yamlparams.blackList.length==0){ - $scope.temp.policy.yamlparams.blackList = []; - } + if($scope.temp.policy.yamlparams.blackList == null || $scope.temp.policy.yamlparams.blackList.length==0){ + $scope.temp.policy.yamlparams.blackList = []; + } + if($scope.temp.policy.blackListEntries == null || $scope.temp.policy.blackListEntries.length==0){ + $scope.temp.policy.blackListEntries = []; + } + $scope.blackListEntries = []; + $scope.temp.policy.appendBlackListEntries = []; + $scope.blackListEntries = arrayUnique($scope.temp.policy.blackListEntries.concat($scope.temp.policy.yamlparams.blackList)); }else if($scope.temp.policy.ruleProvider=="GUARD_YAML"){ if($scope.temp.policy.yamlparams.targets.length==0){ $scope.temp.policy.yamlparams.targets = []; @@ -259,9 +271,11 @@ angular.module('abs').controller('decisionPolicyController', ['$scope', 'PolicyA $scope.addNewBL = function() { $scope.temp.policy.yamlparams.blackList.push(''); }; - $scope.removeBL = function() { - var lastItem = $scope.temp.policy.yamlparams.blackList.length-1; - $scope.temp.policy.yamlparams.blackList.splice(lastItem); + + $scope.removeBL = function(id) { + $scope.temp.policy.yamlparams.blackList = $scope.temp.policy.yamlparams.blackList.filter(function (obj){ + return obj !== id; + }); }; $scope.treatmentDatas = [{"treatmentValues" : $scope.temp.policy.rainyday.treatmentTableChoices}]; @@ -324,4 +338,93 @@ angular.module('abs').controller('decisionPolicyController', ['$scope', 'PolicyA $scope.temp.policy.attributes = []; } }; + + $scope.importButton = true; + var fd; + $scope.uploadBLFile = function(files) { + fd = new FormData(); + fd.append("file", files[0]); + var fileExtension = files[0].name.split(".")[1]; + if(fileExtension == "xls"){ + $scope.importButton = false; + $scope.$apply(); + }else{ + Notification.error("Upload the BlackList file which extends with .xls format."); + } + }; + + function arrayUnique(array) { + var a = array.concat(); + for(var i=0; i<a.length; ++i) { + for(var j=i+1; j<a.length; ++j) { + if(a[i] === a[j]) + a.splice(j--, 1); + } + } + return a; + } + + $scope.submitUpload = function(){ + $http.post("policycreation/importBlackListForDecisionPolicy", fd, { + withCredentials: false, + headers: {'Content-Type': undefined}, + transformRequest: angular.identity + }).success(function(data){ + $scope.data = JSON.parse(data.data); + $scope.temp.policy.blackListEntries = $scope.data.blackListEntries; + if($scope.temp.policy.blackListEntries[0] !== "error"){ + $scope.blackListEntries = arrayUnique($scope.temp.policy.blackListEntries.concat($scope.temp.policy.yamlparams.blackList)); + $scope.temp.policy.appendBlackListEntries = $scope.data.appendBlackListEntries; + $scope.blackListEntries = $scope.blackListEntries.filter(function (obj){ + return !$scope.temp.policy.appendBlackListEntries.includes(obj); + }); + if($scope.blackListEntries.length == 0){ + $scope.validateButton = true; + Notification.error("Black Lists are empty. Minimum one entry required."); + }else{ + $scope.temp.policy.blackListEntries = $scope.blackListEntries; + Notification.success("Blacklist File Uploaded Successfully."); + $scope.validateButton = false; + $scope.importButton = true; + } + }else{ + Notification.error("Blacklist File Upload Failed." + $scope.temp.policy.blackListEntries[1]); + } + }).error(function(data){ + Notification.error("Blacklist File Upload Failed."); + }); + }; + + $scope.initializeBlackList = function(){ + if($scope.temp.policy.blackListEntryType === "Use File Upload"){ + $scope.validateButton = true; + } else { + $scope.validateButton = false; + } + $("#importFile").val(''); + }; + + $scope.exportBlackListEntries = function(){ + var uuu = "policycreation/exportDecisionBlackListEntries"; + var postData={policyData: $scope.temp.policy, date : $scope.temp.model.modifiedDate, version : $scope.temp.model.version}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.data=data.data; + var url = '../' + $scope.data; + window.location = url; + Notification.success("BlackList Entries Exported Successfully."); + }); + console.log($scope.data); + }, + error : function(data){ + Notification.error("Error Occured while Exporting BlackList Entries."); + } + }); + }; }]);
\ No newline at end of file diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplates/DecisionPolicyTemplate.html b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplates/DecisionPolicyTemplate.html index 27b62870e..151af152d 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplates/DecisionPolicyTemplate.html +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplates/DecisionPolicyTemplate.html @@ -31,8 +31,8 @@ <div class="form-group col-sm-6"> <label>Description:</label> <input type="text" class="form-control" ng-disabled="temp.policy.readOnly" - ng-model="temp.policy.policyDescription" - title="Description field will accept any type of data."/> + ng-model="temp.policy.policyDescription" + title="Description field will accept any type of data." /> </div> </div> <div class="form-group row"> @@ -41,7 +41,8 @@ class="form-control" ng-disabled="temp.policy.readOnly" ng-model="temp.policy.onapName" ng-options="option for option in onapNameDictionaryDatas track by option" - required pattern="\S+" title="Select the dropdown value driven from OnapName (common)Dictionary."></select> + required pattern="\S+" + title="Select the dropdown value driven from OnapName (common)Dictionary."></select> </div> <div class="form-group col-sm-6"> <label>Rule Provider:<sup><b>*</b></sup></label><select @@ -53,7 +54,7 @@ <option>AAF</option> <option>Rainy_Day</option> <option>GUARD_YAML</option> - <option>GUARD_BL_YAML<option> + <option>GUARD_BL_YAML</option> </select> </div> </div> @@ -67,39 +68,40 @@ </div> <div class="form-group col-sm-2"> <input type="text" class="form-control" - ng-disabled="temp.policy.readOnly" ng-model="temp.policy.rainyday.serviceType" - placeholder="Service Type" title="Enter Service Type value."/> + ng-disabled="temp.policy.readOnly" + ng-model="temp.policy.rainyday.serviceType" + placeholder="Service Type" title="Enter Service Type value." /> </div> <div class="form-group col-sm-1"> <label>VNF Type:<sup><b>*</b></sup></label> </div> <div class="form-group col-sm-2"> <input type="text" class="form-control" - ng-disabled="temp.policy.readOnly" ng-model="temp.policy.rainyday.vnfType" - placeholder="VNF Type" title="Enter VNF Type value."/> + ng-disabled="temp.policy.readOnly" + ng-model="temp.policy.rainyday.vnfType" placeholder="VNF Type" + title="Enter VNF Type value." /> </div> <div class="form-group col-sm-1"> <label>Building Block ID:<sup><b>*</b></sup></label> </div> <div class="form-group col-sm-2"> - <select - class="form-control" ng-disabled="temp.policy.readOnly" - ng-model="temp.policy.rainyday.bbid" - ng-options="option for option in rainyDayDictionaryDatas track by option" - ng-change="getWorkstepValues(temp.policy.rainyday.bbid)" title="Select the dropdown value driven from Rainday Allowed Treatments (Decision)Dictionary."> - <option value="">{{temp.policy.rainyday.bbid}}</option> - </select> + <select class="form-control" ng-disabled="temp.policy.readOnly" + ng-model="temp.policy.rainyday.bbid" + ng-options="option for option in rainyDayDictionaryDatas track by option" + ng-change="getWorkstepValues(temp.policy.rainyday.bbid)" + title="Select the dropdown value driven from Rainday Allowed Treatments (Decision)Dictionary."> + <option value="">{{temp.policy.rainyday.bbid}}</option> + </select> </div> <div class="form-group col-sm-1"> <label>Work Step:<sup><b>*</b></sup></label> </div> <div class="form-group col-sm-2"> - <select - class="form-control" ng-disabled="temp.policy.readOnly" - ng-model="temp.policy.rainyday.workstep" - ng-options="option for option in workstepDictionaryDatas track by option" - ng-change="getTreatmentValues(temp.policy.rainyday.bbid, temp.policy.rainyday.workstep)"> - <option value="">{{temp.policy.rainyday.workstep}}</option> + <select class="form-control" ng-disabled="temp.policy.readOnly" + ng-model="temp.policy.rainyday.workstep" + ng-options="option for option in workstepDictionaryDatas track by option" + ng-change="getTreatmentValues(temp.policy.rainyday.bbid, temp.policy.rainyday.workstep)"> + <option value="">{{temp.policy.rainyday.workstep}}</option> </select> </div> </div> @@ -107,46 +109,44 @@ <div class="form-group col-sm-3"> <label>Desired Automated Treatments:</label> <button type="button" class="btn btn-default" - ng-disabled="temp.policy.readOnly" - ng-click="addNewTreatment()"> + ng-disabled="temp.policy.readOnly" ng-click="addNewTreatment()"> <i class="fa fa-plus"></i> </button> </div> </div> <div class="form-group row"> - <div data-ng-repeat="treatmentTableChoice in temp.policy.rainyday.treatmentTableChoices"> - <div class="form-group row" style="margin-left: 2%"> - <div class="form-group col-sm-1"> - <label>Error Code:<sup><b>*</b></sup></label> - </div> - <div class="form-group col-sm-3"> - <input type="text" class="form-control" - ng-disabled="temp.policy.readOnly" - ng-model="treatmentTableChoice.errorcode" - placeholder="Error Code" /> - </div> - <div class="form-group col-sm-1"> - <label>Desired Treatment:<sup><b>*</b></sup></label> - </div> - <div class="form-group col-sm-3"> - <select - class="form-control" - ng-disabled="temp.policy.readOnly" - ng-model="treatmentTableChoice.treatment" - ng-options="option for option in allowedTreatmentsDatas track by option"> - <option value="">{{treatmentTableChoice.treatment}}</option> - </select> - </div> - <div class="form-group col-sm-1"> - <button type="button" class="btn btn-default" - ng-disabled="temp.policy.readOnly" - ng-click="removeTreatment()"> - <i class="fa fa-minus"></i> - </button> + <div + data-ng-repeat="treatmentTableChoice in temp.policy.rainyday.treatmentTableChoices"> + <div class="form-group row" style="margin-left: 2%"> + <div class="form-group col-sm-1"> + <label>Error Code:<sup><b>*</b></sup></label> + </div> + <div class="form-group col-sm-3"> + <input type="text" class="form-control" + ng-disabled="temp.policy.readOnly" + ng-model="treatmentTableChoice.errorcode" + placeholder="Error Code" /> + </div> + <div class="form-group col-sm-1"> + <label>Desired Treatment:<sup><b>*</b></sup></label> + </div> + <div class="form-group col-sm-3"> + <select class="form-control" ng-disabled="temp.policy.readOnly" + ng-model="treatmentTableChoice.treatment" + ng-options="option for option in allowedTreatmentsDatas track by option"> + <option value="">{{treatmentTableChoice.treatment}}</option> + </select> + </div> + <div class="form-group col-sm-1"> + <button type="button" class="btn btn-default" + ng-disabled="temp.policy.readOnly" + ng-click="removeTreatment()"> + <i class="fa fa-minus"></i> + </button> + </div> </div> </div> </div> - </div> </div> </div> </div> @@ -158,86 +158,145 @@ </div> </div> <div class="form-group row"> - <div class="form-group row" style="margin-left: 2%"> - <div class="form-group col-sm-3"> - <label> actor: </label> - </div> - <div class="form-group col-sm-3"> - <input type="text" class="form-control" - ng-disabled="temp.policy.readOnly" ng-model="temp.policy.yamlparams.actor" - placeholder="Actor" /> - </div> + <div class="form-group row" style="margin-left: 2%"> + <div class="form-group col-sm-3"> + <label> actor: </label> </div> - <div class="form-group row" style="margin-left: 2%"> - <div class="form-group col-sm-3"> - <label> recipe: </label> - </div> - <div class="form-group col-sm-3"> - <input type="text" class="form-control" - ng-disabled="temp.policy.readOnly" ng-model="temp.policy.yamlparams.recipe" - placeholder="Recipe" /> - </div> + <div class="form-group col-sm-3"> + <input type="text" class="form-control" + ng-disabled="temp.policy.readOnly" + ng-model="temp.policy.yamlparams.actor" placeholder="Actor" /> </div> - <div class="form-group row" style="margin-left: 2%"> - <div class="form-group col-sm-3"> - <label> CLName: </label> - </div> - <div class="form-group col-sm-3"> - <input type="text" class="form-control" - ng-disabled="temp.policy.readOnly" ng-model="temp.policy.yamlparams.clname" - placeholder="CLName" /> - </div> + </div> + <div class="form-group row" style="margin-left: 2%"> + <div class="form-group col-sm-3"> + <label> recipe: </label> </div> - <div class="form-group row" style="margin-left: 2%"> - <div class="form-group col-sm-3"> - <label> guardActiveStart: </label> - </div> - <div class="form-group col-sm-3"> - <input type="text" class="form-control" - ng-disabled="temp.policy.readOnly" ng-model="temp.policy.yamlparams.guardActiveStart" - placeholder="00:00:00-05:00" /> - </div> + <div class="form-group col-sm-3"> + <input type="text" class="form-control" + ng-disabled="temp.policy.readOnly" + ng-model="temp.policy.yamlparams.recipe" placeholder="Recipe" /> </div> - <div class="form-group row" style="margin-left: 2%"> - <div class="form-group col-sm-3"> - <label> guardActiveEnd: </label> - </div> - <div class="form-group col-sm-3"> - <input type="text" class="form-control" - ng-disabled="temp.policy.readOnly" ng-model="temp.policy.yamlparams.guardActiveEnd" - placeholder="00:00:00-05:00" /> - </div> + </div> + <div class="form-group row" style="margin-left: 2%"> + <div class="form-group col-sm-3"> + <label> CLName: </label> </div> - <div class="form-group row" style="margin-left: 2%"> - <div class="form-group col-sm-3"> - <label> BlackList: </label> - <button type="button" class="btn btn-default" - ng-disabled="temp.policy.readOnly" ng-click="addNewBL()"> - <i class="fa fa-plus"></i> - </button> - </div> - <div class="form-group col-sm-4"> - <div data-ng-repeat="choice in temp.policy.yamlparams.blackList track by $index"> - <div class="form-group row"> + <div class="form-group col-sm-3"> + <input type="text" class="form-control" + ng-disabled="temp.policy.readOnly" + ng-model="temp.policy.yamlparams.clname" placeholder="CLName" /> + </div> + </div> + <div class="form-group row" style="margin-left: 2%"> + <div class="form-group col-sm-3"> + <label> guardActiveStart: </label> + </div> + <div class="form-group col-sm-3"> + <input type="text" class="form-control" + ng-disabled="temp.policy.readOnly" + ng-model="temp.policy.yamlparams.guardActiveStart" + placeholder="00:00:00-05:00" /> + </div> + </div> + <div class="form-group row" style="margin-left: 2%"> + <div class="form-group col-sm-3"> + <label> guardActiveEnd: </label> + </div> + <div class="form-group col-sm-3"> + <input type="text" class="form-control" + ng-disabled="temp.policy.readOnly" + ng-model="temp.policy.yamlparams.guardActiveEnd" + placeholder="00:00:00-05:00" /> + </div> + </div> + <div class="form-group row" style="margin-left: 2%"> + <div class="form-group col-sm-3"> + <label> BlackList Entry Type: </label> + </div> + <div class="form-group col-sm-3"> + <select class="form-control" + ng-model="temp.policy.blackListEntryType" + ng-disabled="temp.policy.readOnly" + ng-change="initializeBlackList(temp.policy.blackListEntryType)"> + <option>Use Manual Entry</option> + <option>Use File Upload</option> + </select> + </div> + </div> + <div class="form-group row" style="margin-left: 2%"> + <div class="form-group col-sm-3"> + <label>Export BlackList Entries:</label> + </div> + <div class="form-group col-sm-3"> + <button type="button" class="btn btn-default" + ng-disabled="disableOnCreate" + ng-click="exportBlackListEntries()">Export BlackList</button> + </div> + </div> + <div ng-if="temp.policy.blackListEntryType == 'Use File Upload'" + class="form-group row" style="margin-left: 2%"> + <div class="form-group col-sm-3"> + <label>Upload BlackList: </label> + </div> + <div class="form-group col-sm-4"> + <input type="file" name="file" class="form-control" + id="importFile" + onchange="angular.element(this).scope().uploadBLFile(this.files)" /> + </div> + <div class="form-group col-sm-2"> + <button class="btn btn-primary" ng-disabled="importButton" + ng-click="submitUpload()">Upload</button> + </div> + </div> + <div ng-if="temp.policy.blackListEntryType == 'Use File Upload'" + class="form-group row" style="margin-left: 2%"> + <div class="form-group col-sm-3"> + <label>Search BlackList: </label> + </div> + <div class="form-group col-sm-4"> + <input type="text" class="form-control" class="search" + placeholder="{{'search'}}..." ng-model="search"> <select + class="form-control" multiple ng-disabled="true" + style="height: 400px;" + ng-model="temp.policy.blackListSearchEntry" + ng-options="option for option in blackListEntries | filter:search"></select> + </div> + </div> + <div ng-if="temp.policy.blackListEntryType == 'Use Manual Entry'" + class="form-group row" style="margin-left: 2%"> + <div class="form-group col-sm-3"> + <label> BlackList: </label> + <button type="button" class="btn btn-default" + ng-disabled="temp.policy.readOnly" ng-click="addNewBL()"> + <i class="fa fa-plus"></i> + </button> + </div> + <div class="form-group col-sm-4"> + <div + data-ng-repeat="choice in temp.policy.yamlparams.blackList track by $index"> + <div class="form-group row"> <div class="form-group col-sm-9"> <input type="text" class="form-control" - ng-disabled="temp.policy.readOnly" - ng-model="temp.policy.yamlparams.blackList[$index]" placeholder="BlackList" /> + ng-disabled="temp.policy.readOnly" + ng-model="temp.policy.yamlparams.blackList[$index]" + placeholder="BlackList" /> </div> <div class="form-group col-sm-1"> - <button type="button" class="btn btn-default" ng-show="$last" - ng-disabled="temp.policy.readOnly" ng-click="removeBL()"> - <i class="fa fa-minus"></i> + <button type="button" class="btn btn-default" + ng-disabled="temp.policy.readOnly" + ng-click="removeBL(temp.policy.yamlparams.blackList[$index])"> + <i class="fa fa-minus"></i> </button> </div> - </div> </div> </div> </div> + </div> </div> </div> </div> - + <div ng-if="temp.policy.ruleProvider == 'GUARD_YAML'"> <div class="well"> <div class="form-group row"> @@ -246,113 +305,122 @@ </div> </div> <div class="form-group row"> - <div class="form-group row" style="margin-left: 2%"> - <div class="form-group col-sm-3"> - <label> actor: </label> - </div> - <div class="form-group col-sm-3"> - <input type="text" class="form-control" - ng-disabled="temp.policy.readOnly" ng-model="temp.policy.yamlparams.actor" - placeholder="Actor" /> - </div> + <div class="form-group row" style="margin-left: 2%"> + <div class="form-group col-sm-3"> + <label> actor: </label> </div> - <div class="form-group row" style="margin-left: 2%"> - <div class="form-group col-sm-3"> - <label> recipe: </label> - </div> - <div class="form-group col-sm-3"> - <input type="text" class="form-control" - ng-disabled="temp.policy.readOnly" ng-model="temp.policy.yamlparams.recipe" - placeholder="Recipe" /> - </div> + <div class="form-group col-sm-3"> + <input type="text" class="form-control" + ng-disabled="temp.policy.readOnly" + ng-model="temp.policy.yamlparams.actor" placeholder="Actor" /> </div> - <div class="form-group row" style="margin-left: 2%"> - <div class="form-group col-sm-3"> - <label> CLName: </label> - </div> - <div class="form-group col-sm-3"> - <input type="text" class="form-control" - ng-disabled="temp.policy.readOnly" ng-model="temp.policy.yamlparams.clname" - placeholder="CLName" /> - </div> + </div> + <div class="form-group row" style="margin-left: 2%"> + <div class="form-group col-sm-3"> + <label> recipe: </label> </div> - <div class="form-group row" style="margin-left: 2%"> - <div class="form-group col-sm-3"> - <label> Targets: </label> - <button type="button" class="btn btn-default" - ng-disabled="temp.policy.readOnly" ng-click="addNewTarget()"> - <i class="fa fa-plus"></i> - </button> - </div> - <div class="form-group col-sm-4"> - <div data-ng-repeat="choice in temp.policy.yamlparams.targets track by $index"> - <div class="form-group row"> + <div class="form-group col-sm-3"> + <input type="text" class="form-control" + ng-disabled="temp.policy.readOnly" + ng-model="temp.policy.yamlparams.recipe" placeholder="Recipe" /> + </div> + </div> + <div class="form-group row" style="margin-left: 2%"> + <div class="form-group col-sm-3"> + <label> CLName: </label> + </div> + <div class="form-group col-sm-3"> + <input type="text" class="form-control" + ng-disabled="temp.policy.readOnly" + ng-model="temp.policy.yamlparams.clname" placeholder="CLName" /> + </div> + </div> + <div class="form-group row" style="margin-left: 2%"> + <div class="form-group col-sm-3"> + <label> Targets: </label> + <button type="button" class="btn btn-default" + ng-disabled="temp.policy.readOnly" ng-click="addNewTarget()"> + <i class="fa fa-plus"></i> + </button> + </div> + <div class="form-group col-sm-4"> + <div + data-ng-repeat="choice in temp.policy.yamlparams.targets track by $index"> + <div class="form-group row"> <div class="form-group col-sm-9"> <input type="text" class="form-control" - ng-disabled="temp.policy.readOnly" - ng-model="temp.policy.yamlparams.targets[$index]" placeholder="Target" /> + ng-disabled="temp.policy.readOnly" + ng-model="temp.policy.yamlparams.targets[$index]" + placeholder="Target" /> </div> <div class="form-group col-sm-1"> <button type="button" class="btn btn-default" ng-show="$last" - ng-disabled="temp.policy.readOnly" ng-click="removeTarget()"> - <i class="fa fa-minus"></i> + ng-disabled="temp.policy.readOnly" ng-click="removeTarget()"> + <i class="fa fa-minus"></i> </button> </div> - </div> </div> </div> </div> - <div class="form-group row" style="margin-left: 2%"> - <div class="form-group col-sm-3"> - <label> limit: </label> - </div> - <div class="form-group col-sm-3"> - <input type="text" class="form-control" - ng-disabled="temp.policy.readOnly" ng-model="temp.policy.yamlparams.limit" - placeholder="Limit" title="Enter time limit value."/> - </div> + </div> + <div class="form-group row" style="margin-left: 2%"> + <div class="form-group col-sm-3"> + <label> limit: </label> </div> - <div class="form-group row" style="margin-left: 2%"> - <div class="form-group col-sm-3"> - <label> timeWindow: </label> - </div> - <div class="form-group col-sm-2"> - <input type="text" class="form-control" - ng-disabled="temp.policy.readOnly" ng-model="temp.policy.yamlparams.timeWindow" - placeholder="Time Window" title="Enter time window value."/> - </div> - <div class="form-group col-sm-1"> - <select class="form-control" ng-disabled="temp.policy.readOnly" - ng-model="temp.policy.yamlparams.timeUnits" title="Select the Time Units value from dropdown options."> + <div class="form-group col-sm-3"> + <input type="text" class="form-control" + ng-disabled="temp.policy.readOnly" + ng-model="temp.policy.yamlparams.limit" placeholder="Limit" + title="Enter time limit value." /> + </div> + </div> + <div class="form-group row" style="margin-left: 2%"> + <div class="form-group col-sm-3"> + <label> timeWindow: </label> + </div> + <div class="form-group col-sm-2"> + <input type="text" class="form-control" + ng-disabled="temp.policy.readOnly" + ng-model="temp.policy.yamlparams.timeWindow" + placeholder="Time Window" title="Enter time window value." /> + </div> + <div class="form-group col-sm-1"> + <select class="form-control" ng-disabled="temp.policy.readOnly" + ng-model="temp.policy.yamlparams.timeUnits" + title="Select the Time Units value from dropdown options."> <option>minute</option> <option>hour</option> <option>day</option> <option>week</option> <option>month</option> <option>year</option> - </select> - </div> + </select> </div> - <div class="form-group row" style="margin-left: 2%"> - <div class="form-group col-sm-3"> - <label> guardActiveStart: </label> - </div> - <div class="form-group col-sm-3"> - <input type="text" class="form-control" - ng-disabled="temp.policy.readOnly" ng-model="temp.policy.yamlparams.guardActiveStart" title="Enter Guard Active Start value in following patren '00:00:00-05:00'." - placeholder="00:00:00-05:00" /> - </div> + </div> + <div class="form-group row" style="margin-left: 2%"> + <div class="form-group col-sm-3"> + <label> guardActiveStart: </label> </div> - <div class="form-group row" style="margin-left: 2%"> - <div class="form-group col-sm-3"> - <label> guardActiveEnd: </label> - </div> - <div class="form-group col-sm-3"> - <input type="text" class="form-control" - ng-disabled="temp.policy.readOnly" ng-model="temp.policy.yamlparams.guardActiveEnd" title="Enter Guard Active End value in following patren '00:00:00-05:00'." - placeholder="00:00:00-05:00" /> - </div> + <div class="form-group col-sm-3"> + <input type="text" class="form-control" + ng-disabled="temp.policy.readOnly" + ng-model="temp.policy.yamlparams.guardActiveStart" + title="Enter Guard Active Start value in following patren '00:00:00-05:00'." + placeholder="00:00:00-05:00" /> + </div> + </div> + <div class="form-group row" style="margin-left: 2%"> + <div class="form-group col-sm-3"> + <label> guardActiveEnd: </label> </div> + <div class="form-group col-sm-3"> + <input type="text" class="form-control" + ng-disabled="temp.policy.readOnly" + ng-model="temp.policy.yamlparams.guardActiveEnd" + title="Enter Guard Active End value in following patren '00:00:00-05:00'." + placeholder="00:00:00-05:00" /> + </div> + </div> </div> </div> </div> @@ -364,7 +432,8 @@ <div class="form-group col-sm-1"> <label>Component Attributes:</label><br> <button type="button" class="btn btn-default" - ng-disabled="temp.policy.readOnly" ng-click="addNewChoice()" title="onClick Component Attribute row is added."> + ng-disabled="temp.policy.readOnly" ng-click="addNewChoice()" + title="onClick Component Attribute row is added."> <i class="fa fa-plus"></i> </button> </div> @@ -375,18 +444,21 @@ <div class="form-group col-sm-3"> <select class="form-control" ng-disabled="temp.policy.readOnly" ng-model="choice.key" - ng-options="option for option in attributeDictionaryDatas track by option" title="Select the dropdown value driven from Attribute (common)Dictionary."> + ng-options="option for option in attributeDictionaryDatas track by option" + title="Select the dropdown value driven from Attribute (common)Dictionary."> <option value="">{{choice.key}}</option> </select> </div> <div class="form-group col-sm-3"> <input type="text" class="form-control" ng-disabled="temp.policy.readOnly" ng-model="choice.value" - placeholder="Attribute Value" title="Enter the Attribute Value without any spaces and special characters"/> + placeholder="Attribute Value" + title="Enter the Attribute Value without any spaces and special characters" /> </div> <div class="form-group col-sm-1"> <button type="button" class="btn btn-default" ng-show="$last" - ng-disabled="temp.policy.readOnly" ng-click="removeChoice()" title="onClick will remove the last row"> + ng-disabled="temp.policy.readOnly" ng-click="removeChoice()" + title="onClick will remove the last row"> <i class="fa fa-minus"></i> </button> </div> @@ -403,7 +475,8 @@ <label>Settings Attributes:</label><br> <button type="button" class="btn btn-default" ng-disabled="temp.policy.readOnly" - ng-click="addNewSettingsChoice()" title="onClick Settings Attribute row is added."> + ng-click="addNewSettingsChoice()" + title="onClick Settings Attribute row is added."> <i class="fa fa-plus"></i> </button> </div> @@ -414,19 +487,22 @@ <div class="form-group col-sm-3"> <select class="form-control" ng-disabled="temp.policy.readOnly" ng-model="settingschoice.key" - ng-options="option for option in settingsDictionaryDatas track by option" title="Select the dropdown value driven from Settings (Decision)Dictionary."> + ng-options="option for option in settingsDictionaryDatas track by option" + title="Select the dropdown value driven from Settings (Decision)Dictionary."> <option value="">{{settingschoice.key}}</option> </select> </div> <div class="form-group col-sm-3"> <input type="text" class="form-control" ng-disabled="temp.policy.readOnly" - ng-model="settingschoice.value" placeholder="Settings Value" title="Enter the Settings Attribute Value without any spaces and special characters"/> + ng-model="settingschoice.value" placeholder="Settings Value" + title="Enter the Settings Attribute Value without any spaces and special characters" /> </div> <div class="form-group col-sm-1"> <button type="button" class="btn btn-default" ng-show="$last" ng-disabled="temp.policy.readOnly" - ng-click="removeSettingsChoice()" title="onClick will remove the last row"> + ng-click="removeSettingsChoice()" + title="onClick will remove the last row"> <i class="fa fa-minus"></i> </button> </div> @@ -443,7 +519,8 @@ <div class="form-group col-sm-1"> <button type="button" class="btn btn-default" ng-disabled="temp.policy.readOnly" - ng-click="addNewRuleAlgorithm()" title="onClick Rule Algorithms row is added."> + ng-click="addNewRuleAlgorithm()" + title="onClick Rule Algorithms row is added."> <i class="fa fa-plus"></i> </button> </div> @@ -462,7 +539,8 @@ ng-disabled="temp.policy.readOnly" ng-model="ruleAlgorithmschoice.dynamicRuleAlgorithmField1" ng-options="option for option in attributeDictionaryDatas track by option" - name="dynamicRuleAlgorithmField1" title="Select the dropdown value driven from Attribute (common)Dictionary or Settings (Decision)Dictionary."> + name="dynamicRuleAlgorithmField1" + title="Select the dropdown value driven from Attribute (common)Dictionary or Settings (Decision)Dictionary."> <option value="">{{ruleAlgorithmschoice.dynamicRuleAlgorithmField1}}</option> </select> </div> @@ -471,18 +549,21 @@ ng-disabled="temp.policy.readOnly" ng-model="ruleAlgorithmschoice.dynamicRuleAlgorithmCombo" ng-options="option for option in functionDefinitionDatas track by option" - name="dynamicRuleAlgorithmCombo" title="Select the dropdown value driven from FunctionDataType."></select> + name="dynamicRuleAlgorithmCombo" + title="Select the dropdown value driven from FunctionDataType."></select> </div> <div class="form-group col-sm-3"> <input type="text" class="form-control" ng-disabled="temp.policy.readOnly" ng-model="ruleAlgorithmschoice.dynamicRuleAlgorithmField2" - name="dynamicRuleAlgorithmField2" title="Enter the Value without any spaces and special characters and for rule formation use A1, A2,..etc., based on above Rules."/> + name="dynamicRuleAlgorithmField2" + title="Enter the Value without any spaces and special characters and for rule formation use A1, A2,..etc., based on above Rules." /> </div> <div class="form-group col-sm-1"> <button type="button" class="btn btn-default" ng-disabled="temp.policy.readOnly" - ng-click="removeRuleAlgorithm()" title="onClick will remove the last row"> + ng-click="removeRuleAlgorithm()" + title="onClick will remove the last row"> <i class="fa fa-minus"></i> </button> </div> @@ -497,11 +578,14 @@ <div class="modal-footer"> <button class="btn btn-primary" herf="javascript:void(0)" ng-disabled="temp.policy.readOnly" - ng-click="validatePolicy(temp.policy);" title="Validate the data entered in the Policy fields.">Validate</button> + ng-click="validatePolicy(temp.policy);" + title="Validate the data entered in the Policy fields.">Validate</button> <button class="btn btn-success" herf="javascript:void(0)" ng-disabled="savebutton" ng-disabled="temp.policy.readOnly" - ng-click="saveDecisionPolicy(temp);" title="Save the Policy with validated data.">Save</button> - <button type="button" class="btn btn-default" ng-click="refresh();" title="Close the template.">Close</button> + ng-click="saveDecisionPolicy(temp);" + title="Save the Policy with validated data.">Save</button> + <button type="button" class="btn btn-default" ng-click="refresh();" + title="Close the template.">Close</button> </div> </form> </div>
\ No newline at end of file diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/ExportAndImportDecisionBlackListEntriesTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/ExportAndImportDecisionBlackListEntriesTest.java new file mode 100644 index 000000000..bf01ac1d9 --- /dev/null +++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/ExportAndImportDecisionBlackListEntriesTest.java @@ -0,0 +1,126 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP Policy Engine + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.policy.controller; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.mock; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.StringReader; + +import javax.servlet.ReadListener; +import javax.servlet.ServletInputStream; +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.io.IOUtils; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.mock.web.MockHttpServletResponse; + +public class ExportAndImportDecisionBlackListEntriesTest { + + private HttpServletRequest request; + private MockHttpServletResponse response; + String jsonString; + + @Before + public void setUp() throws Exception { + request = mock(HttpServletRequest.class); + response = new MockHttpServletResponse(); + } + + @Test + public void testExportBlackList() throws IOException{ + ClassLoader classLoader = getClass().getClassLoader(); + jsonString = IOUtils.toString(classLoader.getResourceAsStream("DecisionPolicyData.txt")); + try(BufferedReader reader = new BufferedReader(new StringReader(jsonString))){ + Mockito.when(request.getReader()).thenReturn(reader); + ExportAndImportDecisionBlackListEntries controller = new ExportAndImportDecisionBlackListEntries(); + controller.exportBlackList(request, response); + assertTrue("".equals(response.getContentAsString())); + }catch(Exception e){ + fail("Not expecting Exception while Exporting BlackListEntries."); + } + } + + @Test + public void testImportBlackList() throws Exception{ + MockHttpServletRequest request = new MockHttpServletRequest(); + ExportAndImportDecisionBlackListEntries controller = new ExportAndImportDecisionBlackListEntries(); + File file = new File("src/test/resources/BlackList.xls"); + try(FileInputStream targetStream = new FileInputStream(file)){ + ExportAndImportDecisionBlackListEntriesTest testController = Mockito.mock(ExportAndImportDecisionBlackListEntriesTest.class); + ServletInputStream inputStream = testController.getInputStream(getBytes(targetStream)); + Mockito.when(request.getInputStream()).thenReturn(inputStream); + String boundary = "===" + System.currentTimeMillis() + "==="; + request.addHeader("Content-Type", "multipart/form-data; boundary=" + boundary); + request.addHeader("name", "BlackList.xls"); + controller.importBlackListFile(request, response); + assertTrue(response.getContentAsString().contains("data")); + }catch(Exception e){ + fail("Not expecting Exception while importing BlackListEntries."); + } + } + + public static byte[] getBytes(InputStream is) throws IOException { + int len; + int size = 1024; + byte[] buf; + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + buf = new byte[size]; + while ((len = is.read(buf, 0, size)) != -1) + bos.write(buf, 0, len); + buf = bos.toByteArray(); + return buf; + } + + public ServletInputStream getInputStream(byte[] body) throws IOException { + final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(body); + ServletInputStream servletInputStream = new ServletInputStream() { + public int read() throws IOException { + return byteArrayInputStream.read(); + } + + @Override + public boolean isFinished() { + return false; + } + + @Override + public boolean isReady() { + return false; + } + + @Override + public void setReadListener(ReadListener readListener) { + } + }; + return servletInputStream; + } +} diff --git a/POLICY-SDK-APP/src/test/resources/BlackList.xls b/POLICY-SDK-APP/src/test/resources/BlackList.xls Binary files differnew file mode 100644 index 000000000..228d7245f --- /dev/null +++ b/POLICY-SDK-APP/src/test/resources/BlackList.xls diff --git a/POLICY-SDK-APP/src/test/resources/DecisionPolicyData.txt b/POLICY-SDK-APP/src/test/resources/DecisionPolicyData.txt new file mode 100644 index 000000000..26b07cfcf --- /dev/null +++ b/POLICY-SDK-APP/src/test/resources/DecisionPolicyData.txt @@ -0,0 +1 @@ +{"policyData":{"data":{"description":"SampelGuardBLOne@CreatedBy:demo@CreatedBy:@ModifiedBy:demo@ModifiedBy:","policyIssuer":null,"policyDefaults":null,"target":{"anyOf":[{"allOf":[{"match":[{"attributeValue":{"content":["com.Decision_SampelGuardBLOne.4.xml"],"dataType":"http://www.w3.org/2001/XMLSchema#string","otherAttributes":{}},"attributeDesignator":{"category":"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject","attributeId":"PolicyName","dataType":"http://www.w3.org/2001/XMLSchema#string","issuer":null,"mustBePresent":false},"attributeSelector":null,"matchId":"org.onap.function.regex-match"}]},{"match":[{"attributeValue":{"content":["Test"],"dataType":"http://www.w3.org/2001/XMLSchema#string","otherAttributes":{}},"attributeDesignator":{"category":"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject","attributeId":"ONAPName","dataType":"http://www.w3.org/2001/XMLSchema#string","issuer":null,"mustBePresent":false},"attributeSelector":null,"matchId":"org.onap.function.regex-match"},{"attributeValue":{"content":["(?i)testActor"],"dataType":"http://www.w3.org/2001/XMLSchema#string","otherAttributes":{}},"attributeDesignator":{"category":"urn:oasis:names:tc:xacml:3.0:attribute-category:resource","attributeId":"actor","dataType":"http://www.w3.org/2001/XMLSchema#string","issuer":null,"mustBePresent":false},"attributeSelector":null,"matchId":"urn:oasis:names:tc:xacml:1.0:function:string-regexp-match"},{"attributeValue":{"content":["(?i)testRecipe"],"dataType":"http://www.w3.org/2001/XMLSchema#string","otherAttributes":{}},"attributeDesignator":{"category":"urn:oasis:names:tc:xacml:3.0:attribute-category:resource","attributeId":"recipe","dataType":"http://www.w3.org/2001/XMLSchema#string","issuer":null,"mustBePresent":false},"attributeSelector":null,"matchId":"urn:oasis:names:tc:xacml:1.0:function:string-regexp-match"},{"attributeValue":{"content":["testCLName"],"dataType":"http://www.w3.org/2001/XMLSchema#string","otherAttributes":{}},"attributeDesignator":{"category":"urn:oasis:names:tc:xacml:3.0:attribute-category:resource","attributeId":"clname","dataType":"http://www.w3.org/2001/XMLSchema#string","issuer":null,"mustBePresent":false},"attributeSelector":null,"matchId":"urn:oasis:names:tc:xacml:1.0:function:string-regexp-match"},{"attributeValue":{"content":["Use Manual Entry"],"dataType":"http://www.w3.org/2001/XMLSchema#string","otherAttributes":{}},"attributeDesignator":{"category":"urn:oasis:names:tc:xacml:3.0:attribute-category:resource","attributeId":"blackListEntryType","dataType":"http://www.w3.org/2001/XMLSchema#string","issuer":null,"mustBePresent":false},"attributeSelector":null,"matchId":"urn:oasis:names:tc:xacml:1.0:function:string-regexp-match"}]}]}]},"combinerParametersOrRuleCombinerParametersOrVariableDefinition":[{"description":null,"target":{"anyOf":[{"allOf":[{"match":[{"attributeValue":{"content":["DECIDE"],"dataType":"http://www.w3.org/2001/XMLSchema#string","otherAttributes":{}},"attributeDesignator":{"category":"urn:oasis:names:tc:xacml:3.0:attribute-category:action","attributeId":"urn:oasis:names:tc:xacml:1.0:action:action-id","dataType":"http://www.w3.org/2001/XMLSchema#string","issuer":null,"mustBePresent":false},"attributeSelector":null,"matchId":"urn:oasis:names:tc:xacml:3.0:function:string-equal-ignore-case"}]}]}]},"condition":{"expression":{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Apply","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"description":null,"expression":[{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Apply","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"description":null,"expression":[{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Apply","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"description":null,"expression":[{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Apply","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"description":null,"expression":[{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}AttributeDesignator","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"category":"urn:oasis:names:tc:xacml:3.0:attribute-category:environment","attributeId":"urn:oasis:names:tc:xacml:1.0:environment:current-time","dataType":"http://www.w3.org/2001/XMLSchema#time","issuer":null,"mustBePresent":false},"nil":false,"globalScope":true,"typeSubstituted":false}],"functionId":"urn:oasis:names:tc:xacml:1.0:function:time-one-and-only"},"nil":false,"globalScope":true,"typeSubstituted":false},{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}AttributeValue","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"content":["5:00"],"dataType":"http://www.w3.org/2001/XMLSchema#time","otherAttributes":{}},"nil":false,"globalScope":true,"typeSubstituted":false},{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}AttributeValue","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"content":["10:00"],"dataType":"http://www.w3.org/2001/XMLSchema#time","otherAttributes":{}},"nil":false,"globalScope":true,"typeSubstituted":false}],"functionId":"urn:oasis:names:tc:xacml:2.0:function:time-in-range"},"nil":false,"globalScope":true,"typeSubstituted":false},{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Apply","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"description":null,"expression":[{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Function","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.FunctionType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"functionId":"urn:oasis:names:tc:xacml:1.0:function:string-equal"},"nil":false,"globalScope":true,"typeSubstituted":false},{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Apply","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"description":null,"expression":[{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}AttributeDesignator","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"category":"urn:oasis:names:tc:xacml:3.0:attribute-category:resource","attributeId":"target","dataType":"http://www.w3.org/2001/XMLSchema#string","issuer":null,"mustBePresent":false},"nil":false,"globalScope":true,"typeSubstituted":false}],"functionId":"urn:oasis:names:tc:xacml:1.0:function:string-one-and-only"},"nil":false,"globalScope":true,"typeSubstituted":false},{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Apply","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"description":null,"expression":[{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}AttributeValue","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"content":["testBL2"],"dataType":"http://www.w3.org/2001/XMLSchema#string","otherAttributes":{}},"nil":false,"globalScope":true,"typeSubstituted":false},{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}AttributeValue","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"content":["testBL3"],"dataType":"http://www.w3.org/2001/XMLSchema#string","otherAttributes":{}},"nil":false,"globalScope":true,"typeSubstituted":false},{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}AttributeValue","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"content":["testBL4"],"dataType":"http://www.w3.org/2001/XMLSchema#string","otherAttributes":{}},"nil":false,"globalScope":true,"typeSubstituted":false}],"functionId":"urn:oasis:names:tc:xacml:1.0:function:string-bag"},"nil":false,"globalScope":true,"typeSubstituted":false}],"functionId":"urn:oasis:names:tc:xacml:3.0:function:any-of"},"nil":false,"globalScope":true,"typeSubstituted":false}],"functionId":"urn:oasis:names:tc:xacml:1.0:function:and"},"nil":false,"globalScope":true,"typeSubstituted":false}],"functionId":"urn:oasis:names:tc:xacml:1.0:function:not"},"nil":false,"globalScope":true,"typeSubstituted":false}},"obligationExpressions":null,"adviceExpressions":null,"ruleId":"urn:com:xacml:rule:id:284d9393-f861-4250-b62d-fc36640a363a","effect":"PERMIT"},{"description":null,"target":{"anyOf":[{"allOf":[{"match":[{"attributeValue":{"content":["DECIDE"],"dataType":"http://www.w3.org/2001/XMLSchema#string","otherAttributes":{}},"attributeDesignator":{"category":"urn:oasis:names:tc:xacml:3.0:attribute-category:action","attributeId":"urn:oasis:names:tc:xacml:1.0:action:action-id","dataType":"http://www.w3.org/2001/XMLSchema#string","issuer":null,"mustBePresent":false},"attributeSelector":null,"matchId":"urn:oasis:names:tc:xacml:3.0:function:string-equal-ignore-case"}]}]}]},"condition":{"expression":{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Apply","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"description":null,"expression":[{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Apply","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"description":null,"expression":[{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Apply","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"description":null,"expression":[{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Apply","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"description":null,"expression":[{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Apply","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"description":null,"expression":[{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}AttributeDesignator","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"category":"urn:oasis:names:tc:xacml:3.0:attribute-category:environment","attributeId":"urn:oasis:names:tc:xacml:1.0:environment:current-time","dataType":"http://www.w3.org/2001/XMLSchema#time","issuer":null,"mustBePresent":false},"nil":false,"globalScope":true,"typeSubstituted":false}],"functionId":"urn:oasis:names:tc:xacml:1.0:function:time-one-and-only"},"nil":false,"globalScope":true,"typeSubstituted":false},{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}AttributeValue","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"content":["5:00"],"dataType":"http://www.w3.org/2001/XMLSchema#time","otherAttributes":{}},"nil":false,"globalScope":true,"typeSubstituted":false},{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}AttributeValue","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"content":["10:00"],"dataType":"http://www.w3.org/2001/XMLSchema#time","otherAttributes":{}},"nil":false,"globalScope":true,"typeSubstituted":false}],"functionId":"urn:oasis:names:tc:xacml:2.0:function:time-in-range"},"nil":false,"globalScope":true,"typeSubstituted":false},{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Apply","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"description":null,"expression":[{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Function","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.FunctionType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"functionId":"urn:oasis:names:tc:xacml:1.0:function:string-equal"},"nil":false,"globalScope":true,"typeSubstituted":false},{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Apply","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"description":null,"expression":[{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}AttributeDesignator","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"category":"urn:oasis:names:tc:xacml:3.0:attribute-category:resource","attributeId":"target","dataType":"http://www.w3.org/2001/XMLSchema#string","issuer":null,"mustBePresent":false},"nil":false,"globalScope":true,"typeSubstituted":false}],"functionId":"urn:oasis:names:tc:xacml:1.0:function:string-one-and-only"},"nil":false,"globalScope":true,"typeSubstituted":false},{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Apply","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"description":null,"expression":[{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}AttributeValue","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"content":["testBL2"],"dataType":"http://www.w3.org/2001/XMLSchema#string","otherAttributes":{}},"nil":false,"globalScope":true,"typeSubstituted":false},{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}AttributeValue","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"content":["testBL3"],"dataType":"http://www.w3.org/2001/XMLSchema#string","otherAttributes":{}},"nil":false,"globalScope":true,"typeSubstituted":false},{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}AttributeValue","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"content":["testBL4"],"dataType":"http://www.w3.org/2001/XMLSchema#string","otherAttributes":{}},"nil":false,"globalScope":true,"typeSubstituted":false}],"functionId":"urn:oasis:names:tc:xacml:1.0:function:string-bag"},"nil":false,"globalScope":true,"typeSubstituted":false}],"functionId":"urn:oasis:names:tc:xacml:3.0:function:any-of"},"nil":false,"globalScope":true,"typeSubstituted":false}],"functionId":"urn:oasis:names:tc:xacml:1.0:function:and"},"nil":false,"globalScope":true,"typeSubstituted":false}],"functionId":"urn:oasis:names:tc:xacml:1.0:function:not"},"nil":false,"globalScope":true,"typeSubstituted":false}],"functionId":"urn:oasis:names:tc:xacml:1.0:function:not"},"nil":false,"globalScope":true,"typeSubstituted":false}},"obligationExpressions":null,"adviceExpressions":{"adviceExpression":[{"attributeAssignmentExpression":[{"expression":{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}AttributeValue","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"content":["Denied!"],"dataType":"http://www.w3.org/2001/XMLSchema#string","otherAttributes":{}},"nil":false,"globalScope":true,"typeSubstituted":false},"attributeId":"guard.response","category":"urn:oasis:names:tc:xacml:3.0:attribute-category:resource","issuer":null}],"adviceId":"GUARD_BL_YAML","appliesTo":"DENY"}]},"ruleId":"urn:com:xacml:rule:id:284d9393-f861-4250-b62d-fc36640a363a","effect":"DENY"}],"obligationExpressions":null,"adviceExpressions":null,"policyId":"urn:com:xacml:policy:id:d56af069-6cf1-430c-ba07-e26602e06a52","version":"4","ruleCombiningAlgId":"urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides","maxDelegationDepth":null},"policyName":"SampelGuardBLOne","configBodyData":null,"configType":null,"policyID":null,"policyType":"Decision","comboPolicyType":null,"configPolicyType":null,"policyDescription":"SampelGuardBLOne","onapName":"Test","configName":null,"ruleID":null,"parentPath":null,"adminNotification":null,"policyData":{"description":"SampelGuardBLOne@CreatedBy:demo@CreatedBy:@ModifiedBy:demo@ModifiedBy:","policyIssuer":null,"policyDefaults":null,"target":{"anyOf":[{"allOf":[{"match":[{"attributeValue":{"content":["com.Decision_SampelGuardBLOne.4.xml"],"dataType":"http://www.w3.org/2001/XMLSchema#string","otherAttributes":{}},"attributeDesignator":{"category":"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject","attributeId":"PolicyName","dataType":"http://www.w3.org/2001/XMLSchema#string","issuer":null,"mustBePresent":false},"attributeSelector":null,"matchId":"org.onap.function.regex-match"}]},{"match":[{"attributeValue":{"content":["Test"],"dataType":"http://www.w3.org/2001/XMLSchema#string","otherAttributes":{}},"attributeDesignator":{"category":"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject","attributeId":"ONAPName","dataType":"http://www.w3.org/2001/XMLSchema#string","issuer":null,"mustBePresent":false},"attributeSelector":null,"matchId":"org.onap.function.regex-match"},{"attributeValue":{"content":["(?i)testActor"],"dataType":"http://www.w3.org/2001/XMLSchema#string","otherAttributes":{}},"attributeDesignator":{"category":"urn:oasis:names:tc:xacml:3.0:attribute-category:resource","attributeId":"actor","dataType":"http://www.w3.org/2001/XMLSchema#string","issuer":null,"mustBePresent":false},"attributeSelector":null,"matchId":"urn:oasis:names:tc:xacml:1.0:function:string-regexp-match"},{"attributeValue":{"content":["(?i)testRecipe"],"dataType":"http://www.w3.org/2001/XMLSchema#string","otherAttributes":{}},"attributeDesignator":{"category":"urn:oasis:names:tc:xacml:3.0:attribute-category:resource","attributeId":"recipe","dataType":"http://www.w3.org/2001/XMLSchema#string","issuer":null,"mustBePresent":false},"attributeSelector":null,"matchId":"urn:oasis:names:tc:xacml:1.0:function:string-regexp-match"},{"attributeValue":{"content":["testCLName"],"dataType":"http://www.w3.org/2001/XMLSchema#string","otherAttributes":{}},"attributeDesignator":{"category":"urn:oasis:names:tc:xacml:3.0:attribute-category:resource","attributeId":"clname","dataType":"http://www.w3.org/2001/XMLSchema#string","issuer":null,"mustBePresent":false},"attributeSelector":null,"matchId":"urn:oasis:names:tc:xacml:1.0:function:string-regexp-match"},{"attributeValue":{"content":["Use Manual Entry"],"dataType":"http://www.w3.org/2001/XMLSchema#string","otherAttributes":{}},"attributeDesignator":{"category":"urn:oasis:names:tc:xacml:3.0:attribute-category:resource","attributeId":"blackListEntryType","dataType":"http://www.w3.org/2001/XMLSchema#string","issuer":null,"mustBePresent":false},"attributeSelector":null,"matchId":"urn:oasis:names:tc:xacml:1.0:function:string-regexp-match"}]}]}]},"combinerParametersOrRuleCombinerParametersOrVariableDefinition":[{"description":null,"target":{"anyOf":[{"allOf":[{"match":[{"attributeValue":{"content":["DECIDE"],"dataType":"http://www.w3.org/2001/XMLSchema#string","otherAttributes":{}},"attributeDesignator":{"category":"urn:oasis:names:tc:xacml:3.0:attribute-category:action","attributeId":"urn:oasis:names:tc:xacml:1.0:action:action-id","dataType":"http://www.w3.org/2001/XMLSchema#string","issuer":null,"mustBePresent":false},"attributeSelector":null,"matchId":"urn:oasis:names:tc:xacml:3.0:function:string-equal-ignore-case"}]}]}]},"condition":{"expression":{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Apply","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"description":null,"expression":[{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Apply","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"description":null,"expression":[{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Apply","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"description":null,"expression":[{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Apply","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"description":null,"expression":[{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}AttributeDesignator","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"category":"urn:oasis:names:tc:xacml:3.0:attribute-category:environment","attributeId":"urn:oasis:names:tc:xacml:1.0:environment:current-time","dataType":"http://www.w3.org/2001/XMLSchema#time","issuer":null,"mustBePresent":false},"nil":false,"globalScope":true,"typeSubstituted":false}],"functionId":"urn:oasis:names:tc:xacml:1.0:function:time-one-and-only"},"nil":false,"globalScope":true,"typeSubstituted":false},{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}AttributeValue","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"content":["5:00"],"dataType":"http://www.w3.org/2001/XMLSchema#time","otherAttributes":{}},"nil":false,"globalScope":true,"typeSubstituted":false},{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}AttributeValue","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"content":["10:00"],"dataType":"http://www.w3.org/2001/XMLSchema#time","otherAttributes":{}},"nil":false,"globalScope":true,"typeSubstituted":false}],"functionId":"urn:oasis:names:tc:xacml:2.0:function:time-in-range"},"nil":false,"globalScope":true,"typeSubstituted":false},{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Apply","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"description":null,"expression":[{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Function","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.FunctionType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"functionId":"urn:oasis:names:tc:xacml:1.0:function:string-equal"},"nil":false,"globalScope":true,"typeSubstituted":false},{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Apply","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"description":null,"expression":[{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}AttributeDesignator","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"category":"urn:oasis:names:tc:xacml:3.0:attribute-category:resource","attributeId":"target","dataType":"http://www.w3.org/2001/XMLSchema#string","issuer":null,"mustBePresent":false},"nil":false,"globalScope":true,"typeSubstituted":false}],"functionId":"urn:oasis:names:tc:xacml:1.0:function:string-one-and-only"},"nil":false,"globalScope":true,"typeSubstituted":false},{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Apply","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"description":null,"expression":[{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}AttributeValue","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"content":["testBL2"],"dataType":"http://www.w3.org/2001/XMLSchema#string","otherAttributes":{}},"nil":false,"globalScope":true,"typeSubstituted":false},{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}AttributeValue","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"content":["testBL3"],"dataType":"http://www.w3.org/2001/XMLSchema#string","otherAttributes":{}},"nil":false,"globalScope":true,"typeSubstituted":false},{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}AttributeValue","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"content":["testBL4"],"dataType":"http://www.w3.org/2001/XMLSchema#string","otherAttributes":{}},"nil":false,"globalScope":true,"typeSubstituted":false}],"functionId":"urn:oasis:names:tc:xacml:1.0:function:string-bag"},"nil":false,"globalScope":true,"typeSubstituted":false}],"functionId":"urn:oasis:names:tc:xacml:3.0:function:any-of"},"nil":false,"globalScope":true,"typeSubstituted":false}],"functionId":"urn:oasis:names:tc:xacml:1.0:function:and"},"nil":false,"globalScope":true,"typeSubstituted":false}],"functionId":"urn:oasis:names:tc:xacml:1.0:function:not"},"nil":false,"globalScope":true,"typeSubstituted":false}},"obligationExpressions":null,"adviceExpressions":null,"ruleId":"urn:com:xacml:rule:id:284d9393-f861-4250-b62d-fc36640a363a","effect":"PERMIT"},{"description":null,"target":{"anyOf":[{"allOf":[{"match":[{"attributeValue":{"content":["DECIDE"],"dataType":"http://www.w3.org/2001/XMLSchema#string","otherAttributes":{}},"attributeDesignator":{"category":"urn:oasis:names:tc:xacml:3.0:attribute-category:action","attributeId":"urn:oasis:names:tc:xacml:1.0:action:action-id","dataType":"http://www.w3.org/2001/XMLSchema#string","issuer":null,"mustBePresent":false},"attributeSelector":null,"matchId":"urn:oasis:names:tc:xacml:3.0:function:string-equal-ignore-case"}]}]}]},"condition":{"expression":{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Apply","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"description":null,"expression":[{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Apply","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"description":null,"expression":[{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Apply","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"description":null,"expression":[{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Apply","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"description":null,"expression":[{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Apply","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"description":null,"expression":[{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}AttributeDesignator","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"category":"urn:oasis:names:tc:xacml:3.0:attribute-category:environment","attributeId":"urn:oasis:names:tc:xacml:1.0:environment:current-time","dataType":"http://www.w3.org/2001/XMLSchema#time","issuer":null,"mustBePresent":false},"nil":false,"globalScope":true,"typeSubstituted":false}],"functionId":"urn:oasis:names:tc:xacml:1.0:function:time-one-and-only"},"nil":false,"globalScope":true,"typeSubstituted":false},{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}AttributeValue","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"content":["5:00"],"dataType":"http://www.w3.org/2001/XMLSchema#time","otherAttributes":{}},"nil":false,"globalScope":true,"typeSubstituted":false},{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}AttributeValue","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"content":["10:00"],"dataType":"http://www.w3.org/2001/XMLSchema#time","otherAttributes":{}},"nil":false,"globalScope":true,"typeSubstituted":false}],"functionId":"urn:oasis:names:tc:xacml:2.0:function:time-in-range"},"nil":false,"globalScope":true,"typeSubstituted":false},{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Apply","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"description":null,"expression":[{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Function","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.FunctionType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"functionId":"urn:oasis:names:tc:xacml:1.0:function:string-equal"},"nil":false,"globalScope":true,"typeSubstituted":false},{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Apply","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"description":null,"expression":[{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}AttributeDesignator","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"category":"urn:oasis:names:tc:xacml:3.0:attribute-category:resource","attributeId":"target","dataType":"http://www.w3.org/2001/XMLSchema#string","issuer":null,"mustBePresent":false},"nil":false,"globalScope":true,"typeSubstituted":false}],"functionId":"urn:oasis:names:tc:xacml:1.0:function:string-one-and-only"},"nil":false,"globalScope":true,"typeSubstituted":false},{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Apply","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"description":null,"expression":[{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}AttributeValue","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"content":["testBL2"],"dataType":"http://www.w3.org/2001/XMLSchema#string","otherAttributes":{}},"nil":false,"globalScope":true,"typeSubstituted":false},{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}AttributeValue","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"content":["testBL3"],"dataType":"http://www.w3.org/2001/XMLSchema#string","otherAttributes":{}},"nil":false,"globalScope":true,"typeSubstituted":false},{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}AttributeValue","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"content":["testBL4"],"dataType":"http://www.w3.org/2001/XMLSchema#string","otherAttributes":{}},"nil":false,"globalScope":true,"typeSubstituted":false}],"functionId":"urn:oasis:names:tc:xacml:1.0:function:string-bag"},"nil":false,"globalScope":true,"typeSubstituted":false}],"functionId":"urn:oasis:names:tc:xacml:3.0:function:any-of"},"nil":false,"globalScope":true,"typeSubstituted":false}],"functionId":"urn:oasis:names:tc:xacml:1.0:function:and"},"nil":false,"globalScope":true,"typeSubstituted":false}],"functionId":"urn:oasis:names:tc:xacml:1.0:function:not"},"nil":false,"globalScope":true,"typeSubstituted":false}],"functionId":"urn:oasis:names:tc:xacml:1.0:function:not"},"nil":false,"globalScope":true,"typeSubstituted":false}},"obligationExpressions":null,"adviceExpressions":{"adviceExpression":[{"attributeAssignmentExpression":[{"expression":{"name":"{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}AttributeValue","declaredType":"oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"content":["Denied!"],"dataType":"http://www.w3.org/2001/XMLSchema#string","otherAttributes":{}},"nil":false,"globalScope":true,"typeSubstituted":false},"attributeId":"guard.response","category":"urn:oasis:names:tc:xacml:3.0:attribute-category:resource","issuer":null}],"adviceId":"GUARD_BL_YAML","appliesTo":"DENY"}]},"ruleId":"urn:com:xacml:rule:id:284d9393-f861-4250-b62d-fc36640a363a","effect":"DENY"}],"obligationExpressions":null,"adviceExpressions":null,"policyId":"urn:com:xacml:policy:id:d56af069-6cf1-430c-ba07-e26602e06a52","version":"4","ruleCombiningAlgId":"urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides","maxDelegationDepth":null},"gitPath":null,"readOnly":false,"configHome":null,"configUrl":null,"finalPolicyPath":null,"version":null,"jsonBody":null,"apiflag":null,"prevJsonBody":null,"highestVersion":null,"entityManagerFactory":null,"policyExists":false,"oldPolicyFileName":"Decision_SampelGuardBLOne","userId":null,"newFileName":null,"clWarning":null,"newCLName":null,"existingCLName":null,"onapNameField":null,"jsonBodyData":null,"dirPath":null,"configBodyPath":null,"attributes":[],"settings":[],"ruleAlgorithmschoices":[],"serviceTypePolicyName":null,"verticaMetrics":null,"description":null,"attributeFields":null,"clearTimeOut":null,"trapMaxAge":null,"verificationclearTimeOut":null,"dynamicLayoutMap":null,"trapDatas":null,"faultDatas":null,"fwPolicyType":null,"fwattributes":null,"parentForChild":null,"securityZone":null,"ruleCombiningAlgId":null,"dynamicFieldConfigAttributes":null,"dynamicSettingsMap":null,"dropDownMap":null,"actionPerformer":null,"actionAttribute":null,"dynamicRuleAlgorithmLabels":null,"dynamicRuleAlgorithmCombo":null,"dynamicRuleAlgorithmField1":null,"dynamicRuleAlgorithmField2":null,"dynamicVariableList":null,"dataTypeList":null,"actionAttributeValue":null,"ruleProvider":"GUARD_BL_YAML","actionBody":null,"actionDictHeader":null,"actionDictType":null,"actionDictUrl":null,"actionDictMethod":null,"yamlparams":{"actor":"testActor","recipe":"testRecipe","clname":"testCLName","limit":null,"timeWindow":null,"timeUnits":null,"guardActiveStart":"5:00","guardActiveEnd":"10:00","blackList":["testBL2","testBL3","testBL4"],"targets":null,"blackListEntryType":"Use Manual Entry"},"blackListEntries":[],"appendBlackListEntries":[],"rainyday":{"serviceType":null,"vnfType":null,"bbid":null,"workstep":null,"treatmentTableChoices":[],"errorcode":null,"treatment":null},"rainydayMap":null,"errorCodeList":null,"treatmentList":null,"serviceType":null,"uuid":null,"location":null,"priority":null,"msLocation":null,"policyJSON":null,"ruleName":null,"brmsParamBody":null,"brmsController":null,"brmsDependency":null,"ruleData":null,"ruleListData":null,"drlRuleAndUIParams":null,"policyScope":null,"providerComboBox":null,"riskType":null,"riskLevel":null,"guard":null,"ttlDate":null,"matching":null,"triggerSignatures":null,"symptomSignatures":null,"logicalConnector":null,"policyStatus":null,"gocServerScope":null,"supressionType":null,"editPolicy":true,"domainDir":"com","validData":false,"draft":false,"viewPolicy":false,"blackListEntryType":"Use Manual Entry"},"date":"2018-03-27 13:36:12.0","version":4}
\ No newline at end of file diff --git a/PolicyEngineUtils/src/main/java/org/onap/policy/utils/AAFPolicyClientImpl.java b/PolicyEngineUtils/src/main/java/org/onap/policy/utils/AAFPolicyClientImpl.java index 732183d47..5c46c76f7 100644 --- a/PolicyEngineUtils/src/main/java/org/onap/policy/utils/AAFPolicyClientImpl.java +++ b/PolicyEngineUtils/src/main/java/org/onap/policy/utils/AAFPolicyClientImpl.java @@ -3,6 +3,7 @@ * PolicyEngineUtils * ================================================================================ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Modified Copyright (C) 2018 Samsung Electronics Co., Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,173 +43,175 @@ import org.onap.aaf.cadi.principal.UnAuthPrincipal; * */ public class AAFPolicyClientImpl implements AAFPolicyClient{ - private static Logger logger = Logger.getLogger(AAFPolicyClientImpl.class.getName()); - - private static final String ENVIRONMENT = "ENVIRONMENT"; - - // Warning Please don't Change these Values. Confirm with AAF team. - private static final String DEVL_AAF_URL = ""; - private static final String TEST_AAF_URL = ""; - private static final String PROD_AAF_URL = ""; - private static final String DEFAULT_AFT_LATITUDE = "32.780140"; - private static final String DEFAULT_AFT_LONGITUDE = "-96.800451"; - private static final String TEST_AFT_ENVIRONMENT = "AFTUAT"; - private static final String PROD_AFT_ENVIRONMENT = "AFTPRD"; - private static final String DEFAULT_AAF_USER_EXPIRES = Integer.toString(5*60000); // 5 minutes for found items to live in cache - private static final String DEFAULT_AAF_HIGH_COUNT = Integer.toString(400); // Maximum number of items in Cache - - private static AAFPolicyClientImpl instance = null; - - private static Properties props = new Properties(); - private static AAFCon<?> aafCon = null; - private static AAFLurPerm aafLurPerm = null; - private static AAFAuthn<?> aafAuthn = null; - private static PropAccess access = null; - - private AAFPolicyClientImpl(Properties properties) throws AAFPolicyException{ - setup(properties); - } - - /** - * Gets the instance of the AAFClient instance. Needs Proper properties with CLIENT_ID, CLIENT_KEY and ENVIRONMENT - * - * @param properties Properties with CLIENT_ID, CLIENT_KEY and ENVIRONMENT - * @return AAFClient instance. - * @throws AAFPolicyException Exceptions. - */ - public static synchronized AAFPolicyClientImpl getInstance(Properties properties) throws AAFPolicyException{ - if(instance == null) { - logger.info("Creating AAFClient Instance "); - instance = new AAFPolicyClientImpl(properties); - } - return instance; - } - - // To set Property values && Connections. - private static void setup(Properties properties) throws AAFPolicyException { - if(properties!=null && !properties.isEmpty()){ - props = System.getProperties(); - props.setProperty("AFT_LATITUDE", properties.getProperty("AFT_LATITUDE", DEFAULT_AFT_LATITUDE)); - props.setProperty("AFT_LONGITUDE", properties.getProperty("AFT_LONGITUDE", DEFAULT_AFT_LONGITUDE)); - String aftEnv = TEST_AFT_ENVIRONMENT; - props.setProperty("aaf_id",properties.getProperty("aaf_id", "aafID")); - props.setProperty("aaf_password", properties.getProperty("aaf_password", "aafPass")); - if(properties.containsKey(Config.AAF_URL)){ - // if given a value in properties file. - props.setProperty(Config.AAF_URL, properties.getProperty(Config.AAF_URL)); - }else{ - // Set Default values. - if(properties.getProperty(ENVIRONMENT, "DEVL").equalsIgnoreCase(AAFEnvironment.TEST.toString())){ - props.setProperty(Config.AAF_URL, TEST_AAF_URL); - }else if(properties.getProperty(ENVIRONMENT, "DEVL").equalsIgnoreCase(AAFEnvironment.PROD.toString())){ - props.setProperty(Config.AAF_URL, PROD_AAF_URL); - aftEnv = PROD_AFT_ENVIRONMENT; - }else{ - props.setProperty(Config.AAF_URL, DEVL_AAF_URL); - } - } - props.setProperty("AFT_ENVIRONMENT", properties.getProperty("AFT_ENVIRONMENT", aftEnv)); - props.setProperty(Config.AAF_USER_EXPIRES, properties.getProperty(Config.AAF_USER_EXPIRES, DEFAULT_AAF_USER_EXPIRES)); - props.setProperty(Config.AAF_HIGH_COUNT, properties.getProperty(Config.AAF_HIGH_COUNT, DEFAULT_AAF_HIGH_COUNT)); - }else{ - logger.error("Required Property value is missing : " + ENVIRONMENT); - throw new AAFPolicyException("Required Property value is missing : " + ENVIRONMENT); - } - access = new PolicyAccess(props, Level.valueOf(properties.getProperty("AAF_LOG_LEVEL", Level.ERROR.toString()))); - setUpAAF(); - } - - /** - * Updates the Properties file in case if required. - * - * @param properties Properties with CLIENT_ID, CLIENT_KEY and ENVIRONMENT - * @throws AAFPolicyException exceptions if any. - */ - @Override - public void updateProperties(Properties properties) throws AAFPolicyException{ - setup(properties); - } - - /** - * Checks the Authentication and Permissions for the given values. - * - * @param mechID MechID or ATT ID must be registered under the Name space. - * @param pass Password pertaining to the MechID or ATTID. - * @param type Permissions Type. - * @param instance Permissions Instance. - * @param action Permissions Action. - * @return - */ - @Override - public boolean checkAuthPerm(String mechID, String pass, String type, String instance, String action){ - return checkAuth(mechID, pass) && checkPerm(mechID, pass, type, instance, action); - } - - /** - * Checks the Authentication of the UserName and Password Given. - * - * @param userName UserName or MechID - * @param pass Password. - * @return True or False. - */ - @Override - public boolean checkAuth(String userName, String pass){ - if(aafAuthn!=null){ - try { - int i=0; - do{ - if(aafAuthn.validate(userName, pass)==null){ - return true; - } - i++; - }while(i<2); - } catch (Exception e) { - logger.error(e.getMessage() + e); - } - } - return false; - } - - /** - * Checks Permissions for the given UserName, Password and Type, Instance Action. - * - * @param userName UserName or MechID - * @param pass Password. - * @param type Permissions Type. - * @param instance Permissions Instance. - * @param action Permissions Action. - * @return True or False. - */ - @Override - public boolean checkPerm(String userName, String pass, String type, String instance, String action){ - int i =0; - Boolean result= false; - do{ - if(aafCon!=null && aafLurPerm !=null){ - try { - aafCon.basicAuth(userName, pass); - AAFPermission perm = new AAFPermission(type, instance, action); - final Principal p = new UnAuthPrincipal(userName); - result = aafLurPerm.fish(p, perm); - } catch (CadiException e) { - logger.error(e.getMessage() + e); - aafLurPerm.destroy(); - } - } - i++; - }while(i<2 && !result); // Try once more to check if this can be passed. AAF has some issues. - return result; - } - - private static boolean setUpAAF(){ - try { - aafCon = new AAFConHttp(access,new PropertyLocator("https://aaf-onap-beijing-test.osaaf.org:8100")); - aafLurPerm = aafCon.newLur(); - aafAuthn = aafCon.newAuthn(aafLurPerm); - return true; - } catch (Exception e) { - logger.error("Error while setting up AAF Connection " + e.getMessage() + e); - return false; - } - } + private static Logger logger = Logger.getLogger(AAFPolicyClientImpl.class.getName()); + + private static final String ENVIRONMENT = "ENVIRONMENT"; + + // Warning Please don't Change these Values. Confirm with AAF team. + private static final String DEVL_AAF_URL = ""; + private static final String TEST_AAF_URL = ""; + private static final String PROD_AAF_URL = ""; + private static final String DEFAULT_AFT_LATITUDE = "32.780140"; + private static final String DEFAULT_AFT_LONGITUDE = "-96.800451"; + private static final String TEST_AFT_ENVIRONMENT = "AFTUAT"; + private static final String PROD_AFT_ENVIRONMENT = "AFTPRD"; + private static final String DEFAULT_AAF_USER_EXPIRES = Integer.toString(5*60000); // 5 minutes for found items to live in cache + private static final String DEFAULT_AAF_HIGH_COUNT = Integer.toString(400); // Maximum number of items in Cache + + private static AAFPolicyClientImpl instance = null; + + private static Properties props = new Properties(); + private static AAFCon<?> aafCon = null; + private static AAFLurPerm aafLurPerm = null; + private static AAFAuthn<?> aafAuthn = null; + private static PropAccess access = null; + + private AAFPolicyClientImpl(Properties properties) throws AAFPolicyException{ + setup(properties); + } + + /** + * Gets the instance of the AAFClient instance. Needs Proper properties with CLIENT_ID, CLIENT_KEY and ENVIRONMENT + * + * @param properties Properties with CLIENT_ID, CLIENT_KEY and ENVIRONMENT + * @return AAFClient instance. + * @throws AAFPolicyException Exceptions. + */ + public static synchronized AAFPolicyClientImpl getInstance(Properties properties) throws AAFPolicyException{ + if(instance == null) { + logger.info("Creating AAFClient Instance "); + instance = new AAFPolicyClientImpl(properties); + } + return instance; + } + + // To set Property values && Connections. + private static void setup(Properties properties) throws AAFPolicyException { + if(properties!=null && !properties.isEmpty()){ + props = System.getProperties(); + props.setProperty("AFT_LATITUDE", properties.getProperty("AFT_LATITUDE", DEFAULT_AFT_LATITUDE)); + props.setProperty("AFT_LONGITUDE", properties.getProperty("AFT_LONGITUDE", DEFAULT_AFT_LONGITUDE)); + String aftEnv = TEST_AFT_ENVIRONMENT; + props.setProperty("aaf_id",properties.getProperty("aaf_id", "aafID")); + props.setProperty("aaf_password", properties.getProperty("aaf_password", "aafPass")); + if(properties.containsKey(Config.AAF_URL)){ + // if given a value in properties file. + props.setProperty(Config.AAF_URL, properties.getProperty(Config.AAF_URL)); + }else{ + // Set Default values. + if(properties.getProperty(ENVIRONMENT, "DEVL").equalsIgnoreCase(AAFEnvironment.TEST.toString())){ + props.setProperty(Config.AAF_URL, TEST_AAF_URL); + }else if(properties.getProperty(ENVIRONMENT, "DEVL").equalsIgnoreCase(AAFEnvironment.PROD.toString())){ + props.setProperty(Config.AAF_URL, PROD_AAF_URL); + aftEnv = PROD_AFT_ENVIRONMENT; + }else{ + props.setProperty(Config.AAF_URL, DEVL_AAF_URL); + } + } + props.setProperty("AFT_ENVIRONMENT", properties.getProperty("AFT_ENVIRONMENT", aftEnv)); + props.setProperty(Config.AAF_USER_EXPIRES, properties.getProperty(Config.AAF_USER_EXPIRES, DEFAULT_AAF_USER_EXPIRES)); + props.setProperty(Config.AAF_HIGH_COUNT, properties.getProperty(Config.AAF_HIGH_COUNT, DEFAULT_AAF_HIGH_COUNT)); + }else{ + logger.error("Required Property value is missing : " + ENVIRONMENT); + throw new AAFPolicyException("Required Property value is missing : " + ENVIRONMENT); + } + access = new PolicyAccess(props, Level.valueOf(properties.getProperty("AAF_LOG_LEVEL", Level.ERROR.toString()))); + setUpAAF(); + } + + /** + * Updates the Properties file in case if required. + * + * @param properties Properties with CLIENT_ID, CLIENT_KEY and ENVIRONMENT + * @throws AAFPolicyException exceptions if any. + */ + @Override + public void updateProperties(Properties properties) throws AAFPolicyException{ + setup(properties); + } + + /** + * Checks the Authentication and Permissions for the given values. + * + * @param mechID MechID or ATT ID must be registered under the Name space. + * @param pass Password pertaining to the MechID or ATTID. + * @param type Permissions Type. + * @param instance Permissions Instance. + * @param action Permissions Action. + * @return + */ + @Override + public boolean checkAuthPerm(String mechID, String pass, String type, String instance, String action){ + return checkAuth(mechID, pass) && checkPerm(mechID, pass, type, instance, action); + } + + /** + * Checks the Authentication of the UserName and Password Given. + * + * @param userName UserName or MechID + * @param pass Password. + * @return True or False. + */ + @Override + public boolean checkAuth(String userName, String pass){ + if (aafAuthn == null) { + return false; + } + try { + int i=0; + do{ + if(aafAuthn.validate(userName, pass)==null){ + return true; + } + i++; + }while(i<2); + } catch (Exception e) { + logger.error(e.getMessage() + e); + } + + return false; + } + + /** + * Checks Permissions for the given UserName, Password and Type, Instance Action. + * + * @param userName UserName or MechID + * @param pass Password. + * @param type Permissions Type. + * @param instance Permissions Instance. + * @param action Permissions Action. + * @return True or False. + */ + @Override + public boolean checkPerm(String userName, String pass, String type, String instance, String action){ + int i =0; + Boolean result= false; + do{ + if(aafCon!=null && aafLurPerm !=null){ + try { + aafCon.basicAuth(userName, pass); + AAFPermission perm = new AAFPermission(type, instance, action); + final Principal p = new UnAuthPrincipal(userName); + result = aafLurPerm.fish(p, perm); + } catch (CadiException e) { + logger.error(e.getMessage() + e); + aafLurPerm.destroy(); + } + } + i++; + }while(i<2 && !result); // Try once more to check if this can be passed. AAF has some issues. + return result; + } + + private static boolean setUpAAF(){ + try { + aafCon = new AAFConHttp(access,new PropertyLocator("https://aaf-onap-beijing-test.osaaf.org:8100")); + aafLurPerm = aafCon.newLur(); + aafAuthn = aafCon.newAuthn(aafLurPerm); + return true; + } catch (Exception e) { + logger.error("Error while setting up AAF Connection " + e.getMessage() + e); + return false; + } + } } |