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));
}
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;
}
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);
}
}
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;
}
Aggregations