Search in sources :

Example 16 with RequestType

use of com.helger.peppol.wsclient2.RequestType in project ddf by codice.

the class XacmlClientTest method testIllegalStateException.

@Test(expected = IllegalStateException.class)
public void testIllegalStateException() throws Exception {
    LOGGER.debug("\n\n\n##### testExecption");
    File policyDir = folder.newFolder("tempDir");
    // Perform Test
    XacmlClient pdp = new XacmlClient(policyDir.getCanonicalPath(), null, mock(SecurityLogger.class));
    File srcFile = new File(projectHome + File.separator + RELATIVE_POLICIES_DIR + File.separator + POLICY_FILE);
    FileUtils.copyFileToDirectory(srcFile, policyDir);
    RequestType xacmlRequestType = new RequestType();
    xacmlRequestType.setCombinedDecision(false);
    xacmlRequestType.setReturnPolicyIdList(false);
    AttributesType actionAttributes = new AttributesType();
    actionAttributes.setCategory(ACTION_CATEGORY);
    AttributeType actionAttribute = new AttributeType();
    actionAttribute.setAttributeId(ACTION_ID);
    actionAttribute.setIncludeInResult(false);
    AttributeValueType actionValue = new AttributeValueType();
    actionValue.setDataType(STRING_DATA_TYPE);
    actionValue.getContent().add(QUERY_ACTION);
    actionAttribute.getAttributeValue().add(actionValue);
    actionAttributes.getAttribute().add(actionAttribute);
    AttributesType subjectAttributes = new AttributesType();
    subjectAttributes.setCategory(SUBJECT_CATEGORY);
    AttributeType subjectAttribute = new AttributeType();
    subjectAttribute.setAttributeId(SUBJECT_ID);
    subjectAttribute.setIncludeInResult(false);
    AttributeValueType subjectValue = new AttributeValueType();
    subjectValue.setDataType(STRING_DATA_TYPE);
    subjectValue.getContent().add(TEST_USER_1);
    subjectAttribute.getAttributeValue().add(subjectValue);
    subjectAttributes.getAttribute().add(subjectAttribute);
    AttributeType roleAttribute = new AttributeType();
    roleAttribute.setAttributeId(ROLE_CLAIM);
    roleAttribute.setIncludeInResult(false);
    AttributeValueType roleValue = new AttributeValueType();
    roleValue.setDataType(STRING_DATA_TYPE);
    roleValue.getContent().add(ROLE);
    roleAttribute.getAttributeValue().add(roleValue);
    subjectAttributes.getAttribute().add(roleAttribute);
    AttributesType categoryAttributes = new AttributesType();
    categoryAttributes.setCategory(PERMISSIONS_CATEGORY);
    AttributeType citizenshipAttribute = new AttributeType();
    citizenshipAttribute.setAttributeId(CITIZENSHIP_ATTRIBUTE);
    citizenshipAttribute.setIncludeInResult(false);
    AttributeValueType citizenshipValue = new AttributeValueType();
    citizenshipValue.setDataType(STRING_DATA_TYPE);
    citizenshipValue.getContent().add(US_COUNTRY);
    citizenshipAttribute.getAttributeValue().add(citizenshipValue);
    categoryAttributes.getAttribute().add(citizenshipAttribute);
    xacmlRequestType.getAttributes().add(actionAttributes);
    xacmlRequestType.getAttributes().add(subjectAttributes);
    xacmlRequestType.getAttributes().add(categoryAttributes);
    // Perform Test
    pdp.evaluate(xacmlRequestType);
}
Also used : AttributeValueType(oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType) AttributeType(oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeType) AttributesType(oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributesType) File(java.io.File) SecurityLogger(ddf.security.audit.SecurityLogger) RequestType(oasis.names.tc.xacml._3_0.core.schema.wd_17.RequestType) Test(org.junit.Test)

Example 17 with RequestType

use of com.helger.peppol.wsclient2.RequestType in project ddf by codice.

the class XacmlClientTest method testEvaluateroleuseractionquerycitizenshipCA.

