Search in sources :

Example 6 with ConditionDecision

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

the class AuthLevelConditionTest method conditionShouldEvaluateToTrueWhenUsingRequestAuthLevelsFromEnvironmentWithoutRealmAndIsGE.

@Test
public void conditionShouldEvaluateToTrueWhenUsingRequestAuthLevelsFromEnvironmentWithoutRealmAndIsGE() throws EntitlementException {
    //Given
    String realm = "REALM";
    Subject subject = new Subject();
    String resourceName = "RESOURCE_NAME";
    Map<String, Set<String>> env = new HashMap<String, Set<String>>();
    Set<String> requestAuthLevels = new HashSet<String>();
    given(coreWrapper.getDataFromRealmQualifiedData("3")).willReturn("3");
    given(coreWrapper.getDataFromRealmQualifiedData("4")).willReturn("4");
    given(coreWrapper.getDataFromRealmQualifiedData("6")).willReturn("6");
    requestAuthLevels.add("3");
    requestAuthLevels.add("4");
    requestAuthLevels.add("6");
    env.put("requestAuthLevel", requestAuthLevels);
    condition.setState("{\"authLevel\": 5}");
    //When
    ConditionDecision decision = condition.evaluate(realm, subject, resourceName, env);
    //Then
    assertThat(decision.isSatisfied()).isTrue();
    assertThat(decision.getAdvice()).isEmpty();
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ConditionDecision(com.sun.identity.entitlement.ConditionDecision) Subject(javax.security.auth.Subject) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 7 with ConditionDecision

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

the class AuthenticateToRealmConditionTest method conditionShouldEvaluateToFalseWhenEnvironmentContainsRealmsAndDoesNotMatch.

@Test
public void conditionShouldEvaluateToFalseWhenEnvironmentContainsRealmsAndDoesNotMatch() throws EntitlementException {
    //Given
    String realm = "REALM";
    Subject subject = new Subject();
    String resourceName = "RESOURCE_NAME";
    Map<String, Set<String>> env = new HashMap<String, Set<String>>();
    Set<String> realms = new HashSet<String>();
    realms.add("OTHER_REALM");
    env.put(REQUEST_AUTHENTICATED_TO_REALMS, realms);
    condition.setState("{\"authenticateToRealm\": \"REALM\"}");
    //When
    ConditionDecision decision = condition.evaluate(realm, subject, resourceName, env);
    //Then
    assertThat(decision.isSatisfied()).isFalse();
    assertThat(decision.getAdvice()).containsOnly(entry(AUTHENTICATE_TO_REALM_CONDITION_ADVICE, Collections.singleton("REALM")));
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ConditionDecision(com.sun.identity.entitlement.ConditionDecision) Subject(javax.security.auth.Subject) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 8 with ConditionDecision

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

the class OAuth2ScopeConditionTest method conditionShouldEvaluateToFalseWhenMultipleRequiredScopesSetAndPartialMatchingScopeSetInEnvironment.

@Test
public void conditionShouldEvaluateToFalseWhenMultipleRequiredScopesSetAndPartialMatchingScopeSetInEnvironment() throws EntitlementException {
    //Given
    String realm = "REALM";
    Subject subject = new Subject();
    String resourceName = "RESOURCE_NAME";
    Map<String, Set<String>> env = new HashMap<String, Set<String>>();
    Set<String> requiredScopes = new HashSet<String>();
    env.put("scope", Collections.singleton("cn"));
    requiredScopes.add("cn");
    requiredScopes.add("givenName");
    condition.setRequiredScopes(requiredScopes);
    //When
    ConditionDecision decision = condition.evaluate(realm, subject, resourceName, env);
    //Then
    assertThat(decision.isSatisfied()).isFalse();
    assertThat(decision.getAdvice()).isEmpty();
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ConditionDecision(com.sun.identity.entitlement.ConditionDecision) Subject(javax.security.auth.Subject) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 9 with ConditionDecision

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

the class OAuth2ScopeConditionTest method conditionShouldEvaluateToFalseWhenSingleRequiredScopeSetAndEmptyScopeSetInEnvironment.

@Test
public void conditionShouldEvaluateToFalseWhenSingleRequiredScopeSetAndEmptyScopeSetInEnvironment() throws EntitlementException {
    //Given
    String realm = "REALM";
    Subject subject = new Subject();
    String resourceName = "RESOURCE_NAME";
    Map<String, Set<String>> env = new HashMap<String, Set<String>>();
    env.put("scope", Collections.singleton(""));
    condition.setRequiredScopes(Collections.singleton("cn"));
    //When
    ConditionDecision decision = condition.evaluate(realm, subject, resourceName, env);
    //Then
    assertThat(decision.isSatisfied()).isFalse();
    assertThat(decision.getAdvice()).isEmpty();
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ConditionDecision(com.sun.identity.entitlement.ConditionDecision) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test)

Example 10 with ConditionDecision

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

the class OAuth2ScopeConditionTest method conditionShouldEvaluateToTrueWhenMultipleRequiredScopesSetAndMatchingScopeSetInEnvironment.

@Test
public void conditionShouldEvaluateToTrueWhenMultipleRequiredScopesSetAndMatchingScopeSetInEnvironment() throws EntitlementException {
    //Given
    String realm = "REALM";
    Subject subject = new Subject();
    String resourceName = "RESOURCE_NAME";
    Map<String, Set<String>> env = new HashMap<String, Set<String>>();
    Set<String> requiredScopes = new HashSet<String>();
    env.put("scope", Collections.singleton("cn givenName maidenName"));
    requiredScopes.add("cn");
    requiredScopes.add("givenName");
    condition.setRequiredScopes(requiredScopes);
    //When
    ConditionDecision decision = condition.evaluate(realm, subject, resourceName, env);
    //Then
    assertThat(decision.isSatisfied()).isTrue();
    assertThat(decision.getAdvice()).isEmpty();
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ConditionDecision(com.sun.identity.entitlement.ConditionDecision) Subject(javax.security.auth.Subject) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

ConditionDecision (com.sun.identity.entitlement.ConditionDecision)59 Set (java.util.Set)56 HashMap (java.util.HashMap)54 HashSet (java.util.HashSet)53 Test (org.testng.annotations.Test)48 Subject (javax.security.auth.Subject)47 SSOToken (com.iplanet.sso.SSOToken)24 AMIdentity (com.sun.identity.idm.AMIdentity)7 SSOException (com.iplanet.sso.SSOException)5 EntitlementException (com.sun.identity.entitlement.EntitlementException)4 IdType (com.sun.identity.idm.IdType)4 Date (java.util.Date)4 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)1 Entitlement (com.sun.identity.entitlement.Entitlement)1 SubjectDecision (com.sun.identity.entitlement.SubjectDecision)1 PolicyException (com.sun.identity.policy.PolicyException)1 Condition (com.sun.identity.policy.interfaces.Condition)1 AuthSPrincipal (com.sun.identity.rest.AuthSPrincipal)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1