Search in sources :

Example 41 with ConditionDecision

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

the class SessionConditionTest method conditionShouldEvaluateToTrueWhenEnvironmentHasTokenCreationTimeLessThanMaxSessionTime.

@Test
public void conditionShouldEvaluateToTrueWhenEnvironmentHasTokenCreationTimeLessThanMaxSessionTime() throws EntitlementException, SSOException {
    //Given
    String realm = "REALM";
    Subject subject = new Subject();
    String resourceName = "RESOURCE_NAME";
    Map<String, Set<String>> env = new HashMap<String, Set<String>>();
    SSOToken ssoToken = mock(SSOToken.class);
    long now = System.currentTimeMillis();
    long tokenCreationTime = now - (5 * 60000) + 1;
    given(timeService.now()).willReturn(now);
    env.put(REQUEST_SESSION_CREATION_TIME, Collections.singleton(tokenCreationTime + ""));
    subject.getPrivateCredentials().add(ssoToken);
    condition.setState("{\"maxSessionTime\": 5, \"terminateSession\": false}");
    //When
    ConditionDecision decision = condition.evaluate(realm, subject, resourceName, env);
    //Then
    assertThat(decision.isSatisfied()).isTrue();
    assertThat(decision.getAdvice()).isEmpty();
    assertThat(decision.getTimeToLive()).isEqualTo(tokenCreationTime + (5 * 60000));
    verify(coreWrapper, never()).destroyToken(ssoToken);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) SSOToken(com.iplanet.sso.SSOToken) HashMap(java.util.HashMap) ConditionDecision(com.sun.identity.entitlement.ConditionDecision) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test)

Example 42 with ConditionDecision

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

the class LEAuthLevelConditionTest method conditionShouldEvaluateToTrueWhenUsingAuthLevelsFromSSOTokenWithRealmAndIsLE.

@Test
public void conditionShouldEvaluateToTrueWhenUsingAuthLevelsFromSSOTokenWithRealmAndIsLE() throws EntitlementException, SSOException {
    //Given
    String realm = "REALM";
    Subject subject = new Subject();
    String resourceName = "RESOURCE_NAME";
    Map<String, Set<String>> env = new HashMap<String, Set<String>>();
    SSOToken ssoToken = mock(SSOToken.class);
    Set<String> authenticatedLevels = new HashSet<String>();
    given(authUtils.getRealmFromRealmQualifiedData("5")).willReturn("REALM");
    given(authUtils.getRealmFromRealmQualifiedData("3")).willReturn("REALM");
    given(authUtils.getRealmFromRealmQualifiedData("4")).willReturn("REALM");
    given(authUtils.getRealmFromRealmQualifiedData("6")).willReturn("OTHER_REALM");
    given(authUtils.getDataFromRealmQualifiedData("3")).willReturn("3");
    given(authUtils.getDataFromRealmQualifiedData("4")).willReturn("4");
    given(authUtils.getDataFromRealmQualifiedData("6")).willReturn("6");
    condition.setState("{\"authLevel\": 5}");
    subject.getPrivateCredentials().add(ssoToken);
    authenticatedLevels.add("3");
    authenticatedLevels.add("4");
    authenticatedLevels.add("6");
    given(authUtils.getRealmQualifiedAuthenticatedLevels(ssoToken)).willReturn(authenticatedLevels);
    //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) SSOToken(com.iplanet.sso.SSOToken) 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 43 with ConditionDecision

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

the class LEAuthLevelConditionTest method conditionShouldEvaluateToFalseWhenUsingAuthLevelsFromSSOTokenWithRealmAndNotLE.

@Test
public void conditionShouldEvaluateToFalseWhenUsingAuthLevelsFromSSOTokenWithRealmAndNotLE() throws EntitlementException, SSOException {
    //Given
    String realm = "REALM";
    Subject subject = new Subject();
    String resourceName = "RESOURCE_NAME";
    Map<String, Set<String>> env = new HashMap<String, Set<String>>();
    SSOToken ssoToken = mock(SSOToken.class);
    Set<String> authenticatedLevels = new HashSet<String>();
    given(authUtils.getDataFromRealmQualifiedData("3")).willReturn("3");
    given(authUtils.getDataFromRealmQualifiedData("4")).willReturn("4");
    given(authUtils.getDataFromRealmQualifiedData("6")).willReturn("6");
    condition.setState("{\"authLevel\": 5}");
    subject.getPrivateCredentials().add(ssoToken);
    authenticatedLevels.add("3");
    authenticatedLevels.add("4");
    authenticatedLevels.add("6");
    given(authUtils.getAuthenticatedLevels(ssoToken)).willReturn(authenticatedLevels);
    //When
    ConditionDecision decision = condition.evaluate(realm, subject, resourceName, env);
    //Then
    assertThat(decision.isSatisfied()).isFalse();
    assertThat(decision.getAdvice()).isEmpty();
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) SSOToken(com.iplanet.sso.SSOToken) 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 44 with ConditionDecision

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

the class AuthLevelConditionTest method conditionShouldEvaluateToFalseWhenUsingRequestAuthLevelsFromEnvironmentWithRealmAndNotGE.

@Test
public void conditionShouldEvaluateToFalseWhenUsingRequestAuthLevelsFromEnvironmentWithRealmAndNotGE() 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.getRealmFromRealmQualifiedData("5")).willReturn("REALM");
    given(coreWrapper.getRealmFromRealmQualifiedData("3")).willReturn("REALM");
    given(coreWrapper.getRealmFromRealmQualifiedData("4")).willReturn("REALM");
    given(coreWrapper.getRealmFromRealmQualifiedData("6")).willReturn("OTHER_REALM");
    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()).isFalse();
    assertThat(decision.getAdvice()).containsOnly(entry("AuthLevelConditionAdvice", Collections.singleton("5")));
}
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 45 with ConditionDecision

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