@Test
public void testEvaluateroleuseractionquerycitizenshipCA() throws Exception {
    LOGGER.debug("\n\n\n##### testEvaluate_role_user_action_query_citizenship_CA");
    final String country = "CA";
    testSetup();
    RequestType xacmlRequestType = new RequestType();
    xacmlRequestType.setCombinedDecision(false);
    xacmlRequestType.setReturnPolicyIdList(false);
    AttributesType actionAttributes = new AttributesType();
    actionAttributes.setCategory(ACTION_CATEGORY);
    AttributeType actionAttribute = new AttributeType();
    actionAttribute.setAttributeId(ACTION_ID);
    actionAttribute.setIncludeInResult(false);
    AttributeValueType actionValue = new AttributeValueType();
    actionValue.setDataType(STRING_DATA_TYPE);
    actionValue.getContent().add(QUERY_ACTION);
    actionAttribute.getAttributeValue().add(actionValue);
    actionAttributes.getAttribute().add(actionAttribute);
    AttributesType subjectAttributes = new AttributesType();
    subjectAttributes.setCategory(SUBJECT_CATEGORY);
    AttributeType subjectAttribute = new AttributeType();
    subjectAttribute.setAttributeId(SUBJECT_ID);
    subjectAttribute.setIncludeInResult(false);
    AttributeValueType subjectValue = new AttributeValueType();
    subjectValue.setDataType(STRING_DATA_TYPE);
    subjectValue.getContent().add(TEST_USER_2);
    subjectAttribute.getAttributeValue().add(subjectValue);
    subjectAttributes.getAttribute().add(subjectAttribute);
    AttributeType roleAttribute = new AttributeType();
    roleAttribute.setAttributeId(ROLE_CLAIM);
    roleAttribute.setIncludeInResult(false);
    AttributeValueType roleValue = new AttributeValueType();
    roleValue.setDataType(STRING_DATA_TYPE);
    roleValue.getContent().add(ROLE);
    roleAttribute.getAttributeValue().add(roleValue);
    subjectAttributes.getAttribute().add(roleAttribute);
    AttributesType categoryAttributes = new AttributesType();
    categoryAttributes.setCategory(PERMISSIONS_CATEGORY);
    AttributeType citizenshipAttribute = new AttributeType();
    citizenshipAttribute.setAttributeId(CITIZENSHIP_ATTRIBUTE);
    citizenshipAttribute.setIncludeInResult(false);
    AttributeValueType citizenshipValue = new AttributeValueType();
    citizenshipValue.setDataType(STRING_DATA_TYPE);
    citizenshipValue.getContent().add(country);
    citizenshipAttribute.getAttributeValue().add(citizenshipValue);
    categoryAttributes.getAttribute().add(citizenshipAttribute);
    xacmlRequestType.getAttributes().add(actionAttributes);
    xacmlRequestType.getAttributes().add(subjectAttributes);
    xacmlRequestType.getAttributes().add(categoryAttributes);
    XacmlClient pdp = new XacmlClient(tempDir.getCanonicalPath(), new XmlParser(), mock(SecurityLogger.class));
    // Perform Test
    ResponseType xacmlResponse = pdp.evaluate(xacmlRequestType);
    // Verify
    JAXBContext jaxbContext = JAXBContext.newInstance(ResponseType.class);
    Marshaller marshaller = jaxbContext.createMarshaller();
    ObjectFactory objectFactory = new ObjectFactory();
    Writer writer = new StringWriter();
    marshaller.marshal(objectFactory.createResponse(xacmlResponse), writer);
    LOGGER.debug("\nXACML 3.0 Response:\n{}", writer.toString());
    assertEquals(xacmlResponse.getResult().get(0).getDecision(), DecisionType.DENY);
}
Also used : XmlParser(org.codice.ddf.parser.xml.XmlParser) Marshaller(javax.xml.bind.Marshaller) AttributeValueType(oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType) JAXBContext(javax.xml.bind.JAXBContext) ResponseType(oasis.names.tc.xacml._3_0.core.schema.wd_17.ResponseType) ObjectFactory(oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory) StringWriter(java.io.StringWriter) AttributeType(oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeType) AttributesType(oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributesType) StringWriter(java.io.StringWriter) Writer(java.io.Writer) RequestType(oasis.names.tc.xacml._3_0.core.schema.wd_17.RequestType) SecurityLogger(ddf.security.audit.SecurityLogger) Test(org.junit.Test)

Example 18 with RequestType

use of com.helger.peppol.wsclient2.RequestType in project ddf by codice.

the class XacmlClientTest method testEvaluateroleuseractionquerycitizenshipUS.

