1 /* 2 * Copyright (c) 2002-2022, City of Paris 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright notice 10 * and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright notice 13 * and the following disclaimer in the documentation and/or other materials 14 * provided with the distribution. 15 * 16 * 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its 17 * contributors may be used to endorse or promote products derived from 18 * this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE 24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 * 32 * License 1.0 33 */ 34 package fr.paris.lutece.portal.service.security; 35 36 import fr.paris.lutece.api.user.User; 37 import fr.paris.lutece.portal.service.spring.SpringContextService; 38 import java.util.List; 39 40 /** 41 * Access Log service 42 * 43 * - Report all actions regarding authentication, user or rights management. - All messages should contain the application Id, the event type, a specific 44 * application event code, the logged user, and specific contextual data. - The logger should implement the interface IAccessLogger of lutece core 45 * 46 * Use "debug" or "trace" level for fine access control history, use "info" level otherwise 47 * 48 * By default : - Lutece authentication, user and rights management are logged at INFO level, - action requests at DEBUG level, - views requests are logged at 49 * TRACE level. 50 * 51 * To log specific actions, use : 52 * 53 * AccessLogService.getInstance( ).warn( String strEventType, String strAppEventCode, String strConnectedUserLogin, Object data ); AccessLogService.getInstance( 54 * ).info( String strEventType, String strAppEventCode, String strConnectedUserLogin, Object data ); AccessLogService.getInstance( ).debug( String strEventType, 55 * String strAppEventCode, String strConnectedUserLogin, Object data ); AccessLogService.getInstance( ).trace( String strEventType, String strAppEventCode, 56 * String strConnectedUserLogin, Object data ); 57 * 58 * Event types are available in AccessLoggerConstants class. 59 * 60 */ 61 public final class AccessLogService 62 { 63 // constants 64 public static final String ACCESS_LOG_FO = "fo"; 65 public static final String ACCESS_LOG_BO = "bo"; 66 67 private final List<IAccessLogger> _accessLoggerList; 68 private static AccessLogServiceity/AccessLogService.html#AccessLogService">AccessLogService _singleton = new AccessLogService( ); 69 70 /** 71 * Creates a new AppLogService object. 72 */ 73 private AccessLogService( ) 74 { 75 _accessLoggerList = SpringContextService.getBeansOfType( IAccessLogger.class ); 76 } 77 78 /** 79 * Get the unique instance of the Service 80 * 81 * @return The instance 82 */ 83 public static AccessLogService getInstance( ) 84 { 85 return _singleton; 86 } 87 88 /** 89 * Log action with info level 90 * 91 * @param strEventType 92 * the event type 93 * @param strAppEventCode 94 * the event code 95 * @param connectedUser 96 * the user connected 97 * @param data 98 * the message object to log 99 * @param specificOrigin 100 * specific origin of the event to log 101 */ 102 public void info( String strEventType, String strAppEventCode, User connectedUser, Object data, String specificOrigin ) 103 { 104 _accessLoggerList.forEach( accessLogger -> { 105 accessLogger.info( strEventType, strAppEventCode, connectedUser, data, specificOrigin ); 106 } ); 107 } 108 109 /** 110 * Log action with info level 111 * 112 * @param strEventType 113 * the event type 114 * @param strAppEventCode 115 * the event code 116 * @param connectedUser 117 * the user connected 118 * @param data 119 * the message object to log 120 */ 121 public void info( String strEventType, String strAppEventCode, User connectedUser, Object data ) 122 { 123 info( strEventType, strAppEventCode, connectedUser, data, null ); 124 } 125 126 /** 127 * Log action with Debug level 128 * 129 * @param strEventType 130 * @param strAppEventCode 131 * @param connectedUser 132 * @param data 133 * @param specificOrigin 134 */ 135 public void debug( String strEventType, String strAppEventCode, User connectedUser, Object data, String specificOrigin ) 136 { 137 _accessLoggerList.forEach( accessLogger -> { 138 accessLogger.debug( strEventType, strAppEventCode, connectedUser, data, specificOrigin ); 139 } ); 140 } 141 142 /** 143 * Log action with Debug level 144 * 145 * @param strEventType 146 * @param strAppEventCode 147 * @param connectedUser 148 * @param data 149 */ 150 public void debug( String strEventType, String strAppEventCode, User connectedUser, Object data ) 151 { 152 debug( strEventType, strAppEventCode, connectedUser, data, null ); 153 } 154 155 /** 156 * Log action with trace level 157 * 158 * @param strEventType 159 * @param strAppEventCode 160 * @param connectedUser 161 * @param data 162 * @param specificOrigin 163 */ 164 public void trace( String strEventType, String strAppEventCode, User connectedUser, Object data, String specificOrigin ) 165 { 166 _accessLoggerList.forEach( accessLogger -> { 167 accessLogger.trace( strEventType, strAppEventCode, connectedUser, data, specificOrigin ); 168 } ); 169 } 170 171 /** 172 * Log action with trace level 173 * 174 * @param strEventType 175 * @param strAppEventCode 176 * @param connectedUser 177 * @param data 178 */ 179 public void trace( String strEventType, String strAppEventCode, User connectedUser, Object data ) 180 { 181 trace( strEventType, strAppEventCode, connectedUser, data, null ); 182 } 183 184 /** 185 * Log action with warn level 186 * 187 * @param strEventType 188 * @param strAppEventCode 189 * @param connectedUser 190 * @param data 191 * @param specificOrigin 192 */ 193 public void warn( String strEventType, String strAppEventCode, User connectedUser, Object data, String specificOrigin ) 194 { 195 _accessLoggerList.forEach( accessLogger -> { 196 accessLogger.warn( strEventType, strAppEventCode, connectedUser, data, specificOrigin ); 197 } ); 198 } 199 200 /** 201 * Log action with warn level 202 * 203 * @param strEventType 204 * @param strAppEventCode 205 * @param connectedUser 206 * @param data 207 */ 208 public void warn( String strEventType, String strAppEventCode, User connectedUser, Object data ) 209 { 210 warn( strEventType, strAppEventCode, connectedUser, data, null ); 211 } 212 213 }