Commit d0681430 authored by cdanger's avatar cdanger

Modified test pdp extensions schema: rename XML types:

- TestAttributeProvider -> TestAttributeProviderDescriptor
- MongoDbBasedPolicyProvider -> MongoDbBasedPolicyProviderDescriptor
... to avoid confusion with the name of the Java implementation class
parent 1e5b74e2
......@@ -42,17 +42,11 @@ import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.Attributes;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.Request;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.Response;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.Result;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.Status;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.StatusCode;
import org.ow2.authzforce.core.pdp.api.XmlUtils.XmlnsFilteringParser;
import org.ow2.authzforce.core.pdp.impl.DefaultEnvironmentProperties;
import org.ow2.authzforce.core.pdp.impl.PdpEngineConfiguration;
import org.ow2.authzforce.core.pdp.testutil.ext.xmlns.TestAttributeProvider;
import org.ow2.authzforce.core.pdp.testutil.ext.TestAttributeProvider;
import org.ow2.authzforce.core.pdp.testutil.ext.xmlns.TestAttributeProviderDescriptor;
import org.ow2.authzforce.core.xmlns.pdp.InOutProcChain;
import org.ow2.authzforce.core.xmlns.pdp.Pdp;
import org.ow2.authzforce.core.xmlns.pdp.StaticRefPolicyProvider;
......@@ -63,6 +57,13 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.ResourceUtils;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.Attributes;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.Request;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.Response;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.Result;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.Status;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.StatusCode;
public class TestUtils
{
......@@ -139,7 +140,7 @@ public class TestUtils
{
try
{
TEST_ATTRIBUTE_PROVIDER_JAXB_CONTEXT = JAXBContext.newInstance(TestAttributeProvider.class);
TEST_ATTRIBUTE_PROVIDER_JAXB_CONTEXT = JAXBContext.newInstance(TestAttributeProviderDescriptor.class);
}
catch (final JAXBException e)
{
......@@ -272,27 +273,20 @@ public class TestUtils
}
}
results.add(new Result(result.getDecision(), newStatus, result.getObligations(), result.getAssociatedAdvice(), normalizeAttributeCategories(result.getAttributes()), result
.getPolicyIdentifierList()));
results.add(new Result(result.getDecision(), newStatus, result.getObligations(), result.getAssociatedAdvice(), normalizeAttributeCategories(result.getAttributes()),
result.getPolicyIdentifierList()));
}
return new Response(results);
}
private static final Comparator<Attributes> ATTRIBUTES_COMPARATOR = new Comparator<Attributes>()
{
@Override
public int compare(final Attributes arg0, final Attributes arg1)
private static final Comparator<Attributes> ATTRIBUTES_COMPARATOR = (arg0, arg1) -> {
if (arg0 == null || arg1 == null)
{
if (arg0 == null || arg1 == null)
{
throw new IllegalArgumentException("Invalid Attribtues args for comparator");
}
return arg0.getCategory().compareTo(arg1.getCategory());
throw new IllegalArgumentException("Invalid Attribtues args for comparator");
}
return arg0.getCategory().compareTo(arg1.getCategory());
};
private static List<Attributes> normalizeAttributeCategories(final List<Attributes> attributesList)
......@@ -337,7 +331,7 @@ public class TestUtils
* cannot create Attribute Provider configuration (XML) unmarshaller
*/
public static PdpEngineConfiguration newPdpEngineConfiguration(final String rootPolicyLocation, final String refPoliciesDirectoryLocation, final boolean enableXPath,
final String attributeProviderConfLocation, final String requestPreprocId, final String resultPostprocId) throws IllegalArgumentException, IOException, URISyntaxException, JAXBException
final String attributeProviderConfLocation, final String requestPreprocId, final String resultPostprocId) throws IllegalArgumentException, IOException, URISyntaxException, JAXBException
{
final Pdp jaxbPDP = new Pdp();
jaxbPDP.setEnableXPath(enableXPath);
......@@ -403,7 +397,7 @@ public class TestUtils
{
final URL testAttrProviderURL = ResourceUtils.getURL(attributeProviderConfLocation);
final Unmarshaller unmarshaller = TEST_ATTRIBUTE_PROVIDER_JAXB_CONTEXT.createUnmarshaller();
final JAXBElement<TestAttributeProvider> testAttributeProviderElt = (JAXBElement<TestAttributeProvider>) unmarshaller.unmarshal(testAttrProviderURL);
final JAXBElement<TestAttributeProviderDescriptor> testAttributeProviderElt = (JAXBElement<TestAttributeProviderDescriptor>) unmarshaller.unmarshal(testAttrProviderURL);
jaxbPDP.getAttributeProviders().add(testAttributeProviderElt.getValue());
}
catch (final FileNotFoundException e)
......@@ -454,7 +448,7 @@ public class TestUtils
final Response normalizedActualResponse = TestUtils.normalizeForComparison(actualResponseFromPDP);
final Marshaller marshaller = Xacml3JaxbHelper.createXacml3Marshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
assertEquals("Test '" + testId + "' (Status elements removed/ignored for comparison): ", new MarshallableWithToString(normalizedExpectedResponse, marshaller), new MarshallableWithToString(
normalizedActualResponse, marshaller));
assertEquals("Test '" + testId + "' (Status elements removed/ignored for comparison): ", new MarshallableWithToString(normalizedExpectedResponse, marshaller),
new MarshallableWithToString(normalizedActualResponse, marshaller));
}
}
......@@ -43,7 +43,7 @@ import org.ow2.authzforce.core.pdp.api.policy.PolicyVersionPattern;
import org.ow2.authzforce.core.pdp.api.policy.PolicyVersionPatterns;
import org.ow2.authzforce.core.pdp.api.policy.StaticTopLevelPolicyElementEvaluator;
import org.ow2.authzforce.core.pdp.impl.policy.PolicyEvaluators;
import org.ow2.authzforce.core.pdp.testutil.ext.xmlns.MongoDBBasedPolicyProvider;
import org.ow2.authzforce.core.pdp.testutil.ext.xmlns.MongoDBBasedPolicyProviderDescriptor;
import org.ow2.authzforce.xacml.identifiers.XacmlNodeName;
import org.ow2.authzforce.xacml.identifiers.XacmlStatusCode;
import org.ow2.authzforce.xacml.identifiers.XacmlVersion;
......@@ -107,7 +107,7 @@ public final class MongoDbRefPolicyProvider extends BaseStaticRefPolicyProvider
* Factory
*
*/
public static class Factory extends CloseableRefPolicyProvider.Factory<MongoDBBasedPolicyProvider>
public static class Factory extends CloseableRefPolicyProvider.Factory<MongoDBBasedPolicyProviderDescriptor>
{
private static final IllegalArgumentException ILLEGAL_COMBINING_ALG_REGISTRY_ARGUMENT_EXCEPTION = new IllegalArgumentException("Undefined CombiningAlgorithm registry");
private static final IllegalArgumentException ILLEGAL_EXPRESSION_FACTORY_ARGUMENT_EXCEPTION = new IllegalArgumentException("Undefined Expression factory");
......@@ -115,13 +115,13 @@ public final class MongoDbRefPolicyProvider extends BaseStaticRefPolicyProvider
private static final IllegalArgumentException NULL_CONF_ARGUMENT_EXCEPTION = new IllegalArgumentException("PolicyProvider configuration undefined");
@Override
public Class<MongoDBBasedPolicyProvider> getJaxbClass()
public Class<MongoDBBasedPolicyProviderDescriptor> getJaxbClass()
{
return MongoDBBasedPolicyProvider.class;
return MongoDBBasedPolicyProviderDescriptor.class;
}
@Override
public CloseableRefPolicyProvider getInstance(final MongoDBBasedPolicyProvider conf, final XmlnsFilteringParserFactory xmlParserFactory, final int maxPolicySetRefDepth,
public CloseableRefPolicyProvider getInstance(final MongoDBBasedPolicyProviderDescriptor conf, final XmlnsFilteringParserFactory xmlParserFactory, final int maxPolicySetRefDepth,
final ExpressionFactory expressionFactory, final CombiningAlgRegistry combiningAlgRegistry, final EnvironmentProperties environmentProperties) throws IllegalArgumentException
{
if (conf == null)
......
......@@ -45,6 +45,7 @@ import org.ow2.authzforce.core.pdp.api.value.AttributeValue;
import org.ow2.authzforce.core.pdp.api.value.AttributeValueFactoryRegistry;
import org.ow2.authzforce.core.pdp.api.value.Bag;
import org.ow2.authzforce.core.pdp.api.value.Datatype;
import org.ow2.authzforce.core.pdp.testutil.ext.xmlns.TestAttributeProviderDescriptor;
import org.ow2.authzforce.xacml.identifiers.XacmlStatusCode;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.Attribute;
......@@ -59,7 +60,7 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.Attributes;
public class TestAttributeProvider extends BaseNamedAttributeProvider
{
private static AttributeDesignatorType newAttributeDesignator(Entry<AttributeFqn, AttributeBag<?>> attributeEntry)
private static AttributeDesignatorType newAttributeDesignator(final Entry<AttributeFqn, AttributeBag<?>> attributeEntry)
{
final AttributeFqn attrKey = attributeEntry.getKey();
final Bag<?> attrVals = attributeEntry.getValue();
......@@ -69,29 +70,10 @@ public class TestAttributeProvider extends BaseNamedAttributeProvider
private final Set<AttributeDesignatorType> supportedDesignatorTypes;
private final Map<AttributeFqn, AttributeBag<?>> attrMap;
private TestAttributeProvider(final org.ow2.authzforce.core.pdp.testutil.ext.xmlns.TestAttributeProvider conf, final AttributeValueFactoryRegistry attributeValueFactoryRegistry)
throws IllegalArgumentException
private TestAttributeProvider(final String id, final Map<AttributeFqn, AttributeBag<?>> attributeMap) throws IllegalArgumentException
{
super(conf.getId());
final NamedXacmlAttributeParser<Attribute> namedXacmlAttParser = new NamedXacmlJaxbAttributeParser(attributeValueFactoryRegistry);
final XacmlRequestAttributeParser<Attribute, AttributeBag<?>> xacmlAttributeParser = new NonIssuedLikeIssuedStrictXacmlAttributeParser<>(namedXacmlAttParser);
final Set<String> attrCategoryNames = new HashSet<>();
final Map<AttributeFqn, AttributeBag<?>> mutableAttMap = new HashMap<>();
for (final Attributes jaxbAttributes : conf.getAttributes())
{
final String categoryName = jaxbAttributes.getCategory();
if (!attrCategoryNames.add(categoryName))
{
throw new IllegalArgumentException("Unsupported repetition of Attributes[@Category='" + categoryName + "']");
}
for (final Attribute jaxbAttr : jaxbAttributes.getAttributes())
{
xacmlAttributeParser.parseNamedAttribute(categoryName, jaxbAttr, null, mutableAttMap);
}
}
attrMap = Collections.unmodifiableMap(mutableAttMap);
super(id);
attrMap = Collections.unmodifiableMap(attributeMap);
final Set<AttributeDesignatorType> mutableSupportedAttDesignatorSet = attrMap.entrySet().stream().map(attEntry -> newAttributeDesignator(attEntry)).collect(Collectors.toSet());
this.supportedDesignatorTypes = Collections.unmodifiableSet(mutableSupportedAttDesignatorSet);
}
......@@ -131,17 +113,17 @@ public class TestAttributeProvider extends BaseNamedAttributeProvider
* {@link TestAttributeProvider} factory
*
*/
public static class Factory extends CloseableNamedAttributeProvider.FactoryBuilder<org.ow2.authzforce.core.pdp.testutil.ext.xmlns.TestAttributeProvider>
public static class Factory extends CloseableNamedAttributeProvider.FactoryBuilder<TestAttributeProviderDescriptor>
{
@Override
public Class<org.ow2.authzforce.core.pdp.testutil.ext.xmlns.TestAttributeProvider> getJaxbClass()
public Class<TestAttributeProviderDescriptor> getJaxbClass()
{
return org.ow2.authzforce.core.pdp.testutil.ext.xmlns.TestAttributeProvider.class;
return TestAttributeProviderDescriptor.class;
}
@Override
public DependencyAwareFactory getInstance(final org.ow2.authzforce.core.pdp.testutil.ext.xmlns.TestAttributeProvider conf, final EnvironmentProperties environmentProperties)
public DependencyAwareFactory getInstance(final TestAttributeProviderDescriptor conf, final EnvironmentProperties environmentProperties)
{
return new DependencyAwareFactory()
{
......@@ -154,9 +136,27 @@ public class TestAttributeProvider extends BaseNamedAttributeProvider
}
@Override
public CloseableNamedAttributeProvider getInstance(final AttributeValueFactoryRegistry attrDatatypeFactory, final AttributeProvider depAttrProvider)
public CloseableNamedAttributeProvider getInstance(final AttributeValueFactoryRegistry attributeValueFactories, final AttributeProvider depAttrProvider)
{
return new TestAttributeProvider(conf, attrDatatypeFactory);
final NamedXacmlAttributeParser<Attribute> namedXacmlAttParser = new NamedXacmlJaxbAttributeParser(attributeValueFactories);
final XacmlRequestAttributeParser<Attribute, AttributeBag<?>> xacmlAttributeParser = new NonIssuedLikeIssuedStrictXacmlAttributeParser<>(namedXacmlAttParser);
final Set<String> attrCategoryNames = new HashSet<>();
final Map<AttributeFqn, AttributeBag<?>> mutableAttMap = new HashMap<>();
for (final Attributes jaxbAttributes : conf.getAttributes())
{
final String categoryName = jaxbAttributes.getCategory();
if (!attrCategoryNames.add(categoryName))
{
throw new IllegalArgumentException("Unsupported repetition of Attributes[@Category='" + categoryName + "']");
}
for (final Attribute jaxbAttr : jaxbAttributes.getAttributes())
{
xacmlAttributeParser.parseNamedAttribute(categoryName, jaxbAttr, null, mutableAttMap);
}
}
return new TestAttributeProvider(conf.getId(), mutableAttMap);
}
};
}
......
......@@ -7,13 +7,13 @@
<xs:import namespace="http://authzforce.github.io/xmlns/pdp/ext/3" />
<xs:annotation>
<xs:documentation xml:lang="en">
Data Model for PDP test extensions, e.g. the Test Attribute Provider module
Data Models (configuration descriptors) for PDP test extensions, e.g. the Test Attribute Provider module
</xs:documentation>
</xs:annotation>
<xs:complexType name="TestAttributeProvider">
<xs:complexType name="TestAttributeProviderDescriptor">
<xs:annotation>
<xs:documentation>
Test Attribute Provider. This Provider is used for test purposes only. It can be
Test Attribute Provider configuration descriptor. This Provider is used for test purposes only. It can be
configured to support any attribute but returns always an empty bag as attribute value.
</xs:documentation>
</xs:annotation>
......@@ -25,10 +25,10 @@
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="MongoDBBasedPolicyProvider">
<xs:complexType name="MongoDBBasedPolicyProviderDescriptor">
<xs:annotation>
<xs:documentation>
Policy provider module that retrieves policies (given a Policy(Set)IdReference) from documents in a MongoDB-hosted collection. The document model must correspond to JSON form:
Configuration descriptor for the policy provider module that retrieves policies (given a Policy(Set)IdReference) from documents in a MongoDB-hosted collection. The document model must correspond to JSON form:
<![CDATA[{id: $policy_ID, version: $policy_version, type: $policy_type, content: $policy_doc}]]>,
where $policy_ID must be a valid XACML 3.0 PolicyId, $policy_version a valid XACML 3.0 policy version, $policy_type either '{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Policy' if the
policy is XACML 3.0 Policy or '{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}PolicySet' if it is a XACML 3.0 PolicySet, and $policy_doc a valid XACML 3.0 Policy or PolicySet according to
......
......@@ -66,7 +66,7 @@ import org.ow2.authzforce.core.pdp.testutil.PdpTest;
import org.ow2.authzforce.core.pdp.testutil.TestUtils;
import org.ow2.authzforce.core.pdp.testutil.ext.MongoDbRefPolicyProvider;
import org.ow2.authzforce.core.pdp.testutil.ext.PolicyPojo;
import org.ow2.authzforce.core.pdp.testutil.ext.xmlns.MongoDBBasedPolicyProvider;
import org.ow2.authzforce.core.pdp.testutil.ext.xmlns.MongoDBBasedPolicyProviderDescriptor;
import org.ow2.authzforce.core.xmlns.pdp.Pdp;
import org.ow2.authzforce.xacml.Xacml3JaxbHelper;
import org.ow2.authzforce.xmlns.pdp.ext.AbstractPolicyProvider;
......@@ -102,12 +102,12 @@ public class MongoDBRefPolicyProviderTest
}
final AbstractPolicyProvider policyProviderConf = pdpConf.getRefPolicyProvider();
if (!(policyProviderConf instanceof MongoDBBasedPolicyProvider))
if (!(policyProviderConf instanceof MongoDBBasedPolicyProviderDescriptor))
{
throw new RuntimeException("Invalid type of refPolicyProvider in pdp.xml. Expected: " + MongoDBBasedPolicyProvider.class);
throw new RuntimeException("Invalid type of refPolicyProvider in pdp.xml. Expected: " + MongoDBBasedPolicyProviderDescriptor.class);
}
final MongoDBBasedPolicyProvider mongodbBasedPolicyProviderConf = (MongoDBBasedPolicyProvider) policyProviderConf;
final MongoDBBasedPolicyProviderDescriptor mongodbBasedPolicyProviderConf = (MongoDBBasedPolicyProviderDescriptor) policyProviderConf;
final BigInteger maxAllowedIntVal = BigInteger.valueOf(Integer.MAX_VALUE);
final AttributeValueFactoryRegistry valFactoryReg = StandardAttributeValueFactories.getRegistry(false, Optional.of(maxAllowedIntVal));
......@@ -156,7 +156,8 @@ public class MongoDBRefPolicyProviderTest
policyTypeId = MongoDbRefPolicyProvider.XACML3_POLICY_TYPE_ID;
policyId = policy.getPolicyId();
policyVersion = policy.getVersion();
} else
}
else
{
// PolicySet
policyTypeId = MongoDbRefPolicyProvider.XACML3_POLICYSET_TYPE_ID;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment