Auditoría

La auditoría es una core módulo que puede ser habilitado configurando la siguiente propiedad:

ipf.business-operations.audit.enabled = true

Para auditar un método, usted necesita añadir el @Auditable anotación a la firma del método. La anotación toma un parámetro llamado type que indica la acción que usted está auditando.

Ejemplo:

@GetMapping("auth/basic")
@Auditable(type = "LOGIN_BASIC")
public void loginBasic() {}

Un registro de auditoría consiste en los siguientes campos de datos:

public class AuditRecord {
    @Id
    String id;
    String userId;
    String clientIpAddress;
    String processingEntity;
    String transactionId;
    String action;
    Instant time;
    Map<String, Object> request;
    Map<String, Object> response;
}

Para poder poblar el mapa de solicitud y respuesta, usted debe implementar un AuditRequestExtractor y un AuditResponseExtractor respectivamente:

import java.util.Map;
import java.util.Set;

/**
 * This class can be extended to implement a custom request extractor for a particular
 * type of audited method.
 */
public interface AuditRequestExtractor {
    /**
     * Return the extractor type that should match the corresponding
     * @Auditable types
     *
     * @return The types of extractor
     */
    Set<String> types();

    /**
     * Here you can extract the fields from the request parameters
     * you would like to be audited
     *
     * @param args The method arguments from the annotated method
     * @return A map representing the key value params extracted from the request method arguments
     */
    Map<String, Object> extractRequestData(Object[] args);
}
import java.util.Map;
import java.util.Set;

/**
 * This class can be extended to implement a custom response extractor for a particular
 * type of audited method.
 */
public interface AuditResponseExtractor {
    /**
     * Return the extractor type that should match the corresponding
     * @Auditable types
     *
     * @return The type of extractor
     */
    Set<String> types();

    /**
     * Here you can extract the fields from the response message
     * you would like to be audited
     *
     * @param responseData The response data from the annotated method
     * @return A map representing the key value params extracted from the response
     */
    Map<String, Object> extractResponseData(Object responseData);
}

El tipo del extractor debe coincidir con el tipo @Auditable anotado para que sepamos qué extractor utilizar para el método auditado. Se pueden definir múltiples extractores para cubrir todos los tipos auditados. Por defecto, no se extraen campos a menos que usted implemente un custom extractor.

Custom Tipos

A veces no es posible utilizar la anotación para cosas como SAML/OAUTH que requieren un procesamiento especial. En estos tipos de casos, es posible registrar custom tipos de acción que luego aparecerán como tipos de acción en la interfaz de usuario para fines de filtrado. Para hacer esto, registre un bean de tipo CustomAuditable que devuelve un conjunto de cadenas que representan los tipos de acción.

Ejemplo:

@Bean
public CustomAuditable getCustomAuthAuditables(SamlProperties samlProperties, OAuthProperties oAuthProperties) {
    return new CustomAuditable() {
        @Override
        public Set<String> actionTypes() {
            Set<String> actionTypes = new HashSet<>();
            if(samlProperties.isEnabled()) {
                actionTypes.add("SAML_LOGIN_SUCCESS");
                actionTypes.add("SAML_LOGIN_FAILURE");
            }
            if(oAuthProperties.isEnabled()) {
                actionTypes.add("OAUTH_LOGIN_SUCCESS");
                actionTypes.add("OAUTH_LOGIN_FAILURE");
            }
            return actionTypes;
        }
    };
}