Adding code to enable the pdp type to be configurable.
Issue-ID: POLICY-3071
Change-Id: I51c873f68bff1866c6b2e96958b6c33872aea2c8
Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
/*-
* ============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.
/**
* 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);
/*-
* ============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");
private String name;
private String pdpGroup;
+ private String pdpType;
private RestServerParameters restServerParameters;
private RestServerParameters policyApiParameters;
private TopicParameterGroup topicParameterGroup;
* @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;
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");
/*-
* ============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.
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);
@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;
XacmlPdpActivator.setCurrent(act);
- state = new XacmlState(appmgr, GROUP);
+ state = new XacmlState(appmgr, GROUP, PDP_TYPE);
}
@AfterClass
/*-
* ============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");
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()));
/*-
* ============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");
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());
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());
}
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());
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());
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());
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());
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());
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());
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());
/*-
* ============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");
+ "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");
}
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
"field \"pdpGroup\" type \"java.lang.String\" value \" \" INVALID, must be a non-blank string");
}
+ @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 =
/*-
* ============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");
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");
/*-
* ============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");
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");
{
"name":"XacmlPdpParameters",
"pdpGroup": "XacmlPdpGroup",
+ "pdpType": "xacml",
"restServerParameters": {
"host": "0.0.0.0",
"port": 6969,
{
"name": "XacmlPdpParameters",
"pdpGroup": "XacmlPdpGroup",
+ "pdpType": "xacml",
"restServerParameters": {
"host": "0.0.0.0",
"port": 6969,
--- /dev/null
+{
+ "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
{
"name":"XacmlPdpParameters",
"pdpGroup": "XacmlPdpGroup",
+ "pdpType": "xacml",
"restServerParameters":{
"host":"0.0.0.0",
"port":${port},
{
"name": "XacmlPdpParameters",
"pdpGroup": "defaultGroup",
+ "pdpType": "xacml",
"restServerParameters": {
"host": "0.0.0.0",
"port": 6969,
{
"name": "XacmlPdpParameters",
"pdpGroup": "defaultGroup",
+ "pdpType": "xacml",
"restServerParameters":{
"host":"0.0.0.0",
"port":6969,