Search in sources :

Example 11 with DelegationException

use of com.sun.identity.delegation.DelegationException in project OpenAM by OpenRock.

the class IdServicesImpl method checkPermission.

private boolean checkPermission(SSOToken token, String realm, String name, Set attrs, IdOperation op, IdType type) throws IdRepoException, SSOException {
    if (!ServiceManager.isConfigMigratedTo70()) {
        // in coexistence mode. Do not perform any delegation check
        return true;
    }
    Set thisAction = null;
    if (op.equals(IdOperation.READ)) {
        // thisAction = readAction;
        // TODO This is a temporary fix where-in all users are
        // being allowed read permisions, till delegation component
        // is fixed to support "user self read" operations
        thisAction = READ_ACTION;
    } else {
        thisAction = WRITE_ACTION;
    }
    try {
        DelegationEvaluator de = new DelegationEvaluatorImpl();
        String resource = type.getName();
        if (name != null) {
            resource += "/" + name;
        }
        DelegationPermission dp = new DelegationPermission(realm, IdConstants.REPO_SERVICE, "1.0", "application", resource, thisAction, Collections.EMPTY_MAP);
        Map envMap = Collections.EMPTY_MAP;
        if (attrs != null) {
            envMap = new HashMap();
            envMap.put(DELEGATION_ATTRS_NAME, attrs);
        }
        if (!de.isAllowed(token, dp, envMap)) {
            Object[] args = { op.getName(), token.getPrincipal().getName() };
            throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.ACCESS_DENIED, args);
        }
        return true;
    } catch (DelegationException dex) {
        DEBUG.error("IdServicesImpl.checkPermission Got Delegation Exception: ", dex);
        Object[] args = { op.getName(), token.getPrincipal().getName() };
        throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.ACCESS_DENIED, args);
    }
}
Also used : DelegationEvaluatorImpl(com.sun.identity.delegation.DelegationEvaluatorImpl) Set(java.util.Set) OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) IdRepoException(com.sun.identity.idm.IdRepoException) DelegationEvaluator(com.sun.identity.delegation.DelegationEvaluator) DelegationException(com.sun.identity.delegation.DelegationException) Map(java.util.Map) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) DelegationPermission(com.sun.identity.delegation.DelegationPermission)

Example 12 with DelegationException

use of com.sun.identity.delegation.DelegationException in project OpenAM by OpenRock.

the class SMSEntry method isAllowedByDelegation.

private static boolean isAllowedByDelegation(SSOToken token, String dnName, Set actions) throws SMSException {
    boolean delPermFlag = true;
    // Parse the DN
    String[] parseTokens = parseOrgDN(dnName);
    String orgName = parseTokens[0];
    String subConfigName = parseTokens[1];
    String configType = parseTokens[2];
    String version = parseTokens[3];
    String serviceName = parseTokens[4];
    // and subConfigName, except for sunAMRealmService and for read only
    if (!serviceName.equals(REALM_SERVICE) && (configType.equalsIgnoreCase("*") || subConfigName.equalsIgnoreCase("*")) && (actions.size() == 1) && actions.contains(READ)) {
        return (delPermFlag);
    }
    try {
        // get orgName,serviceName,subConfigName from the parsed result.
        // Call DelegatedPermission's constructor
        DelegationPermission dlgPerm = new DelegationPermission(orgName, serviceName, version, configType, subConfigName, actions, Collections.EMPTY_MAP);
        // Perform delegation check
        delPermFlag = DelegationEvaluatorHolder.dlgEval.isAllowed(token, dlgPerm, Collections.EMPTY_MAP);
        if (!delPermFlag) {
            // Debug the message
            if (debug.warningEnabled()) {
                try {
                    debug.warning("SMSEntry: Attempt by:  " + token.getPrincipal().getName() + " to read/modify entry: " + dnName + " has no permissions");
                } catch (SSOException ssoe) {
                    debug.warning("SMSEntry: Attempted to:  " + "read/modify an entry that has invalid " + "delegation privilege: " + dnName, ssoe);
                }
            }
        }
    } catch (SSOException se) {
        debug.error("SMSEntry.isAllowed : " + "Invalid Token: ", se);
        throw (new SMSException(bundle.getString("sms-INVALID_SSO_TOKEN"), "sms-INVALID_SSO_TOKEN"));
    } catch (DelegationException de) {
        debug.error("SMSEntry.isAllowed : " + "Invalid DelegationPermission: ", de);
        throw (new SMSException(bundle.getString("sms-invalid_delegation_privilege"), "sms-invalid_delegation_privilege"));
    }
    return delPermFlag;
}
Also used : SSOException(com.iplanet.sso.SSOException) DelegationException(com.sun.identity.delegation.DelegationException) DelegationPermission(com.sun.identity.delegation.DelegationPermission)

Example 13 with DelegationException

use of com.sun.identity.delegation.DelegationException in project OpenAM by OpenRock.

the class XacmlServiceTest method testPermissionsCheckSuccess.

