use of org.forgerock.openam.rest.resource.SubjectContext in project OpenAM by OpenRock.
the class BatchPolicyRequestTest method shouldConstructBatchPolicyRequest.
@Test
public void shouldConstructBatchPolicyRequest() throws EntitlementException {
given(subjectContext.getCallerSubject()).willReturn(restSubject);
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("resources", Arrays.asList("/resource/a", "/resource/b"));
given(actionRequest.getContent()).willReturn(JsonValue.json(properties));
Context context = buildContextStructure("/abc");
BatchPolicyRequest request = BatchPolicyRequest.getBatchPolicyRequest(context, actionRequest, tokenManager);
assertThat(request).isNotNull();
assertThat(request.getResources()).containsOnly("/resource/a", "/resource/b");
verify(subjectContext).getCallerSubject();
verify(actionRequest, times(2)).getContent();
verifyNoMoreInteractions(subjectContext, actionRequest);
}
use of org.forgerock.openam.rest.resource.SubjectContext in project OpenAM by OpenRock.
the class TreePolicyRequestTest method shouldConstructBatchPolicyRequest.
@Test
public void shouldConstructBatchPolicyRequest() throws EntitlementException {
// Given...
given(subjectContext.getCallerSubject()).willReturn(restSubject);
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("resource", "/resource/a");
given(actionRequest.getContent()).willReturn(JsonValue.json(properties));
// When...
Context context = buildContextStructure("/abc");
TreePolicyRequest request = TreePolicyRequest.getTreePolicyRequest(context, actionRequest, tokenManager);
// Then...
assertThat(request).isNotNull();
assertThat(request.getResource()).isEqualTo("/resource/a");
verify(subjectContext).getCallerSubject();
verify(actionRequest, times(2)).getContent();
verifyNoMoreInteractions(subjectContext, actionRequest);
}
use of org.forgerock.openam.rest.resource.SubjectContext in project OpenAM by OpenRock.
the class PolicyRequestTest method shouldDefaultToEmptyEnvironment.
@Test
public void shouldDefaultToEmptyEnvironment() throws EntitlementException {
// Given...
given(subjectContext.getCallerSubject()).willReturn(restSubject);
Map<String, Object> properties = new HashMap<String, Object>();
given(actionRequest.getContent()).willReturn(json(properties));
// When...
Context context = buildContextStructure("");
PolicyRequest request = getRequest(context, actionRequest);
// Then...
assertThat(request).isNotNull();
assertThat(request.getEnvironment()).isNotNull();
assertThat(request.getEnvironment()).isEmpty();
verify(subjectContext).getCallerSubject();
verify(actionRequest).getContent();
verifyNoMoreInteractions(subjectContext, actionRequest);
}
use of org.forgerock.openam.rest.resource.SubjectContext in project OpenAM by OpenRock.
the class PolicyRequestTest method shouldConstructPolicyRequest.
@Test
public void shouldConstructPolicyRequest() throws Exception {
// Given...
Map<String, List<String>> env = new HashMap<String, List<String>>();
env.put("test", Arrays.asList("123", "456"));
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("subject", Collections.singletonMap("ssoToken", "some-value"));
properties.put("application", "some-application");
properties.put("environment", env);
given(actionRequest.getContent()).willReturn(json(properties));
given(subjectContext.getCallerSubject()).willReturn(restSubject);
SSOToken token = mock(SSOToken.class);
given(token.getProperty(Constants.UNIVERSAL_IDENTIFIER)).willReturn("Fred");
given(tokenManager.createSSOToken(anyString())).willReturn(token);
// When...
Context context = buildContextStructure("/abc");
PolicyRequest request = getRequest(context, actionRequest);
// Then...
assertThat(request).isNotNull();
assertThat(request.getRestSubject()).isEqualTo(restSubject);
assertThat(request.getPolicySubject().getPrincipals().iterator().next().getName()).isEqualTo("Fred");
assertThat(request.getRealm()).isEqualTo("/abc");
assertThat(request.getApplication()).isEqualTo("some-application");
assertThat(request.getEnvironment()).is(new EnvMapCondition(env));
verify(subjectContext).getCallerSubject();
verify(actionRequest).getContent();
verifyNoMoreInteractions(subjectContext, actionRequest);
}
use of org.forgerock.openam.rest.resource.SubjectContext in project OpenAM by OpenRock.
the class PolicyRequestTest method shouldDefaultToAdminSubject.
@Test
public void shouldDefaultToAdminSubject() throws EntitlementException {
// Given...
given(subjectContext.getCallerSubject()).willReturn(restSubject);
Map<String, Object> properties = new HashMap<String, Object>();
given(actionRequest.getContent()).willReturn(json(properties));
// When...
Context context = buildContextStructure("/abc");
PolicyRequest request = getRequest(context, actionRequest);
// Then...
assertThat(request).isNotNull();
assertThat(request.getRestSubject()).isEqualTo(restSubject);
assertThat(request.getPolicySubject()).isEqualTo(restSubject);
verify(subjectContext).getCallerSubject();
verify(actionRequest).getContent();
verifyNoMoreInteractions(subjectContext, actionRequest);
}
Aggregations