Giter VIP home page Giter VIP logo

log4j2-masking-policy's Introduction

Log4j2 Masking Policy

A Log4j2 Rewrite policy to mask sensitive data in XML and JSON.

Installation

Add the following dependency to the project:

<dependency>
    <groupId>com.mariocairone</groupId>
    <artifactId>log4j2-masking-policy</artifactId>
    <version>1.0.2</version>
</dependency>

Configuration

MaskPolicies

Wrapper for one or more MaskPolicy elements.

Converters

Wrapper for one or more Converter elements.

Converter

Convert are used to transform the log4j2 Message into string before masking and convert the masked string back to log4j2 Message. The Converter class must implement the MessageConverter interface.

attribute values description required
className Fully qualified class name Specify formatter class true
Example
    ...
    <MaskPolicies>
        <Converters>
            <Converter className="com.mycompany.MyMessageConverter" />
        </Converters>
        <MaskPolicy type="JSON" enabled="true"> 
            <Exclusions>
                <Exclusion value="$.store.book[*].author" />
            </Exclusions>
        </MaskPolicy>				
    </MaskPolicies>
    ...        

MaskPolicy

attribute values description required
type XML/JSON Specify the type of Masker true
enabled true/false Enable or disable the masking false

Exclusions

Wrapper for one or more Exlusion elements.

Exclusion

Specify the element that shouldn't be masked. The value attribute can be a simple string or a path. If a single string is specified, all the nodes/elements/attributes having that string as key/name will not be masked.

JSON
attribute MaskPolicyType values required
value JSON String/JsonPath true
Example
    ...
    <MaskPolicies>
        <MaskPolicy type="JSON" enabled="true"> 
            <Exclusions>
                <Exclusion value="$.name" />
            </Exclusions>
        </MaskPolicy>				
    </MaskPolicies>
    ...        
XML
attribute values description
value XPath Specify the elements that shouldn't be masked
Example
    ...
    <MaskPolicies>
        <MaskPolicy type="XML" > 
            <Exclusions>
                <Exclusion value="/customer/order[1]" />
            </Exclusions>
        </MaskPolicy>				
    </MaskPolicies>
    ...        

Log4j2 Complete Configuration Example

Below is an example of log4j2 configuration file.

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="debug" packages="com.mariocairone.log4j2">

    <Appenders>
        
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout   pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n" />
        </Console>

        <Rewrite name="REWRITE">
            <AppenderRef ref="Console" />
            <MaskPolicies>
                <MaskPolicy type="JSON" enabled="true"> 
                    <Exclusions>
                        <Exclusion value="$.name" />
                    </Exclusions>
                </MaskPolicy>				
            </MaskPolicies>
        </Rewrite>   

    </Appenders>

    <Loggers>
        <Root level="debug" additivity="false">
            <appender-ref ref="Console" />
        </Root>
    </Loggers>

</Configuration>

Note: the package com.mariocairone.log4j2 must be added in the log4j2 configuration file.

log4j2-masking-policy's People

Contributors

dependabot[bot] avatar mariocairone avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

suraj1110 shyding

log4j2-masking-policy's Issues

Converts should be optional

The Converters element and its child should be completely optional, but when not provided the policy fails to start

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.