use of com.sun.identity.delegation.DelegationException in project OpenAM by OpenRock.
the class XacmlService method checkPermission.
/**
* This "lower level" version of checkPermission is really only here to make testing easier.
*
* @return true if the user has the "action" permission (action being "READ" or "MODIFY"), false otherwise.
*/
private boolean checkPermission(String action, String urlLastSegment, String realm, SSOToken token) throws EntitlementException {
boolean result;
try {
final Set<String> actions = new HashSet<String>(Arrays.asList(action));
final DelegationPermissionFactory permissionFactory = new DelegationPermissionFactory();
final DelegationPermission permissionRequest = permissionFactory.newInstance(realm, REST, VERSION, urlLastSegment, action, actions, Collections.<String, String>emptyMap());
result = checkPermission(permissionRequest, token, urlLastSegment);
} catch (SSOException e) {
debug.warning("XacmlService permission evaluation failed", e);
throw new EntitlementException(INTERNAL_ERROR, e);
} catch (DelegationException e) {
debug.warning("XacmlService permission evaluation failed", e);
throw new EntitlementException(INTERNAL_ERROR, e);
}
return result;
}
use of com.sun.identity.delegation.DelegationException in project OpenAM by OpenRock.
the class XacmlServiceTest method testPermissionsCheckFail.
@Test
public void testPermissionsCheckFail() {
RestLog restLog = PowerMockito.mock(RestLog.class);
DelegationEvaluator evaluator = mock(DelegationEvaluator.class);
XacmlService xacmlService = new XacmlService(importExport, adminTokenAction, this.debug, restLog, evaluator, jacksonRepresentationFactory);
SSOToken adminToken = mock(SSOToken.class);
DelegationPermission delegationPermission = mock(DelegationPermission.class);
String urlLastSegment = "blah";
try {
// when
when(evaluator.isAllowed(adminToken, delegationPermission, Collections.EMPTY_MAP)).thenReturn(false);
boolean result = xacmlService.checkPermission(delegationPermission, adminToken, urlLastSegment);
assertThat(result).isFalse();
verify(restLog).auditAccessDenied(anyString(), anyString(), anyString(), any(SSOToken.class));
} catch (DelegationException de) {
// then
fail("Did not expect DelegationException");
} catch (SSOException ssoe) {
//then
fail("Did not expect SSOException");
} catch (Exception e) {
fail("Did not expect " + e.getClass().getName() + " with message " + e.getMessage());
}
}
Aggregations