Search in sources :

Example 6 with ReferralPrivilege

use of com.sun.identity.entitlement.ReferralPrivilege in project OpenAM by OpenRock.

the class FactoryMethods method createArbitraryReferralPrivilege.

public static ReferralPrivilege createArbitraryReferralPrivilege(String name, long now) throws EntitlementException {
    Map<String, Set<String>> appNameToResources = new HashMap<String, Set<String>>();
    appNameToResources.put("arbitraryApplicationName", asSet("arbitraryResource1", "arbitraryResource2"));
    ReferralPrivilege referralPrivilege = new ReferralPrivilege(name, appNameToResources, asSet("arbitraryRealm"));
    referralPrivilege.setDescription("ReferralPrivilege " + name);
    referralPrivilege.setCreatedBy("creatingAuthor");
    referralPrivilege.setLastModifiedBy("modifyingAuthor");
    referralPrivilege.setCreationDate(now);
    referralPrivilege.setLastModifiedDate(now);
    referralPrivilege.setActive(true);
    return referralPrivilege;
}
Also used : PolicySet(com.sun.identity.entitlement.xacml3.core.PolicySet) Set(java.util.Set) CollectionUtils.asSet(org.forgerock.openam.utils.CollectionUtils.asSet) HashSet(java.util.HashSet) ReferralPrivilege(com.sun.identity.entitlement.ReferralPrivilege) HashMap(java.util.HashMap)

Example 7 with ReferralPrivilege

use of com.sun.identity.entitlement.ReferralPrivilege in project OpenAM by OpenRock.

the class XACMLPrivilegeUtilsTest method shouldReturnNullWhenGivenNullAsReferralPrivilege.

@Test
public void shouldReturnNullWhenGivenNullAsReferralPrivilege() throws JSONException {
    //Given
    ReferralPrivilege referralPrivilege = null;
    //When
    Policy policy = XACMLPrivilegeUtils.referralToPolicy(referralPrivilege);
    //Then
    assertNull(policy, "Expected Policy to be null.");
}
Also used : Policy(com.sun.identity.entitlement.xacml3.core.Policy) ReferralPrivilege(com.sun.identity.entitlement.ReferralPrivilege) Test(org.testng.annotations.Test)

Example 8 with ReferralPrivilege

use of com.sun.identity.entitlement.ReferralPrivilege in project OpenAM by OpenRock.

the class XACMLReaderWriterTest method canReadAndWritePrivilegesAsXACML.

@Test
public void canReadAndWritePrivilegesAsXACML() throws Exception {
    // Given
    Privilege privilege = createArbitraryPrivilege("Privilege", now);
    ReferralPrivilege referralPrivilege = createArbitraryReferralPrivilege("ReferralPrivilege", now);
    XACMLReaderWriter xacmlReaderWriter = new XACMLReaderWriter();
    PrivilegeSet inputPrivilegeSet = new PrivilegeSet(asList(referralPrivilege), asList(privilege));
    // When
    PolicySet policySet = xacmlReaderWriter.toXACML(ROOT_REALM, inputPrivilegeSet);
    PrivilegeSet outputPrivilegeSet = xacmlReaderWriter.fromXACML(policySet);
    // Then
    assertThat(outputPrivilegeSet.getPrivileges()).hasSize(1);
    assertPrivilegesEquivalent(outputPrivilegeSet.getPrivileges().get(0), privilege);
    assertThat(outputPrivilegeSet.getReferralPrivileges()).hasSize(1);
    assertReferralPrivilegesEquivalent(outputPrivilegeSet.getReferralPrivileges().get(0), referralPrivilege);
}
Also used : ReferralPrivilege(com.sun.identity.entitlement.ReferralPrivilege) ReferralPrivilege(com.sun.identity.entitlement.ReferralPrivilege) Privilege(com.sun.identity.entitlement.Privilege) PolicySet(com.sun.identity.entitlement.xacml3.core.PolicySet) Test(org.testng.annotations.Test)

Example 9 with ReferralPrivilege

use of com.sun.identity.entitlement.ReferralPrivilege in project OpenAM by OpenRock.

the class OpenSSOIndexStore method getReferredResources.

/**
     * Returns a set of resources that are referred to this realm.
     *
     * @param applicationTypeName Application type name,
     * @return a set of resources that are referred to this realm.
     * @throws EntitlementException if resources cannot be returned.
     */
