Examples of AuditContext


Examples of org.apache.hadoop.gateway.audit.api.AuditContext

    Matcher<Chain>.Match match = chains.match( pathTemplate );
   
    assignCorrelationRequestId();
    // Populate Audit/correlation parameters
    AuditContext auditContext = auditService.createContext();
    auditContext.setTargetServiceName( match == null ? null : match.getValue().getResourceRole() );
    auditContext.setRemoteIp( servletRequest.getRemoteAddr() );
    auditContext.setRemoteHostname( servletRequest.getRemoteHost() );
    auditor.audit( Action.ACCESS, pathWithContext, ResourceType.URI, ActionOutcome.UNAVAILABLE );
   
    if( match != null ) {
      Chain chain = match.getValue();
      try {
View Full Code Here

Examples of org.apache.hadoop.gateway.audit.api.AuditContext

  @Override
  public String format( LoggingEvent event ) {
    sb.setLength( 0 );
    dateFormat( sb, event );
    CorrelationContext cc = (CorrelationContext)event.getMDC( Log4jCorrelationService.MDC_CORRELATION_CONTEXT_KEY );
    AuditContext ac = (AuditContext)event.getMDC( Log4jAuditService.MDC_AUDIT_CONTEXT_KEY );
    appendParameter( cc == null ? null : cc.getRootRequestId() );
    appendParameter( cc == null ? null : cc.getParentRequestId() );
    appendParameter( cc == null ? null : cc.getRequestId() );
    appendParameter( event.getLoggerName() );
    appendParameter( ac == null ? null : ac.getTargetServiceName() );
    appendParameter( ac == null ? null : ac.getUsername() );
    appendParameter( ac == null ? null : ac.getProxyUsername() );
    appendParameter( ac == null ? null : ac.getSystemUsername() );
    appendParameter( (String)event.getMDC( AuditConstants.MDC_ACTION_KEY ) );
    appendParameter( (String)event.getMDC( AuditConstants.MDC_RESOURCE_TYPE_KEY ) );
    appendParameter( (String)event.getMDC( AuditConstants.MDC_RESOURCE_NAME_KEY ) );
    appendParameter( (String)event.getMDC( AuditConstants.MDC_OUTCOME_KEY ) );
    String message = event.getRenderedMessage();
View Full Code Here

Examples of org.apache.hadoop.gateway.audit.api.AuditContext

    PropertyConfigurator.configure( ClassLoader.getSystemResourceAsStream( "audit-log4j.properties" ) );
  }

  @Test
  public void testFullyFilledAuditEvent() {
    AuditContext auditContext = auditService.createContext();
    auditContext.setProxyUsername( PROXYUSERNAME );
    auditContext.setSystemUsername( SYSTEMUSERNAME );
    auditContext.setUsername( USERNAME );
    auditContext.setRemoteHostname( HOST_NAME );
    auditContext.setRemoteIp( HOST_ADDRESS );
    auditContext.setTargetServiceName( TARGET_SERVICE );
   
    CorrelationContext correlationContext = correlationService.createContext();
    correlationContext.setRequestId( REQUEST_ID );
    correlationContext.setParentRequestId( PARENT_REQUEST_ID );
    correlationContext.setRootRequestId( ROOT_REQUEST_ID );
View Full Code Here

Examples of org.apache.hadoop.gateway.audit.api.AuditContext

      String message ) {
    event.getMDCCopy();
    CorrelationContext cc = (CorrelationContext) event.getMDC( Log4jCorrelationService.MDC_CORRELATION_CONTEXT_KEY );
    assertThat( cc, notNullValue() );
    assertThat( cc.getRequestId(), is( notNullValue() ) );
    AuditContext ac = (AuditContext) event.getMDC( Log4jAuditService.MDC_AUDIT_CONTEXT_KEY );
    assertThat( ac, notNullValue() );
    assertThat( ac.getRemoteIp(), is( ADDRESS ) );
    assertThat( ac.getRemoteHostname(), is( HOST ) );
    assertThat( (String) event.getMDC( AuditConstants.MDC_SERVICE_KEY ), is( AuditConstants.KNOX_SERVICE_NAME ) );
    assertThat( (String) event.getMDC( AuditConstants.MDC_COMPONENT_KEY ), is( AuditConstants.KNOX_COMPONENT_NAME ) );
    assertThat( (String) event.getLoggerName(), is( AuditConstants.DEFAULT_AUDITOR_NAME ) );
    verifyValue( (String) event.getMDC( AuditConstants.MDC_RESOURCE_NAME_KEY ), resourceName );
    verifyValue( (String) event.getMDC( AuditConstants.MDC_RESOURCE_TYPE_KEY ), resourceType );
    verifyValue( (String) event.getMDC( AuditConstants.MDC_ACTION_KEY ), action );
    verifyValue( (String) event.getMDC( AuditConstants.MDC_OUTCOME_KEY ), outcome );
    verifyValue( ac.getTargetServiceName(), targetService );
    verifyValue( event.getRenderedMessage(), message );
  }
View Full Code Here

Examples of org.apache.hadoop.gateway.audit.api.AuditContext

  public static final String MDC_AUDIT_CONTEXT_KEY = "audit_context";
  private Map<String, Auditor> auditors = new ConcurrentHashMap<String, Auditor>();

  @Override
  public AuditContext createContext() {
    AuditContext context = getContext();
    if ( context == null ) {
      context = new Log4jAuditContext();
      attachContext( context );
    }
    return context;
View Full Code Here

Examples of org.apache.hadoop.gateway.audit.api.AuditContext

    }
  }

  @Override
  public AuditContext detachContext() {
    AuditContext context = (AuditContext) MDC.get( MDC_AUDIT_CONTEXT_KEY );
    MDC.remove( MDC_AUDIT_CONTEXT_KEY );
    return context;
  }
View Full Code Here

Examples of org.apache.hadoop.gateway.audit.api.AuditContext

  }

  @Override
  public void audit( CorrelationContext correlationContext, AuditContext auditContext, String action, String resourceName, String resourceType, String outcome, String message ) {
    CorrelationContext previousCorrelationContext = null;
    AuditContext previousAuditContext = null;
    try {
      previousCorrelationContext = correlationService.getContext();
      previousAuditContext = auditService.getContext();
      auditService.attachContext( auditContext );
      correlationService.attachContext( correlationContext );
View Full Code Here

Examples of org.apache.hadoop.gateway.audit.api.AuditContext

  @Test
  public void testMultipleRequestEvents() {
    int iterations = 1000;
   
    AuditContext ac = auditService.createContext();
    ac.setUsername( username );
    ac.setProxyUsername( proxyUsername );
    ac.setRemoteIp( remoteIp );
    ac.setRemoteHostname( remoteHostname );
    ac.setTargetServiceName( targetServiceName );
   
    CorrelationContext cc = correlationService.createContext();
    cc.setRequestId( UUID.randomUUID().toString() );
    cc.setParentRequestId( UUID.randomUUID().toString() );
    cc.setRootRequestId( UUID.randomUUID().toString() );
View Full Code Here

Examples of org.apache.hadoop.gateway.audit.api.AuditContext

   
  }

  @Test
  public void testSequentialRequests() {
    AuditContext ac = auditService.createContext();
    ac.setUsername( username );
    ac.setProxyUsername( proxyUsername );
    ac.setRemoteIp( remoteIp );
    ac.setRemoteHostname( remoteHostname );
    ac.setTargetServiceName( targetServiceName );
   
    CorrelationContext cc = correlationService.createContext();
    cc.setRequestId( UUID.randomUUID().toString() );
    cc.setParentRequestId( UUID.randomUUID().toString() );
    cc.setRootRequestId( UUID.randomUUID().toString() );

    auditor.audit( "action", "resource", "resource type", "outcome", "message" );
   
    auditService.detachContext();
    correlationService.detachContext();
   
    assertThat( CollectAppender.queue.size(), is( 1 ) );
    LoggingEvent event = CollectAppender.queue.iterator().next();
    checkLogEventContexts( event, cc, ac );
   
    CollectAppender.queue.clear();
   
    ac = auditService.createContext();
    ac.setUsername( username + "1" );
    ac.setProxyUsername( proxyUsername + "1" );
    ac.setRemoteIp( remoteIp + "1" );
    ac.setRemoteHostname( remoteHostname + "1" );
    ac.setTargetServiceName( targetServiceName + "1" );
   
    cc = correlationService.createContext();
    cc.setRequestId( UUID.randomUUID().toString() );
    cc.setParentRequestId( UUID.randomUUID().toString() );
    cc.setRootRequestId( UUID.randomUUID().toString() );
View Full Code Here

Examples of org.apache.hadoop.gateway.audit.api.AuditContext

    event = CollectAppender.queue.iterator().next();
    checkLogEventContexts( event, cc, ac );
  }
 
  private void checkLogEventContexts( LoggingEvent event, CorrelationContext expectedCorrelationContext, AuditContext expectedAuditContext ) {
    AuditContext context = (AuditContext) event.getMDC( Log4jAuditService.MDC_AUDIT_CONTEXT_KEY );
    assertThat( context.getUsername(), is( expectedAuditContext.getUsername() ) );
    assertThat( context.getProxyUsername(), is( expectedAuditContext.getProxyUsername() ) );
    assertThat( context.getSystemUsername(), is( expectedAuditContext.getSystemUsername() ) );
    assertThat( context.getRemoteIp(), is( expectedAuditContext.getRemoteIp() ) );
    assertThat( context.getRemoteHostname(), is( expectedAuditContext.getRemoteHostname() ) );
    assertThat( context.getTargetServiceName(), is( expectedAuditContext.getTargetServiceName() ) );
        
    CorrelationContext correlationContext =  (CorrelationContext)event.getMDC( Log4jCorrelationService.MDC_CORRELATION_CONTEXT_KEY );
    assertThat( correlationContext.getRequestId(), is( expectedCorrelationContext.getRequestId() ) );
    assertThat( correlationContext.getRootRequestId(), is( expectedCorrelationContext.getRootRequestId() ) );
    assertThat( correlationContext.getParentRequestId(), is( expectedCorrelationContext.getParentRequestId() ) );
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.