Search in sources :

Example 21 with EntitlementCondition

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

the class FactoryMethods method createArbitraryPrivilege.

public static Privilege createArbitraryPrivilege(String name, long now) throws EntitlementException {
    Privilege privilege = Privilege.getNewInstance();
    privilege.setName(name);
    privilege.setDescription("Privilege " + name);
    privilege.setCreatedBy("creatingAuthor");
    privilege.setLastModifiedBy("modifyingAuthor");
    privilege.setCreationDate(now);
    privilege.setLastModifiedDate(now);
    privilege.setActive(true);
    privilege.setApplicationIndexes(asSet("arbitraryApplicationIndex"));
    EntitlementCondition entitlementCondition = new SessionCondition();
    entitlementCondition.setState("{ 'maxSessionTime': 10, 'terminateSession': true }");
    privilege.setCondition(entitlementCondition);
    // TODO: Define entitlement Subject
    Set<ResourceAttribute> resourceAttributes = new HashSet<ResourceAttribute>();
    // TODO: Define some ResourceAttributes
    privilege.setResourceAttributes(resourceAttributes);
    Entitlement entitlement = new Entitlement();
    entitlement.setName("arbitraryEntitlementName");
    entitlement.setResourceName("http://www.artibrary.com/resource");
    Map<String, Boolean> actionValues = new HashMap<String, Boolean>();
    actionValues.put("arbitraryAction", true);
    entitlement.setActionValues(actionValues);
    privilege.setEntitlement(entitlement);
    return privilege;
}
Also used : EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) HashMap(java.util.HashMap) ReferralPrivilege(com.sun.identity.entitlement.ReferralPrivilege) Privilege(com.sun.identity.entitlement.Privilege) SessionCondition(org.forgerock.openam.entitlement.conditions.environment.SessionCondition) ResourceAttribute(com.sun.identity.entitlement.ResourceAttribute) Entitlement(com.sun.identity.entitlement.Entitlement) HashSet(java.util.HashSet)

Example 22 with EntitlementCondition

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

the class JsonPolicyParserTest method shouldPrintComplexConditions.

@Test
public void shouldPrintComplexConditions() throws Exception {
    // Given
    Privilege policy = new StubPrivilege();
    AndCondition and = new AndCondition();
    Set<EntitlementCondition> subConditions = new LinkedHashSet<EntitlementCondition>();
    Map<String, Set<String>> props = new HashMap<String, Set<String>>();
    props.put("AuthenticateToRealm", Collections.singleton("REALM"));
    PolicyCondition policyCondition = new PolicyCondition("test", AuthenticateToRealmCondition.class.getName(), props);
    NotCondition not = new NotCondition(policyCondition);
    subConditions.add(not);
    and.setEConditions(subConditions);
    policy.setCondition(and);
    // When
    JsonValue result = parser.printPolicy(policy);
    // Then
    assertThat(result.get(new JsonPointer("condition/type")).asString()).isEqualTo("AND");
    assertThat(result.get(new JsonPointer("condition/conditions/0/type")).asString()).isEqualTo("NOT");
    assertThat(result.get(new JsonPointer("condition/conditions/0/condition/type")).asString()).isEqualTo("Policy");
    assertThat(result.get(new JsonPointer("condition/conditions/0/condition/className")).asString()).isEqualTo(AuthenticateToRealmCondition.class.getName());
    assertThat(result.get(new JsonPointer("condition/conditions/0/condition/properties")).asMapOfList(String.class)).includes(entry("AuthenticateToRealm", Arrays.asList("REALM")));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) NotCondition(com.sun.identity.entitlement.NotCondition) HashMap(java.util.HashMap) JsonValue(org.forgerock.json.JsonValue) PolicyCondition(com.sun.identity.entitlement.opensso.PolicyCondition) JsonPointer(org.forgerock.json.JsonPointer) AndCondition(com.sun.identity.entitlement.AndCondition) AuthenticateToRealmCondition(com.sun.identity.policy.plugins.AuthenticateToRealmCondition) OpenSSOPrivilege(com.sun.identity.entitlement.opensso.OpenSSOPrivilege) Privilege(com.sun.identity.entitlement.Privilege) Test(org.testng.annotations.Test)

Example 23 with EntitlementCondition

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

the class PrivilegeUtilsTest method testPrivilegeToPolicy.

