use of alien4cloud.audit.model.AuditedMethod 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.AuditedMethod 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.AuditedMethod in project alien4cloud by alien4cloud.
the class AuditController method getAllAvailableMethodsForAudit.
private <T extends Method> Map<T, Boolean> getAllAvailableMethodsForAudit(RequestMappingHandlerMapping requestMappingHandlerMapping, IAuditedMethodFactory<T> methodFactory) {
Map<RequestMappingInfo, HandlerMethod> handlerMethods = requestMappingHandlerMapping.getHandlerMethods();
Map<T, Boolean> allMethods = Maps.newHashMap();
for (Map.Entry<RequestMappingInfo, HandlerMethod> handlerMethodEntry : handlerMethods.entrySet()) {
HandlerMethod method = handlerMethodEntry.getValue();
Method auditedMethod = auditService.getAuditedMethod(method);
if (auditedMethod != null) {
Audit audit = method.getMethodAnnotation(Audit.class);
boolean enabledByDefault = audit != null && audit.enabledByDefault();
allMethods.put(methodFactory.buildAuditedMethod(auditedMethod, method), enabledByDefault);
}
}
return allMethods;
}
use of alien4cloud.audit.model.AuditedMethod in project alien4cloud by alien4cloud.
the class AuditController method enableMethodAudit.
private void enableMethodAudit(Map<Method, Boolean> auditedMethodsMap, AuditedMethod method) {
if (method.getMethod() == null) {
throw new InvalidArgumentException("Method's path or http method is null");
}
Method auditedMethodKey = new Method(method.getSignature(), method.getMethod(), method.getCategory(), method.getAction(), method.getBodyHiddenFields());
if (!auditedMethodsMap.containsKey(auditedMethodKey)) {
throw new NotFoundException("Method " + method + " does not exist ");
}
auditedMethodsMap.put(auditedMethodKey, method.isEnabled());
}
use of alien4cloud.audit.model.AuditedMethod in project alien4cloud by alien4cloud.
the class AuditLogStepsDefinitions method enableMethods.
private void enableMethods(DataTable rawMethods, boolean enable) throws IOException {
List<AuditedMethod> methodsToEnableDisable = Lists.newArrayList();
for (List<String> row : rawMethods.raw()) {
String category = row.get(0);
String action = row.get(1);
AuditedMethod method = getMethod(currentAuditConfiguration.getMethodsConfiguration().get(category), action, !enable);
method.setEnabled(enable);
Assert.assertNotNull(method);
methodsToEnableDisable.add(method);
}
Context.getRestClientInstance().postJSon("/rest/v1/audit/configuration/audited-methods", JsonUtil.toString(methodsToEnableDisable));
}
Aggregations