@Test public void getCompleteLogs() throws Exception { AuditLog al = mock(AuditLogImpl.class); Authorization auth = mock(Authorization.class); List<AuditLogEntry> list = new ArrayList<>(); AuditLogResource lr = new AuditLogResource(al, auth, new HttpHeader("MyApp-???", "600"), new PaginationHelper<>(new AuditLogEntryFilter(), new AuditLogEntryComparator())); Mockito.when(al.getAuditLogs()).thenReturn(list); Response r = lr.getLogsForAllApplications( "", 1, 10, "", "", null); assertThat("{logEntries=[], totalEntries=0}", is(r.getEntity().toString())); for (int i = 0; i < 5; i++) { list.add(AuditLogEntryFactory.createFromEvent(new SimpleEvent("Event"))); } Mockito.when(al.getAuditLogs()).thenReturn(list); r = lr.getLogsForAllApplications( "", 1, 10, "", "", null); Assert.assertTrue(r.getEntity().toString().contains("totalEntries=5")); for (int i = 0; i < 6; i++) { list.add(AuditLogEntryFactory.createFromEvent(new SimpleEvent("Event"))); } Mockito.when(al.getAuditLogs()).thenReturn(list); r = lr.getLogsForAllApplications( "", 1, 10, "", "", null); Assert.assertTrue(r.getEntity().toString().contains("totalEntries=11")); }
@GET @Produces(APPLICATION_JSON) @ApiOperation(value = "Returns all logs if the requesting user has SuperAdmin permissions.", notes = "Returns all logs if the requesting user has SuperAdmin permissions. " + "The parameters allow for filtering, sorting, and pagination.", response = Response.class, httpMethod = "GET", produces = "application/json", protocols = "https") @Timed(name = "getLogsForAllApplications") public Response getLogsForAllApplications( @HeaderParam(AUTHORIZATION) @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true) final String authorizationHeader, @QueryParam("page") @DefaultValue(DEFAULT_PAGE) @ApiParam(name = "page", defaultValue = DEFAULT_PAGE, value = DOC_PAGE) final int page, @QueryParam("per_page") @DefaultValue(DEFAULT_PER_PAGE) @ApiParam(name = "per_page", defaultValue = DEFAULT_PER_PAGE, value = DOC_PER_PAGE) final int perPage, @QueryParam("filter") @DefaultValue("") @ApiParam(name = "filter", defaultValue = DEFAULT_FILTER, value = DOC_FILTER) final String filter, @QueryParam("sort") @DefaultValue("") @ApiParam(name = "sort", defaultValue = DEFAULT_SORT, value = DOC_SORT) final String sort, @QueryParam("timezone") @DefaultValue(DEFAULT_TIMEZONE) @ApiParam(name = "timezone", defaultValue = DEFAULT_TIMEZONE, value = DOC_TIMEZONE) final String timezoneOffset) { try { return getLogsForApplication(authorizationHeader, null, page, perPage, filter, sort, timezoneOffset); } catch (Exception exception) { LOGGER.error("getLogsForAllApplications failed for page:{}, perPage={}, filter={}," + " sort={}, timezoneOffset={} with error:", page, perPage, filter, sort, timezoneOffset, exception); throw exception; } }
AuditLogResource { @GET @Produces(APPLICATION_JSON) @ApiOperation(value = "Returns all logs if the requesting user has SuperAdmin permissions.", notes = "Returns all logs if the requesting user has SuperAdmin permissions. " + "The parameters allow for filtering, sorting, and pagination.", response = Response.class, httpMethod = "GET", produces = "application/json", protocols = "https") @Timed(name = "getLogsForAllApplications") public Response getLogsForAllApplications( @HeaderParam(AUTHORIZATION) @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true) final String authorizationHeader, @QueryParam("page") @DefaultValue(DEFAULT_PAGE) @ApiParam(name = "page", defaultValue = DEFAULT_PAGE, value = DOC_PAGE) final int page, @QueryParam("per_page") @DefaultValue(DEFAULT_PER_PAGE) @ApiParam(name = "per_page", defaultValue = DEFAULT_PER_PAGE, value = DOC_PER_PAGE) final int perPage, @QueryParam("filter") @DefaultValue("") @ApiParam(name = "filter", defaultValue = DEFAULT_FILTER, value = DOC_FILTER) final String filter, @QueryParam("sort") @DefaultValue("") @ApiParam(name = "sort", defaultValue = DEFAULT_SORT, value = DOC_SORT) final String sort, @QueryParam("timezone") @DefaultValue(DEFAULT_TIMEZONE) @ApiParam(name = "timezone", defaultValue = DEFAULT_TIMEZONE, value = DOC_TIMEZONE) final String timezoneOffset) { try { return getLogsForApplication(authorizationHeader, null, page, perPage, filter, sort, timezoneOffset); } catch (Exception exception) { LOGGER.error("getLogsForAllApplications failed for page:{}, perPage={}, filter={}," + " sort={}, timezoneOffset={} with error:", page, perPage, filter, sort, timezoneOffset, exception); throw exception; } } }
AuditLogResource { @GET @Produces(APPLICATION_JSON) @ApiOperation(value = "Returns all logs if the requesting user has SuperAdmin permissions.", notes = "Returns all logs if the requesting user has SuperAdmin permissions. " + "The parameters allow for filtering, sorting, and pagination.", response = Response.class, httpMethod = "GET", produces = "application/json", protocols = "https") @Timed(name = "getLogsForAllApplications") public Response getLogsForAllApplications( @HeaderParam(AUTHORIZATION) @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true) final String authorizationHeader, @QueryParam("page") @DefaultValue(DEFAULT_PAGE) @ApiParam(name = "page", defaultValue = DEFAULT_PAGE, value = DOC_PAGE) final int page, @QueryParam("per_page") @DefaultValue(DEFAULT_PER_PAGE) @ApiParam(name = "per_page", defaultValue = DEFAULT_PER_PAGE, value = DOC_PER_PAGE) final int perPage, @QueryParam("filter") @DefaultValue("") @ApiParam(name = "filter", defaultValue = DEFAULT_FILTER, value = DOC_FILTER) final String filter, @QueryParam("sort") @DefaultValue("") @ApiParam(name = "sort", defaultValue = DEFAULT_SORT, value = DOC_SORT) final String sort, @QueryParam("timezone") @DefaultValue(DEFAULT_TIMEZONE) @ApiParam(name = "timezone", defaultValue = DEFAULT_TIMEZONE, value = DOC_TIMEZONE) final String timezoneOffset) { try { return getLogsForApplication(authorizationHeader, null, page, perPage, filter, sort, timezoneOffset); } catch (Exception exception) { LOGGER.error("getLogsForAllApplications failed for page:{}, perPage={}, filter={}," + " sort={}, timezoneOffset={} with error:", page, perPage, filter, sort, timezoneOffset, exception); throw exception; } } @Inject  AuditLogResource(final AuditLog auditLog, final Authorization authorization,
                     final HttpHeader httpHeader, final PaginationHelper<AuditLogEntry> paginationHelper); }
