Search in sources :

Example 1 with AuditConfiguration

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);
}
Also used : AuditConfiguration(alien4cloud.audit.model.AuditConfiguration) Method(alien4cloud.audit.model.Method) AuditedMethod(alien4cloud.audit.model.AuditedMethod) HandlerMethod(org.springframework.web.method.HandlerMethod) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) PostConstruct(javax.annotation.PostConstruct)

Example 2 with 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();
}
Also used : AuditConfiguration(alien4cloud.audit.model.AuditConfiguration) AuditedMethod(alien4cloud.audit.model.AuditedMethod) Method(alien4cloud.audit.model.Method) AuditedMethod(alien4cloud.audit.model.AuditedMethod) HandlerMethod(org.springframework.web.method.HandlerMethod) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with AuditConfiguration

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();
}
Also used : AuditConfiguration(alien4cloud.audit.model.AuditConfiguration) AuditedMethod(alien4cloud.audit.model.AuditedMethod) List(java.util.List) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with AuditConfiguration

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();
}
Also used : AuditConfiguration(alien4cloud.audit.model.AuditConfiguration) Method(alien4cloud.audit.model.Method) AuditedMethod(alien4cloud.audit.model.AuditedMethod) HandlerMethod(org.springframework.web.method.HandlerMethod) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) RequestMappingHandlerMapping(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with AuditConfiguration

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);
            }
        }
    }
}
Also used : AuditConfiguration(alien4cloud.audit.model.AuditConfiguration) User(alien4cloud.security.model.User) AuditTrace(alien4cloud.audit.model.AuditTrace) HandlerMethod(org.springframework.web.method.HandlerMethod) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Aggregations

AuditConfiguration (alien4cloud.audit.model.AuditConfiguration)7 AuditedMethod (alien4cloud.audit.model.AuditedMethod)5 HandlerMethod (org.springframework.web.method.HandlerMethod)5 Method (alien4cloud.audit.model.Method)4 ApiOperation (io.swagger.annotations.ApiOperation)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 RequestMethod (org.springframework.web.bind.annotation.RequestMethod)4 AuditTrace (alien4cloud.audit.model.AuditTrace)1 User (alien4cloud.security.model.User)1 IOException (java.io.IOException)1 List (java.util.List)1 PostConstruct (javax.annotation.PostConstruct)1 ServletException (javax.servlet.ServletException)1 RequestMappingHandlerMapping (org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping)1