APISonar


org.apache.ambari.server.audit.AuditLogger.log

> org > apache > ambari > server > audit > AuditLogger > log
org APIs apache APIs ambari APIs server APIs audit APIs AuditLogger APIs log APIs

Example 1
private static AuditLogger auditLogger;

  private void auditLog(HttpServletRequest servletRequest) {
    if(!auditLogger.isEnabled()) {
      return;
    }
    LogoutAuditEvent logoutEvent = LogoutAuditEvent.builder()
      .withTimestamp(System.currentTimeMillis())
      .withRemoteIp(RequestUtils.getRemoteAddress(servletRequest))
      .withUserName(AuthorizationHelper.getAuthenticatedName())
      .build();
    auditLogger.log(logoutEvent);
  }
Example 2
private AuditLogger auditLogger;

  protected void onSuccessfulAuthentication(HttpServletRequest servletRequest,
                                            HttpServletResponse servletResponse,
                                            Authentication authResult) throws IOException {
    if (auditLogger.isEnabled()) {
      AuditEvent loginSucceededAuditEvent = LoginAuditEvent.builder()
          .withRemoteIp(RequestUtils.getRemoteAddress(servletRequest))
          .withUserName(authResult.getName())
          .withTimestamp(System.currentTimeMillis())
          .withRoles(permissionHelper.getPermissionLabels(authResult))
          .build();
      auditLogger.log(loginSucceededAuditEvent);
    }
  }
Example 3
private AuditLogger auditLogger;

  public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
    HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;

    if (auditLogger.isEnabled() && shouldApply(httpServletRequest) && (AuthorizationHelper.getAuthenticatedName() == null)) {
      AuditEvent loginFailedAuditEvent = LoginAuditEvent.builder()
          .withRemoteIp(RequestUtils.getRemoteAddress(httpServletRequest))
          .withTimestamp(System.currentTimeMillis())
          .withReasonOfFailure("Authentication required")
          .withUserName(null)
          .build();
      auditLogger.log(loginFailedAuditEvent);
    }

    super.doFilter(servletRequest, servletResponse, chain);
  }
Example 4
private static AuditLogger mockAuditLogger;

  private Capture<AuditEvent> createCapture() {
    EasyMock.expect(mockAuditLogger.isEnabled()).andReturn(true).anyTimes();
    Capture<AuditEvent> capture = EasyMock.newCapture();
    mockAuditLogger.log(EasyMock.capture(capture));
    EasyMock.expectLastCall();
    EasyMock.replay(mockAuditLogger);
    return capture;
  }