use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.
the class AuditRestRouteProvider method addResourceRoutes.
@Override
public void addResourceRoutes(ResourceRouter rootRouter, ResourceRouter realmRouter) {
rootRouter.route("global-audit").auditAs(AUDIT, AuditEndpointAuditFilter.class).authorizeWith(SpecialOrAdminOrAgentAuthzModule.class).forVersion(1).toRequestHandler(STARTS_WITH, auditServiceProvider.getDefaultAuditService());
rootRouter.route("realm-audit").auditAs(AUDIT, AuditEndpointAuditFilter.class).authorizeWith(SpecialOrAdminOrAgentAuthzModule.class).forVersion(1).through(RealmContextFilter.class).toRequestHandler(STARTS_WITH, new RequestHandler() {
@Override
public Promise<ActionResponse, ResourceException> handleAction(Context context, ActionRequest actionRequest) {
return getAuditService(context).handleAction(context, actionRequest);
}
@Override
public Promise<ResourceResponse, ResourceException> handleCreate(Context context, CreateRequest createRequest) {
return getAuditService(context).handleCreate(context, createRequest);
}
@Override
public Promise<ResourceResponse, ResourceException> handleDelete(Context context, DeleteRequest deleteRequest) {
return getAuditService(context).handleDelete(context, deleteRequest);
}
@Override
public Promise<ResourceResponse, ResourceException> handlePatch(Context context, PatchRequest patchRequest) {
return getAuditService(context).handlePatch(context, patchRequest);
}
@Override
public Promise<QueryResponse, ResourceException> handleQuery(Context context, QueryRequest queryRequest, QueryResourceHandler queryResourceHandler) {
return getAuditService(context).handleQuery(context, queryRequest, queryResourceHandler);
}
@Override
public Promise<ResourceResponse, ResourceException> handleRead(Context context, ReadRequest readRequest) {
return getAuditService(context).handleRead(context, readRequest);
}
@Override
public Promise<ResourceResponse, ResourceException> handleUpdate(Context context, UpdateRequest updateRequest) {
return getAuditService(context).handleUpdate(context, updateRequest);
}
private AMAuditService getAuditService(Context context) {
String realm = context.asContext(RealmContext.class).getResolvedRealm();
if (StringUtils.isEmpty(realm)) {
logger.warn("Context contained RealmContext but had an empty resolved realm");
return auditServiceProvider.getDefaultAuditService();
}
return auditServiceProvider.getAuditService(realm);
}
});
}
use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.
the class AuditEventPublisherImpl method publishForRealm.
private void publishForRealm(String realm, String topic, AuditEvent auditEvent) throws ResourceException {
AMAuditService auditService = auditServiceProvider.getAuditService(realm);
Connection connection = newInternalConnection(auditService);
CreateRequest request = newCreateRequest(topic, auditEvent.getValue());
try {
connection.create(new RootContext(), request);
} catch (ServiceUnavailableException e) {
debug.message("Audit Service for realm {} is unavailable. Trying the default Audit Service.", realm, e);
publishToDefault(topic, auditEvent);
}
}
use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.
the class CoreTokenResourceTest method shouldCreateTokenInCTS.
@Test
public void shouldCreateTokenInCTS() throws CoreTokenException {
// Given
CreateRequest request = mock(CreateRequest.class);
given(request.getContent()).willReturn(new JsonValue(""));
given(mockSerialisation.deserialise(anyString(), Matchers.<Class<Object>>any())).willReturn(mockToken);
// When
resource.createInstance(null, request);
// Then
verify(mockStore).createAsync(mockToken);
}
use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.
the class CoreTokenResourceTest method shouldGetBadRequestForMissingTokenId.
@Test
public void shouldGetBadRequestForMissingTokenId() throws CoreTokenException {
// Given
CreateRequest request = mock(CreateRequest.class);
given(request.getContent()).willReturn(new JsonValue(""));
doThrow(IllegalArgumentException.class).when(mockStore).createAsync(any(Token.class));
// When
Promise<ResourceResponse, ResourceException> promise = resource.createInstance(null, request);
// Then
assertThat(promise).failedWithException().isInstanceOf(BadRequestException.class);
}
use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.
the class PolicyResourceTest method shouldReportCreatePolicyStoreErrors.
@Test
public void shouldReportCreatePolicyStoreErrors() throws Exception {
// Given
String id = "uniqueId";
JsonValue json = new JsonValue("");
CreateRequest request = mockCreateRequest(id, json);
Privilege policy = mockPrivilege(id, 123l);
given(mockParser.parsePolicy(id, json)).willReturn(policy);
willThrow(new EntitlementException(EntitlementException.INVALID_APPLICATION_CLASS)).given(mockStore).create(policy);
// When
Promise<ResourceResponse, ResourceException> promise = policyResource.createInstance(mockServerContext, request);
// Then
assertThat(promise).failedWithException().isInstanceOf(InternalServerErrorException.class);
}
Aggregations