diff options
author | Pamela Dragosh <pdragosh@research.att.com> | 2021-05-07 12:37:05 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2021-05-07 12:37:05 +0000 |
commit | 5e1e87eaa4ba802c5179744516812e52e562f816 (patch) | |
tree | c1a7c05eb718cc0947e43160aaa9ade6ab95fd8e /applications/common | |
parent | 07a780ed00e2d494707765951c227e19b5dec43b (diff) | |
parent | 5301a4b0b49eb568d05d59fd20d7b5724b47b8ac (diff) |
Merge "Fix sonars in xacml-pdp"
Diffstat (limited to 'applications/common')
15 files changed, 109 insertions, 113 deletions
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/OnapObligation.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/OnapObligation.java index c1a949f3..4febd212 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/OnapObligation.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/OnapObligation.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2021 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. @@ -129,7 +129,7 @@ public class OnapObligation { // // Create an ObligationExpression // - ObligationExpressionType obligation = new ObligationExpressionType(); + var obligation = new ObligationExpressionType(); obligation.setFulfillOn(effectType); obligation.setObligationId(obligationId.stringValue()); // @@ -238,14 +238,14 @@ public class OnapObligation { // // Create an AttributeValue for it // - AttributeValueType value = new AttributeValueType(); + var value = new AttributeValueType(); value.setDataType(datatype.stringValue()); value.getContent().add(theValue.toString()); // // Create our AttributeAssignmentExpression where we will // store the contents of the policy id. // - AttributeAssignmentExpressionType expressionType = new AttributeAssignmentExpressionType(); + var expressionType = new AttributeAssignmentExpressionType(); expressionType.setAttributeId(id.stringValue()); expressionType.setCategory(category.stringValue()); expressionType.setExpression(factory.createAttributeValue(value)); diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/OnapPolicyFinderFactory.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/OnapPolicyFinderFactory.java index b000db92..a4fc03fd 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/OnapPolicyFinderFactory.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/OnapPolicyFinderFactory.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2021 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. @@ -121,7 +121,7 @@ public class OnapPolicyFinderFactory extends PolicyFinderFactory { } protected PolicyDef loadPolicyFileDef(String propLocation) { - File fileLocation = new File(propLocation); + var fileLocation = new File(propLocation); if (!fileLocation.exists()) { logger.error("Policy file {} does not exist.", fileLocation.getAbsolutePath()); return null; @@ -132,7 +132,7 @@ public class OnapPolicyFinderFactory extends PolicyFinderFactory { } try { logger.info("Loading policy file {}", fileLocation); - PolicyDef policyDef = DOMPolicyDef.load(fileLocation); + var policyDef = DOMPolicyDef.load(fileLocation); if (policyDef != null) { return policyDef; } @@ -163,7 +163,7 @@ public class OnapPolicyFinderFactory extends PolicyFinderFactory { List<PolicyDef> listPolicyDefs = new ArrayList<>(); for (String policyId : policyIdArray) { - PolicyDef policyDef = this.loadPolicyDef(policyId); + var policyDef = this.loadPolicyDef(policyId); if (policyDef != null) { listPolicyDefs.add(policyDef); } @@ -194,7 +194,7 @@ public class OnapPolicyFinderFactory extends PolicyFinderFactory { // // Create our root policy // - PolicySet root = new PolicySet(); + var root = new PolicySet(); root.setIdentifier(new IdentifierImpl(UUID.randomUUID().toString())); root.setVersion(StdVersion.newInstance("1.0")); root.setTarget(new Target()); diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaPolicyTranslatorUtils.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaPolicyTranslatorUtils.java index a5e804e0..e19130d3 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaPolicyTranslatorUtils.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaPolicyTranslatorUtils.java @@ -70,12 +70,12 @@ public final class ToscaPolicyTranslatorUtils { // // Create the MatchType object and set its function // - MatchType match = new MatchType(); + var match = new MatchType(); match.setMatchId(function.stringValue()); // // Add in the AttributeValue object // - AttributeValueType valueType = new AttributeValueType(); + var valueType = new AttributeValueType(); valueType.setDataType(datatype.stringValue()); valueType.getContent().add(value); @@ -83,7 +83,7 @@ public final class ToscaPolicyTranslatorUtils { // // Add in the AttributeDesignator object // - AttributeDesignatorType designator = new AttributeDesignatorType(); + var designator = new AttributeDesignatorType(); designator.setAttributeId(designatorId.stringValue()); designator.setCategory(designatorCategory.stringValue()); designator.setDataType(datatype.stringValue()); @@ -102,7 +102,7 @@ public final class ToscaPolicyTranslatorUtils { * @return The AllOf object */ public static AllOfType buildAllOf(MatchType... matches) { - AllOfType allOf = new AllOfType(); + var allOf = new AllOfType(); for (MatchType match : matches) { allOf.getMatch().add(match); } @@ -121,26 +121,26 @@ public final class ToscaPolicyTranslatorUtils { return null; } - AttributeDesignatorType designator = new AttributeDesignatorType(); + var designator = new AttributeDesignatorType(); designator.setAttributeId(XACML3.ID_ENVIRONMENT_CURRENT_TIME.stringValue()); designator.setCategory(XACML3.ID_ATTRIBUTE_CATEGORY_ENVIRONMENT.stringValue()); designator.setDataType(XACML3.ID_DATATYPE_TIME.stringValue()); - AttributeValueType valueStart = new AttributeValueType(); + var valueStart = new AttributeValueType(); valueStart.setDataType(XACML3.ID_DATATYPE_TIME.stringValue()); valueStart.getContent().add(start); - AttributeValueType valueEnd = new AttributeValueType(); + var valueEnd = new AttributeValueType(); valueEnd.setDataType(XACML3.ID_DATATYPE_TIME.stringValue()); valueEnd.getContent().add(end); - ApplyType applyOneAndOnly = new ApplyType(); + var applyOneAndOnly = new ApplyType(); applyOneAndOnly.setDescription("Unbag the current time"); applyOneAndOnly.setFunctionId(XACML3.ID_FUNCTION_TIME_ONE_AND_ONLY.stringValue()); applyOneAndOnly.getExpression().add(factory.createAttributeDesignator(designator)); - ApplyType applyTimeInRange = new ApplyType(); + var applyTimeInRange = new ApplyType(); applyTimeInRange.setDescription("return true if current time is in range."); if (useRecurringFunction) { applyTimeInRange.setFunctionId(XACML3.ID_FUNCTION_TIME_IN_RECURRING_RANGE.stringValue()); @@ -185,7 +185,7 @@ public final class ToscaPolicyTranslatorUtils { */ public static AnyOfType buildAndAppendAllof(AnyOfType anyOf, Object type) { if (type instanceof MatchType) { - AllOfType allOf = new AllOfType(); + var allOf = new AllOfType(); allOf.getMatch().add((MatchType) type); if (anyOf == null) { anyOf = new AnyOfType(); @@ -212,9 +212,9 @@ public final class ToscaPolicyTranslatorUtils { if (object instanceof AnyOfType) { target.getAnyOf().add((AnyOfType) object); } else if (object instanceof MatchType) { - AllOfType allOf = new AllOfType(); + var allOf = new AllOfType(); allOf.getMatch().add((MatchType) object); - AnyOfType anyOf = new AnyOfType(); + var anyOf = new AnyOfType(); anyOf.getAllOf().add(allOf); target.getAnyOf().add(anyOf); } @@ -232,11 +232,11 @@ public final class ToscaPolicyTranslatorUtils { */ public static ConditionType addVariableToCondition(ConditionType condition, VariableReferenceType variable, Identifier functionId) { - ApplyType applyFunction = new ApplyType(); + var applyFunction = new ApplyType(); applyFunction.setFunctionId(functionId.stringValue()); applyFunction.getExpression().add(condition.getExpression()); applyFunction.getExpression().add(factory.createVariableReference(variable)); - ConditionType newCondition = new ConditionType(); + var newCondition = new ConditionType(); newCondition.setExpression(factory.createApply(applyFunction)); return newCondition; } diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtils.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtils.java index a2ecf8c0..860189f9 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtils.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtils.java @@ -29,7 +29,6 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; -import java.io.InputStream; import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; @@ -80,7 +79,7 @@ public class XacmlPolicyUtils { * @return PolicySetType object */ public static PolicySetType createEmptyPolicySet(String policyId, Identifier policyCombiningAlgorithm) { - PolicySetType policy = new PolicySetType(); + var policy = new PolicySetType(); policy.setPolicySetId(policyId); policy.setPolicyCombiningAlgId(policyCombiningAlgorithm.stringValue()); policy.setTarget(new TargetType()); @@ -96,7 +95,7 @@ public class XacmlPolicyUtils { * @return PolicyType object */ public static PolicyType createEmptyPolicy(String policyId, Identifier ruleCombiningAlgorithm) { - PolicyType policy = new PolicyType(); + var policy = new PolicyType(); policy.setPolicyId(policyId); policy.setRuleCombiningAlgId(ruleCombiningAlgorithm.stringValue()); policy.setTarget(new TargetType()); @@ -113,12 +112,12 @@ public class XacmlPolicyUtils { */ public static PolicySetType addPoliciesToXacmlRootPolicy(PolicySetType rootPolicy, PolicyType... referencedPolicies) { - ObjectFactory factory = new ObjectFactory(); + var factory = new ObjectFactory(); // // Iterate each policy // for (PolicyType referencedPolicy : referencedPolicies) { - IdReferenceType reference = new IdReferenceType(); + var reference = new IdReferenceType(); reference.setValue(referencedPolicy.getPolicyId()); // // Add it in @@ -140,12 +139,12 @@ public class XacmlPolicyUtils { */ public static PolicySetType addPolicySetsToXacmlRootPolicy(PolicySetType rootPolicy, PolicySetType... referencedPolicySets) { - ObjectFactory factory = new ObjectFactory(); + var factory = new ObjectFactory(); // // Iterate each policy // for (PolicySetType referencedPolicySet : referencedPolicySets) { - IdReferenceType reference = new IdReferenceType(); + var reference = new IdReferenceType(); reference.setValue(referencedPolicySet.getPolicySetId()); // // Add it in @@ -173,7 +172,7 @@ public class XacmlPolicyUtils { // // Construct a unique id // - int id = 1; + var id = 1; while (true) { String refId = "root" + id; if (rootPolicies.contains(refId)) { @@ -207,7 +206,7 @@ public class XacmlPolicyUtils { // // Construct a unique id // - int id = 1; + var id = 1; while (true) { String refId = "ref" + id; if (referencedPolicies.contains(refId)) { @@ -238,8 +237,8 @@ public class XacmlPolicyUtils { // // Get the current set of referenced policy ids // - StringJoiner join = new StringJoiner(","); - boolean found = false; + var join = new StringJoiner(","); + var found = false; Set<String> rootPolicies = XACMLProperties.getRootPolicyIDs(properties); for (String refPolicy : rootPolicies) { String refPolicyFile = refPolicy + DOT_FILE_SUFFIX; @@ -282,8 +281,8 @@ public class XacmlPolicyUtils { // // Get the current set of referenced policy ids // - StringJoiner join = new StringJoiner(","); - boolean found = false; + var join = new StringJoiner(","); + var found = false; Set<String> referencedPolicies = XACMLProperties.getReferencedPolicyIDs(properties); for (String refPolicy : referencedPolicies) { String refPolicyFile = refPolicy + DOT_FILE_SUFFIX; @@ -391,8 +390,8 @@ public class XacmlPolicyUtils { */ public static Properties loadXacmlProperties(Path propertyPath) throws IOException { LOGGER.info("Loading xacml properties {}", propertyPath); - try (InputStream is = Files.newInputStream(propertyPath)) { - Properties properties = new Properties(); + try (var is = Files.newInputStream(propertyPath)) { + var properties = new Properties(); properties.load(is); if (LOGGER.isInfoEnabled()) { LOGGER.info("Loaded xacml properties {} {}", XacmlPolicyUtils.LINE_SEPARATOR, properties); @@ -411,9 +410,8 @@ public class XacmlPolicyUtils { */ public static void storeXacmlProperties(Properties properties, Path propertyPath) throws IOException { LOGGER.info("Storing xacml properties {} {} {}", properties, XacmlPolicyUtils.LINE_SEPARATOR, propertyPath); - try (OutputStream os = Files.newOutputStream(propertyPath)) { - String strComments = "#"; - properties.store(os, strComments); + try (var os = Files.newOutputStream(propertyPath)) { + properties.store(os, "#"); } } @@ -447,7 +445,7 @@ public class XacmlPolicyUtils { // // Open the properties file // - try (InputStream is = new FileInputStream(propertiesPath)) { + try (var is = new FileInputStream(propertiesPath)) { // // Load in the properties // @@ -455,7 +453,7 @@ public class XacmlPolicyUtils { // // Now we create a new xacml.properties in the temporary folder location // - File propertiesFile = creator.createAFile(XACML_PROPERTY_FILE); + var propertiesFile = creator.createAFile(XACML_PROPERTY_FILE); // // Iterate through any root policies defined // @@ -463,12 +461,12 @@ public class XacmlPolicyUtils { // // Get a file // - Path rootPath = Paths.get(properties.getProperty(root + DOT_FILE_SUFFIX)); + var rootPath = Paths.get(properties.getProperty(root + DOT_FILE_SUFFIX)); LOGGER.info("Root file {} {}", rootPath, rootPath.getFileName()); // // Construct new path for the root policy // - File newRootPath = creator.createAFile(rootPath.getFileName().toString()); + var newRootPath = creator.createAFile(rootPath.getFileName().toString()); // // Copy the policy file to the temporary folder // @@ -486,12 +484,12 @@ public class XacmlPolicyUtils { // // Get a file // - Path refPath = Paths.get(properties.getProperty(referenced + DOT_FILE_SUFFIX)); + var refPath = Paths.get(properties.getProperty(referenced + DOT_FILE_SUFFIX)); LOGGER.info("Referenced file {} {}", refPath, refPath.getFileName()); // // Construct new path for the root policy // - File newReferencedPath = creator.createAFile(refPath.getFileName().toString()); + var newReferencedPath = creator.createAFile(refPath.getFileName().toString()); // // Copy the policy file to the temporary folder // diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePolicyType.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePolicyType.java index c0cbb77f..fe79e861 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePolicyType.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePolicyType.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2020-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -117,7 +117,7 @@ public class MatchablePolicyType { MatchableCallback callback) { for (Entry<String, ToscaProperty> entrySet : properties.entrySet()) { final String property = entrySet.getKey(); - final ToscaProperty toscaProperty = entrySet.getValue(); + final var toscaProperty = entrySet.getValue(); // // Most likely case is its a primitive // diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePropertyTypeMap.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePropertyTypeMap.java index 5687e251..f6d8414a 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePropertyTypeMap.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePropertyTypeMap.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -61,7 +61,7 @@ public class MatchablePropertyTypeMap extends MatchablePropertyTypeBase<Map<Stri @Override public Object generate(Object value, Identifier attributeId) throws ToscaPolicyConversionException { - AnyOfType anyOf = new AnyOfType(); + var anyOf = new AnyOfType(); for (Entry<String, MatchablePropertyType<?>> entrySet : this.validate(value).entrySet()) { final String id = entrySet.getKey(); final Object val = entrySet.getValue(); diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPip.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPip.java index 3d7270e1..0d2b1ddd 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPip.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPip.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2021 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. @@ -90,7 +90,7 @@ public class CountRecentOperationsPip extends StdOnapPip { // String[] s1 = pipRequest.getIssuer().split("tw:"); String[] s2 = s1[1].split(":"); - int timeWindowVal = Integer.parseInt(s2[0]); + var timeWindowVal = Integer.parseInt(s2[0]); String timeWindowScale = s2[1]; // // Grab other attribute values @@ -118,7 +118,7 @@ public class CountRecentOperationsPip extends StdOnapPip { // // Create and return PipResponse // - StdMutablePIPResponse pipResponse = new StdMutablePIPResponse(); + var pipResponse = new StdMutablePIPResponse(); this.addLongAttribute(pipResponse, XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, ToscaDictionary.ID_RESOURCE_GUARD_OPERATIONCOUNT, diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePip.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePip.java index 95595986..a2440d5b 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePip.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePip.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2021 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. @@ -93,7 +93,7 @@ public class GetOperationOutcomePip extends StdOnapPip { String outcome = doDatabaseQuery(clname); logger.info("Query result is: {}", outcome); - StdMutablePIPResponse pipResponse = new StdMutablePIPResponse(); + var pipResponse = new StdMutablePIPResponse(); this.addStringAttribute(pipResponse, XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, ToscaDictionary.ID_RESOURCE_GUARD_OPERATIONOUTCOME, outcome, pipRequest); return new StdPIPResponse(pipResponse); diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslator.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslator.java index a6c9977e..61d28f58 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslator.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslator.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2021 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. @@ -37,7 +37,6 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.ConditionType; -import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory; import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObligationExpressionType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObligationExpressionsType; @@ -76,7 +75,7 @@ public abstract class StdBaseTranslator implements ToscaPolicyTranslator { @Override public DecisionResponse convertResponse(Response xacmlResponse) { LOGGER.info("Converting Response {}", xacmlResponse); - DecisionResponse decisionResponse = new DecisionResponse(); + var decisionResponse = new DecisionResponse(); // // Setup policies // @@ -182,7 +181,7 @@ public abstract class StdBaseTranslator implements ToscaPolicyTranslator { // // Create our OnapObligation // - OnapObligation onapObligation = new OnapObligation(policyId, jsonPolicy, policyType, weight); + var onapObligation = new OnapObligation(policyId, jsonPolicy, policyType, weight); // // Generate the obligation // @@ -190,7 +189,7 @@ public abstract class StdBaseTranslator implements ToscaPolicyTranslator { // // Now we can add it into the rule/policy/policyset // - ObligationExpressionsType obligations = new ObligationExpressionsType(); + var obligations = new ObligationExpressionsType(); obligations.getObligationExpression().add(obligation); if (ruleOrPolicy instanceof RuleType) { ((RuleType) ruleOrPolicy).setObligationExpressions(obligations); @@ -218,7 +217,7 @@ public abstract class StdBaseTranslator implements ToscaPolicyTranslator { // // Create the match for the policy type // - MatchType match = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator( + var match = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator( XACML3.ID_FUNCTION_STRING_EQUAL, type, XACML3.ID_DATATYPE_STRING, @@ -227,7 +226,7 @@ public abstract class StdBaseTranslator implements ToscaPolicyTranslator { // // Add it to an AnyOfType object // - AnyOfType anyOf = new AnyOfType(); + var anyOf = new AnyOfType(); anyOf.getAllOf().add(ToscaPolicyTranslatorUtils.buildAllOf(match)); // // Return new AnyOfType @@ -250,22 +249,22 @@ public abstract class StdBaseTranslator implements ToscaPolicyTranslator { // Create an ApplyType that checks if the request contains the // policy-type attribute // - AttributeDesignatorType designator = new AttributeDesignatorType(); + var designator = new AttributeDesignatorType(); designator.setAttributeId(ToscaDictionary.ID_RESOURCE_POLICY_TYPE.stringValue()); designator.setCategory(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE.stringValue()); designator.setDataType(XACML3.ID_DATATYPE_STRING.stringValue()); - ApplyType applyBagSize = new ApplyType(); + var applyBagSize = new ApplyType(); applyBagSize.setDescription("Get the size of policy-type attributes"); applyBagSize.setFunctionId(XACML3.ID_FUNCTION_STRING_BAG_SIZE.stringValue()); - AttributeValueType valueZero = new AttributeValueType(); + var valueZero = new AttributeValueType(); valueZero.setDataType(XACML3.ID_DATATYPE_INTEGER.stringValue()); valueZero.getContent().add("0"); // Yes really - represent as a string applyBagSize.getExpression().add(factory.createAttributeDesignator(designator)); - ApplyType applyGreaterThan = new ApplyType(); + var applyGreaterThan = new ApplyType(); applyGreaterThan.setDescription("Does the policy-type attribute exist?"); applyGreaterThan.setFunctionId(XACML3.ID_FUNCTION_INTEGER_EQUAL.stringValue()); @@ -275,7 +274,7 @@ public abstract class StdBaseTranslator implements ToscaPolicyTranslator { // // Create an apply type that checks the actual value // - AttributeValueType value = new AttributeValueType(); + var value = new AttributeValueType(); value.setDataType(XACML3.ID_DATATYPE_STRING.stringValue()); value.getContent().add(type); @@ -283,7 +282,7 @@ public abstract class StdBaseTranslator implements ToscaPolicyTranslator { // Create string-is-in apply - which determines if the policy-type // is in the request bag of resources for policy-type // - ApplyType applyIsIn = new ApplyType(); + var applyIsIn = new ApplyType(); applyIsIn.setDescription("Is this policy-type in the list?"); applyIsIn.setFunctionId(XACML3.ID_FUNCTION_STRING_IS_IN.stringValue()); applyIsIn.getExpression().add(factory.createAttributeValue(value)); @@ -292,7 +291,7 @@ public abstract class StdBaseTranslator implements ToscaPolicyTranslator { // // Create our outer apply // - ApplyType applyOr = new ApplyType(); + var applyOr = new ApplyType(); applyOr.setDescription("IF exists and is equal"); applyOr.setFunctionId(XACML3.ID_FUNCTION_OR.stringValue()); @@ -302,7 +301,7 @@ public abstract class StdBaseTranslator implements ToscaPolicyTranslator { // // Finally create the condition // - ConditionType condition = new ConditionType(); + var condition = new ConditionType(); condition.setExpression(factory.createApply(applyOr)); diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyRequest.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyRequest.java index 4b50e724..75b89d24 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyRequest.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyRequest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2021 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. @@ -77,7 +77,7 @@ public class StdCombinedPolicyRequest { // // Create our request object // - StdCombinedPolicyRequest request = new StdCombinedPolicyRequest(); + var request = new StdCombinedPolicyRequest(); // // Add the subject attributes // diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslator.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslator.java index 8db9948d..c22545cd 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslator.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslator.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2021 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. @@ -34,7 +34,6 @@ import java.util.Collection; import java.util.Map; import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.EffectType; -import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; @@ -76,7 +75,7 @@ public class StdCombinedPolicyResultsTranslator extends StdBaseTranslator { // // Set it as the policy ID // - PolicyType newPolicyType = new PolicyType(); + var newPolicyType = new PolicyType(); newPolicyType.setPolicyId(policyId); // // Optional description @@ -93,14 +92,14 @@ public class StdCombinedPolicyResultsTranslator extends StdBaseTranslator { // // Generate the TargetType // - TargetType target = this.generateTargetType(policyId, toscaPolicy.getType(), toscaPolicy.getVersion()); + var target = this.generateTargetType(policyId, toscaPolicy.getType(), toscaPolicy.getVersion()); newPolicyType.setTarget(target); // // Now create the Permit Rule // No target since the policy has a target // With obligations. // - RuleType rule = new RuleType(); + var rule = new RuleType(); rule.setDescription("Default is to PERMIT if the policy matches."); rule.setRuleId(policyId + ":rule"); rule.setEffect(EffectType.PERMIT); @@ -108,7 +107,7 @@ public class StdCombinedPolicyResultsTranslator extends StdBaseTranslator { // // Now represent the policy as Json // - StandardCoder coder = new StandardCoder(); + var coder = new StandardCoder(); String jsonPolicy; try { jsonPolicy = coder.encode(toscaPolicy); @@ -179,7 +178,7 @@ public class StdCombinedPolicyResultsTranslator extends StdBaseTranslator { // // Create our OnapObligation which will scan for attributes // - OnapObligation onapObligation = new OnapObligation(obligation); + var onapObligation = new OnapObligation(obligation); // // Get the attributes we care about // @@ -211,7 +210,7 @@ public class StdCombinedPolicyResultsTranslator extends StdBaseTranslator { // // This is for the Policy Id // - MatchType matchPolicyId = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator( + var matchPolicyId = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator( XACML3.ID_FUNCTION_STRING_EQUAL, policyId, XACML3.ID_DATATYPE_STRING, @@ -220,7 +219,7 @@ public class StdCombinedPolicyResultsTranslator extends StdBaseTranslator { // // This is for the Policy Type // - MatchType matchPolicyType = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator( + var matchPolicyType = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator( XACML3.ID_FUNCTION_STRING_EQUAL, policyType, XACML3.ID_DATATYPE_STRING, @@ -229,7 +228,7 @@ public class StdCombinedPolicyResultsTranslator extends StdBaseTranslator { // // This is for the Policy Type version // - MatchType matchPolicyTypeVersion = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator( + var matchPolicyTypeVersion = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator( XACML3.ID_FUNCTION_STRING_EQUAL, policyTypeVersion, XACML3.ID_DATATYPE_STRING, @@ -238,7 +237,7 @@ public class StdCombinedPolicyResultsTranslator extends StdBaseTranslator { // // This is our outer AnyOf - which is an OR // - AnyOfType anyOf = new AnyOfType(); + var anyOf = new AnyOfType(); // // Create AllOf (AND) of just Policy Id // @@ -255,7 +254,7 @@ public class StdCombinedPolicyResultsTranslator extends StdBaseTranslator { // Now we can create the TargetType, add the top-level anyOf (OR), // and return the value. // - TargetType target = new TargetType(); + var target = new TargetType(); target.getAnyOf().add(anyOf); return target; } diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchablePolicyRequest.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchablePolicyRequest.java index d0ae524c..c038f383 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchablePolicyRequest.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchablePolicyRequest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2021 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. @@ -103,7 +103,7 @@ public class StdMatchablePolicyRequest { // // Create our request object // - StdMatchablePolicyRequest request = new StdMatchablePolicyRequest(); + var request = new StdMatchablePolicyRequest(); // // Add the subject attributes // @@ -127,8 +127,8 @@ public class StdMatchablePolicyRequest { // // Create an object we can add to // - StdMutableRequest mutableRequest = new StdMutableRequest(xacmlRequest); - StdMutableRequestAttributes resourceAttributes = new StdMutableRequestAttributes(); + var mutableRequest = new StdMutableRequest(xacmlRequest); + var resourceAttributes = new StdMutableRequestAttributes(); resourceAttributes.setCategory(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE); // // Add the resource attributes @@ -166,12 +166,12 @@ public class StdMatchablePolicyRequest { protected static StdMutableRequestAttributes addResources(StdMutableRequestAttributes attributes, Collection<Object> values, String id) throws DataTypeException { - DataTypeFactory factory = getDataTypeFactory(); + var factory = getDataTypeFactory(); if (factory == null) { return null; } for (Object value : values) { - StdMutableAttribute mutableAttribute = new StdMutableAttribute(); + var mutableAttribute = new StdMutableAttribute(); mutableAttribute.setCategory(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE); mutableAttribute.setAttributeId(new IdentifierImpl(id)); mutableAttribute.setIncludeInResults(true); diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java index 3222f4ad..1d76d0e3 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java @@ -174,7 +174,7 @@ public class StdMatchableTranslator extends StdBaseTranslator implements Matcha // // Create our OnapObligation object // - OnapObligation onapObligation = new OnapObligation(obligation); + var onapObligation = new OnapObligation(obligation); // // All 4 *should* be there // @@ -257,7 +257,7 @@ public class StdMatchableTranslator extends StdBaseTranslator implements Matcha // // Set it as the policy ID // - PolicyType newPolicyType = new PolicyType(); + var newPolicyType = new PolicyType(); newPolicyType.setPolicyId(policyName); // // Optional description @@ -280,7 +280,7 @@ public class StdMatchableTranslator extends StdBaseTranslator implements Matcha // // Now represent the policy as Json // - StandardCoder coder = new StandardCoder(); + var coder = new StandardCoder(); String jsonPolicy; try { jsonPolicy = coder.encode(toscaPolicy); @@ -294,7 +294,7 @@ public class StdMatchableTranslator extends StdBaseTranslator implements Matcha // // Now create the Permit Rule. // - RuleType rule = new RuleType(); + var rule = new RuleType(); rule.setDescription("Default is to PERMIT if the policy matches."); rule.setRuleId(policyName + ":rule"); rule.setEffect(EffectType.PERMIT); @@ -311,7 +311,7 @@ public class StdMatchableTranslator extends StdBaseTranslator implements Matcha // // Log output of the policy // - try (ByteArrayOutputStream os = new ByteArrayOutputStream()) { + try (var os = new ByteArrayOutputStream()) { XACMLPolicyWriter.writePolicyFile(os, newPolicyType); LOGGER.info("{}", os); } catch (IOException e) { @@ -379,11 +379,11 @@ public class StdMatchableTranslator extends StdBaseTranslator implements Matcha // // Our return object // - TargetType target = new TargetType(); + var target = new TargetType(); // // See if we have a matchable in the cache already // - MatchablePolicyType matchablePolicyType = matchableCache.get(policy.getTypeIdentifier()); + var matchablePolicyType = matchableCache.get(policy.getTypeIdentifier()); // // If not found, create one // @@ -391,7 +391,7 @@ public class StdMatchableTranslator extends StdBaseTranslator implements Matcha // // Our callback // - MyMatchableCallback myCallback = new MyMatchableCallback(this, template); + var myCallback = new MyMatchableCallback(this, template); // // Create the matchable // @@ -459,7 +459,7 @@ public class StdMatchableTranslator extends StdBaseTranslator implements Matcha } protected int calculateWeight(TargetType target) { - int weight = 0; + var weight = 0; for (AnyOfType anyOf : target.getAnyOf()) { for (AllOfType allOf : anyOf.getAllOf()) { weight += allOf.getMatch().size(); @@ -512,7 +512,7 @@ public class StdMatchableTranslator extends StdBaseTranslator implements Matcha // // Construct what the file name should be // - Path policyTypePath = this.constructLocalFilePath(policyTypeId); + var policyTypePath = this.constructLocalFilePath(policyTypeId); // // See if it exists // @@ -546,7 +546,7 @@ public class StdMatchableTranslator extends StdBaseTranslator implements Matcha // // Ensure all the fields are setup correctly // - JpaToscaServiceTemplate jtst = new JpaToscaServiceTemplate(); + var jtst = new JpaToscaServiceTemplate(); jtst.fromAuthorative(template); return jtst.toAuthorative(); } catch (CoderException e) { @@ -574,7 +574,7 @@ public class StdMatchableTranslator extends StdBaseTranslator implements Matcha // ToscaServiceTemplate policyTemplate = null; try { - PolicyApiCaller api = new PolicyApiCaller(this.apiRestParameters); + var api = new PolicyApiCaller(this.apiRestParameters); policyTemplate = api.getPolicyType(policyTypeId); } catch (PolicyApiException e) { diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdOnapPip.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdOnapPip.java index 4cf23652..e8839ecb 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdOnapPip.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdOnapPip.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -99,7 +99,7 @@ public abstract class StdOnapPip extends StdConfigurableEngine { // // In case there are any overloaded properties for the JPA // - Properties emProperties = new Properties(); + var emProperties = new Properties(); emProperties.putAll(properties); // @@ -126,7 +126,7 @@ public abstract class StdOnapPip extends StdConfigurableEngine { // // Get the actor value // - PIPResponse pipResponse = this.getAttribute(pipRequest, pipFinder); + var pipResponse = this.getAttribute(pipRequest, pipFinder); if (pipResponse == null) { logger.error("Need actor attribute which is not found"); return null; diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java index 5e00499e..f29c4e76 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java @@ -133,11 +133,11 @@ public abstract class StdXacmlApplicationServiceProvider implements XacmlApplica // // Create a copy of the properties object // - Properties newProperties = this.getProperties(); + var newProperties = this.getProperties(); // // Construct the filename // - Path refPath = XacmlPolicyUtils.constructUniquePolicyFilename(xacmlPolicy, this.getDataPath()); + var refPath = XacmlPolicyUtils.constructUniquePolicyFilename(xacmlPolicy, this.getDataPath()); // // Write the policy to disk // Maybe check for an error @@ -189,7 +189,7 @@ public abstract class StdXacmlApplicationServiceProvider implements XacmlApplica // // Create a copy of the properties object // - Properties newProperties = this.getProperties(); + var newProperties = this.getProperties(); // // Remove it from the properties // @@ -244,7 +244,7 @@ public abstract class StdXacmlApplicationServiceProvider implements XacmlApplica xacmlRequest = this.getTranslator().convertRequest(request); } catch (ToscaPolicyConversionException e) { LOGGER.error("Failed to convert request", e); - DecisionResponse response = new DecisionResponse(); + var response = new DecisionResponse(); response.setStatus("error"); response.setMessage(e.getLocalizedMessage()); return Pair.of(response, null); @@ -252,7 +252,7 @@ public abstract class StdXacmlApplicationServiceProvider implements XacmlApplica // // Now get a decision // - Response xacmlResponse = this.xacmlDecision(xacmlRequest); + var xacmlResponse = this.xacmlDecision(xacmlRequest); // // Convert to a DecisionResponse // @@ -270,7 +270,7 @@ public abstract class StdXacmlApplicationServiceProvider implements XacmlApplica } protected synchronized Properties getProperties() { - Properties newProperties = new Properties(); + var newProperties = new Properties(); newProperties.putAll(pdpProperties); return newProperties; } @@ -287,7 +287,7 @@ public abstract class StdXacmlApplicationServiceProvider implements XacmlApplica // Now initialize the XACML PDP Engine // try { - PDPEngineFactory factory = getPdpEngineFactory(); + var factory = getPdpEngineFactory(); PDPEngine engine = factory.newEngine(properties); if (engine != null) { // |