Slf4jLogAuditLogger.java

  1. /*
  2.  * Copyright 2018 Global Crop Diversity Trust
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  *   http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  */

  16. package org.genesys.blocks.security.component;

  17. import org.springframework.security.acls.domain.AuditLogger;
  18. import org.springframework.security.acls.model.AccessControlEntry;
  19. import org.springframework.security.acls.model.AuditableAccessControlEntry;

  20. import lombok.extern.slf4j.Slf4j;

  21. /**
  22.  * The Class Slf4jLogAuditLogger.
  23.  */
  24. @Slf4j
  25. public class Slf4jLogAuditLogger implements AuditLogger {

  26.     /*
  27.      * (non-Javadoc)
  28.      * @see
  29.      * org.springframework.security.acls.domain.AuditLogger#logIfNeeded(boolean,
  30.      * org.springframework.security.acls.model.AccessControlEntry)
  31.      */
  32.     @Override
  33.     public void logIfNeeded(final boolean granted, final AccessControlEntry ace) {
  34.         if (ace instanceof AuditableAccessControlEntry) {
  35.             final AuditableAccessControlEntry auditableAce = (AuditableAccessControlEntry) ace;

  36.             if (granted && auditableAce.isAuditSuccess()) {
  37.                 log.debug("GRANTED due to ACE: " + ace);
  38.             } else if (!granted && auditableAce.isAuditFailure()) {
  39.                 log.debug("DENIED due to ACE: " + ace);
  40.             }
  41.         }
  42.     }
  43. }