@Override
public Set<String> getReferredResources(String applicationTypeName) throws EntitlementException {
    String realm = getRealm();
    if (realm.equals("/")) {
        return Collections.EMPTY_SET;
    }
    if (LDAPUtils.isDN(realm)) {
        realm = DNMapper.orgNameToRealmName(realm);
    }
    SSOToken adminToken = SubjectUtils.getSSOToken(superAdminSubject);
    try {
        Set<String> results = new HashSet<String>();
        Set<String> realms = getPeerRealms(realm);
        realms.addAll(getParentRealms(realm));
        String filter = "(&(ou=" + DataStore.REFERRAL_APPLS + "=" + applicationTypeName + ")(ou=" + DataStore.REFERRAL_REALMS + "=" + realm + "))";
        Map<String, Set<ReferralPrivilege>> referrals = new HashMap<String, Set<ReferralPrivilege>>();
        for (String rlm : realms) {
            referrals.put(rlm, dataStore.searchReferrals(adminToken, rlm, filter));
        }
        for (String rlm : referrals.keySet()) {
            Set<ReferralPrivilege> rPrivileges = referrals.get(rlm);
            String realmName = LDAPUtils.isDN(rlm) ? DNMapper.orgNameToRealmName(rlm) : rlm;
            for (ReferralPrivilege r : rPrivileges) {
                Map<String, Set<String>> map = r.getOriginalMapApplNameToResources();
                for (String a : map.keySet()) {
                    Application appl = ApplicationManager.getApplication(PolicyConstants.SUPER_ADMIN_SUBJECT, realmName, a);
                    if (appl.getApplicationType().getName().equals(applicationTypeName)) {
                        results.addAll(map.get(a));
                    }
                }
            }
        }
        results.addAll(getOrgAliasMappingResources(realm, applicationTypeName));
        return results;
    } catch (SMSException ex) {
        PolicyConstants.DEBUG.error("OpenSSOIndexStore.getReferredResources", ex);
        Object[] param = { realm };
        throw new EntitlementException(275, param);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) SMSException(com.sun.identity.sm.SMSException) EntitlementException(com.sun.identity.entitlement.EntitlementException) ReferralPrivilege(com.sun.identity.entitlement.ReferralPrivilege) Application(com.sun.identity.entitlement.Application) HashSet(java.util.HashSet)

Example 10 with ReferralPrivilege

use of com.sun.identity.entitlement.ReferralPrivilege in project OpenAM by OpenRock.

the class OpenSSOIndexStore method getOrgAliasReferral.

private ReferralPrivilege getOrgAliasReferral(ResourceSearchIndexes indexes) throws EntitlementException {
    ReferralPrivilege result = null;
    SSOToken adminToken = SubjectUtils.getSSOToken(superAdminSubject);
    //TOFIX check if it is webagent service
    if (OpenSSOIndexStore.isOrgAliasMappingResourceEnabled(adminToken)) {
        try {
            Set<String> realms = getReferredRealmNames(adminToken, indexes);
            if ((realms != null) && !realms.isEmpty()) {
                Map<String, Set<String>> map = new HashMap<String, Set<String>>();
                Set<String> res = new HashSet<String>();
                res.add("http*://" + getReferralURL(indexes.getHostIndexes()) + ":*");
                map.put(ApplicationTypeManager.URL_APPLICATION_TYPE_NAME, res);
                result = new ReferralPrivilege("referralprivilege111", map, realms);
            }
        } catch (SSOException e) {
            PolicyConstants.DEBUG.error("OpenSSOIndexStore.getOrgAliasReferral", e);
        } catch (SMSException e) {
            PolicyConstants.DEBUG.error("OpenSSOIndexStore.getOrgAliasReferral", e);
        }
    }
    return result;
}
Also used : ReferralPrivilege(com.sun.identity.entitlement.ReferralPrivilege) SSOToken(com.iplanet.sso.SSOToken) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) HashSet(java.util.HashSet)

Aggregations

ReferralPrivilege (com.sun.identity.entitlement.ReferralPrivilege)18 HashSet (java.util.HashSet)9 Set (java.util.Set)7 Test (org.testng.annotations.Test)6 EntitlementException (com.sun.identity.entitlement.EntitlementException)5 SMSException (com.sun.identity.sm.SMSException)5 SSOToken (com.iplanet.sso.SSOToken)4 Policy (com.sun.identity.entitlement.xacml3.core.Policy)4 PolicySet (com.sun.identity.entitlement.xacml3.core.PolicySet)4 IPrivilege (com.sun.identity.entitlement.IPrivilege)3 Privilege (com.sun.identity.entitlement.Privilege)3 BufferedIterator (com.sun.identity.shared.BufferedIterator)3 HashMap (java.util.HashMap)3 JSONException (org.json.JSONException)3 JSONObject (org.json.JSONObject)3 SSOException (com.iplanet.sso.SSOException)2 CaseInsensitiveHashMap (com.sun.identity.common.CaseInsensitiveHashMap)2 FactoryMethods.createArbitraryPrivilege (com.sun.identity.entitlement.xacml3.FactoryMethods.createArbitraryPrivilege)2 FactoryMethods.createArbitraryReferralPrivilege (com.sun.identity.entitlement.xacml3.FactoryMethods.createArbitraryReferralPrivilege)2 ImportStep (com.sun.identity.entitlement.xacml3.XACMLExportImport.ImportStep)2