diff options
Diffstat (limited to 'main/src')
13 files changed, 81 insertions, 24 deletions
diff --git a/main/src/main/java/org/onap/policy/pdpx/main/XacmlState.java b/main/src/main/java/org/onap/policy/pdpx/main/XacmlState.java index cb88d6aa..5ca75a62 100644 --- a/main/src/main/java/org/onap/policy/pdpx/main/XacmlState.java +++ b/main/src/main/java/org/onap/policy/pdpx/main/XacmlState.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 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. @@ -56,12 +56,12 @@ public class XacmlState { /** * Constructs the object, initializing the state. */ - public XacmlState(XacmlPdpApplicationManager appManager, String pdpGroupName) { + public XacmlState(XacmlPdpApplicationManager appManager, String pdpGroupName, String pdpType) { this.appManager = appManager; this.status = new PdpStatus(); this.status.setName(NetworkUtil.getHostname()); - this.status.setPdpType("xacml"); + this.status.setPdpType(pdpType); this.status.setState(PdpState.PASSIVE); this.status.setPolicies(Collections.emptyList()); this.status.setPdpGroup(pdpGroupName); diff --git a/main/src/main/java/org/onap/policy/pdpx/main/parameters/XacmlPdpParameterGroup.java b/main/src/main/java/org/onap/policy/pdpx/main/parameters/XacmlPdpParameterGroup.java index cd8d22b2..9c8eae0b 100644 --- a/main/src/main/java/org/onap/policy/pdpx/main/parameters/XacmlPdpParameterGroup.java +++ b/main/src/main/java/org/onap/policy/pdpx/main/parameters/XacmlPdpParameterGroup.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -45,6 +45,7 @@ public class XacmlPdpParameterGroup implements ParameterGroup { private String name; private String pdpGroup; + private String pdpType; private RestServerParameters restServerParameters; private RestServerParameters policyApiParameters; private TopicParameterGroup topicParameterGroup; @@ -56,11 +57,12 @@ public class XacmlPdpParameterGroup implements ParameterGroup { * @param name the parameter group name * @param pdpGroup the pdp group name */ - public XacmlPdpParameterGroup(final String name, final String pdpGroup, + public XacmlPdpParameterGroup(final String name, final String pdpGroup, final String pdpType, final RestServerParameters restServerParameters, final RestServerParameters policyApiParameters, final TopicParameterGroup topicParameterGroup, final String applicationPath) { this.name = name; this.pdpGroup = pdpGroup; + this.pdpType = pdpType; this.restServerParameters = restServerParameters; this.policyApiParameters = policyApiParameters; this.topicParameterGroup = topicParameterGroup; @@ -81,6 +83,9 @@ public class XacmlPdpParameterGroup implements ParameterGroup { if (!ParameterValidationUtils.validateStringParameter(pdpGroup)) { validationResult.setResult("pdpGroup", ValidationStatus.INVALID, "must be a non-blank string"); } + if (!ParameterValidationUtils.validateStringParameter(pdpType)) { + validationResult.setResult("pdpType", ValidationStatus.INVALID, "must be a non-blank string"); + } if (restServerParameters == null) { validationResult.setResult(PARAM_REST_SERVER, ValidationStatus.INVALID, "must have restServerParameters to configure xacml pdp rest server"); diff --git a/main/src/main/java/org/onap/policy/pdpx/main/startstop/XacmlPdpActivator.java b/main/src/main/java/org/onap/policy/pdpx/main/startstop/XacmlPdpActivator.java index 1d0145fd..0a32d234 100644 --- a/main/src/main/java/org/onap/policy/pdpx/main/startstop/XacmlPdpActivator.java +++ b/main/src/main/java/org/onap/policy/pdpx/main/startstop/XacmlPdpActivator.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 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. @@ -97,7 +97,7 @@ public class XacmlPdpActivator extends ServiceManagerContainer { stats.setTotalPolicyTypesCount(appmgr.getPolicyTypeCount()); stats.setTotalPolicyCount(appmgr.getPolicyCount()); - state = new XacmlState(appmgr, xacmlPdpParameterGroup.getPdpGroup()); + state = new XacmlState(appmgr, xacmlPdpParameterGroup.getPdpGroup(), xacmlPdpParameterGroup.getPdpType()); this.xacmlPdpParameterGroup = xacmlPdpParameterGroup; this.msgDispatcher = new MessageTypeDispatcher(MSG_TYPE_NAMES); diff --git a/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java b/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java index 86804425..43ccab04 100644 --- a/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java +++ b/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java @@ -48,7 +48,7 @@ import org.onap.policy.pdpx.main.startstop.XacmlPdpActivator; @RunWith(MockitoJUnitRunner.class) public class XacmlStateTest { - private static final String PDP_TYPE = "xacml"; + private static final String PDP_TYPE = "xacml-flavor"; private static final String GROUP = "my-group"; private static final String SUBGROUP = "my-subgroup"; private static final PdpState STATE = PdpState.SAFE; @@ -72,7 +72,7 @@ public class XacmlStateTest { XacmlPdpActivator.setCurrent(act); - state = new XacmlState(appmgr, GROUP); + state = new XacmlState(appmgr, GROUP, PDP_TYPE); } @AfterClass diff --git a/main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java b/main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java index 9b13a84f..6f73df56 100644 --- a/main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java +++ b/main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -61,6 +61,7 @@ public class CommonTestData { public static final String PDPX_PARAMETER_GROUP_NAME = "XacmlPdpParameters"; public static final String PDPX_GROUP = "XacmlPdpGroup"; + public static final String PDPX_TYPE = "xacml"; public static final List<TopicParameters> TOPIC_PARAMS = Collections.unmodifiableList(Arrays.asList(getTopicParams())); diff --git a/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java b/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java index 0eea10a1..dfd3216e 100644 --- a/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java +++ b/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -63,7 +63,7 @@ public class TestXacmlPdpParameterGroup { testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class); final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup(CommonTestData.PDPX_PARAMETER_GROUP_NAME, - CommonTestData.PDPX_GROUP, restServerParameters, policyApiParameters, + CommonTestData.PDPX_GROUP, "flavor", restServerParameters, policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath()); final GroupValidationResult validationResult = pdpxParameters.validate(); assertTrue(validationResult.isValid()); @@ -72,6 +72,7 @@ public class TestXacmlPdpParameterGroup { assertEquals(restServerParameters.getUserName(), pdpxParameters.getRestServerParameters().getUserName()); assertEquals(restServerParameters.getPassword(), pdpxParameters.getRestServerParameters().getPassword()); assertEquals(CommonTestData.PDPX_PARAMETER_GROUP_NAME, pdpxParameters.getName()); + assertEquals("flavor", pdpxParameters.getPdpType()); assertFalse(pdpxParameters.getRestServerParameters().isHttps()); assertFalse(pdpxParameters.getRestServerParameters().isAaf()); } @@ -85,7 +86,8 @@ public class TestXacmlPdpParameterGroup { final TopicParameterGroup topicParameterGroup = testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class); final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup(null, CommonTestData.PDPX_GROUP, - restServerParameters, policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath()); + null, restServerParameters, policyApiParameters, topicParameterGroup, + applicationPath.getAbsolutePath()); final GroupValidationResult validationResult = pdpxParameters.validate(); assertFalse(validationResult.isValid()); assertEquals(null, pdpxParameters.getName()); @@ -102,7 +104,8 @@ public class TestXacmlPdpParameterGroup { final TopicParameterGroup topicParameterGroup = testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class); final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup("", CommonTestData.PDPX_GROUP, - restServerParameters, policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath()); + CommonTestData.PDPX_TYPE, restServerParameters, policyApiParameters, topicParameterGroup, + applicationPath.getAbsolutePath()); final GroupValidationResult validationResult = pdpxParameters.validate(); assertFalse(validationResult.isValid()); assertEquals("", pdpxParameters.getName()); @@ -119,7 +122,7 @@ public class TestXacmlPdpParameterGroup { final TopicParameterGroup topicParameterGroup = testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class); final XacmlPdpParameterGroup pdpxParameters = - new XacmlPdpParameterGroup(CommonTestData.PDPX_PARAMETER_GROUP_NAME, null, restServerParameters, + new XacmlPdpParameterGroup(CommonTestData.PDPX_PARAMETER_GROUP_NAME, null, null, restServerParameters, policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath()); final GroupValidationResult validationResult = pdpxParameters.validate(); assertFalse(validationResult.isValid()); @@ -138,7 +141,7 @@ public class TestXacmlPdpParameterGroup { final TopicParameterGroup topicParameterGroup = testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class); final XacmlPdpParameterGroup pdpxParameters = - new XacmlPdpParameterGroup(CommonTestData.PDPX_PARAMETER_GROUP_NAME, "", restServerParameters, + new XacmlPdpParameterGroup(CommonTestData.PDPX_PARAMETER_GROUP_NAME, "", null, restServerParameters, policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath()); final GroupValidationResult validationResult = pdpxParameters.validate(); assertFalse(validationResult.isValid()); @@ -158,7 +161,7 @@ public class TestXacmlPdpParameterGroup { testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class); final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup(CommonTestData.PDPX_PARAMETER_GROUP_NAME, CommonTestData.PDPX_GROUP, - restServerParameters, policyApiParameters, + null, restServerParameters, policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath()); final GroupValidationResult validationResult = pdpxParameters.validate(); assertFalse(validationResult.isValid()); @@ -176,7 +179,7 @@ public class TestXacmlPdpParameterGroup { testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class); final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup(CommonTestData.PDPX_PARAMETER_GROUP_NAME, CommonTestData.PDPX_GROUP, - restServerParameters, policyApiParameters, + null, restServerParameters, policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath()); final GroupValidationResult validationResult = pdpxParameters.validate(); assertFalse(validationResult.isValid()); @@ -194,7 +197,7 @@ public class TestXacmlPdpParameterGroup { testData.toObject(testData.getTopicParametersMap(true), TopicParameterGroup.class); final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup(CommonTestData.PDPX_PARAMETER_GROUP_NAME, CommonTestData.PDPX_GROUP, - restServerParameters, policyApiParameters, + null, restServerParameters, policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath()); final GroupValidationResult validationResult = pdpxParameters.validate(); assertFalse(validationResult.isValid()); diff --git a/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterHandler.java b/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterHandler.java index 02c8d0c5..9a997194 100644 --- a/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterHandler.java +++ b/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterHandler.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 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -102,6 +102,8 @@ public class TestXacmlPdpParameterHandler { + "must be a non-blank string\n" + " field \"pdpGroup\" type \"java.lang.String\" value \"null\" INVALID, " + "must be a non-blank string\n" + + " field \"pdpType\" type \"java.lang.String\" value \"null\" INVALID, " + + "must be a non-blank string\n" + " field \"applicationPath\" type \"java.lang.String\" value \"null\" INVALID, " + "must have application path for applications to store policies and data.\n"); } @@ -116,6 +118,7 @@ public class TestXacmlPdpParameterHandler { final XacmlPdpParameterGroup parGroup = new XacmlPdpParameterHandler().getParameters(minArguments); assertEquals(CommonTestData.PDPX_PARAMETER_GROUP_NAME, parGroup.getName()); assertEquals(CommonTestData.PDPX_GROUP, parGroup.getPdpGroup()); + assertEquals(CommonTestData.PDPX_TYPE, parGroup.getPdpType()); } @Test @@ -154,6 +157,17 @@ public class TestXacmlPdpParameterHandler { } @Test + public void testXacmlPdpParameterGroup_InvalidPdpType() throws PolicyXacmlPdpException { + final String[] xacmlPdpConfigParameters = {"-c", "parameters/XacmlPdpConfigParameters_InvalidPdpType.json"}; + + final XacmlPdpCommandLineArguments arguments = new XacmlPdpCommandLineArguments(); + arguments.parse(xacmlPdpConfigParameters); + + assertThatThrownBy(() -> new XacmlPdpParameterHandler().getParameters(arguments)).hasMessageContaining( + "field \"pdpType\" type \"java.lang.String\" value \"\" INVALID, must be a non-blank string"); + } + + @Test public void testXacmlPdpParameterGroup_InvalidRestServerParameters() throws PolicyXacmlPdpException, IOException { final String[] xacmlPdpConfigParameters = {"-c", "parameters/XacmlPdpConfigParameters_InvalidRestServerParameters.json"}; diff --git a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestAbbreviateDecisionResults.java b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestAbbreviateDecisionResults.java index c9910349..dbf977f2 100644 --- a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestAbbreviateDecisionResults.java +++ b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestAbbreviateDecisionResults.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 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -120,7 +120,7 @@ public class TestAbbreviateDecisionResults { TopicParameterGroup topicParameterGroup = testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class); XacmlPdpParameterGroup params = - new XacmlPdpParameterGroup("XacmlPdpParameters", "XacmlPdpGroup", rest, policyApiParameters, + new XacmlPdpParameterGroup("XacmlPdpParameters", "XacmlPdpGroup", "xacml", rest, policyApiParameters, topicParameterGroup, apps.getAbsolutePath()); StandardCoder gson = new StandardCoder(); File fileParams = appsFolder.newFile("params.json"); diff --git a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestDecision.java b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestDecision.java index 31d09799..2d71543c 100644 --- a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestDecision.java +++ b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestDecision.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) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -109,7 +109,7 @@ public class TestDecision { TopicParameterGroup topicParameterGroup = testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class); XacmlPdpParameterGroup params = - new XacmlPdpParameterGroup("XacmlPdpParameters", "XacmlPdpGroup", rest, policyApiParameters, + new XacmlPdpParameterGroup("XacmlPdpParameters", "XacmlPdpGroup", "xacml", rest, policyApiParameters, topicParameterGroup, apps.getAbsolutePath()); final Gson gson = new GsonBuilder().create(); File fileParams = appsFolder.newFile("params.json"); diff --git a/main/src/test/resources/parameters/MinimumParameters.json b/main/src/test/resources/parameters/MinimumParameters.json index e547e7ee..487a18d1 100644 --- a/main/src/test/resources/parameters/MinimumParameters.json +++ b/main/src/test/resources/parameters/MinimumParameters.json @@ -1,6 +1,7 @@ { "name":"XacmlPdpParameters", "pdpGroup": "XacmlPdpGroup", + "pdpType": "xacml", "restServerParameters": { "host": "0.0.0.0", "port": 6969, diff --git a/main/src/test/resources/parameters/XacmlPdpConfigParameters.json b/main/src/test/resources/parameters/XacmlPdpConfigParameters.json index 5d0a103c..a1376464 100644 --- a/main/src/test/resources/parameters/XacmlPdpConfigParameters.json +++ b/main/src/test/resources/parameters/XacmlPdpConfigParameters.json @@ -1,6 +1,7 @@ { "name": "XacmlPdpParameters", "pdpGroup": "XacmlPdpGroup", + "pdpType": "xacml", "restServerParameters": { "host": "0.0.0.0", "port": 6969, diff --git a/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidPdpType.json b/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidPdpType.json new file mode 100644 index 00000000..803b789c --- /dev/null +++ b/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidPdpType.json @@ -0,0 +1,31 @@ +{ + "name": "XacmlPdpParameters", + "pdpGroup": "defaultGroup", + "pdpType": "", + "restServerParameters":{ + "host":"0.0.0.0", + "port": 6969, + "userName":"healthcheck", + "password":"zb!XztG34", + "https":true + }, + "policyApiParameters": { + "host": "0.0.0.0", + "port": 6970, + "userName": "healthcheck", + "password": "zb!XztG34" + }, + "applicationPath": "src/test/resources/apps", + "topicParameterGroup": { + "topicSources" : [{ + "topic" : "POLICY-PDP-PAP", + "servers" : [ "anyserver" ], + "topicCommInfrastructure" : "noop" + }], + "topicSinks" : [{ + "topic" : "POLICY-PDP-PAP", + "servers" : [ "anyserver" ], + "topicCommInfrastructure" : "noop" + }] + } +}
\ No newline at end of file diff --git a/main/src/test/resources/parameters/XacmlPdpConfigParameters_Std.json b/main/src/test/resources/parameters/XacmlPdpConfigParameters_Std.json index 3f9e6cb1..ec898b6f 100644 --- a/main/src/test/resources/parameters/XacmlPdpConfigParameters_Std.json +++ b/main/src/test/resources/parameters/XacmlPdpConfigParameters_Std.json @@ -1,6 +1,7 @@ { "name":"XacmlPdpParameters", "pdpGroup": "XacmlPdpGroup", + "pdpType": "xacml", "restServerParameters":{ "host":"0.0.0.0", "port":${port}, |