@Test
public void testPrivilegeToPolicy() throws Exception {
    String BASE_DN = Constants.DEFAULT_ROOT_SUFFIX;
    Map<String, Boolean> actionValues = new HashMap<String, Boolean>();
    actionValues.put("GET", Boolean.TRUE);
    actionValues.put("POST", Boolean.TRUE);
    String resourceName = "http://www.sun.com";
    Entitlement entitlement = new Entitlement("iPlanetAMWebAgentService", resourceName, actionValues);
    entitlement.setName("ent1");
    String user11 = "id=user11,ou=user," + BASE_DN;
    String user12 = "id=user12,ou=user," + BASE_DN;
    UserSubject us1 = new OpenSSOUserSubject();
    us1.setID(user11);
    UserSubject us2 = new OpenSSOUserSubject();
    us2.setID(user12);
    Set<EntitlementSubject> subjects = new HashSet<EntitlementSubject>();
    subjects.add(us1);
    subjects.add(us2);
    OrSubject os = new OrSubject(subjects);
    IPv4Condition ipc = new IPv4Condition();
    ipc.setStartIpAndEndIp("100.100.100.100", "200.200.200.200");
    Set<EntitlementCondition> setConditions = new HashSet<EntitlementCondition>();
    setConditions.add(ipc);
    AndCondition andCondition = new AndCondition();
    andCondition.setEConditions(setConditions);
    StaticAttributes sa1 = new StaticAttributes();
    Set<String> aValues = new HashSet<String>();
    aValues.add("a10");
    aValues.add("a20");
    sa1.setPropertyName("a");
    sa1.setPropertyValues(aValues);
    sa1.setPResponseProviderName("sa");
    StaticAttributes sa2 = new StaticAttributes();
    Set<String> bValues = new HashSet<String>();
    bValues.add("b10");
    bValues.add("b20");
    sa2.setPropertyName("b");
    sa2.setPropertyValues(bValues);
    sa2.setPResponseProviderName("sa");
    UserAttributes uat1 = new UserAttributes();
    uat1.setPropertyName("email");
    uat1.setPResponseProviderName("ua");
    UserAttributes uat2 = new UserAttributes();
    uat2.setPropertyName("uid");
    uat2.setPResponseProviderName("ua");
    Set<ResourceAttribute> ra = new HashSet<ResourceAttribute>();
    ra.add(sa1);
    ra.add(sa2);
    ra.add(uat1);
    ra.add(uat2);
    Privilege privilege = Privilege.getNewInstance();
    privilege.setName("PrivilegeUtilsTest");
    privilege.setEntitlement(entitlement);
    //orSubject
    privilege.setSubject(os);
    privilege.setCondition(andCondition);
    privilege.setResourceAttributes(ra);
    Policy policy = PrivilegeUtils.privilegeToPolicy("/", privilege);
    Set<IPrivilege> ps = PrivilegeUtils.policyToPrivileges(policy);
    if ((ps == null) || ps.isEmpty()) {
        throw new Exception("PrivilegeUtilsTest.testPrivilegeToPolicy failed.");
    }
}
Also used : EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) HashMap(java.util.HashMap) AndCondition(com.sun.identity.entitlement.AndCondition) UserAttributes(com.sun.identity.entitlement.UserAttributes) OpenSSOUserSubject(com.sun.identity.entitlement.opensso.OpenSSOUserSubject) UserSubject(com.sun.identity.entitlement.UserSubject) ResourceAttribute(com.sun.identity.entitlement.ResourceAttribute) HashSet(java.util.HashSet) IPv4Condition(org.forgerock.openam.entitlement.conditions.environment.IPv4Condition) OpenSSOUserSubject(com.sun.identity.entitlement.opensso.OpenSSOUserSubject) StaticAttributes(com.sun.identity.entitlement.StaticAttributes) OrSubject(com.sun.identity.entitlement.OrSubject) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) IPrivilege(com.sun.identity.entitlement.IPrivilege) Entitlement(com.sun.identity.entitlement.Entitlement) IPrivilege(com.sun.identity.entitlement.IPrivilege) Privilege(com.sun.identity.entitlement.Privilege) Test(org.testng.annotations.Test)

Example 24 with EntitlementCondition

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

the class PolicyConditionUpgrader method isEnvironmentConditionUpgradable.

private boolean isEnvironmentConditionUpgradable(EntitlementCondition condition) {
    if (condition == null) {
        return true;
    }
    if (condition instanceof LogicalCondition) {
        LogicalCondition logicalCondition = (LogicalCondition) condition;
        boolean upgradable = true;
        for (EntitlementCondition c : logicalCondition.getEConditions()) {
            upgradable &= isUpgradablePolicyCondition(c);
        }
        return upgradable;
    }
    return isUpgradablePolicyCondition(condition);
}
Also used : EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) LogicalCondition(com.sun.identity.entitlement.LogicalCondition)

Example 25 with EntitlementCondition

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

the class PolicyConditionUpgrader method migrateEnvironmentCondition.

private EntitlementCondition migrateEnvironmentCondition(PolicyCondition condition, MigrationReport migrationReport) throws EntitlementException {
    final EntitlementCondition migrated = conditionUpgradeMap.migrateEnvironmentCondition(condition.getClassName(), condition, migrationReport);
    migrated.validate();
    return migrated;
}
Also used : EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition)

Aggregations

EntitlementCondition (com.sun.identity.entitlement.EntitlementCondition)28 HashSet (java.util.HashSet)17 Test (org.testng.annotations.Test)14 Privilege (com.sun.identity.entitlement.Privilege)13 PolicyCondition (com.sun.identity.entitlement.opensso.PolicyCondition)10 Set (java.util.Set)10 AndCondition (com.sun.identity.entitlement.AndCondition)9 EntitlementSubject (com.sun.identity.entitlement.EntitlementSubject)9 OrCondition (com.sun.identity.entitlement.OrCondition)8 Entitlement (com.sun.identity.entitlement.Entitlement)7 HashMap (java.util.HashMap)6 ResourceAttribute (com.sun.identity.entitlement.ResourceAttribute)5 OrSubject (com.sun.identity.entitlement.OrSubject)4 NotCondition (com.sun.identity.entitlement.NotCondition)3 ReferralPrivilege (com.sun.identity.entitlement.ReferralPrivilege)3 Condition (com.sun.identity.policy.interfaces.Condition)3 PrivilegeCondition (com.sun.identity.policy.plugins.PrivilegeCondition)3 IPrivilege (com.sun.identity.entitlement.IPrivilege)2 LogicalCondition (com.sun.identity.entitlement.LogicalCondition)2 NumericAttributeCondition (com.sun.identity.entitlement.NumericAttributeCondition)2