Search in sources :

Example 26 with Context

use of org.forgerock.services.context.Context in project OpenAM by OpenRock.

the class TreePolicyRequestTest method shouldRejectEmptyResources.

@Test(expectedExceptions = EntitlementException.class)
public void shouldRejectEmptyResources() throws EntitlementException {
    // Given...
    Map<String, Object> properties = new HashMap<String, Object>();
    given(actionRequest.getContent()).willReturn(JsonValue.json(properties));
    given(subjectContext.getCallerSubject()).willReturn(restSubject);
    // When...
    Context context = buildContextStructure("/abc");
    TreePolicyRequest.getTreePolicyRequest(context, actionRequest, tokenManager);
}
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 27 with Context

use of org.forgerock.services.context.Context in project OpenAM by OpenRock.

the class SubjectTypesResourceTest method testSuccessfulJsonificationAndQuery.

@Test
public void testSuccessfulJsonificationAndQuery() throws Exception {
    //given
    SSOTokenContext mockSubjectContext = mock(SSOTokenContext.class);
    RealmContext realmContext = new RealmContext(mockSubjectContext);
    Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
    Subject mockSubject = new Subject();
    given(mockSubjectContext.getCallerSubject()).willReturn(mockSubject);
    QueryRequest mockRequest = mock(QueryRequest.class);
    JsonSchema mockSchema = mock(JsonSchema.class);
    QueryResourceHandler mockHandler = mock(QueryResourceHandler.class);
    given(mockRequest.getPageSize()).willReturn(2);
    given(mockHandler.handleResource(any(ResourceResponse.class))).willReturn(true);
    given(mockMapper.generateJsonSchema((Class<?>) any(Class.class))).willReturn(mockSchema);
    //when
    Promise<QueryResponse, ResourceException> promise = testResource.queryCollection(mockServerContext, mockRequest, mockHandler);
    //then
    assertThat(promise).succeeded();
    verify(mockHandler, times(2)).handleResource(any(ResourceResponse.class));
}
Also used : ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) RealmContext(org.forgerock.openam.rest.RealmContext) QueryRequest(org.forgerock.json.resource.QueryRequest) ResourceResponse(org.forgerock.json.resource.ResourceResponse) JsonSchema(com.fasterxml.jackson.databind.jsonschema.JsonSchema) QueryResponse(org.forgerock.json.resource.QueryResponse) ResourceException(org.forgerock.json.resource.ResourceException) QueryResourceHandler(org.forgerock.json.resource.QueryResourceHandler) EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) Subject(javax.security.auth.Subject) LogicalSubject(com.sun.identity.entitlement.LogicalSubject) Test(org.testng.annotations.Test)

Example 28 with Context

use of org.forgerock.services.context.Context in project OpenAM by OpenRock.

the class BatchPolicyRequestTest method shouldRejectNullResources.

@Test(expectedExceptions = EntitlementException.class)
public void shouldRejectNullResources() throws EntitlementException {
    // When...
    Map<String, Object> properties = new HashMap<String, Object>();
    given(actionRequest.getContent()).willReturn(JsonValue.json(properties));
    given(subjectContext.getCallerSubject()).willReturn(restSubject);
    // Given...
    Context context = buildContextStructure("/abc");
    BatchPolicyRequest.getBatchPolicyRequest(context, actionRequest, tokenManager);
}
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 29 with Context

use of org.forgerock.services.context.Context in project OpenAM by OpenRock.

the class PolicyRequestTest method shouldRejectInvalidRestSubject.

@Test(expectedExceptions = EntitlementException.class)
public void shouldRejectInvalidRestSubject() throws EntitlementException {
    // Given...
    given(subjectContext.getCallerSubject()).willReturn(null);
    // When...
    Context context = buildContextStructure("/abc");
    getRequest(context, 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) Test(org.testng.annotations.Test)

Example 30 with Context

use of org.forgerock.services.context.Context in project OpenAM by OpenRock.

the class PolicyRequestTest method shouldAllowJsonSubject.

@Test
public void shouldAllowJsonSubject() throws Exception {
    // Given
    final String subjectName = "test";
    given(subjectContext.getCallerSubject()).willReturn(restSubject);
    final JsonValue jwt = getJsonSubject(subjectName);
    given(actionRequest.getContent()).willReturn(json(object(field("subject", object(field("claims", jwt.asMap()))))));
    // When
    Context context = buildContextStructure("/abc");
    PolicyRequest request = getRequest(context, actionRequest);
    // Then
    Subject policySubject = request.getPolicySubject();
    Set<JwtPrincipal> jwtPrincipals = policySubject.getPrincipals(JwtPrincipal.class);
    assertThat(jwtPrincipals).hasSize(1);
    assertThat(jwtPrincipals).contains(new JwtPrincipal(jwt));
}
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) JwtPrincipal(com.sun.identity.entitlement.JwtPrincipal) JsonValue(org.forgerock.json.JsonValue) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test)

Aggregations

Context (org.forgerock.services.context.Context)250 Test (org.testng.annotations.Test)231 RealmContext (org.forgerock.openam.rest.RealmContext)150 ResourceException (org.forgerock.json.resource.ResourceException)132 ClientContext (org.forgerock.services.context.ClientContext)120 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)101 ResourceResponse (org.forgerock.json.resource.ResourceResponse)82 SubjectContext (org.forgerock.openam.rest.resource.SubjectContext)76 RootContext (org.forgerock.services.context.RootContext)62 JsonValue (org.forgerock.json.JsonValue)56 QueryRequest (org.forgerock.json.resource.QueryRequest)54 ReadRequest (org.forgerock.json.resource.ReadRequest)50 AttributesContext (org.forgerock.services.context.AttributesContext)44 ActionRequest (org.forgerock.json.resource.ActionRequest)43 QueryResponse (org.forgerock.json.resource.QueryResponse)43 Subject (javax.security.auth.Subject)42 Matchers.anyString (org.mockito.Matchers.anyString)38 Request (org.forgerock.http.protocol.Request)37 UpdateRequest (org.forgerock.json.resource.UpdateRequest)36 DeleteRequest (org.forgerock.json.resource.DeleteRequest)35