Search in sources :

Example 6 with DelegationException

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;
    }
}
Also used : DelegationEvaluatorImpl(com.sun.identity.delegation.DelegationEvaluatorImpl) DelegationEvaluator(com.sun.identity.delegation.DelegationEvaluator) DelegationException(com.sun.identity.delegation.DelegationException) SSOException(com.iplanet.sso.SSOException) DelegationPermission(com.sun.identity.delegation.DelegationPermission)

Example 7 with DelegationException

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);
}
Also used : SSOToken(com.iplanet.sso.SSOToken) JsonValue(org.forgerock.json.JsonValue) DelegationException(com.sun.identity.delegation.DelegationException) Test(org.testng.annotations.Test)

Example 8 with DelegationException

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();
}
Also used : Set(java.util.Set) DelegationManager(com.sun.identity.delegation.DelegationManager) Iterator(java.util.Iterator) SSOException(com.iplanet.sso.SSOException) DelegationException(com.sun.identity.delegation.DelegationException)

Example 9 with DelegationException

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);
}
Also used : SSOToken(com.iplanet.sso.SSOToken) JsonValue(org.forgerock.json.JsonValue) DelegationException(com.sun.identity.delegation.DelegationException) Test(org.testng.annotations.Test)

Example 10 with DelegationException

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);
}
Also used : SSOToken(com.iplanet.sso.SSOToken) JsonValue(org.forgerock.json.JsonValue) DelegationException(com.sun.identity.delegation.DelegationException) Test(org.testng.annotations.Test)

Aggregations

DelegationException (com.sun.identity.delegation.DelegationException)37 SSOException (com.iplanet.sso.SSOException)29 Set (java.util.Set)27 HashSet (java.util.HashSet)21 Iterator (java.util.Iterator)18 DelegationPermission (com.sun.identity.delegation.DelegationPermission)17 SSOToken (com.iplanet.sso.SSOToken)12 IdRepoException (com.sun.identity.idm.IdRepoException)12 DelegationEvaluator (com.sun.identity.delegation.DelegationEvaluator)11 DelegationManager (com.sun.identity.delegation.DelegationManager)10 DelegationEvaluatorImpl (com.sun.identity.delegation.DelegationEvaluatorImpl)9 DelegationPrivilege (com.sun.identity.delegation.DelegationPrivilege)9 PolicyException (com.sun.identity.policy.PolicyException)8 AMIdentity (com.sun.identity.idm.AMIdentity)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Test (org.testng.annotations.Test)5 AMIdentityRepository (com.sun.identity.idm.AMIdentityRepository)4 IdType (com.sun.identity.idm.IdType)4 CLIException (com.sun.identity.cli.CLIException)3