use of ddf.security.permission.impl.KeyValueCollectionPermissionImpl in project ddf by codice.
the class XacmlPdpTest method testActionGoodSiteName.
@Test
public void testActionGoodSiteName() {
SimpleAuthorizationInfo blankUserInfo = new SimpleAuthorizationInfo(new HashSet<String>());
blankUserInfo.setObjectPermissions(new HashSet<Permission>());
RequestType request = testRealm.createXACMLRequest(USER_NAME, blankUserInfo, new KeyValueCollectionPermissionImpl(SITE_NAME_ACTION));
assertThat(testRealm.isPermitted(request), equalTo(true));
}
use of ddf.security.permission.impl.KeyValueCollectionPermissionImpl in project ddf by codice.
the class PEPAuthorizingInterceptor method handleMessage.
/**
* Intercepts a message. Interceptors should NOT invoke handleMessage or handleFault on the next
* interceptor - the interceptor chain will take care of this.
*
* @param message
*/
@Override
public void handleMessage(Message message) throws Fault {
if (message != null) {
// grab the SAML assertion associated with this Message from the
// token store
SecurityAssertion assertion = assertionRetriever.apply(message);
boolean isPermitted = false;
if ((assertion != null) && (assertion.getToken() != null)) {
Subject user = null;
CollectionPermission action = null;
String actionURI = getActionUri(message);
try {
user = securityManager.getSubject(assertion.getToken());
if (user == null) {
throw new AccessDeniedException(UNAUTH);
}
LOGGER.debug("Is user authenticated: {}", user.isAuthenticated());
LOGGER.debug("Checking for permission");
securityLogger.audit("Is Subject authenticated? " + user.isAuthenticated(), user);
if (StringUtils.isEmpty(actionURI)) {
securityLogger.audit("Denying access to Subject for unknown action.", user);
throw new AccessDeniedException(UNAUTH);
}
action = new KeyValueCollectionPermissionImpl(actionURI);
LOGGER.debug("Permission: {}", action);
isPermitted = user.isPermitted(action);
LOGGER.debug("Result of permission: {}", isPermitted);
securityLogger.audit("Is Subject permitted? " + isPermitted, user);
// store the subject so the DDF framework can use it later
ThreadContext.bind(user);
message.put(SecurityConstants.SECURITY_TOKEN_KEY, user);
LOGGER.debug("Added assertion information to message at key {}", SecurityConstants.SECURITY_TOKEN_KEY);
} catch (SecurityServiceException e) {
securityLogger.audit("Denying access : Caught exception when trying to authenticate user for service [" + actionURI + "]", e);
throw new AccessDeniedException(UNAUTH);
}
if (!isPermitted) {
securityLogger.audit("Denying access to Subject for service: " + action.getAction(), user);
throw new AccessDeniedException(UNAUTH);
}
} else {
securityLogger.audit("Unable to retrieve the security assertion associated with the web service call.");
throw new AccessDeniedException(UNAUTH);
}
} else {
securityLogger.audit("Unable to retrieve the current message associated with the web service call.");
throw new AccessDeniedException(UNAUTH);
}
}
use of ddf.security.permission.impl.KeyValueCollectionPermissionImpl in project ddf by codice.
the class Policy method getAllowedAttributePermissions.
@Override
public CollectionPermission getAllowedAttributePermissions() {
List<KeyValuePermission> perms = new ArrayList<>();
for (ContextAttributeMapping mapping : attributeMappings) {
perms.add(mapping.getAttributePermission());
}
KeyValueCollectionPermission permissions = new KeyValueCollectionPermissionImpl(getContextPath());
permissions.addAll(perms);
return permissions;
}
use of ddf.security.permission.impl.KeyValueCollectionPermissionImpl in project ddf by codice.
the class AuthzRealmTest method testIsNotPermitted.
@Test
public void testIsNotPermitted() {
HashMap<String, List<String>> security = new HashMap<String, List<String>>();
security.put("country", Arrays.asList("AUS", "CAN", "GBR"));
security.put("country2", Arrays.asList("CAN", "GBR"));
security.put("rule", Arrays.asList("A", "B"));
security.put("rule2", Arrays.asList("A", "B", "C"));
KeyValueCollectionPermission kvcp = new KeyValueCollectionPermissionImpl("action", security);
permissionList.clear();
permissionList.add(kvcp);
boolean[] permittedArray = testRealm.isPermitted(mockSubjectPrincipal, permissionList);
for (boolean permitted : permittedArray) {
Assert.assertEquals(false, permitted);
}
}
use of ddf.security.permission.impl.KeyValueCollectionPermissionImpl in project ddf by codice.
the class AuthzRealmTest method testIsPermitted.
@Test
public void testIsPermitted() {
permissionList.clear();
KeyValueCollectionPermission kvcp = new KeyValueCollectionPermissionImpl("action", security);
permissionList.add(kvcp);
boolean[] permittedArray = testRealm.isPermitted(mockSubjectPrincipal, permissionList);
for (boolean permitted : permittedArray) {
Assert.assertEquals(true, permitted);
}
}
Aggregations