001/* 002 * Copyright 2012-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.boot.actuate.audit.listener; 018 019import java.time.Instant; 020import java.util.Map; 021 022import org.springframework.boot.actuate.audit.AuditEvent; 023import org.springframework.context.ApplicationEvent; 024import org.springframework.util.Assert; 025 026/** 027 * Spring {@link ApplicationEvent} to encapsulate {@link AuditEvent}s. 028 * 029 * @author Dave Syer 030 */ 031public class AuditApplicationEvent extends ApplicationEvent { 032 033 private final AuditEvent auditEvent; 034 035 /** 036 * Create a new {@link AuditApplicationEvent} that wraps a newly created 037 * {@link AuditEvent}. 038 * @param principal the principal 039 * @param type the event type 040 * @param data the event data 041 * @see AuditEvent#AuditEvent(String, String, Map) 042 */ 043 public AuditApplicationEvent(String principal, String type, 044 Map<String, Object> data) { 045 this(new AuditEvent(principal, type, data)); 046 } 047 048 /** 049 * Create a new {@link AuditApplicationEvent} that wraps a newly created 050 * {@link AuditEvent}. 051 * @param principal the principal 052 * @param type the event type 053 * @param data the event data 054 * @see AuditEvent#AuditEvent(String, String, String...) 055 */ 056 public AuditApplicationEvent(String principal, String type, String... data) { 057 this(new AuditEvent(principal, type, data)); 058 } 059 060 /** 061 * Create a new {@link AuditApplicationEvent} that wraps a newly created 062 * {@link AuditEvent}. 063 * @param timestamp the timestamp 064 * @param principal the principal 065 * @param type the event type 066 * @param data the event data 067 * @see AuditEvent#AuditEvent(Instant, String, String, Map) 068 */ 069 public AuditApplicationEvent(Instant timestamp, String principal, String type, 070 Map<String, Object> data) { 071 this(new AuditEvent(timestamp, principal, type, data)); 072 } 073 074 /** 075 * Create a new {@link AuditApplicationEvent} that wraps the specified 076 * {@link AuditEvent}. 077 * @param auditEvent the source of this event 078 */ 079 public AuditApplicationEvent(AuditEvent auditEvent) { 080 super(auditEvent); 081 Assert.notNull(auditEvent, "AuditEvent must not be null"); 082 this.auditEvent = auditEvent; 083 } 084 085 /** 086 * Get the audit event. 087 * @return the audit event 088 */ 089 public AuditEvent getAuditEvent() { 090 return this.auditEvent; 091 } 092 093}