@Test
public void testEvaluateroleuseractionquerycitizenshipUS() throws Exception {
    LOGGER.debug("\n\n\n##### testEvaluate_role_user_action_query_citizenship_US");
    // Setup
    File destDir = folder.newFolder(TEMP_DIR_NAME);
    LOGGER.debug("Making directory: {}", destDir.getPath());
    if (destDir.mkdir()) {
        File srcFile = new File(projectHome + File.separator + RELATIVE_POLICIES_DIR + File.separator + POLICY_FILE);
        FileUtils.copyFileToDirectory(srcFile, destDir);
        RequestType xacmlRequestType = new RequestType();
        xacmlRequestType.setCombinedDecision(false);
        xacmlRequestType.setReturnPolicyIdList(false);
        AttributesType actionAttributes = new AttributesType();
        actionAttributes.setCategory(ACTION_CATEGORY);
        AttributeType actionAttribute = new AttributeType();
        actionAttribute.setAttributeId(ACTION_ID);
        actionAttribute.setIncludeInResult(false);
        AttributeValueType actionValue = new AttributeValueType();
        actionValue.setDataType(STRING_DATA_TYPE);
        actionValue.getContent().add(QUERY_ACTION);
        actionAttribute.getAttributeValue().add(actionValue);
        actionAttributes.getAttribute().add(actionAttribute);
        AttributesType subjectAttributes = new AttributesType();
        subjectAttributes.setCategory(SUBJECT_CATEGORY);
        AttributeType subjectAttribute = new AttributeType();
        subjectAttribute.setAttributeId(SUBJECT_ID);
        subjectAttribute.setIncludeInResult(false);
        AttributeValueType subjectValue = new AttributeValueType();
        subjectValue.setDataType(STRING_DATA_TYPE);
        subjectValue.getContent().add(TEST_USER_1);
        subjectAttribute.getAttributeValue().add(subjectValue);
        subjectAttributes.getAttribute().add(subjectAttribute);
        AttributeType roleAttribute = new AttributeType();
        roleAttribute.setAttributeId(ROLE_CLAIM);
        roleAttribute.setIncludeInResult(false);
        AttributeValueType roleValue = new AttributeValueType();
        roleValue.setDataType(STRING_DATA_TYPE);
        roleValue.getContent().add(ROLE);
        roleAttribute.getAttributeValue().add(roleValue);
        subjectAttributes.getAttribute().add(roleAttribute);
        AttributesType categoryAttributes = new AttributesType();
        categoryAttributes.setCategory(PERMISSIONS_CATEGORY);
        AttributeType citizenshipAttribute = new AttributeType();
        citizenshipAttribute.setAttributeId(CITIZENSHIP_ATTRIBUTE);
        citizenshipAttribute.setIncludeInResult(false);
        AttributeValueType citizenshipValue = new AttributeValueType();
        citizenshipValue.setDataType(STRING_DATA_TYPE);
        citizenshipValue.getContent().add(US_COUNTRY);
        citizenshipAttribute.getAttributeValue().add(citizenshipValue);
        categoryAttributes.getAttribute().add(citizenshipAttribute);
        xacmlRequestType.getAttributes().add(actionAttributes);
        xacmlRequestType.getAttributes().add(subjectAttributes);
        xacmlRequestType.getAttributes().add(categoryAttributes);
        XacmlClient pdp = new XacmlClient(destDir.getCanonicalPath(), new XmlParser(), mock(SecurityLogger.class));
        // Perform Test
        ResponseType xacmlResponse = pdp.evaluate(xacmlRequestType);
        // Verify
        JAXBContext jaxbContext = JAXBContext.newInstance(ResponseType.class);
        Marshaller marshaller = jaxbContext.createMarshaller();
        ObjectFactory objectFactory = new ObjectFactory();
        Writer writer = new StringWriter();
        marshaller.marshal(objectFactory.createResponse(xacmlResponse), writer);
        LOGGER.debug("\nXACML 3.0 Response:\n{}", writer.toString());
        assertEquals(xacmlResponse.getResult().get(0).getDecision(), DecisionType.PERMIT);
        // Cleanup
        LOGGER.debug("Deleting directory: {}", destDir);
        FileUtils.deleteDirectory(destDir);
    } else {
        LOGGER.debug("Could not create directory: {}", destDir);
    }
}
Also used : XmlParser(org.codice.ddf.parser.xml.XmlParser) Marshaller(javax.xml.bind.Marshaller) AttributeValueType(oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType) JAXBContext(javax.xml.bind.JAXBContext) ResponseType(oasis.names.tc.xacml._3_0.core.schema.wd_17.ResponseType) ObjectFactory(oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory) StringWriter(java.io.StringWriter) AttributeType(oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeType) AttributesType(oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributesType) File(java.io.File) StringWriter(java.io.StringWriter) Writer(java.io.Writer) RequestType(oasis.names.tc.xacml._3_0.core.schema.wd_17.RequestType) SecurityLogger(ddf.security.audit.SecurityLogger) Test(org.junit.Test)

Example 19 with RequestType

use of com.helger.peppol.wsclient2.RequestType in project ddf by codice.

the class XacmlPdp method isPermitted.