@Test
public void testPermissionsCheckSuccess() {
    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(true);
        boolean result = xacmlService.checkPermission(delegationPermission, adminToken, urlLastSegment);
        assertThat(result).isTrue();
        verify(restLog).auditAccessGranted(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());
    }
}
Also used : RestLog(org.forgerock.openam.forgerockrest.utils.RestLog) SSOToken(com.iplanet.sso.SSOToken) DelegationEvaluator(com.sun.identity.delegation.DelegationEvaluator) DelegationException(com.sun.identity.delegation.DelegationException) SSOException(com.iplanet.sso.SSOException) DelegationPermission(com.sun.identity.delegation.DelegationPermission) DelegationException(com.sun.identity.delegation.DelegationException) ResourceException(org.restlet.resource.ResourceException) SSOException(com.iplanet.sso.SSOException) EntitlementException(com.sun.identity.entitlement.EntitlementException) IOException(java.io.IOException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 14 with DelegationException

use of com.sun.identity.delegation.DelegationException in project OpenAM by OpenRock.

the class OrgConfigViaAMSDK method checkRealmPermission.

// Check to see if the user has realm permissions
private boolean checkRealmPermission(SSOToken token, String realm, Set action) {
    boolean answer = false;
    if (token != null) {
        try {
            DelegationEvaluator de = new DelegationEvaluatorImpl();
            DelegationPermission dp = new DelegationPermission(realm, com.sun.identity.sm.SMSEntry.REALM_SERVICE, "1.0", "*", "*", action, Collections.EMPTY_MAP);
            answer = de.isAllowed(token, dp, null);
        } catch (DelegationException dex) {
            debug.error("OrgConfigViaAMSDK.checkRealmPermission: " + "Got Delegation Exception: ", dex);
        } catch (SSOException ssoe) {
            if (debug.messageEnabled()) {
                debug.message("OrgConfigViaAMSDK.checkRealmPermission: " + "Invalid SSOToken: ", ssoe);
            }
        }
    }
    return (answer);
}
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 15 with DelegationException

use of com.sun.identity.delegation.DelegationException in project OpenAM by OpenRock.

the class DelegationPolicyImpl method getPrivileges.

/**
     * Returns all the delegation privileges associated with a realm.
     * 
     * @param  token  The <code>SSOToken</code> of the requesting user
     * @param  orgName The name of the realm from which the 
     *         delegation privileges are fetched.
     * 
     * @return <code>Set</code> of <code>DelegationPrivilege</code> objects 
     *         associated with the realm.
     * 
     * @throws SSOException  invalid or expired single-sign-on token
     * @throws DelegationException  for any abnormal condition
     */
public Set getPrivileges(SSOToken token, String orgName) throws SSOException, DelegationException {
    try {
        Set privileges = new HashSet();
        // Need to check if user has "delegate" permissions for org
        if (hasDelegationPermissionsForRealm(token, orgName)) {
            // Replace token with AdminToken
            token = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
        }
        PolicyManager pm = new PolicyManager(token, POLICY_REPOSITORY_REALM);
        Set pnames = pm.getPolicyNames();
        if (pnames != null) {
            /* the name of the policy is in the form of 
                 * orgName^^privilegeName, the privilegeName is the
                 * name of the delegation privilege that the policy 
                 * is corresponding to. In case the orgName is in a 
                 * DN format, the special char ',' is replaced to avoid
                 * saving problem.
                 */
            String prefix = null;
            if (orgName != null) {
                prefix = orgName.toLowerCase() + NAME_DELIMITER;
                prefix = prefix.replace(',', REPLACEMENT_FOR_COMMA);
            } else {
                prefix = NAME_DELIMITER;
            }
            int prefixLength = prefix.length();
            Iterator it = pnames.iterator();
            while (it.hasNext()) {
                String pname = (String) it.next();
                if (pname.toLowerCase().startsWith(prefix)) {
                    Policy p = pm.getPolicy(pname);
                    // converts the policy to its corresponding 
                    // delegation privilege
                    DelegationPrivilege dp = policyToPrivilege(p);
                    if (dp != null) {
                        dp.setName(pname.substring(prefixLength));
                        privileges.add(dp);
                    }
                }
            }
        }
        return (privileges);
    } catch (Exception e) {
        DelegationManager.debug.error("unable to get privileges from realm " + orgName);
        throw new DelegationException(e);
    }
}
Also used : Policy(com.sun.identity.policy.Policy) PolicyManager(com.sun.identity.policy.PolicyManager) DelegationPrivilege(com.sun.identity.delegation.DelegationPrivilege) Set(java.util.Set) HashSet(java.util.HashSet) Iterator(java.util.Iterator) DelegationException(com.sun.identity.delegation.DelegationException) DelegationException(com.sun.identity.delegation.DelegationException) PolicyException(com.sun.identity.policy.PolicyException) SSOException(com.iplanet.sso.SSOException) IdRepoException(com.sun.identity.idm.IdRepoException) HashSet(java.util.HashSet)

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