Search in sources :

Example 1 with PolicyExtension

use of ddf.security.policy.extension.PolicyExtension in project ddf by codice.

the class AuthzRealmTest method testAddRemoveSetPolicyExtension.

@Test
public void testAddRemoveSetPolicyExtension() {
    PolicyExtension policyExtension = new PolicyExtension() {

        @Override
        public KeyValueCollectionPermission isPermittedMatchAll(CollectionPermission subjectAllCollection, KeyValueCollectionPermission matchAllCollection) {
            throw new NullPointerException();
        }

        @Override
        public KeyValueCollectionPermission isPermittedMatchOne(CollectionPermission subjectAllCollection, KeyValueCollectionPermission matchOneCollection) {
            throw new NullPointerException();
        }
    };
    testRealm.addPolicyExtension(policyExtension);
    testRealm.removePolicyExtension(policyExtension);
    testRealm.setPolicyExtensions(Arrays.asList(policyExtension));
}
Also used : KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) CollectionPermission(ddf.security.permission.CollectionPermission) KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) PolicyExtension(ddf.security.policy.extension.PolicyExtension) Test(org.junit.Test)

Example 2 with PolicyExtension

use of ddf.security.policy.extension.PolicyExtension in project ddf by codice.

the class AuthzRealm method isPermittedByExtensionOne.

private KeyValueCollectionPermission isPermittedByExtensionOne(CollectionPermission subjectAllCollection, KeyValueCollectionPermission matchOneCollection) {
    if (!CollectionUtils.isEmpty(policyExtensions)) {
        KeyValueCollectionPermission resultCollection = new KeyValueCollectionPermission();
        resultCollection.addAll(matchOneCollection.getPermissionList());
        resultCollection.setAction(matchOneCollection.getAction());
        for (PolicyExtension policyExtension : policyExtensions) {
            try {
                resultCollection = policyExtension.isPermittedMatchOne(subjectAllCollection, resultCollection);
            } catch (Exception e) {
                SecurityLogger.auditWarn("Policy Extension plugin did not complete correctly. This could allow access to a resource.", e);
                LOGGER.warn("Policy Extension plugin did not complete correctly. This could allow access to a resource.", e);
            }
        }
        return resultCollection;
    }
    return matchOneCollection;
}
Also used : KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) PolicyExtension(ddf.security.policy.extension.PolicyExtension) PdpException(ddf.security.pdp.realm.xacml.processor.PdpException) AuthenticationException(org.apache.shiro.authc.AuthenticationException)

Example 3 with PolicyExtension

use of ddf.security.policy.extension.PolicyExtension in project ddf by codice.

the class AuthzRealmTest method testBadPolicyExtension.

@Test
public void testBadPolicyExtension() {
    permissionList.clear();
    KeyValuePermission kvp = new KeyValuePermission("country", Arrays.asList("AUS", "CAN", "GBR"));
    permissionList.add(kvp);
    testRealm.addPolicyExtension(new PolicyExtension() {

        @Override
        public KeyValueCollectionPermission isPermittedMatchAll(CollectionPermission subjectAllCollection, KeyValueCollectionPermission matchAllCollection) {
            throw new NullPointerException();
        }

        @Override
        public KeyValueCollectionPermission isPermittedMatchOne(CollectionPermission subjectAllCollection, KeyValueCollectionPermission matchOneCollection) {
            throw new NullPointerException();
        }
    });
    boolean[] permittedArray = testRealm.isPermitted(mockSubjectPrincipal, permissionList);
    for (boolean permitted : permittedArray) {
        Assert.assertEquals(true, permitted);
    }
}
Also used : KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) CollectionPermission(ddf.security.permission.CollectionPermission) KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) PolicyExtension(ddf.security.policy.extension.PolicyExtension) KeyValuePermission(ddf.security.permission.KeyValuePermission) Test(org.junit.Test)

Example 4 with PolicyExtension

use of ddf.security.policy.extension.PolicyExtension in project ddf by codice.

the class AuthzRealm method isPermittedByExtensionAll.

private KeyValueCollectionPermission isPermittedByExtensionAll(CollectionPermission subjectAllCollection, KeyValueCollectionPermission matchAllCollection) {
    if (!CollectionUtils.isEmpty(policyExtensions)) {
        KeyValueCollectionPermission resultCollection = new KeyValueCollectionPermission();
        resultCollection.addAll(matchAllCollection.getPermissionList());
        resultCollection.setAction(matchAllCollection.getAction());
        for (PolicyExtension policyExtension : policyExtensions) {
            try {
                resultCollection = policyExtension.isPermittedMatchAll(subjectAllCollection, resultCollection);
            } catch (Exception e) {
                SecurityLogger.auditWarn("Policy Extension plugin did not complete correctly. This could allow access to a resource.", e);
                LOGGER.warn("Policy Extension plugin did not complete correctly. This could allow access to a resource.", e);
            }
        }
        return resultCollection;
    }
    return matchAllCollection;
}
Also used : KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) PolicyExtension(ddf.security.policy.extension.PolicyExtension) PdpException(ddf.security.pdp.realm.xacml.processor.PdpException) AuthenticationException(org.apache.shiro.authc.AuthenticationException)

Aggregations

KeyValueCollectionPermission (ddf.security.permission.KeyValueCollectionPermission)4 PolicyExtension (ddf.security.policy.extension.PolicyExtension)4 PdpException (ddf.security.pdp.realm.xacml.processor.PdpException)2 CollectionPermission (ddf.security.permission.CollectionPermission)2 AuthenticationException (org.apache.shiro.authc.AuthenticationException)2 Test (org.junit.Test)2 KeyValuePermission (ddf.security.permission.KeyValuePermission)1