Search in sources :

Example 21 with Context

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

the class PolicyResourceEvaluationTest method shouldHandleUnknownAction.

@Test
public void shouldHandleUnknownAction() {
    // Given...
    given(request.getAction()).willReturn("unknownAction");
    // When...
    Context context = buildContextStructure("/abc");
    policyResource.actionCollection(context, request);
    // Then...
    verify(request).getAction();
    //verify(jsonHandler).handleError(isA(NotSupportedException.class));
    verifyNoMoreInteractions(request, subjectContext, requestFactory, policyRequest, factory, evaluator, parser);
}
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 22 with Context

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

the class PolicyRequestFactoryTest method shouldRetrieveBatchRequest.

@Test
public void shouldRetrieveBatchRequest() throws EntitlementException {
    // When...
    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));
    // Given...
    Context context = buildContextStructure("/abc");
    PolicyRequest request = factory.buildRequest(PolicyAction.EVALUATE, context, actionRequest);
    // Then...
    assertThat(request).isNotNull();
    assertThat(request.getRealm()).isEqualTo("/abc");
    assertThat(request).isInstanceOfAny(BatchPolicyRequest.class);
    BatchPolicyRequest batchRequest = (BatchPolicyRequest) request;
    assertThat(batchRequest.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) TreePolicyRequest(org.forgerock.openam.entitlement.rest.model.json.TreePolicyRequest) PolicyRequest(org.forgerock.openam.entitlement.rest.model.json.PolicyRequest) BatchPolicyRequest(org.forgerock.openam.entitlement.rest.model.json.BatchPolicyRequest) Test(org.testng.annotations.Test)

Example 23 with Context

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

the class RealmContextFilter method filterUpdate.

@Override
public Promise<ResourceResponse, ResourceException> filterUpdate(Context context, UpdateRequest request, RequestHandler next) {
    try {
        Context newContext = evaluate(context, request);
        UpdateRequest evaluatedRequest = wasEvaluated(context, newContext) ? copyOfUpdateRequest(request).setResourcePath(newContext.asContext(UriRouterContext.class).getRemainingUri()) : request;
        return next.handleUpdate(newContext, evaluatedRequest);
    } catch (ResourceException e) {
        return newExceptionPromise(e);
    }
}
Also used : UriRouterContext(org.forgerock.http.routing.UriRouterContext) Context(org.forgerock.services.context.Context) HttpContext(org.forgerock.json.resource.http.HttpContext) UpdateRequest(org.forgerock.json.resource.UpdateRequest) UriRouterContext(org.forgerock.http.routing.UriRouterContext) ResourceException(org.forgerock.json.resource.ResourceException)

Example 24 with Context

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

the class RealmContextFilter method filterCreate.

@Override
public Promise<ResourceResponse, ResourceException> filterCreate(Context context, CreateRequest request, RequestHandler next) {
    try {
        Context newContext = evaluate(context, request);
        CreateRequest evaluatedRequest = wasEvaluated(context, newContext) ? copyOfCreateRequest(request).setResourcePath(newContext.asContext(UriRouterContext.class).getRemainingUri()) : request;
        return next.handleCreate(evaluate(context, request), evaluatedRequest);
    } catch (ResourceException e) {
        return newExceptionPromise(e);
    }
}
Also used : UriRouterContext(org.forgerock.http.routing.UriRouterContext) Context(org.forgerock.services.context.Context) HttpContext(org.forgerock.json.resource.http.HttpContext) CreateRequest(org.forgerock.json.resource.CreateRequest) UriRouterContext(org.forgerock.http.routing.UriRouterContext) ResourceException(org.forgerock.json.resource.ResourceException)

Example 25 with Context

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

the class PolicyRequestTest method shouldAllowJwtSubject.

@Test
public void shouldAllowJwtSubject() throws Exception {
    // Given
    final String subjectName = "test";
    given(subjectContext.getCallerSubject()).willReturn(restSubject);
    Jwt jwt = getJwtSubject(subjectName);
    given(actionRequest.getContent()).willReturn(json(object(field("subject", object(field("jwt", jwt.build()))))));
    // 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(getJsonSubject(subjectName)));
}
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) Jwt(org.forgerock.json.jose.jwt.Jwt) SignedJwt(org.forgerock.json.jose.jws.SignedJwt) JwtPrincipal(com.sun.identity.entitlement.JwtPrincipal) 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