the class AuthLevelConditionTest method conditionShouldEvaluateToFalseWhenUsingAuthLevelsFromSSOTokenWithRealmAndNotGE.

@Test
public void conditionShouldEvaluateToFalseWhenUsingAuthLevelsFromSSOTokenWithRealmAndNotGE() throws EntitlementException, SSOException {
    //Given
    String realm = "REALM";
    Subject subject = new Subject();
    String resourceName = "RESOURCE_NAME";
    Map<String, Set<String>> env = new HashMap<String, Set<String>>();
    SSOToken ssoToken = mock(SSOToken.class);
    Set<String> authenticatedLevels = new HashSet<String>();
    given(coreWrapper.getRealmFromRealmQualifiedData("5")).willReturn("REALM");
    given(coreWrapper.getRealmFromRealmQualifiedData("3")).willReturn("REALM");
    given(coreWrapper.getRealmFromRealmQualifiedData("4")).willReturn("REALM");
    given(coreWrapper.getRealmFromRealmQualifiedData("6")).willReturn("OTHER_REALM");
    given(coreWrapper.getDataFromRealmQualifiedData("3")).willReturn("3");
    given(coreWrapper.getDataFromRealmQualifiedData("4")).willReturn("4");
    given(coreWrapper.getDataFromRealmQualifiedData("6")).willReturn("6");
    condition.setState("{\"authLevel\": 5}");
    subject.getPrivateCredentials().add(ssoToken);
    authenticatedLevels.add("3");
    authenticatedLevels.add("4");
    authenticatedLevels.add("6");
    given(coreWrapper.getRealmQualifiedAuthenticatedLevels(ssoToken)).willReturn(authenticatedLevels);
    //When
    ConditionDecision decision = condition.evaluate(realm, subject, resourceName, env);
    //Then
    assertThat(decision.isSatisfied()).isFalse();
    assertThat(decision.getAdvice()).containsOnly(entry("AuthLevelConditionAdvice", Collections.singleton("5")));
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) SSOToken(com.iplanet.sso.SSOToken) 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