Search in sources :

Example 6 with FilterChain

use of org.forgerock.json.resource.FilterChain in project OpenAM by OpenRock.

the class RestGuiceModule method getChfRealmRouter.

@Provides
@Named("ChfRealmRouter")
@Singleton
org.forgerock.http.routing.Router getChfRealmRouter(@Named("CrestRealmHandler") RequestHandler crestRealmHandler, ContextFilter contextFilter, CrestProtocolEnforcementFilter crestProtocolEnforcementFilter) {
    org.forgerock.http.routing.Router chfRealmRouter = new org.forgerock.http.routing.Router();
    chfRealmRouter.setDefaultRoute(Handlers.chainOf(newHttpHandler(new FilterChain(crestRealmHandler, contextFilter)), crestProtocolEnforcementFilter));
    return chfRealmRouter;
}
Also used : FilterChain(org.forgerock.json.resource.FilterChain) Router(org.forgerock.json.resource.Router) Named(javax.inject.Named) Singleton(javax.inject.Singleton) Provides(com.google.inject.Provides)

Example 7 with FilterChain

use of org.forgerock.json.resource.FilterChain in project OpenAM by OpenRock.

the class RealmContextFilterTest method getHttpHandler.

private Handler getHttpHandler(RequestHandler requestHandler) {
    ResourceResponse response = mock(ResourceResponse.class);
    Promise<ResourceResponse, ResourceException> result = Promises.newResultPromise(response);
    given(requestHandler.handleCreate(any(Context.class), any(CreateRequest.class))).willReturn(result);
    given(requestHandler.handleRead(any(Context.class), any(ReadRequest.class))).willReturn(result);
    given(requestHandler.handleUpdate(any(Context.class), any(UpdateRequest.class))).willReturn(result);
    given(requestHandler.handleDelete(any(Context.class), any(DeleteRequest.class))).willReturn(result);
    given(requestHandler.handlePatch(any(Context.class), any(PatchRequest.class))).willReturn(result);
    given(requestHandler.handleAction(any(Context.class), any(ActionRequest.class))).willReturn(Promises.<ActionResponse, ResourceException>newResultPromise(mock(ActionResponse.class)));
    given(requestHandler.handleQuery(any(Context.class), any(QueryRequest.class), any(QueryResponseHandler.class))).willReturn(Promises.<QueryResponse, ResourceException>newResultPromise(mock(QueryResponse.class)));
    FilterChain filterChain = new FilterChain(requestHandler, filter);
    return CrestHttp.newHttpHandler(filterChain);
}
Also used : RootContext(org.forgerock.services.context.RootContext) UriRouterContext(org.forgerock.http.routing.UriRouterContext) Context(org.forgerock.services.context.Context) AttributesContext(org.forgerock.services.context.AttributesContext) QueryRequest(org.forgerock.json.resource.QueryRequest) QueryResponseHandler(org.forgerock.openam.rest.query.QueryResponseHandler) UpdateRequest(org.forgerock.json.resource.UpdateRequest) CreateRequest(org.forgerock.json.resource.CreateRequest) FilterChain(org.forgerock.json.resource.FilterChain) PatchRequest(org.forgerock.json.resource.PatchRequest) ResourceResponse(org.forgerock.json.resource.ResourceResponse) ActionRequest(org.forgerock.json.resource.ActionRequest) ResourceException(org.forgerock.json.resource.ResourceException) DeleteRequest(org.forgerock.json.resource.DeleteRequest) ReadRequest(org.forgerock.json.resource.ReadRequest)

Example 8 with FilterChain

use of org.forgerock.json.resource.FilterChain in project OpenAM by OpenRock.

the class PrivilegeAuthzModuleTest method crestActionEvaluateIsAllowed.

