Search in sources :

Example 11 with OpenSSOUserSubject

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

the class OpenProvisioning method createPolicy.

private void createPolicy(SSOToken adminToken) throws EntitlementException {
    PrivilegeManager pMgr = new PolicyPrivilegeManager(applicationServiceFactory, resourceTypeService, constraintValidator);
    pMgr.initialize("/", SubjectUtils.createSubject(adminToken));
    Map<String, Boolean> actionValues = new HashMap<String, Boolean>();
    actionValues.put("CREATE", Boolean.TRUE);
    actionValues.put("READ", Boolean.TRUE);
    actionValues.put("UPDATE", Boolean.TRUE);
    actionValues.put("DELETE", Boolean.TRUE);
    Entitlement entitlement = new Entitlement(APPLICATION, "/OP/*", actionValues);
    entitlement.setName("openProvisioningPrivilege");
    UserSubject sbj = new OpenSSOUserSubject();
    sbj.setID(jSmith.getUniversalId());
    AttributeLookupCondition cond = new AttributeLookupCondition("$USER.postaladdress", "$RES.postaladdress");
    Privilege privilege = Privilege.getNewInstance();
    privilege.setName(PRIVILEGE_NAME);
    privilege.setEntitlement(entitlement);
    privilege.setSubject(sbj);
    privilege.setCondition(cond);
    pMgr.add(privilege);
}
Also used : OpenSSOUserSubject(com.sun.identity.entitlement.opensso.OpenSSOUserSubject) UserSubject(com.sun.identity.entitlement.UserSubject) AttributeLookupCondition(com.sun.identity.entitlement.AttributeLookupCondition) HashMap(java.util.HashMap) PolicyPrivilegeManager(com.sun.identity.entitlement.opensso.PolicyPrivilegeManager) PrivilegeManager(com.sun.identity.entitlement.PrivilegeManager) OpenSSOUserSubject(com.sun.identity.entitlement.opensso.OpenSSOUserSubject) Entitlement(com.sun.identity.entitlement.Entitlement) Privilege(com.sun.identity.entitlement.Privilege) PolicyPrivilegeManager(com.sun.identity.entitlement.opensso.PolicyPrivilegeManager)

Example 12 with OpenSSOUserSubject

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

the class ListPolicyNamesTest method createPrivilege.

private void createPrivilege(String name) throws EntitlementException {
    Map<String, Boolean> actionValues = new HashMap<String, Boolean>();
    actionValues.put("GET", Boolean.TRUE);
    actionValues.put("POST", Boolean.FALSE);
    String resourceName = "http://www.listpolicynamestest.com:80";
    Entitlement entitlement = new Entitlement(APPL_NAME, resourceName, actionValues);
    entitlement.setName("ent1");
    String user = "id=demo,ou=user," + ServiceManager.getBaseDN();
    OpenSSOUserSubject usersubj = new OpenSSOUserSubject();
    usersubj.setID(user);
    Privilege priv = Privilege.getNewInstance();
    priv.setName(name);
    priv.setEntitlement(entitlement);
    priv.setSubject(usersubj);
    pm.addPrivilege(priv);
}
Also used : HashMap(java.util.HashMap) OpenSSOUserSubject(com.sun.identity.entitlement.opensso.OpenSSOUserSubject) Entitlement(com.sun.identity.entitlement.Entitlement) Privilege(com.sun.identity.entitlement.Privilege)

Example 13 with OpenSSOUserSubject

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

the class ApplicationPrivilegeBase method getSubjects.