AuditLogResource { @GET @Produces(APPLICATION_JSON) @ApiOperation(value = "Returns all logs if the requesting user has SuperAdmin permissions.", notes = "Returns all logs if the requesting user has SuperAdmin permissions. " + "The parameters allow for filtering, sorting, and pagination.", response = Response.class, httpMethod = "GET", produces = "application/json", protocols = "https") @Timed(name = "getLogsForAllApplications") public Response getLogsForAllApplications( @HeaderParam(AUTHORIZATION) @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true) final String authorizationHeader, @QueryParam("page") @DefaultValue(DEFAULT_PAGE) @ApiParam(name = "page", defaultValue = DEFAULT_PAGE, value = DOC_PAGE) final int page, @QueryParam("per_page") @DefaultValue(DEFAULT_PER_PAGE) @ApiParam(name = "per_page", defaultValue = DEFAULT_PER_PAGE, value = DOC_PER_PAGE) final int perPage, @QueryParam("filter") @DefaultValue("") @ApiParam(name = "filter", defaultValue = DEFAULT_FILTER, value = DOC_FILTER) final String filter, @QueryParam("sort") @DefaultValue("") @ApiParam(name = "sort", defaultValue = DEFAULT_SORT, value = DOC_SORT) final String sort, @QueryParam("timezone") @DefaultValue(DEFAULT_TIMEZONE) @ApiParam(name = "timezone", defaultValue = DEFAULT_TIMEZONE, value = DOC_TIMEZONE) final String timezoneOffset) { try { return getLogsForApplication(authorizationHeader, null, page, perPage, filter, sort, timezoneOffset); } catch (Exception exception) { LOGGER.error("getLogsForAllApplications failed for page:{}, perPage={}, filter={}," + " sort={}, timezoneOffset={} with error:", page, perPage, filter, sort, timezoneOffset, exception); throw exception; } } @Inject  AuditLogResource(final AuditLog auditLog, final Authorization authorization,
                     final HttpHeader httpHeader, final PaginationHelper<AuditLogEntry> paginationHelper); @GET @Path("/applications/{applicationName}") @Produces(APPLICATION_JSON) @ApiOperation(value = "Returns all logs for the specified application if the requesting user has Admin permissions.", notes = "Returns all logs for the specified application if the requesting user has Admin permissions. " + "The parameters allow for filtering, sorting, and pagination.", response = Response.class, httpMethod = "GET", produces = "application/json", protocols = "https") @Timed(name = "getLogsForApplication") Response getLogsForApplication(
            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authorizationHeader,

            @PathParam("applicationName")
            @ApiParam(value = "Application Name")
            final Application.Name applicationName,

            @QueryParam("page")
            @DefaultValue(DEFAULT_PAGE)
            @ApiParam(name = "page", defaultValue = DEFAULT_PAGE, value = DOC_PAGE)
            final int page,

            @QueryParam("per_page")
            @DefaultValue(DEFAULT_PER_PAGE)
            @ApiParam(name = "per_page", defaultValue = DEFAULT_PER_PAGE, value = DOC_PER_PAGE)
            final int perPage,

            @QueryParam("filter")
            @DefaultValue("")
            @ApiParam(name = "filter", defaultValue = DEFAULT_FILTER, value = DOC_FILTER)
            final String filter,

            @QueryParam("sort")
            @DefaultValue("")
            @ApiParam(name = "sort", defaultValue = DEFAULT_SORT, value = DOC_SORT)
            final String sort,

            @QueryParam("timezone")
            @DefaultValue(DEFAULT_TIMEZONE)
            @ApiParam(name = "timezone", defaultValue = DEFAULT_TIMEZONE, value = DOC_TIMEZONE)
            final String timezoneOffset); @GET @Produces(APPLICATION_JSON) @ApiOperation(value = "Returns all logs if the requesting user has SuperAdmin permissions.", notes = "Returns all logs if the requesting user has SuperAdmin permissions. " + "The parameters allow for filtering, sorting, and pagination.", response = Response.class, httpMethod = "GET", produces = "application/json", protocols = "https") @Timed(name = "getLogsForAllApplications") Response getLogsForAllApplications(
            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authorizationHeader,

            @QueryParam("page")
            @DefaultValue(DEFAULT_PAGE)
            @ApiParam(name = "page", defaultValue = DEFAULT_PAGE, value = DOC_PAGE)
            final int page,

            @QueryParam("per_page")
            @DefaultValue(DEFAULT_PER_PAGE)
            @ApiParam(name = "per_page", defaultValue = DEFAULT_PER_PAGE, value = DOC_PER_PAGE)
            final int perPage,

            @QueryParam("filter")
            @DefaultValue("")
            @ApiParam(name = "filter", defaultValue = DEFAULT_FILTER, value = DOC_FILTER)
            final String filter,

            @QueryParam("sort")
            @DefaultValue("")
            @ApiParam(name = "sort", defaultValue = DEFAULT_SORT, value = DOC_SORT)
            final String sort,

            @QueryParam("timezone")
            @DefaultValue(DEFAULT_TIMEZONE)
            @ApiParam(name = "timezone", defaultValue = DEFAULT_TIMEZONE, value = DOC_TIMEZONE)
            final String timezoneOffset); }