@Test
public void crestActionEvaluateIsAllowed() throws SSOException, DelegationException {
    // Given...
    final Set<String> actions = new HashSet<>(Arrays.asList("READ"));
    final DelegationPermission permission = new DelegationPermission("/abc", "rest", "1.0", "policies", "evaluate", actions, EXTENSIONS, DUMB_FUNC);
    given(factory.newInstance("/abc", "rest", "1.0", "policies", "evaluate", actions, EXTENSIONS)).willReturn(permission);
    given(subjectContext.getCallerSSOToken()).willReturn(token);
    given(evaluator.isAllowed(eq(token), eq(permission), eq(ENVIRONMENT))).willReturn(true);
    JsonValue jsonValue = json(object(field("someKey", "someValue")));
    Promise<ActionResponse, ResourceException> promise = Promises.newResultPromise(Responses.newActionResponse(jsonValue));
    given(provider.actionCollection(isA(Context.class), isA(ActionRequest.class))).willReturn(promise);
    // When...
    final FilterChain chain = AuthorizationFilters.createAuthorizationFilter(provider, module);
    final Router router = new Router();
    router.addRoute(RoutingMode.STARTS_WITH, Router.uriTemplate("/policies"), chain);
    final RealmContext context = new RealmContext(subjectContext);
    context.setSubRealm("abc", "abc");
    final ActionRequest request = Requests.newActionRequest("/policies", "evaluate");
    Promise<ActionResponse, ResourceException> result = router.handleAction(context, request);
    // Then...
    assertThat(result).succeeded().withContent().stringAt("someKey").isEqualTo("someValue");
}
Also used : RealmContext(org.forgerock.openam.rest.RealmContext) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) Context(org.forgerock.services.context.Context) RealmContext(org.forgerock.openam.rest.RealmContext) FilterChain(org.forgerock.json.resource.FilterChain) JsonValue(org.forgerock.json.JsonValue) Router(org.forgerock.json.resource.Router) Matchers.anyString(org.mockito.Matchers.anyString) DelegationPermission(com.sun.identity.delegation.DelegationPermission) ActionResponse(org.forgerock.json.resource.ActionResponse) ActionRequest(org.forgerock.json.resource.ActionRequest) ResourceException(org.forgerock.json.resource.ResourceException) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 9 with FilterChain

use of org.forgerock.json.resource.FilterChain in project OpenAM by OpenRock.

the class PrivilegeAuthzModuleTest method crestActionBlowupIsAllowed.

@Test
public void crestActionBlowupIsAllowed() throws SSOException, DelegationException {
    // Given...
    final Set<String> actions = new HashSet<>(Arrays.asList("MODIFY"));
    final DelegationPermission permission = new DelegationPermission("/abc", "rest", "1.0", "policies", "destroy", actions, EXTENSIONS, DUMB_FUNC);
    given(factory.newInstance("/abc", "rest", "1.0", "policies", "destroy", actions, EXTENSIONS)).willReturn(permission);
    given(subjectContext.getCallerSSOToken()).willReturn(token);
    given(evaluator.isAllowed(eq(token), eq(permission), eq(ENVIRONMENT))).willReturn(true);
    JsonValue jsonValue = json(object(field("someKey", "someValue")));
    Promise<ActionResponse, ResourceException> promise = Promises.newResultPromise(Responses.newActionResponse(jsonValue));
    given(provider.actionCollection(isA(Context.class), isA(ActionRequest.class))).willReturn(promise);
    // When...
    final FilterChain chain = AuthorizationFilters.createAuthorizationFilter(provider, module);
    final Router router = new Router();
    router.addRoute(RoutingMode.STARTS_WITH, Router.uriTemplate("/policies"), chain);
    final RealmContext context = new RealmContext(subjectContext);
    context.setSubRealm("abc", "abc");
    final ActionRequest request = Requests.newActionRequest("/policies", "blowup");
    Promise<ActionResponse, ResourceException> result = router.handleAction(context, request);
    // Then...
    assertThat(result).succeeded().withContent().stringAt("someKey").isEqualTo("someValue");
}
Also used : RealmContext(org.forgerock.openam.rest.RealmContext) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) Context(org.forgerock.services.context.Context) RealmContext(org.forgerock.openam.rest.RealmContext) FilterChain(org.forgerock.json.resource.FilterChain) JsonValue(org.forgerock.json.JsonValue) Router(org.forgerock.json.resource.Router) Matchers.anyString(org.mockito.Matchers.anyString) DelegationPermission(com.sun.identity.delegation.DelegationPermission) ActionResponse(org.forgerock.json.resource.ActionResponse) ActionRequest(org.forgerock.json.resource.ActionRequest) ResourceException(org.forgerock.json.resource.ResourceException) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 10 with FilterChain

