Search in sources :

Example 1 with NumericAttributeCondition

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

the class EntitlementRegistryTest method shouldReturnCorrectConditionName.

@Test
public void shouldReturnCorrectConditionName() {
    // Given
    String name = "test";
    EntitlementCondition testCondition = new NumericAttributeCondition();
    testRegistry.registerConditionType(EntitlementCondition.class);
    testRegistry.registerConditionType(name, NumericAttributeCondition.class);
    // When
    String result = testRegistry.getConditionName(testCondition);
    // Then
    assertThat(result).isEqualTo(name);
}
Also used : EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) NumericAttributeCondition(com.sun.identity.entitlement.NumericAttributeCondition) Test(org.testng.annotations.Test)

Example 2 with NumericAttributeCondition

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

the class EntitlementRegistryTest method shouldNotReturnSuperTypeConditionNames.

@Test
public void shouldNotReturnSuperTypeConditionNames() {
    // Given
    EntitlementCondition testCondition = new NumericAttributeCondition();
    // Only super-type registered
    testRegistry.registerConditionType(EntitlementCondition.class);
    // When
    String result = testRegistry.getConditionName(testCondition);
    // Then
    assertThat(result).isNull();
}
Also used : EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) NumericAttributeCondition(com.sun.identity.entitlement.NumericAttributeCondition) Test(org.testng.annotations.Test)

Example 3 with NumericAttributeCondition

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

the class RestTest method setup.

@BeforeClass
public void setup() throws Exception {
    try {
        PrivilegeManager pm = PrivilegeManager.getInstance(REALM, adminSubject);
        Privilege privilege = Privilege.getNewInstance();
        privilege.setName(PRIVILEGE_NAME);
        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);
        NumericAttributeCondition cond = new NumericAttributeCondition();
        cond.setAttributeName(ATTR_NAME);
        cond.setOperator(NumericAttributeCondition.Operator.EQUAL);
        cond.setValue(ATTR_VAL);
        privilege.setCondition(cond);
        pm.add(privilege);
        user = IdRepoUtils.createAgent(REALM, AGENT_NAME);
        SSOToken ssoToken = AuthUtils.authenticate(REALM, AGENT_NAME, AGENT_NAME);
        String userTokenId = ssoToken.getTokenID().toString();
        hashedUserTokenId = Hash.hash(userTokenId);
        userTokenIdHeader = RestServiceManager.SSOTOKEN_SUBJECT_PREFIX + RestServiceManager.SUBJECT_DELIMITER + userTokenId;
        String cookieValue = userTokenId;
        if (Boolean.parseBoolean(SystemProperties.get(Constants.AM_COOKIE_ENCODE, "false"))) {
            cookieValue = URLEncoder.encode(userTokenId, "UTF-8");
        }
        cookie = new Cookie(SystemProperties.get(Constants.AM_COOKIE_NAME), cookieValue);
        String serverURL = SystemProperties.getServerInstanceName();
        decisionClient = Client.create().resource(serverURL + "/ws/1/entitlement/decision");
        decisionsClient = Client.create().resource(serverURL + "/ws/1/entitlement/decisions");
        entitlementClient = Client.create().resource(serverURL + "/ws/1/entitlement/entitlement");
        entitlementsClient = Client.create().resource(serverURL + "/ws/1/entitlement/entitlements");
    } catch (Exception e) {
        UnittestLog.logError("RestTest.setup() failed:", e);
        throw e;
    }
}
Also used : Cookie(javax.ws.rs.core.Cookie) SSOToken(com.iplanet.sso.SSOToken) NumericAttributeCondition(com.sun.identity.entitlement.NumericAttributeCondition) HashMap(java.util.HashMap) AuthenticatedUsers(org.forgerock.openam.entitlement.conditions.subject.AuthenticatedUsers) PrivilegeManager(com.sun.identity.entitlement.PrivilegeManager) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) Privilege(com.sun.identity.entitlement.Privilege) JSONEntitlement(com.sun.identity.entitlement.JSONEntitlement) Entitlement(com.sun.identity.entitlement.Entitlement) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

NumericAttributeCondition (com.sun.identity.entitlement.NumericAttributeCondition)3 EntitlementCondition (com.sun.identity.entitlement.EntitlementCondition)2 Test (org.testng.annotations.Test)2 SSOToken (com.iplanet.sso.SSOToken)1 Entitlement (com.sun.identity.entitlement.Entitlement)1 EntitlementSubject (com.sun.identity.entitlement.EntitlementSubject)1 JSONEntitlement (com.sun.identity.entitlement.JSONEntitlement)1 Privilege (com.sun.identity.entitlement.Privilege)1 PrivilegeManager (com.sun.identity.entitlement.PrivilegeManager)1 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)1 HashMap (java.util.HashMap)1 Cookie (javax.ws.rs.core.Cookie)1 AuthenticatedUsers (org.forgerock.openam.entitlement.conditions.subject.AuthenticatedUsers)1 BeforeClass (org.testng.annotations.BeforeClass)1