use of com.sun.identity.delegation.DelegationException in project OpenAM by OpenRock.
the class XACMLUtils method hasPermission.
public static boolean hasPermission(String realm, SSOToken adminToken, String action) {
try {
DelegationEvaluator de = new DelegationEvaluatorImpl();
DelegationPermission dp = new DelegationPermission(realm, "rest", "1.0", "policies", action, asSet(action), Collections.<String, String>emptyMap());
return de.isAllowed(adminToken, dp, Collections.EMPTY_MAP);
} catch (DelegationException de) {
DEBUG.error("XACMLUtils.hasPermission", de);
return false;
} catch (SSOException ssoe) {
DEBUG.error("XACMLUtils.hasPermission", ssoe);
return false;
}
}
use of com.sun.identity.delegation.DelegationException in project OpenAM by OpenRock.
the class SessionResourceTest method shouldReturnInternalErrorWhenSetPropertyFailsWithDelegationException.
@Test
public void shouldReturnInternalErrorWhenSetPropertyFailsWithDelegationException() throws SSOException, ExecutionException, InterruptedException, DelegationException {
//given
final String resourceId = "SSO_TOKEN_ID";
final ActionRequest request = mock(ActionRequest.class);
JsonValue jsonContent = json(object(field("one", "testOne")));
given(ssoTokenManager.retrieveValidTokenWithoutResettingIdleTime(resourceId)).willReturn(ssoToken);
given(ssoTokenManager.isValidToken(ssoToken, false)).willReturn(true);
given(request.getAction()).willReturn(SET_PROPERTY_ACTION_ID);
given(request.getContent()).willReturn(jsonContent);
given(propertyWhitelist.isPropertyListed(any(SSOToken.class), any(String.class), anySetOf(String.class))).willThrow(new DelegationException("Error"));
//when
Promise<ActionResponse, ResourceException> promise = sessionResource.actionInstance(realmContext, resourceId, request);
//then
assertThat(promise).failedWithException().isInstanceOf(InternalServerErrorException.class);
}
use of com.sun.identity.delegation.DelegationException in project OpenAM by OpenRock.
the class PrivilegeXMLBuilder method getXML.
public String getXML(String realm, AMModel model) {
StringBuilder xml = new StringBuilder(1000);
if (realm == null) {
realm = model.getStartDN();
}
try {
DelegationManager mgr = new DelegationManager(adminSSOToken, realm);
Set privileges = mgr.getConfiguredPrivilegeNames();
if ((privileges != null) && !privileges.isEmpty()) {
xml.append(PropertyXMLBuilderBase.getXMLDefinitionHeader()).append(START_TAG).append(PRIVILEGE_SECTION_TAG);
for (Iterator iter = privileges.iterator(); iter.hasNext(); ) {
String name = (String) iter.next();
String[] params = { name, name };
xml.append(MessageFormat.format(PRIVILEGE_PROPERTY_TAG, (Object[]) params));
}
xml.append(SECTION_END_TAG).append(END_TAG);
}
} catch (SSOException e) {
PropertyXMLBuilderBase.debug.error("PrivilegeXMLBuilder.getXML", e);
} catch (DelegationException e) {
PropertyXMLBuilderBase.debug.error("PrivilegeXMLBuilder.getXML", e);
}
return xml.toString();
}
use of com.sun.identity.delegation.DelegationException in project OpenAM by OpenRock.
the class SessionResourceTest method shouldReturnInternalErrorWhenGetPropertyFailsWithDelegationException.
@Test
public void shouldReturnInternalErrorWhenGetPropertyFailsWithDelegationException() throws SSOException, DelegationException {
//given
final String resourceId = "SSO_TOKEN_ID";
final ActionRequest request = mock(ActionRequest.class);
final SSOToken ssoToken = mock(SSOToken.class);
final JsonValue content = json(object(field("properties", array("one"))));
given(request.getContent()).willReturn(content);
given(ssoTokenManager.retrieveValidTokenWithoutResettingIdleTime(resourceId)).willReturn(ssoToken);
given(ssoTokenManager.isValidToken(ssoToken, false)).willReturn(true);
given(request.getAction()).willReturn(GET_PROPERTY_ACTION_ID);
given(propertyWhitelist.isPropertyListed(any(SSOToken.class), any(String.class), anySetOf(String.class))).willThrow(new DelegationException("Error"));
//when
Promise<ActionResponse, ResourceException> promise = sessionResource.actionInstance(realmContext, resourceId, request);
//then
assertThat(promise).failedWithException().isInstanceOf(InternalServerErrorException.class);
}
use of com.sun.identity.delegation.DelegationException in project OpenAM by OpenRock.
the class SessionResourceTest method shouldReturnInternalErrorWhenDeletePropertyFailsWithDelegationException.
@Test
public void shouldReturnInternalErrorWhenDeletePropertyFailsWithDelegationException() throws SSOException, ExecutionException, InterruptedException, DelegationException {
//given
final String resourceId = "SSO_TOKEN_ID";
final ActionRequest request = mock(ActionRequest.class);
final JsonValue content = json(object(field("properties", array("one"))));
given(ssoTokenManager.retrieveValidTokenWithoutResettingIdleTime(resourceId)).willReturn(ssoToken);
given(ssoTokenManager.isValidToken(ssoToken, false)).willReturn(true);
given(request.getAction()).willReturn(DELETE_PROPERTY_ACTION_ID);
given(request.getContent()).willReturn(content);
given(propertyWhitelist.isPropertyListed(any(SSOToken.class), any(String.class), anySetOf(String.class))).willThrow(new DelegationException("Error"));
//when
Promise<ActionResponse, ResourceException> promise = sessionResource.actionInstance(realmContext, resourceId, request);
//then
assertThat(promise).failedWithException().isInstanceOf(InternalServerErrorException.class);
}
Aggregations