use of org.forgerock.json.resource.FilterChain in project OpenAM by OpenRock.

the class PrivilegeAuthzModuleTest method crestDeleteIsAllowed.

@Test
public void crestDeleteIsAllowed() throws SSOException, DelegationException {
    // Given...
    final Set<String> actions = new HashSet<>(Arrays.asList("MODIFY"));
    final DelegationPermission permission = new DelegationPermission("/abc", "rest", "1.0", "policies", "modify", actions, EXTENSIONS, DUMB_FUNC);
    given(factory.newInstance("/abc", "rest", "1.0", "policies", "modify", actions, EXTENSIONS)).willReturn(permission);
    given(subjectContext.getCallerSSOToken()).willReturn(token);
    given(evaluator.isAllowed(eq(token), eq(permission), eq(ENVIRONMENT))).willReturn(true);
    JsonValue jsonValue = json(object(field("someKey", "someValue")));
    Promise<ResourceResponse, ResourceException> promise = Promises.newResultPromise(Responses.newResourceResponse("1", "1.0", jsonValue));
    given(provider.deleteInstance(isA(Context.class), eq("123"), isA(DeleteRequest.class))).willReturn(promise);
    // When...
    final FilterChain chain = AuthorizationFilters.createAuthorizationFilter(provider, module);
    final Router router = new Router();
    router.addRoute(RoutingMode.STARTS_WITH, Router.uriTemplate("/policies"), chain);
    final RealmContext context = new RealmContext(subjectContext);
    context.setSubRealm("abc", "abc");
    final DeleteRequest request = Requests.newDeleteRequest("/policies/123");
    Promise<ResourceResponse, ResourceException> result = router.handleDelete(context, request);
    // Then...
    assertThat(result).succeeded().withContent().stringAt("someKey").isEqualTo("someValue");
}
Also used : RealmContext(org.forgerock.openam.rest.RealmContext) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) Context(org.forgerock.services.context.Context) RealmContext(org.forgerock.openam.rest.RealmContext) FilterChain(org.forgerock.json.resource.FilterChain) JsonValue(org.forgerock.json.JsonValue) Router(org.forgerock.json.resource.Router) Matchers.anyString(org.mockito.Matchers.anyString) DelegationPermission(com.sun.identity.delegation.DelegationPermission) ResourceResponse(org.forgerock.json.resource.ResourceResponse) ResourceException(org.forgerock.json.resource.ResourceException) DeleteRequest(org.forgerock.json.resource.DeleteRequest) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

FilterChain (org.forgerock.json.resource.FilterChain)13 ResourceException (org.forgerock.json.resource.ResourceException)11 Router (org.forgerock.json.resource.Router)11 RealmContext (org.forgerock.openam.rest.RealmContext)10 Context (org.forgerock.services.context.Context)10 Test (org.testng.annotations.Test)10 DelegationPermission (com.sun.identity.delegation.DelegationPermission)9 HashSet (java.util.HashSet)9 SubjectContext (org.forgerock.openam.rest.resource.SubjectContext)9 Matchers.anyString (org.mockito.Matchers.anyString)9 JsonValue (org.forgerock.json.JsonValue)7 ResourceResponse (org.forgerock.json.resource.ResourceResponse)7 ActionRequest (org.forgerock.json.resource.ActionRequest)4 ActionResponse (org.forgerock.json.resource.ActionResponse)3 CreateRequest (org.forgerock.json.resource.CreateRequest)3 DeleteRequest (org.forgerock.json.resource.DeleteRequest)2 PatchRequest (org.forgerock.json.resource.PatchRequest)2 QueryRequest (org.forgerock.json.resource.QueryRequest)2 ReadRequest (org.forgerock.json.resource.ReadRequest)2 UpdateRequest (org.forgerock.json.resource.UpdateRequest)2