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();
}
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")));
}
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();
}
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();
}
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();
}
Aggregations