Search in sources :

Example 1 with AuditEvent

use of org.jboss.security.audit.AuditEvent in project wildfly by wildfly.

the class AuditNotificationReceiver method handleNotification.

@Override
public void handleNotification(SecurityNotification notification) {
    EventType event = notification.getEventType();
    if (event == EventType.AUTHENTICATED || event == EventType.FAILED_AUTHENTICATION) {
        AuditEvent auditEvent = new AuditEvent(event == EventType.AUTHENTICATED ? AuditLevel.SUCCESS : AuditLevel.FAILURE);
        Map<String, Object> ctxMap = new HashMap<String, Object>();
        Account account = notification.getAccount();
        if (account != null) {
            ctxMap.put("principal", account.getPrincipal().getName());
        }
        ctxMap.put("message", notification.getMessage());
        ServletRequestContext src = notification.getExchange().getAttachment(ServletRequestContext.ATTACHMENT_KEY);
        if (src != null) {
            ServletRequest hsr = src.getServletRequest();
            if (hsr instanceof HttpServletRequest) {
                ctxMap.put("request", WebUtil.deriveUsefulInfo((HttpServletRequest) hsr));
            }
        }
        ctxMap.put("Source", getClass().getCanonicalName());
        auditEvent.setContextMap(ctxMap);
        auditManager.audit(auditEvent);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Account(io.undertow.security.idm.Account) ServletRequest(javax.servlet.ServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) EventType(io.undertow.security.api.SecurityNotification.EventType) HashMap(java.util.HashMap) ServletRequestContext(io.undertow.servlet.handlers.ServletRequestContext) AuditEvent(org.jboss.security.audit.AuditEvent)

Example 2 with AuditEvent

use of org.jboss.security.audit.AuditEvent in project wildfly by wildfly.

the class SimpleSecurityManager method audit.

/**
     * Sends information to the {@code AuditManager}.
     *
     * @param level
     * @param auditManager
     * @param userPrincipal
     */
private void audit(String level, AuditManager auditManager, Principal userPrincipal) {
    AuditEvent auditEvent = new AuditEvent(level);
    Map<String, Object> ctxMap = new HashMap<String, Object>();
    ctxMap.put("principal", userPrincipal != null ? userPrincipal.getName() : "null");
    ctxMap.put("Source", getClass().getCanonicalName());
    ctxMap.put("Action", "authentication");
    auditEvent.setContextMap(ctxMap);
    auditManager.audit(auditEvent);
}
Also used : HashMap(java.util.HashMap) AuditEvent(org.jboss.security.audit.AuditEvent)

Aggregations

HashMap (java.util.HashMap)2 AuditEvent (org.jboss.security.audit.AuditEvent)2 EventType (io.undertow.security.api.SecurityNotification.EventType)1 Account (io.undertow.security.idm.Account)1 ServletRequestContext (io.undertow.servlet.handlers.ServletRequestContext)1 ServletRequest (javax.servlet.ServletRequest)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1