Search in sources :

Example 1 with EntitlementSubject

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

the class PrivilegeUtils method privilegeToPolicy.

public static Policy privilegeToPolicy(String realm, Privilege privilege) throws PolicyException, SSOException, EntitlementException {
    Policy policy = new Policy(privilege.getName());
    policy.setDescription(privilege.getDescription());
    if (privilege.getEntitlement() != null) {
        Entitlement entitlement = privilege.getEntitlement();
        Set<Rule> rules = entitlementToRule(realm, entitlement);
        for (Rule rule : rules) {
            policy.addRule(rule);
        }
    }
    EntitlementSubject es = privilege.getSubject();
    if ((es != null) && (es != Privilege.NOT_SUBJECT)) {
        Subject sbj = eSubjectToEPSubject(es);
        policy.addSubject(getSubjectName(es), sbj, false);
    }
    EntitlementCondition ec = privilege.getCondition();
    if (ec != null) {
        Condition cond = eConditionToEPCondition(ec);
        policy.addCondition(getConditionName(ec), cond);
    }
    if (privilege.getResourceAttributes() != null) {
        Map<String, ResponseProvider> nrps = resourceAttributesToResponseProviders(privilege.getResourceAttributes());
        for (String rpName : nrps.keySet()) {
            ResponseProvider responseProvider = nrps.get(rpName);
            policy.addResponseProvider(rpName, responseProvider);
        }
    }
    policy.setCreatedBy(privilege.getCreatedBy());
    policy.setCreationDate(privilege.getCreationDate());
    policy.setLastModifiedBy(privilege.getLastModifiedBy());
    policy.setLastModifiedDate(privilege.getLastModifiedDate());
    return policy;
}
Also used : Policy(com.sun.identity.policy.Policy) EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) OrCondition(com.sun.identity.entitlement.OrCondition) AndCondition(com.sun.identity.entitlement.AndCondition) PrivilegeCondition(com.sun.identity.policy.plugins.PrivilegeCondition) Condition(com.sun.identity.policy.interfaces.Condition) EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) IDRepoResponseProvider(com.sun.identity.policy.plugins.IDRepoResponseProvider) ResponseProvider(com.sun.identity.policy.interfaces.ResponseProvider) Rule(com.sun.identity.policy.Rule) Entitlement(com.sun.identity.entitlement.Entitlement) EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) PrivilegeSubject(com.sun.identity.policy.plugins.PrivilegeSubject) Subject(com.sun.identity.policy.interfaces.Subject) OrSubject(com.sun.identity.entitlement.OrSubject)

Example 2 with EntitlementSubject

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

the class PrivilegeUtils method mapGenericSubject.

private static EntitlementSubject mapGenericSubject(String subjectName, Subject objSubject, boolean exclusive) {
    try {
        if (objSubject instanceof com.sun.identity.policy.plugins.PrivilegeSubject) {
            com.sun.identity.policy.plugins.PrivilegeSubject pips = (com.sun.identity.policy.plugins.PrivilegeSubject) objSubject;
            Set<String> values = pips.getValues();
            String val = values.iterator().next();
            int idx = val.indexOf("=");
            String className = val.substring(0, idx);
            String state = val.substring(idx + 1);
            EntitlementSubject es = (EntitlementSubject) Class.forName(className).newInstance();
            es.setState(state);
            return es;
        } else {
            Subject sbj = (Subject) objSubject;
            Set<String> val = sbj.getValues();
            String className = sbj.getClass().getName();
            return new PolicySubject(subjectName, className, val, exclusive);
        }
    } catch (ClassNotFoundException e) {
        PolicyConstants.DEBUG.error("PrivilegeUtils.mapGenericSubject", e);
    } catch (InstantiationException e) {
        PolicyConstants.DEBUG.error("PrivilegeUtils.mapGenericSubject", e);
    } catch (IllegalAccessException e) {
        PolicyConstants.DEBUG.error("PrivilegeUtils.mapGenericSubject", e);
    }
    return null;
}
Also used : PrivilegeSubject(com.sun.identity.policy.plugins.PrivilegeSubject) EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) PrivilegeSubject(com.sun.identity.policy.plugins.PrivilegeSubject) Subject(com.sun.identity.policy.interfaces.Subject) OrSubject(com.sun.identity.entitlement.OrSubject) EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) PrivilegeSubject(com.sun.identity.policy.plugins.PrivilegeSubject)

Example 3 with EntitlementSubject

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

the class MultipleResourceRestTest method setup.

