All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dnastack.audit.util.AuditIgnore Maven / Gradle / Ivy

package com.dnastack.audit.util;


import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * {@code @AuditIgnore} can be used to ensure that only parts of a class are logged. Annotating a field or getter method
 * "hides" that value only in the audit logger, meaning it is safe to add the {@code @AuditIgnore} annotation to your
 * domain models. This is useful when you want to log some of the class's fields but not all of it, or you want to hide
 * sensitive values from being logged.
 * 

* The following {@code User} class has one property and one method annotated with {@code AuditIgnore}. If this class * was added to an {@code AuditEventBody}, both the {@code sinNumber} and {@code password} fields will be ignored and * will not show up in the resulting log. However, the {@code firstName, lastName and dob}, fields will be logged. *

*

 *     @Data
 *     public static class User {
 *
 *        private String firstName;
 *        private String lastName;
 *        private String dob;
 *        private String sinNumber;
 *
 *        @AuditIgnore
 *        private String password
 *
 *        @AuditIgnore
 *        public String getSinNumber(){ return sinNumber }
 *     }
 * 
* * When using the spring-boot-audit-logger library, {@code @AuditIgnore} is used to signal that a specific element * should be ignored by the com.dnastack.audit.aspect.AuditEventLogAspect class in that library. The specific behaviour * triggered by the annotation depends on * what is annotated. *

* When {@code @AuditIgnore} is used on a class annotated with org.springframework.web.bind.annotation.RestController. * all audit logging using the com.dnastack.audit.aspect.AuditEventLogAspect will be disabled for that class. * Similarly, any controller method within a {@code @RestConroller} class, (that is methods annotated with * {@code @RequestMapping, @GetMapping, @PostMapping etc}) will be ignored by the com.dnastack.audit.aspect.AuditEventLogAspect. * Both of these approaches essentially "turn off" auto audting for the controller methods. Auditing may still be * achieved by injecting an instance of the {@link com.dnastack.audit.logger.AuditEventLogger} into the target class * logging a custom event. *

* {@code @AuditIgnore} can additionally be used to annotate the method parameters of controller methods. When used in * this way, the Audit logger will not include the annotated parameter in the {@code extraArgmuments} map which it * writes in the {@code AuditEventBody}. The following example would ensure the {@code apiToken} passed as a query * parameter in the request would not get logged to the audit event * *

*

 *     @GetMapping("/")
 *     public Response getObjects(@AuditIgnore @RequestParam String apiToken, Long pageSize)
 * 
*

*/ @Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.TYPE, ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD }) public @interface AuditIgnore { }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy