Package org.apache.solr.security
Class AuditEvent
- java.lang.Object
-
- org.apache.solr.security.AuditEvent
-
public class AuditEvent extends Object
Audit event that takes request and auth context as input to be able to audit log custom things. This interface may change in next release and is marked experimental- Since:
- 8.1.0
- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AuditEvent.EventType
static class
AuditEvent.Level
static class
AuditEvent.RequestType
-
Constructor Summary
Constructors Modifier Constructor Description protected
AuditEvent()
AuditEvent(AuditEvent.EventType eventType)
Empty event, must be filled by user using setters.AuditEvent(AuditEvent.EventType eventType, Throwable exception, javax.servlet.http.HttpServletRequest httpRequest)
Event based on an HttpServletRequest, typically used during authentication.AuditEvent(AuditEvent.EventType eventType, javax.servlet.http.HttpServletRequest httpRequest)
AuditEvent(AuditEvent.EventType eventType, javax.servlet.http.HttpServletRequest httpRequest, AuthorizationContext authorizationContext)
Event based on request and AuthorizationContext.AuditEvent(AuditEvent.EventType eventType, javax.servlet.http.HttpServletRequest httpRequest, AuthorizationContext authorizationContext, double qTime, Throwable exception)
Event to log completed requests.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description AuthorizationResponse
getAutResponse()
The authorization response object from authorization plugin, or null authz has not happenedString
getBaseUrl()
First part of URL of the request, but not including request parameters, or null if not setString
getClientIp()
IP address of the client doing the requestList<String>
getCollections()
List of collection names involved in requestMap<String,Object>
getContext()
A general purpose context map with potential extra information about the eventDate
getDate()
Date that the event happenedAuditEvent.EventType
getEventType()
EventType tells the outcome of the event such as REJECTED, UNAUTHORIZED or ERRORThrowable
getException()
In case of ERROR event, find the exception causing the errorMap<String,String>
getHeaders()
Map of all HTTP request headers belonging to the requestString
getHttpMethod()
The HTTP method.String
getHttpQueryString()
Query part of URL or null if query partAuditEvent.Level
getLevel()
Level of this event.String
getMessage()
The human readable message about this eventString
getNodeName()
Node name of Solr node, on the internal format host:port_context, e.g.double
getQTime()
Request time in milliseconds for completed requestsAuditEvent.RequestType
getRequestType()
Determines the type of request.StringBuffer
getRequestUrl()
Deprecated.Please usegetBaseUrl()
insteadString
getResource()
Identifies the resource being operated on.String
getSession()
Session identifierString
getSolrHost()
Host name of the Solr node logging the eventString
getSolrIp()
IP address of the Solr node logging the eventString
getSolrParamAsString(String key)
Gets first value of a certain Solr request parameterMap<String,List<String>>
getSolrParams()
Map of all Solr request parameters attached to the request.int
getSolrPort()
Port number of the Solr node logging the eventint
getStatus()
HTTP status code of event, i.e.String
getUrl()
Full URL of the original request.String
getUsername()
Username of logged in user, or null if no authenticated userprotected String
normalizeResourcePath(String resourcePath)
AuditEvent
setAutResponse(AuthorizationResponse autResponse)
AuditEvent
setBaseUrl(String baseUrl)
AuditEvent
setClientIp(String clientIp)
AuditEvent
setCollections(List<String> collections)
AuditEvent
setContext(Map<String,Object> context)
AuditEvent
setContextEntry(String key, Object value)
AuditEvent
setDate(Date date)
AuditEvent
setException(Throwable exception)
AuditEvent
setHeaders(Map<String,String> headers)
AuditEvent
setHttpMethod(String httpMethod)
AuditEvent
setHttpQueryString(String httpQueryString)
AuditEvent
setLevel(AuditEvent.Level level)
AuditEvent
setMessage(String message)
AuditEvent
setQTime(double qTime)
AuditEvent
setRequestType(AuditEvent.RequestType requestType)
AuditEvent
setResource(String resource)
AuditEvent
setSession(String session)
AuditEvent
setSolrHost(String solrHost)
AuditEvent
setSolrIp(String solrIp)
AuditEvent
setSolrParams(Map<String,List<String>> solrParams)
AuditEvent
setSolrPort(int solrPort)
AuditEvent
setStatus(int status)
AuditEvent
setUsername(String username)
-
-
-
Constructor Detail
-
AuditEvent
public AuditEvent(AuditEvent.EventType eventType)
Empty event, must be filled by user using setters. Message and Loglevel will be initialized from EventType but can be overridden with setters afterwards.- Parameters:
eventType
- a predefined or custom EventType
-
AuditEvent
public AuditEvent(AuditEvent.EventType eventType, javax.servlet.http.HttpServletRequest httpRequest)
-
AuditEvent
protected AuditEvent()
-
AuditEvent
public AuditEvent(AuditEvent.EventType eventType, Throwable exception, javax.servlet.http.HttpServletRequest httpRequest)
Event based on an HttpServletRequest, typically used during authentication. Solr will fill in details such as ip, http method etc from the request, and username if Principal exists on the request.- Parameters:
eventType
- a predefined or custom EventTypehttpRequest
- the request to initialize from
-
AuditEvent
public AuditEvent(AuditEvent.EventType eventType, javax.servlet.http.HttpServletRequest httpRequest, AuthorizationContext authorizationContext)
Event based on request and AuthorizationContext. Solr will fill in details such as collections, ip, http method etc from the context.- Parameters:
eventType
- a predefined or custom EventTypehttpRequest
- the request to initialize fromauthorizationContext
- the context to initialize from
-
AuditEvent
public AuditEvent(AuditEvent.EventType eventType, javax.servlet.http.HttpServletRequest httpRequest, AuthorizationContext authorizationContext, double qTime, Throwable exception)
Event to log completed requests. Takes time and status. Solr will fill in details such as collections, ip, http method etc from the HTTP request and context.- Parameters:
eventType
- a predefined or custom EventTypehttpRequest
- the request to initialize fromauthorizationContext
- the context to initialize fromqTime
- query timeexception
- exception from query response, or null if OK
-
-
Method Detail
-
getMessage
public String getMessage()
The human readable message about this event
-
getLevel
public AuditEvent.Level getLevel()
Level of this event. Can be INFO, WARN or ERROR- Returns:
AuditEvent.Level
enum
-
getDate
public Date getDate()
Date that the event happened
-
getUsername
public String getUsername()
Username of logged in user, or null if no authenticated user
-
getSession
public String getSession()
Session identifier
-
getClientIp
public String getClientIp()
IP address of the client doing the request
-
getContext
public Map<String,Object> getContext()
A general purpose context map with potential extra information about the event
-
getResource
public String getResource()
Identifies the resource being operated on. This is not the same as URL path. For queries the resource is relative to collection name, e.g. /select or /update. For other events the resource may be /api/node/health or /admin/collection
-
getHttpMethod
public String getHttpMethod()
The HTTP method. E.g. GET, POST, PUT
-
getHttpQueryString
public String getHttpQueryString()
Query part of URL or null if query part
-
getEventType
public AuditEvent.EventType getEventType()
EventType tells the outcome of the event such as REJECTED, UNAUTHORIZED or ERROR- Returns:
AuditEvent.EventType
enum
-
getSolrHost
public String getSolrHost()
Host name of the Solr node logging the event
-
getSolrIp
public String getSolrIp()
IP address of the Solr node logging the event
-
getSolrPort
public int getSolrPort()
Port number of the Solr node logging the event
-
getHeaders
public Map<String,String> getHeaders()
Map of all HTTP request headers belonging to the request
-
getSolrParams
public Map<String,List<String>> getSolrParams()
Map of all Solr request parameters attached to the request. Pulled from url
-
getSolrParamAsString
public String getSolrParamAsString(String key)
Gets first value of a certain Solr request parameter- Parameters:
key
- name of request parameter to retrieve- Returns:
- String value of the first value, regardless of number of valies
-
getAutResponse
public AuthorizationResponse getAutResponse()
The authorization response object from authorization plugin, or null authz has not happened
-
getNodeName
public String getNodeName()
Node name of Solr node, on the internal format host:port_context, e.g. 10.0.0.1:8983_solr
-
getRequestType
public AuditEvent.RequestType getRequestType()
Determines the type of request. Can be ADMIN, SEARCH, UPDATE, STREAMING, UNKNOWN- Returns:
AuditEvent.RequestType
enum
-
getStatus
public int getStatus()
HTTP status code of event, i.e. 200 = OK, 401 = unauthorized
-
getQTime
public double getQTime()
Request time in milliseconds for completed requests
-
getException
public Throwable getException()
In case of ERROR event, find the exception causing the error
-
getRequestUrl
@Deprecated public StringBuffer getRequestUrl()
Deprecated.Please usegetBaseUrl()
insteadGet baseUrl as StringBuffer for back compat with previous version- Returns:
- StringBuffer of the base url without query part
-
getUrl
public String getUrl()
Full URL of the original request. This isbaseUrl
+ "?" +httpQueryString
. Returns null if not set
-
getBaseUrl
public String getBaseUrl()
First part of URL of the request, but not including request parameters, or null if not set
-
setBaseUrl
public AuditEvent setBaseUrl(String baseUrl)
-
setSession
public AuditEvent setSession(String session)
-
setClientIp
public AuditEvent setClientIp(String clientIp)
-
setContext
public AuditEvent setContext(Map<String,Object> context)
-
setContextEntry
public AuditEvent setContextEntry(String key, Object value)
-
setMessage
public AuditEvent setMessage(String message)
-
setLevel
public AuditEvent setLevel(AuditEvent.Level level)
-
setDate
public AuditEvent setDate(Date date)
-
setUsername
public AuditEvent setUsername(String username)
-
setCollections
public AuditEvent setCollections(List<String> collections)
-
setResource
public AuditEvent setResource(String resource)
-
setHttpMethod
public AuditEvent setHttpMethod(String httpMethod)
-
setHttpQueryString
public AuditEvent setHttpQueryString(String httpQueryString)
-
setSolrHost
public AuditEvent setSolrHost(String solrHost)
-
setSolrPort
public AuditEvent setSolrPort(int solrPort)
-
setSolrIp
public AuditEvent setSolrIp(String solrIp)
-
setHeaders
public AuditEvent setHeaders(Map<String,String> headers)
-
setSolrParams
public AuditEvent setSolrParams(Map<String,List<String>> solrParams)
-
setAutResponse
public AuditEvent setAutResponse(AuthorizationResponse autResponse)
-
setRequestType
public AuditEvent setRequestType(AuditEvent.RequestType requestType)
-
setQTime
public AuditEvent setQTime(double qTime)
-
setStatus
public AuditEvent setStatus(int status)
-
setException
public AuditEvent setException(Throwable exception)
-
-