Search in sources :

Example 11 with ResourceAttribute

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

the class EntitlementRegistryTest method shouldNotReturnSuperTypeAttributeNames.

@Test
public void shouldNotReturnSuperTypeAttributeNames() {
    // Given
    ResourceAttribute testAttribute = new StaticAttributes();
    // Only super-type registered
    testRegistry.registerAttributeType(ResourceAttribute.class);
    // When
    String result = testRegistry.getAttributeName(testAttribute);
    // Then
    assertThat(result).isNull();
}
Also used : StaticAttributes(com.sun.identity.entitlement.StaticAttributes) ResourceAttribute(com.sun.identity.entitlement.ResourceAttribute) Test(org.testng.annotations.Test)

Example 12 with ResourceAttribute

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

the class EntitlementRegistryTest method shouldReturnCorrectAttributeName.

@Test
public void shouldReturnCorrectAttributeName() {
    // Given
    String name = "test";
    ResourceAttribute testAttribute = new StaticAttributes();
    testRegistry.registerAttributeType(ResourceAttribute.class);
    testRegistry.registerAttributeType(name, StaticAttributes.class);
    // When
    String result = testRegistry.getAttributeName(testAttribute);
    // Then
    assertThat(result).isEqualTo(name);
}
Also used : StaticAttributes(com.sun.identity.entitlement.StaticAttributes) ResourceAttribute(com.sun.identity.entitlement.ResourceAttribute) Test(org.testng.annotations.Test)

Example 13 with ResourceAttribute

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

the class JsonPolicyParserTest method shouldParseResourceAttributes.

@Test
public void shouldParseResourceAttributes() throws Exception {
    // Given
    List<String> values = Arrays.asList("one", "two", "three");
    JsonValue content = buildJson(field("resourceAttributes", Arrays.asList(object(field("type", "Static"), field("propertyName", "test"), field("propertyValues", values)))));
    // Given
    Privilege result = parser.parsePolicy(POLICY_NAME, content);
    // Then
    assertThat(result.getResourceAttributes()).hasSize(1);
    ResourceAttribute attr = result.getResourceAttributes().iterator().next();
    assertThat(attr).isInstanceOf(StaticAttributes.class);
    assertThat(attr.getPropertyName()).isEqualTo("test");
    assertThat(attr.getPropertyValues()).containsOnly(values.toArray());
}
Also used : JsonValue(org.forgerock.json.JsonValue) OpenSSOPrivilege(com.sun.identity.entitlement.opensso.OpenSSOPrivilege) Privilege(com.sun.identity.entitlement.Privilege) ResourceAttribute(com.sun.identity.entitlement.ResourceAttribute) Test(org.testng.annotations.Test)

Example 14 with ResourceAttribute

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

the class JsonPolicyParserTest method shouldPrintResourceAttributes.

@Test
public void shouldPrintResourceAttributes() throws Exception {
    // Given
    Privilege policy = new StubPrivilege();
    ResourceAttribute userAttrs = new UserAttributes();
    String userAttrName = "testUserAttribute";
    userAttrs.setPropertyName(userAttrName);
    StaticAttributes staticAttributes = new StaticAttributes();
    String staticAttrName = "testStaticAttribute";
    staticAttributes.setPropertyName(staticAttrName);
    Set<String> staticAttrValue = CollectionUtils.asSet("one", "two", "three");
    staticAttributes.setPropertyValues(staticAttrValue);
    policy.setResourceAttributes(new LinkedHashSet<ResourceAttribute>(Arrays.asList(userAttrs, staticAttributes)));
    // When
    JsonValue result = parser.printPolicy(policy);
    // Then
    assertThat(result.get("resourceAttributes").asList()).hasSize(2);
    assertThat(result.get(new JsonPointer("resourceAttributes/0/type")).asString()).isEqualTo("User");
    assertThat(result.get(new JsonPointer("resourceAttributes/0/propertyName")).asString()).isEqualTo(userAttrName);
    assertThat(result.get(new JsonPointer("resourceAttributes/1/type")).asString()).isEqualTo("Static");
    assertThat(result.get(new JsonPointer("resourceAttributes/1/propertyName")).asString()).isEqualTo(staticAttrName);
    assertThat(result.get(new JsonPointer("resourceAttributes/1/propertyValues")).asList(String.class)).containsOnly(staticAttrValue.toArray());
}
Also used : JsonValue(org.forgerock.json.JsonValue) StaticAttributes(com.sun.identity.entitlement.StaticAttributes) JsonPointer(org.forgerock.json.JsonPointer) OpenSSOPrivilege(com.sun.identity.entitlement.opensso.OpenSSOPrivilege) Privilege(com.sun.identity.entitlement.Privilege) ResourceAttribute(com.sun.identity.entitlement.ResourceAttribute) UserAttributes(com.sun.identity.entitlement.UserAttributes) Test(org.testng.annotations.Test)

Example 15 with ResourceAttribute

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

Aggregations

ResourceAttribute (com.sun.identity.entitlement.ResourceAttribute)20 Test (org.testng.annotations.Test)11 HashSet (java.util.HashSet)8 StaticAttributes (com.sun.identity.entitlement.StaticAttributes)7 Entitlement (com.sun.identity.entitlement.Entitlement)6 EntitlementCondition (com.sun.identity.entitlement.EntitlementCondition)6 Privilege (com.sun.identity.entitlement.Privilege)6 EntitlementSubject (com.sun.identity.entitlement.EntitlementSubject)5 UserAttributes (com.sun.identity.entitlement.UserAttributes)5 HashMap (java.util.HashMap)5 ReferralPrivilege (com.sun.identity.entitlement.ReferralPrivilege)3 AdviceExpression (com.sun.identity.entitlement.xacml3.core.AdviceExpression)3 AdviceExpressions (com.sun.identity.entitlement.xacml3.core.AdviceExpressions)3 Set (java.util.Set)3 AndCondition (com.sun.identity.entitlement.AndCondition)2 OrSubject (com.sun.identity.entitlement.OrSubject)2 UserSubject (com.sun.identity.entitlement.UserSubject)2 OpenSSOPrivilege (com.sun.identity.entitlement.opensso.OpenSSOPrivilege)2 OpenSSOUserSubject (com.sun.identity.entitlement.opensso.OpenSSOUserSubject)2 ResponseProvider (com.sun.identity.policy.interfaces.ResponseProvider)2