AuditLogResource { @GET @Produces(APPLICATION_JSON) @ApiOperation(value = "Returns all logs if the requesting user has SuperAdmin permissions.", notes = "Returns all logs if the requesting user has SuperAdmin permissions. " + "The parameters allow for filtering, sorting, and pagination.", response = Response.class, httpMethod = "GET", produces = "application/json", protocols = "https") @Timed(name = "getLogsForAllApplications") public Response getLogsForAllApplications( @HeaderParam(AUTHORIZATION) @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true) final String authorizationHeader, @QueryParam("page") @DefaultValue(DEFAULT_PAGE) @ApiParam(name = "page", defaultValue = DEFAULT_PAGE, value = DOC_PAGE) final int page, @QueryParam("per_page") @DefaultValue(DEFAULT_PER_PAGE) @ApiParam(name = "per_page", defaultValue = DEFAULT_PER_PAGE, value = DOC_PER_PAGE) final int perPage, @QueryParam("filter") @DefaultValue("") @ApiParam(name = "filter", defaultValue = DEFAULT_FILTER, value = DOC_FILTER) final String filter, @QueryParam("sort") @DefaultValue("") @ApiParam(name = "sort", defaultValue = DEFAULT_SORT, value = DOC_SORT) final String sort, @QueryParam("timezone") @DefaultValue(DEFAULT_TIMEZONE) @ApiParam(name = "timezone", defaultValue = DEFAULT_TIMEZONE, value = DOC_TIMEZONE) final String timezoneOffset) { try { return getLogsForApplication(authorizationHeader, null, page, perPage, filter, sort, timezoneOffset); } catch (Exception exception) { LOGGER.error("getLogsForAllApplications failed for page:{}, perPage={}, filter={}," + " sort={}, timezoneOffset={} with error:", page, perPage, filter, sort, timezoneOffset, exception); throw exception; } } @Inject  AuditLogResource(final AuditLog auditLog, final Authorization authorization,
                     final HttpHeader httpHeader, final PaginationHelper<AuditLogEntry> paginationHelper); @GET @Path("/applications/{applicationName}") @Produces(APPLICATION_JSON) @ApiOperation(value = "Returns all logs for the specified application if the requesting user has Admin permissions.", notes = "Returns all logs for the specified application if the requesting user has Admin permissions. " + "The parameters allow for filtering, sorting, and pagination.", response = Response.class, httpMethod = "GET", produces = "application/json", protocols = "https") @Timed(name = "getLogsForApplication") Response getLogsForApplication(
            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authorizationHeader,

            @PathParam("applicationName")
            @ApiParam(value = "Application Name")
            final Application.Name applicationName,

            @QueryParam("page")
            @DefaultValue(DEFAULT_PAGE)
            @ApiParam(name = "page", defaultValue = DEFAULT_PAGE, value = DOC_PAGE)
            final int page,

            @QueryParam("per_page")
            @DefaultValue(DEFAULT_PER_PAGE)
            @ApiParam(name = "per_page", defaultValue = DEFAULT_PER_PAGE, value = DOC_PER_PAGE)
            final int perPage,

            @QueryParam("filter")
            @DefaultValue("")
            @ApiParam(name = "filter", defaultValue = DEFAULT_FILTER, value = DOC_FILTER)
            final String filter,

            @QueryParam("sort")
            @DefaultValue("")
            @ApiParam(name = "sort", defaultValue = DEFAULT_SORT, value = DOC_SORT)
            final String sort,

            @QueryParam("timezone")
            @DefaultValue(DEFAULT_TIMEZONE)
            @ApiParam(name = "timezone", defaultValue = DEFAULT_TIMEZONE, value = DOC_TIMEZONE)
            final String timezoneOffset); @GET @Produces(APPLICATION_JSON) @ApiOperation(value = "Returns all logs if the requesting user has SuperAdmin permissions.", notes = "Returns all logs if the requesting user has SuperAdmin permissions. " + "The parameters allow for filtering, sorting, and pagination.", response = Response.class, httpMethod = "GET", produces = "application/json", protocols = "https") @Timed(name = "getLogsForAllApplications") Response getLogsForAllApplications(
            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authorizationHeader,

            @QueryParam("page")
            @DefaultValue(DEFAULT_PAGE)
            @ApiParam(name = "page", defaultValue = DEFAULT_PAGE, value = DOC_PAGE)
            final int page,

            @QueryParam("per_page")
            @DefaultValue(DEFAULT_PER_PAGE)
            @ApiParam(name = "per_page", defaultValue = DEFAULT_PER_PAGE, value = DOC_PER_PAGE)
            final int perPage,

            @QueryParam("filter")
            @DefaultValue("")
            @ApiParam(name = "filter", defaultValue = DEFAULT_FILTER, value = DOC_FILTER)
            final String filter,

            @QueryParam("sort")
            @DefaultValue("")
            @ApiParam(name = "sort", defaultValue = DEFAULT_SORT, value = DOC_SORT)
            final String sort,

            @QueryParam("timezone")
            @DefaultValue(DEFAULT_TIMEZONE)
            @ApiParam(name = "timezone", defaultValue = DEFAULT_TIMEZONE, value = DOC_TIMEZONE)
            final String timezoneOffset);  }