use of alien4cloud.audit.model.AuditConfiguration in project alien4cloud by alien4cloud.
the class AuditController method postConstruct.
@PostConstruct
private void postConstruct() {
AuditConfiguration auditConfiguration = auditService.getAuditConfiguration();
Map<Method, Boolean> allAvailableMethodsForAudit = getAllAvailableMethodsForAudit(requestMappingHandlerMapping);
if (auditConfiguration == null) {
log.info("Generate default configuration for audit");
auditConfiguration = new AuditConfiguration();
} else {
log.info("Try to merge with existing audit configuration");
Map<Method, Boolean> existingMethodsMap = auditConfiguration.getAuditedMethodsMap();
allAvailableMethodsForAudit.putAll(existingMethodsMap);
}
auditConfiguration.setAuditedMethodsMap(allAvailableMethodsForAudit);
auditService.saveAuditConfiguration(auditConfiguration);
}
use of alien4cloud.audit.model.AuditConfiguration in project alien4cloud by alien4cloud.
the class AuditController method enableMethodAudit.
@ApiOperation(value = "Enable/Disable audit on a list of methods", notes = "Audit configuration update is only accessible to user with role [ ADMIN ]")
@RequestMapping(value = "/configuration/audited-methods", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
public RestResponse<Void> enableMethodAudit(@RequestBody AuditedMethod[] methods) {
AuditConfiguration auditConfiguration = auditService.getMandatoryAuditConfiguration();
Map<Method, Boolean> auditedMethodsMap = auditConfiguration.getAuditedMethodsMap();
for (AuditedMethod method : methods) {
enableMethodAudit(auditedMethodsMap, method);
}
auditConfiguration.setAuditedMethodsMap(auditedMethodsMap);
auditService.saveAuditConfiguration(auditConfiguration);
return RestResponseBuilder.<Void>builder().build();
}
use of alien4cloud.audit.model.AuditConfiguration in project alien4cloud by alien4cloud.
the class AuditController method getAuditConfiguration.
@ApiOperation(value = "Get audit configuration", notes = "Get the audit configuration object. Audit configuration is only accessible to user with role [ ADMIN ]")
@RequestMapping(value = "/configuration", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
public RestResponse<AuditConfigurationDTO> getAuditConfiguration() {
AuditConfiguration currentConfiguration = auditService.getMandatoryAuditConfiguration();
boolean auditEnabled = currentConfiguration.isEnabled();
Map<String, List<AuditedMethod>> methodsConfigurationDTO = Maps.newHashMap();
for (AuditedMethod methodDTO : currentConfiguration.getAuditedMethods()) {
List<AuditedMethod> currentMethodsForCategory = methodsConfigurationDTO.get(methodDTO.getCategory());
if (currentMethodsForCategory == null) {
currentMethodsForCategory = Lists.newArrayList();
methodsConfigurationDTO.put(methodDTO.getCategory(), currentMethodsForCategory);
}
currentMethodsForCategory.add(methodDTO);
}
AuditConfigurationDTO auditConfigurationDTO = new AuditConfigurationDTO(auditEnabled, methodsConfigurationDTO);
return RestResponseBuilder.<AuditConfigurationDTO>builder().data(auditConfigurationDTO).build();
}
use of alien4cloud.audit.model.AuditConfiguration in project alien4cloud by alien4cloud.
the class AuditController method generateDefaultConfiguration.
@ApiOperation(value = "Reset the audit configuration", notes = "Reset the audit configuration to its default state. Audit search is only accessible to user with role [ ADMIN ]")
@RequestMapping(value = "/configuration/reset", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
public RestResponse<AuditConfigurationDTO> generateDefaultConfiguration() {
AuditConfiguration auditConfiguration = new AuditConfiguration();
Map<Method, Boolean> allAvailableMethodsForAudit = getAllAvailableMethodsForAudit(requestMappingHandlerMapping);
for (RequestMappingHandlerMapping registeredHandlerMapping : this.registeredRequestMappingHandlerMapping) {
allAvailableMethodsForAudit.putAll(getAllAvailableMethodsForAudit(registeredHandlerMapping));
}
auditConfiguration.setAuditedMethodsMap(allAvailableMethodsForAudit);
auditService.saveAuditConfiguration(auditConfiguration);
return getAuditConfiguration();
}
use of alien4cloud.audit.model.AuditConfiguration in project alien4cloud by alien4cloud.
the class AuditLogFilter method doFilterInternal.
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
AuditConfiguration configuration = auditService.getAuditConfiguration();
if (configuration == null || !configuration.isEnabled()) {
filterChain.doFilter(request, response);
return;
}
User user = AuthorizationUtil.getCurrentUser();
if (user == null) {
filterChain.doFilter(request, response);
return;
}
HandlerMethod method = getHandlerMethod(request);
if (method == null) {
filterChain.doFilter(request, response);
return;
}
if (!auditService.isMethodAudited(configuration, method)) {
filterChain.doFilter(request, response);
return;
}
boolean requestContainsJson = isRequestContainingJson(request);
if (requestContainsJson) {
request = new MultiReadHttpServletRequest(request);
}
try {
filterChain.doFilter(request, response);
} finally {
AuditTrace auditTrace = null;
try {
auditTrace = getAuditTrace(request, response, method, user, requestContainsJson, configuration);
} catch (Exception e) {
logger.warn("Unable to construct audit trace", e);
}
if (auditTrace != null) {
if (logger.isDebugEnabled()) {
logger.debug(auditTrace.toString());
}
try {
auditService.saveAuditTrace(auditTrace);
} catch (Exception e) {
logger.warn("Unable to save audit trace " + auditTrace, e);
}
}
}
}
Aggregations