Search in sources :

Example 16 with OpenSSOUserSubject

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

the class DelegationPrivilegeIdRepoAccessTest method addPrivilege.

private void addPrivilege() throws EntitlementException {
    ApplicationPrivilegeManager mgr = ApplicationPrivilegeManager.getInstance(SUB_REALM, PrivilegeManager.superAdminSubject);
    ApplicationPrivilege ap = new ApplicationPrivilege(DELEGATE_PRIVILEGE_NAME);
    OpenSSOUserSubject sbj = new OpenSSOUserSubject();
    sbj.setID(delegatedUser.getUniversalId());
    Set<SubjectImplementation> subjects = new HashSet<SubjectImplementation>();
    subjects.add(sbj);
    ap.setSubject(subjects);
    Map<String, Set<String>> appRes = new HashMap<String, Set<String>>();
    Set<String> res = new HashSet<String>();
    appRes.put(ApplicationTypeManager.URL_APPLICATION_TYPE_NAME, res);
    res.add(DELEGATED_RESOURCE);
    ap.setApplicationResources(appRes);
    ap.setActionValues(ApplicationPrivilege.PossibleAction.READ_MODIFY_DELEGATE);
    mgr.addPrivilege(ap);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) OpenSSOUserSubject(com.sun.identity.entitlement.opensso.OpenSSOUserSubject) HashSet(java.util.HashSet)

Example 17 with OpenSSOUserSubject

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

the class DelegationIsAllowedSubResourceTest method createPrivilege.

private void createPrivilege() throws EntitlementException {
    PrivilegeManager pm = PrivilegeManager.getInstance("/", adminSubject);
    Map<String, Boolean> actionValues = new HashMap<String, Boolean>();
    actionValues.put("GET", Boolean.TRUE);
    Entitlement entitlement = new Entitlement(APPL_NAME, DELEGATED_RESOURCE_BASE, actionValues);
    OpenSSOUserSubject subject = new OpenSSOUserSubject("id=isallowedtestdummy,ou=user," + SMSEntry.getRootSuffix());
    Privilege privilege1 = Privilege.getNewInstance();
    privilege1.setName(PRIVILEGE_NAME1);
    privilege1.setEntitlement(entitlement);
    privilege1.setSubject(subject);
    pm.add(privilege1);
}
Also used : HashMap(java.util.HashMap) OpenSSOUserSubject(com.sun.identity.entitlement.opensso.OpenSSOUserSubject)

Example 18 with OpenSSOUserSubject

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

the class CanBeDeletedAppTest method createApplicationPrivilege.

private void createApplicationPrivilege() throws Exception {
    ApplicationPrivilegeManager mgr = ApplicationPrivilegeManager.getInstance("/", adminSubject);
    ApplicationPrivilege ap = new ApplicationPrivilege(DELEGATE_PRIVILEGE_NAME);
    OpenSSOUserSubject sbj = new OpenSSOUserSubject();
    sbj.setID("uid=demo,ou=user,dc=openam,dc=forgerock,dc=org");
    Set<SubjectImplementation> subjects = new HashSet<SubjectImplementation>();
    subjects.add(sbj);
    ap.setSubject(subjects);
    Map<String, Set<String>> appRes = new HashMap<String, Set<String>>();
    Set<String> res = new HashSet<String>();
    appRes.put(APPL_NAME, res);
    res.add("http://www.CanBeDeletedAppTest.com");
    ap.setApplicationResources(appRes);
    ap.setActionValues(ApplicationPrivilege.PossibleAction.READ_MODIFY_DELEGATE);
    mgr.addPrivilege(ap);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) OpenSSOUserSubject(com.sun.identity.entitlement.opensso.OpenSSOUserSubject) HashSet(java.util.HashSet)

Example 19 with OpenSSOUserSubject

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

the class PrivilegeUtilsTest method testPrivilegeToXACMLPolicy.

@Test
public void testPrivilegeToXACMLPolicy() throws Exception {
    try {
        UnittestLog.logMessage("PrivilegeUtils.testPrivilegeToXACMLPolicy():" + " entered");
        Map<String, Boolean> actionValues = new HashMap<String, Boolean>();
        actionValues.put("GET", Boolean.TRUE);
        actionValues.put("POST", Boolean.FALSE);
        // The port is required for passing equals  test
        // opensso policy would add default port if port not specified
        String resourceName = "http://www.sun.com:80";
        Entitlement entitlement = new Entitlement(SERVICE_NAME, resourceName, actionValues);
        entitlement.setName("ent1");
        String user11 = "id=user11,ou=user," + ServiceManager.getBaseDN();
        String user12 = "id=user12,ou=user," + ServiceManager.getBaseDN();
        UserSubject ua1 = new OpenSSOUserSubject();
        ua1.setID(user11);
        UserSubject ua2 = new OpenSSOUserSubject();
        ua2.setID(user12);
        Set<EntitlementSubject> subjects = new HashSet<EntitlementSubject>();
        subjects.add(ua1);
        subjects.add(ua2);
        OrSubject os = new OrSubject(subjects);
        Set<EntitlementCondition> conditions = new HashSet<EntitlementCondition>();
        String startIp = "100.100.100.100";
        String endIp = "200.200.200.200";
        IPv4Condition ipc = new IPv4Condition();
        ipc.setStartIpAndEndIp(startIp, endIp);
        conditions.add(ipc);
        OrCondition oc = new OrCondition(conditions);
        AndCondition ac = new AndCondition(conditions);
        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(PRIVILEGE_NAME);
        privilege.setEntitlement(entitlement);
        privilege.setSubject(ua1);
        privilege.setCondition(ipc);
        privilege.setResourceAttributes(ra);
        privilege.setCreatedBy("amadmin");
        privilege.setLastModifiedBy("amadmin");
        privilege.setCreationDate(System.currentTimeMillis());
        privilege.setLastModifiedDate(System.currentTimeMillis());
        UnittestLog.logMessage("PrivilegeUtils.testPrivilegeToXACMLPolicy():" + "Privilege=" + privilege.toString());
        UnittestLog.logMessage("PrivilegeUtils.testPrivilegeToXACMLPolicy():" + "converting to xacml policy");
        // TODO(jtb): not compiling
        String xacmlString = XACMLPrivilegeUtils.toXACML(privilege);
        UnittestLog.logMessage("xacml policy=" + xacmlString);
    } catch (Throwable t) {
        UnittestLog.logError("Throwable:", t);
        UnittestLog.logMessage("Throwable:" + t.getMessage());
        t.printStackTrace();
    }
}
Also used : EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) HashMap(java.util.HashMap) 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) AndCondition(com.sun.identity.entitlement.AndCondition) UserAttributes(com.sun.identity.entitlement.UserAttributes) EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) OpenSSOUserSubject(com.sun.identity.entitlement.opensso.OpenSSOUserSubject) UserSubject(com.sun.identity.entitlement.UserSubject) OrCondition(com.sun.identity.entitlement.OrCondition) Entitlement(com.sun.identity.entitlement.Entitlement) ResourceAttribute(com.sun.identity.entitlement.ResourceAttribute) Privilege(com.sun.identity.entitlement.Privilege) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 20 with OpenSSOUserSubject

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

the class XACMLExportTest method setup.

@BeforeClass
public void setup() throws SSOException, IdRepoException, EntitlementException, SMSException, InstantiationException, IllegalAccessException {
    if (!migrated) {
        throw new RuntimeException("Server not in entitlement mode");
    }
    pm = PrivilegeManager.getInstance("/", SubjectUtils.createSubject(adminToken));
    Map<String, Boolean> actionValues = new HashMap<String, Boolean>();
    actionValues.put("GET", Boolean.TRUE);
    actionValues.put("POST", Boolean.FALSE);
    Entitlement entitlement = new Entitlement(APPLICATION_NAME, RESOURCE, actionValues);
    entitlement.setName("ent1");
    String user11 = "id=user11,ou=user," + ServiceManager.getBaseDN();
    UserSubject ua1 = new OpenSSOUserSubject();
    ua1.setID(user11);
    UserSubject ua2 = new OpenSSOUserSubject();
    String user12 = "id=user12,ou=user," + ServiceManager.getBaseDN();
    ua2.setID(user12);
    Set<EntitlementSubject> subjects = new HashSet<EntitlementSubject>();
    subjects.add(ua1);
    subjects.add(ua2);
    OrSubject os = new OrSubject(subjects);
    Set<EntitlementCondition> conditions = new HashSet<EntitlementCondition>();
    String startIp = "100.100.100.100";
    String endIp = "200.200.200.200";
    IPv4Condition ipc = new IPv4Condition();
    ipc.setStartIpAndEndIp(startIp, endIp);
    conditions.add(ipc);
    OrCondition oc = new OrCondition(conditions);
    /*
        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);
        */
    privilege1 = Privilege.getNewInstance();
    privilege1.setName(PRIVILEGE_NAME);
    privilege1.setEntitlement(entitlement);
    privilege1.setSubject(ua1);
    privilege1.setCondition(ipc);
    //privilege.setResourceAttributes(ra);
    pm.add(privilege1);
//UnittestLog.logMessage("XACMLExportTest.setup(), added privilege:" +
//"Privilege1=" + privilege1.toString());
}
Also used : HashMap(java.util.HashMap) IPv4Condition(org.forgerock.openam.entitlement.conditions.environment.IPv4Condition) OpenSSOUserSubject(com.sun.identity.entitlement.opensso.OpenSSOUserSubject) OpenSSOUserSubject(com.sun.identity.entitlement.opensso.OpenSSOUserSubject) HashSet(java.util.HashSet) BeforeClass(org.testng.annotations.BeforeClass)

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