use of com.sun.identity.rest.AuthSPrincipal in project OpenAM by OpenRock.
the class ScriptConditionTest method successfulEvaluation.
@Test
public void successfulEvaluation() throws EntitlementException, ScriptException, javax.script.ScriptException, IdRepoException, SSOException {
// Given
Subject subject = new Subject();
SSOToken token = mock(SSOToken.class);
subject.getPrivateCredentials().add(token);
subject.getPrincipals().add(new AuthSPrincipal("user"));
Map<String, Set<String>> env = new HashMap<>();
Map<String, Set<String>> advice = new HashMap<>();
final ScriptConfiguration configuration = ScriptConfiguration.builder().setId("123-456-789").setName("test-script").setContext(ScriptContext.POLICY_CONDITION).setLanguage(SupportedScriptingLanguage.JAVASCRIPT).setScript("some-script-here").build();
scriptCondition = new ScriptCondition() {
@Override
protected ScriptConfiguration getScriptConfiguration(String realm) throws ScriptException {
return configuration;
}
};
given(coreWrapper.getIdentity(token)).willReturn(mock(AMIdentity.class));
// When
scriptCondition.setScriptId("123-456-789");
ConditionDecision decision = scriptCondition.evaluate("/abc", subject, "http://a:b/c", env);
// Then
// Hard to test true scenario
assertThat(decision.isSatisfied()).isFalse();
verify(scriptEvaluator).evaluateScript(scriptObjectCaptor.capture(), bindingsCaptor.capture());
ScriptObject scriptObject = scriptObjectCaptor.getValue();
assertThat(scriptObject.getName()).isEqualTo("test-script");
assertThat(scriptObject.getLanguage()).isEqualTo(SupportedScriptingLanguage.JAVASCRIPT);
assertThat(scriptObject.getScript()).isEqualTo("some-script-here");
Bindings bindings = bindingsCaptor.getValue();
assertThat(bindings.get("logger")).isEqualTo(PolicyConstants.DEBUG);
assertThat(bindings.get("username")).isEqualTo("user");
assertThat(bindings.get("resourceURI")).isEqualTo("http://a:b/c");
assertThat(bindings.get("environment")).isEqualTo(env);
assertThat(bindings.get("advice")).isEqualTo(advice);
assertThat(bindings.get("httpClient")).isEqualTo(restletHttpClient);
assertThat(bindings.get("authorized")).isEqualTo(Boolean.FALSE);
assertThat(bindings.get("ttl")).isEqualTo(Long.MAX_VALUE);
}
use of com.sun.identity.rest.AuthSPrincipal in project OpenAM by OpenRock.
the class ScriptConditionTest method missingScriptConfiguration.
@Test(expectedExceptions = EntitlementException.class, expectedExceptionsMessageRegExp = "Script condition is unable to load script 123-456-789.")
public void missingScriptConfiguration() throws ScriptException, EntitlementException {
// Given
Subject subject = new Subject();
subject.getPrincipals().add(new AuthSPrincipal("user"));
Map<String, Set<String>> env = new HashMap<>();
scriptCondition = new ScriptCondition() {
@Override
protected ScriptConfiguration getScriptConfiguration(String realm) throws ScriptException {
return null;
}
};
// When
scriptCondition.setScriptId("123-456-789");
scriptCondition.evaluate("/abc", subject, "http://a:b/c", env);
}
use of com.sun.identity.rest.AuthSPrincipal in project OpenAM by OpenRock.
the class AuthUtils method createSubject.
public static Subject createSubject(String uuid) {
Set<Principal> userPrincipals = new HashSet<Principal>(2);
userPrincipals.add(new AuthSPrincipal(uuid));
return new Subject(false, userPrincipals, new HashSet(), new HashSet());
}
Aggregations