public boolean isPermitted(String primaryPrincipal, AuthorizationInfo info, KeyValueCollectionPermission curPermission) {
    boolean curResponse;
    LOGGER.debug("Checking if {} has access for action {}", primaryPrincipal, curPermission.getAction());
    if (CollectionUtils.isEmpty(info.getObjectPermissions()) && CollectionUtils.isEmpty(info.getStringPermissions()) && CollectionUtils.isEmpty(info.getRoles()) && !CollectionUtils.isEmpty(curPermission.getKeyValuePermissionList())) {
        securityLogger.audit(String.format(AUDIT_MSG_FORMAT, "short-circuit denied", primaryPrincipal, curPermission.getAction()));
        return false;
    }
    if ((!CollectionUtils.isEmpty(info.getObjectPermissions()) || !CollectionUtils.isEmpty(info.getStringPermissions()) || !CollectionUtils.isEmpty(info.getRoles())) && CollectionUtils.isEmpty(curPermission.getKeyValuePermissionList())) {
        securityLogger.audit(String.format(AUDIT_MSG_FORMAT, "short-circuit permitted", primaryPrincipal, curPermission.getAction()));
        return true;
    }
    LOGGER.debug("Received authZ info, creating XACML request.");
    RequestType curRequest = createXACMLRequest(primaryPrincipal, info, curPermission);
    LOGGER.debug("Created XACML request, calling PDP.");
    curResponse = isPermitted(curRequest);
    if (curResponse) {
        securityLogger.audit(String.format(AUDIT_MSG_FORMAT, "permitted", primaryPrincipal, curPermission.getAction()));
    } else {
        securityLogger.audit(String.format(AUDIT_MSG_FORMAT, "denied", primaryPrincipal, curPermission.getAction()));
    }
    return curResponse;
}
Also used : RequestType(oasis.names.tc.xacml._3_0.core.schema.wd_17.RequestType)

Example 20 with RequestType

use of com.helger.peppol.wsclient2.RequestType in project mod-oai-pmh by folio-org.

the class Request method isResumptionTokenParsableAndValid.

/**
 * Restores original request encoded in resumptionToken.
 * The resumptionToken is exclusive param, so the request cannot be restored if some other params are provided
 * in the request along with the resumptionToken.
 *
 * @return true if the request was restored, false otherwise.
 */
public boolean isResumptionTokenParsableAndValid() {
    try {
        String resumptionToken = new String(Base64.getUrlDecoder().decode(oaiRequest.getResumptionToken()), StandardCharsets.UTF_8);
        Map<String, String> params = URLEncodedUtils.parse(resumptionToken, UTF_8, PARAMETER_SEPARATOR).stream().collect(toMap(NameValuePair::getName, NameValuePair::getValue));
        restoredOaiRequest = new RequestType();
        restoredOaiRequest.setMetadataPrefix(params.get(METADATA_PREFIX_PARAM));
        restoredOaiRequest.setFrom(params.get(FROM_PARAM));
        restoredOaiRequest.setUntil(params.get(UNTIL_PARAM));
        restoredOaiRequest.setSet(params.get(SET_PARAM));
        this.offset = Integer.parseInt(params.get(OFFSET_PARAM));
        final String value = params.get(TOTAL_RECORDS_PARAM);
        this.totalRecords = value == null ? 0 : Integer.parseInt(value);
        this.nextRecordId = params.get(NEXT_RECORD_ID_PARAM);
        this.requestId = params.get(REQUEST_ID_PARAM);
        if (Objects.nonNull(params.get(NEXT_INSTANCE_PK_VALUE))) {
            this.nextInstancePkValue = Integer.parseInt(params.get(NEXT_INSTANCE_PK_VALUE));
        }
    } catch (Exception e) {
        return false;
    }
    return true;
}
Also used : MalformedURLException(java.net.MalformedURLException) RequestType(org.openarchives.oai._2.RequestType)

Aggregations

RequestType (oasis.names.tc.xacml._3_0.core.schema.wd_17.RequestType)14 Test (org.junit.Test)14 KeyValueCollectionPermissionImpl (ddf.security.permission.impl.KeyValueCollectionPermissionImpl)8 AttributesType (oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributesType)6 KeyValueCollectionPermission (ddf.security.permission.KeyValueCollectionPermission)5 AttributeType (oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeType)5 AttributeValueType (oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType)5 SecurityLogger (ddf.security.audit.SecurityLogger)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 File (java.io.File)3 StringWriter (java.io.StringWriter)3 Writer (java.io.Writer)3 ItemType (com.helger.peppol.wsclient2.ItemType)2 ResponseType (com.helger.peppol.wsclient2.ResponseType)2 ValidationResultType (com.helger.peppol.wsclient2.ValidationResultType)2 KeyValuePermission (ddf.security.permission.KeyValuePermission)2 AbstractRestServiceTest (eu.europa.ec.fisheries.uvms.docker.validation.common.AbstractRestServiceTest)2 HashMap (java.util.HashMap)2 JAXBContext (javax.xml.bind.JAXBContext)2