protected Map<String, Set<String>> getSubjects(ApplicationPrivilege appPrivilege) {
    Map<String, Set<String>> results = new HashMap<String, Set<String>>();
    Set<SubjectImplementation> subjects = appPrivilege.getSubjects();
    for (SubjectImplementation subject : subjects) {
        String type = null;
        String uuid = null;
        if (subject instanceof OpenSSOUserSubject) {
            type = PARAM_SUBJECT_USER;
            uuid = ((OpenSSOUserSubject) subject).getID();
        } else if (subject instanceof OpenSSOGroupSubject) {
            type = PARAM_SUBJECT_GROUP;
            uuid = ((OpenSSOGroupSubject) subject).getID();
        }
        if (type != null) {
            Set<String> set = results.get(type);
            if (set == null) {
                set = new HashSet<String>();
                results.put(type, set);
            }
            set.add(uuid);
        }
    }
    return results;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) OpenSSOGroupSubject(com.sun.identity.entitlement.opensso.OpenSSOGroupSubject) OpenSSOUserSubject(com.sun.identity.entitlement.opensso.OpenSSOUserSubject) SubjectImplementation(com.sun.identity.entitlement.SubjectImplementation)

Example 14 with OpenSSOUserSubject

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

the class ApplicationPrivilegeCLITest method validateSubjects.

private void validateSubjects(ApplicationPrivilege ap, Set<AMIdentity> users, String methodName) throws Exception {
    Set<SubjectImplementation> subjects = ap.getSubjects();
    if ((subjects == null) || (subjects.size() != users.size())) {
        throw new Exception("ApplicationPrivilegeCLITest." + methodName + ": " + "subjects is empty.");
    }
    for (SubjectImplementation subject : subjects) {
        if (!(subject instanceof OpenSSOUserSubject)) {
            throw new Exception("ApplicationPrivilegeCLITest." + methodName + ": " + "subject is incorrect.");
        }
        String uuid = ((OpenSSOUserSubject) subject).getID();
        boolean found = false;
        for (AMIdentity user : users) {
            if (uuid.equals(user.getUniversalId())) {
                found = true;
                break;
            }
        }
        if (!found) {
            throw new Exception("ApplicationPrivilegeCLITest." + methodName + ": " + "uuid is incorrect.");
        }
    }
}
Also used : AMIdentity(com.sun.identity.idm.AMIdentity) OpenSSOUserSubject(com.sun.identity.entitlement.opensso.OpenSSOUserSubject) SubjectImplementation(com.sun.identity.entitlement.SubjectImplementation) IdRepoException(com.sun.identity.idm.IdRepoException) EntitlementException(com.sun.identity.entitlement.EntitlementException) SSOException(com.iplanet.sso.SSOException)

Example 15 with OpenSSOUserSubject

use of com.sun.identity.entitlement.opensso.OpenSSOUserSubject 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)

Aggregations

OpenSSOUserSubject (com.sun.identity.entitlement.opensso.OpenSSOUserSubject)22 HashMap (java.util.HashMap)19 HashSet (java.util.HashSet)17 Set (java.util.Set)11 Entitlement (com.sun.identity.entitlement.Entitlement)4 Privilege (com.sun.identity.entitlement.Privilege)4 IPv4Condition (org.forgerock.openam.entitlement.conditions.environment.IPv4Condition)4 SubjectImplementation (com.sun.identity.entitlement.SubjectImplementation)3 UserSubject (com.sun.identity.entitlement.UserSubject)3 Test (org.testng.annotations.Test)3 SSOException (com.iplanet.sso.SSOException)2 AndCondition (com.sun.identity.entitlement.AndCondition)2 EntitlementCondition (com.sun.identity.entitlement.EntitlementCondition)2 EntitlementSubject (com.sun.identity.entitlement.EntitlementSubject)2 OrSubject (com.sun.identity.entitlement.OrSubject)2 ResourceAttribute (com.sun.identity.entitlement.ResourceAttribute)2 StaticAttributes (com.sun.identity.entitlement.StaticAttributes)2 UserAttributes (com.sun.identity.entitlement.UserAttributes)2 OpenSSOGroupSubject (com.sun.identity.entitlement.opensso.OpenSSOGroupSubject)2 AMIdentity (com.sun.identity.idm.AMIdentity)2