Search in sources :

Example 21 with SubjectContext

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);
}
Also used : Context(org.forgerock.services.context.Context) ClientContext(org.forgerock.services.context.ClientContext) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) RealmContext(org.forgerock.openam.rest.RealmContext) HashMap(java.util.HashMap) BatchPolicyRequest(org.forgerock.openam.entitlement.rest.model.json.BatchPolicyRequest) Test(org.testng.annotations.Test)

Example 22 with SubjectContext

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);
}
Also used : Context(org.forgerock.services.context.Context) ClientContext(org.forgerock.services.context.ClientContext) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) RealmContext(org.forgerock.openam.rest.RealmContext) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Example 23 with SubjectContext

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);
}
Also used : ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Example 24 with SubjectContext

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);
}
Also used : ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) SSOToken(com.iplanet.sso.SSOToken) HashMap(java.util.HashMap) List(java.util.List) Test(org.testng.annotations.Test)

Example 25 with SubjectContext

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);
}
Also used : ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Aggregations

SubjectContext (org.forgerock.openam.rest.resource.SubjectContext)33 RealmContext (org.forgerock.openam.rest.RealmContext)31 Test (org.testng.annotations.Test)28 Context (org.forgerock.services.context.Context)27 ClientContext (org.forgerock.services.context.ClientContext)18 ResourceException (org.forgerock.json.resource.ResourceException)15 ResourceResponse (org.forgerock.json.resource.ResourceResponse)12 HashMap (java.util.HashMap)10 DelegationPermission (com.sun.identity.delegation.DelegationPermission)9 FilterChain (org.forgerock.json.resource.FilterChain)9 Router (org.forgerock.json.resource.Router)9 HashSet (java.util.HashSet)8 Subject (javax.security.auth.Subject)8 JsonValue (org.forgerock.json.JsonValue)8 Matchers.anyString (org.mockito.Matchers.anyString)8 JsonSchema (com.fasterxml.jackson.databind.jsonschema.JsonSchema)7 ReadRequest (org.forgerock.json.resource.ReadRequest)6 SSOToken (com.iplanet.sso.SSOToken)4 ActionResponse (org.forgerock.json.resource.ActionResponse)4 Map (java.util.Map)3