@BeforeClass
public void setup() throws Exception {
    PrivilegeManager pm = PrivilegeManager.getInstance(REALM, adminSubject);
    {
        Privilege privilege = Privilege.getNewInstance();
        privilege.setName(PRIVILEGE_NAME + "1");
        Map<String, Boolean> actions = new HashMap<String, Boolean>();
        actions.put("GET", true);
        Entitlement entitlement = new Entitlement(RESOURCE_NAME + "/*", actions);
        privilege.setEntitlement(entitlement);
        EntitlementSubject sbj = new AuthenticatedUsers();
        privilege.setSubject(sbj);
        pm.add(privilege);
    }
    {
        Privilege privilege = Privilege.getNewInstance();
        privilege.setName(PRIVILEGE_NAME + "2");
        Map<String, Boolean> actions = new HashMap<String, Boolean>();
        actions.put("GET", false);
        Entitlement entitlement = new Entitlement(RESOURCE_NAME + "/index.html", actions);
        privilege.setEntitlement(entitlement);
        EntitlementSubject sbj = new AuthenticatedUsers();
        privilege.setSubject(sbj);
        pm.add(privilege);
    }
    String tokenId = adminToken.getTokenID().toString();
    hashedTokenId = Hash.hash(tokenId);
    tokenIdHeader = RestServiceManager.SSOTOKEN_SUBJECT_PREFIX + RestServiceManager.SUBJECT_DELIMITER + tokenId;
    String cookieValue = tokenId;
    if (Boolean.parseBoolean(SystemProperties.get(Constants.AM_COOKIE_ENCODE, "false"))) {
        cookieValue = URLEncoder.encode(tokenId, "UTF-8");
    }
    cookie = new Cookie(SystemProperties.get(Constants.AM_COOKIE_NAME), cookieValue);
    user = IdRepoUtils.createUser(REALM, "MultipleResourceRestTestUser");
    decisionsClient = Client.create().resource(SystemProperties.getServerInstanceName() + "/ws/1/entitlement/decisions");
    entitlementsClient = Client.create().resource(SystemProperties.getServerInstanceName() + "/ws/1/entitlement/entitlements");
}
Also used : EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) Cookie(javax.ws.rs.core.Cookie) AuthenticatedUsers(org.forgerock.openam.entitlement.conditions.subject.AuthenticatedUsers) PrivilegeManager(com.sun.identity.entitlement.PrivilegeManager) Privilege(com.sun.identity.entitlement.Privilege) JSONEntitlement(com.sun.identity.entitlement.JSONEntitlement) Entitlement(com.sun.identity.entitlement.Entitlement) HashMap(java.util.HashMap) Map(java.util.Map) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) BeforeClass(org.testng.annotations.BeforeClass)

Example 4 with EntitlementSubject

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

the class PolicyConditionUpgrader method isSubjectConditionUpgradable.

private boolean isSubjectConditionUpgradable(EntitlementSubject subject) {
    if (subject == null) {
        return true;
    }
    if (subject instanceof NoSubject) {
        return true;
    }
    if (subject instanceof LogicalSubject) {
        LogicalSubject logicalSubject = (LogicalSubject) subject;
        boolean upgradable = true;
        for (EntitlementSubject sub : logicalSubject.getESubjects()) {
            upgradable &= isUpgradablePolicySubject(sub);
        }
        return upgradable;
    }
    return isUpgradablePolicySubject(subject);
}
Also used : EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) NoSubject(com.sun.identity.entitlement.NoSubject) LogicalSubject(com.sun.identity.entitlement.LogicalSubject)

Example 5 with EntitlementSubject

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

the class PolicyConditionUpgraderTest method isPolicyWithAndSubjectConditionUpgradable.

@Test(dataProvider = "isPolicyWithAndSubjectConditionUpgradableDataProvider")
public void isPolicyWithAndSubjectConditionUpgradable(Class<? extends EntitlementSubject> sub1, boolean sub1InMap, Class<? extends EntitlementSubject> sub2, boolean sub2InMap, boolean expectedResult) {
    //Given
    Privilege policy = mock(Privilege.class);
    AndSubject andSubject = mock(AndSubject.class);
    Set<EntitlementSubject> andSubjects = new HashSet<EntitlementSubject>();
    EntitlementSubject subject1 = mock(sub1);
    EntitlementSubject subject2 = mock(sub2);
    andSubjects.add(subject1);
    andSubjects.add(subject2);
    given(policy.getSubject()).willReturn(andSubject);
    given(andSubject.getESubjects()).willReturn(andSubjects);
    if (subject1 instanceof PolicySubject) {
        given(((PolicySubject) subject1).getClassName()).willReturn("SUBJECT1_CLASS_NAME");
    }
    if (subject2 instanceof PolicySubject) {
        given(((PolicySubject) subject2).getClassName()).willReturn("SUBJECT2_CLASS_NAME");
    }
    given(conditionUpgradeMap.containsSubjectCondition("SUBJECT1_CLASS_NAME")).willReturn(sub1InMap);
    given(conditionUpgradeMap.containsSubjectCondition("SUBJECT2_CLASS_NAME")).willReturn(sub2InMap);
    //When
    boolean upgradable = conditionUpgrader.isPolicyUpgradable(policy);
    //Then
    assertThat(upgradable).isEqualTo(expectedResult);
}
Also used : AndSubject(com.sun.identity.entitlement.AndSubject) EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) PolicySubject(com.sun.identity.entitlement.opensso.PolicySubject) Privilege(com.sun.identity.entitlement.Privilege) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

EntitlementSubject (com.sun.identity.entitlement.EntitlementSubject)30 Privilege (com.sun.identity.entitlement.Privilege)17 HashSet (java.util.HashSet)15 Entitlement (com.sun.identity.entitlement.Entitlement)13 Test (org.testng.annotations.Test)13 EntitlementCondition (com.sun.identity.entitlement.EntitlementCondition)11 OrSubject (com.sun.identity.entitlement.OrSubject)9 PolicySubject (com.sun.identity.entitlement.opensso.PolicySubject)9 HashMap (java.util.HashMap)6 PrivilegeManager (com.sun.identity.entitlement.PrivilegeManager)5 ResourceAttribute (com.sun.identity.entitlement.ResourceAttribute)5 Set (java.util.Set)5 AuthenticatedUsers (org.forgerock.openam.entitlement.conditions.subject.AuthenticatedUsers)4 AndCondition (com.sun.identity.entitlement.AndCondition)3 IPrivilege (com.sun.identity.entitlement.IPrivilege)3 OrCondition (com.sun.identity.entitlement.OrCondition)3 ReferralPrivilege (com.sun.identity.entitlement.ReferralPrivilege)3 Subject (com.sun.identity.policy.interfaces.Subject)3 PrivilegeSubject (com.sun.identity.policy.plugins.PrivilegeSubject)3 Cookie (javax.ws.rs.core.Cookie)3