Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audit Log Service - /v1/events endpoint implementation #540

Merged
merged 17 commits into from
Jun 26, 2020

Conversation

dhanyak-btc
Copy link
Contributor

@dhanyak-btc dhanyak-btc commented Jun 22, 2020

  1. Moved HealthController class to common-service module
  2. Used everit-org JSON Schema validator (Apache 2.0 license) for event request validation.
  3. Used JSoup (MIT license) to extract the error response details from RestClientResponseException thrown by tomcat server
  4. Added Spring Boot Actuator to view the log file when deployed to DEV/QA environment and the mapping details. This will help during deployment and while integrating the APIs.
  5. Implemented /v1/events endpoint
  6. Added token introspection filter and common exception handler for filters in common-service.

Moved filters and health controller to common-service, added actuator, added JSoup to extract error message from Html etc
convert xpath to json path
minor refactoring and removed unused getEncodedAuthorization() from BaseServiceImpl
Added getUriTemplateAndHttpMethodsMap() abstract method to BaseTokenIntrospectionFilter
Removed unused method: getEventInfo() from AuditLogEventEntity
@googlebot googlebot added the cla: yes Do not use - reserved for devops label Jun 22, 2020
"properties": {
"alert": {
"type": "boolean"
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is alert used for? and why is it required.

Copy link
Contributor Author

@dhanyak-btc dhanyak-btc Jun 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stores the value of Alert flag. I'll request Shanthala to connect with you to discuss on Audit Log Event fields & requirements.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file no longer in use. Replaced json schema with validation annotations.

Fixed PR#540 comments
Copy link
Contributor

@nikklassen nikklassen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR could've been split into OAuth code, followed by AuditLog code, to make it easier to review.

ErrorResponse err = new ErrorResponse(url, e);
return ResponseEntity.status(e.getRawStatusCode()).body(err);
}
return restTemplate.exchange(url, method, requestEntity, JsonNode.class, uriVariables);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid wrapping one-liners.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you. Initially this method had try..catch block but now exception handling moved to RestExceptionHandler and FilterChainExceptionHandler so this method became one-liners.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case that mean you don't need BaseServiceImpl anymore. The AuditLogEventService isn't doing anything with the methods anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you, but I've already implemented the Service classes using these methods. We'll keep this class.

Fixed PR review comments
Removed JSoup, Json Schema validator dependencies.
Added server-side validation using validation annotations,
Added ErrorController, GlobalExceptionHandler, ValidationErrorResponse and AuditLogEventRequest to common-service module
Added jsonassert dependency to assert json values.
Added logger statements to GlobalExceptionHandler
Moved AuditLogEventResponse to common-service module
Deleted postman collection
Added @ToString.Exclude to entity class
Removed params from logger.entry
@nikklassen
Copy link
Contributor

Fixes #551

Copy link
Contributor

@nikklassen nikklassen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just a few small things.

Fixed Imports and Removed beans, request/response from logger statements
Changed the column definition to TIMESTAMP for eventTimestamp and createdTimestamp in AuditLogEventEntity class.

Added javdocs to eventTimestamp in AuditLogEventRequest
Removed  @SuppressWarnings("rawtypes")
Changed log level to trace in handleConstraintValidationException() method
Copy link
Contributor

@zohrehj zohrehj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, added some suggestions; some need to be addressed at some point but nothing immediately concerning.

insertable = false,
updatable = false,
columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
private Timestamp createdTimestamp;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Google API guideline suggests calling these timestamp columns simply:
created, modified etc

Copy link
Contributor Author

@dhanyak-btc dhanyak-btc Jun 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This link has different naming convention. Please share the Google API guideline link to refer. Renamed both column and property name to 'created', it'll be pushed for review in next PR.

nullable = false,
updatable = false,
columnDefinition = "TIMESTAMP")
private Timestamp eventTimestamp;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be renamed to occured maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed both column and property name to 'occured', it'll be pushed for review in next PR.


class ApplicationTest extends BaseMockIT {

@Autowired HealthController controller;
@Autowired AuditLogEventController controller;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add back the healthcheck test as well. It should assert that the response status is 200

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added assertNotNull(healthController); in this Test. There is already a HealthControllerTest that assert response status is 200. This will be pushed for review in next PR.

"status=%d and response=%s",
healthResponse.getStatusCodeValue(), healthResponse.getBody()));
return healthResponse;
return oauthService.health();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this method calling oauthservice.health()?

Ideally it should just return a 200 status.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I referred Monitoring Microservices With Health Checks, all services in our project requires token introspection so added downstream services in /healthCheck endpoint. I've changed to code to returns always OK. This will be pushed for review in next PR. Thanks a lot for approving the PR #540.

@@ -0,0 +1,18 @@
{
"request": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: indentation should probably be 2 spaces to be consistent with other files.

@dhanyak-btc dhanyak-btc merged commit 7e74896 into early-access Jun 26, 2020
@zohrehj zohrehj deleted the auditlog-events-endpoint branch July 7, 2020 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Do not use - reserved for devops
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants