Audit Aspect.

@param jointPoint
the joint point
@throws Throwable
the throwable
431356
@Before("@within(org.audit4j.core.annotation.Audit) || @annotation(org.audit4j.core.annotation.Audit)")
    public void audit(final JoinPoint jointPoint) throws Throwable {

        MethodSignature methodSignature = (MethodSignature) jointPoint.getSignature();
        Method method = methodSignature.getMethod();

        if (method.getDeclaringClass().isInterface()) {
            try {
                method = jointPoint.getTarget().getClass()
                        .getDeclaredMethod(jointPoint.getSignature().getName(), method.getParameterTypes());
            } catch (final SecurityException exception) {
                throw new Audit4jRuntimeException(
                        "Exception occured while proceding Audit Aspect in Audit4j Spring Integration", exception);
            } catch (final NoSuchMethodException exception) {
                throw new Audit4jRuntimeException(
                        "Exception occured while proceding Audit Aspect in Audit4j Spring Integration", exception);
            }
        }

        AuditManager.getInstance().audit(jointPoint.getTarget().getClass(), method, jointPoint.getArgs());
    }
481605
public void abortPendingCheckpoints(CheckpointException exception) {
		synchronized (lock) {
			for (PendingCheckpoint p : pendingCheckpoints.values()) {
				p.abort(exception.getCheckpointFailureReason());
			}

			pendingCheckpoints.clear();
		}
	}
865101
public <T extends Throwable> T throwing(Level level, T throwable) {
        if (instanceofLAL) {
            ((LocationAwareLogger) logger).log(THROWING_MARKER, FQCN, level.level, "throwing", null, throwable);
        }
        return throwable;
    }
1133381
private void reportFailedCheckpoint(Exception cause) {
		// to prevent null-pointers from concurrent modification, copy reference onto stack
		final PendingCheckpointStats statsCallback = this.statsCallback;
		if (statsCallback != null) {
			long failureTimestamp = System.currentTimeMillis();
			statsCallback.reportFailedCheckpoint(failureTimestamp, cause);
		}
	}
837856
@Around("execution(* *(..)) && @annotation(TimerJ)")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        String methodName = MethodSignature.class.cast(point.getSignature()).getMethod().getName();
        String methodArgs = point.getArgs().toString();
        MetricRegistry metricRegistry = Metrics.getRegistry();
        Timer timer;

        String metricName = "Starting method "+methodName + "at "+System.nanoTime();
        synchronized (this) {
            if(metricRegistry.getTimers().containsKey(methodName)){
                timer = metricRegistry.getTimers().get(metricName);
            }
            else{
                timer = metricRegistry.register(metricName, new Timer());
            }
        }
        Timer.Context before = timer.time();
        Object result = point.proceed();
        long timeAfter = before.stop();

        logger.debug("Method " + methodName + " with args " + methodArgs + " executed in " + timeAfter + " ns");

        return result;
    }
700588
public void rollbackToSavepoint(Object savepoint) throws TransactionException {
		SavePoints savePoints = (SavePoints) savepoint;
		savePoints.rollback();
	}
773507
protected final void setRequiresCheckpoint()
    {
        final String methodName = "setRequiresCheckpoint";
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this,
                        cclass,
                        methodName,
                        new Object[] { new Boolean(requiresPersistentCheckpoint) });

        // The states for which a checkpoint log Record must be written to the log unless this transactions ends first.
        // Has any logging been done? If The transaction enters one of thse states after this
        // call then all of its state will be in the log after CheckpointStart.
        final boolean checkpointRequired[] = { false
                                              , false
                                              , false
                                              , true // ActivePersistent.
                                              , false
                                              , false
                                              , true // PrePreparedPersistent.
                                              , false
                                              , false
                                              , true // PreparedPersistent.
                                              , false
                                              , false
                                              , true // CommitingPersistent. Not needed because of synchronize in commit.
                                              , false
                                              , false
                                              , true // BackingOutPersistent.  Not needed because of synchronize in commit.
                                              , false
        };

        requiresPersistentCheckpoint = checkpointRequired[state];

        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this,
                       cclass,
                       methodName,
                       new Object[] { new Boolean(requiresPersistentCheckpoint) });
    }
915720
public boolean audit(Class<?> clazz, Method method, Object[] args) {
        return audit(new AnnotationAuditEvent(clazz, method, args));
    }
642131
public void execute(@Observes ExecuteWarp event, HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain, RequestPayload requestPayload, ResponsePayload responsePayload) throws Throwable {

        List<Inspection> inspections = requestPayload.getInspections();

        try {
            lifecycleManager.get().bindTo(ServletRequest.class, request);
            inspectionRegistry.get().registerInspections(inspections);

            warpLifecycleStarted.fire(new WarpLifecycleStarted());
            lifecycleManager.get().fireEvent(new BeforeServlet());

            filterChain.doFilter(request, response);

            lifecycleManager.get().fireEvent(new AfterServlet());

            responsePayload.setInspections(inspections);
        } finally {
            warpLifecycleFinished.fire(new WarpLifecycleFinished());

            inspectionRegistry.get().unregisterInspections(inspections);

            lifecycleManager.get().unbindFrom(ServletRequest.class, request);
        }
    }
258353
@Override
	public AuditEvent transformToEvent(AnnotationAuditEvent annotationEvent) {
		AuditEvent event = null;

		if (annotationEvent.getClazz().isAnnotationPresent(Audit.class)
				&& !annotationEvent.getMethod().isAnnotationPresent(IgnoreAudit.class)) {
			event = new AuditEvent();
			Audit audit = annotationEvent.getClazz().getAnnotation(Audit.class);

			// Extract fields
			event.setFields(getFields(annotationEvent.getMethod(), annotationEvent.getArgs()));

			// Extract Actor
			String annotationAction = audit.action();
			if (ACTION.equals(annotationAction)) {
				event.setAction(annotationEvent.getMethod().getName());
			} else {
				event.setAction(annotationAction);
			}

			// Extract repository
			event.setRepository(audit.repository());

			event.setActor(annotationEvent.getActor());
			event.setOrigin(annotationEvent.getOrigin());
		} else if (!annotationEvent.getClazz().isAnnotationPresent(Audit.class)
				&& annotationEvent.getMethod().isAnnotationPresent(Audit.class)) {
			event = new AuditEvent();
			Audit audit = annotationEvent.getMethod().getAnnotation(Audit.class);

			// Extract fields
			event.setFields(getFields(annotationEvent.getMethod(), annotationEvent.getArgs()));

			// Extract Actor
			String annotationAction = audit.action();
			if (ACTION.equals(annotationAction)) {
				event.setAction(annotationEvent.getMethod().getName());
			} else {
				event.setAction(annotationAction);
			}

			// Extract repository
			event.setRepository(audit.repository());

			event.setActor(annotationEvent.getActor());
			event.setOrigin(annotationEvent.getOrigin());
		}

		return event;
	}
901289
@AfterReturning(pointcut = "anyMethod() && withAttachmentAnnotation()", returning = "result")
    public void attachment(final JoinPoint joinPoint, final Object result) {
        final MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
        final Attachment attachment = methodSignature.getMethod().getAnnotation(Attachment.class);

        final String title = Allure1Utils.getTitle(
                attachment.value(),
                methodSignature.getName(),
                joinPoint.getThis(),
                joinPoint.getArgs()
        );

        final byte[] bytes = (result instanceof byte[])
                ? (byte[]) result : Objects.toString(result).getBytes(StandardCharsets.UTF_8);
        getLifecycle().addAttachment(title, attachment.type(), "", bytes);
    }
12076
public void validateInjectionPointForDefinitionErrors(InjectionPoint ij, Bean<?> bean, BeanManagerImpl beanManager) {
        if (ij.getAnnotated().getAnnotation(New.class) != null && ij.getQualifiers().size() > 1) {
            throw ValidatorLogger.LOG.newWithQualifiers(ij, Formats.formatAsStackTraceElement(ij));
        }
        if (ij.getType() instanceof TypeVariable<?>) {
            throw ValidatorLogger.LOG.injectionPointWithTypeVariable(ij, Formats.formatAsStackTraceElement(ij));
        }

        // WELD-1739
        if (ij.getMember() instanceof Executable && ij.getAnnotated().isAnnotationPresent(Named.class)
                && ij.getAnnotated().getAnnotation(Named.class).value().equals("")) {

            Executable executable = (Executable) ij.getMember();
            AnnotatedParameter<?> annotatedParameter = (AnnotatedParameter<?>) ij.getAnnotated();

            if (!executable.getParameters()[annotatedParameter.getPosition()].isNamePresent()) {
                // No parameters info available
                throw ValidatorLogger.LOG.nonFieldInjectionPointCannotUseNamed(ij, Formats.formatAsStackTraceElement(ij));
            }
        }

        if (ij.getAnnotated().isAnnotationPresent(Produces.class)) {
            if (bean != null) {
                throw BeanLogger.LOG.injectedFieldCannotBeProducer(ij.getAnnotated(), bean);
            } else {
                throw BeanLogger.LOG.injectedFieldCannotBeProducer(ij.getAnnotated(), Reflections.<AnnotatedField<?>>cast(ij.getAnnotated()).getDeclaringType());
            }
        }
        boolean newBean = (bean instanceof NewBean);
        if (!newBean) {
            checkScopeAnnotations(ij, beanManager.getServices().get(MetaAnnotationStore.class));
        }
        checkFacadeInjectionPoint(ij, Instance.class);
        checkFacadeInjectionPoint(ij, Event.class);

        if (InterceptionFactory.class.equals(Reflections.getRawType(ij.getType())) && !(bean instanceof ProducerMethod<?, ?>)) {
            throw ValidatorLogger.LOG.invalidInterceptionFactoryInjectionPoint(ij, Formats.formatAsStackTraceElement(ij));
        }

        for (PlugableValidator validator : plugableValidators) {
            validator.validateInjectionPointForDefinitionErrors(ij, bean, beanManager);
        }
    }
478946
@Override
    public boolean checkTopicAccess(Subject authenticatedSubject, String topicSpace, String topicName, String operationType) throws MessagingAuthorizationException {
        String busName = null;
        String messagingEngine = null;
        String[] roles = null;
        String resource = null;
        
        if (auditManager != null) {
            if (auditManager.getJMSBusName() != null)
                busName = auditManager.getJMSBusName();
            if (auditManager.getJMSMessagingEngine() != null)
                messagingEngine = auditManager.getJMSMessagingEngine();
        }

        String destinationName = topicSpace;
        resource = "topicSpace";
        if (topicName != null) {
            destinationName = topicSpace + MessagingSecurityConstants.TOPIC_DELIMITER + topicName;
            resource = "topic";
        }
        
        SibTr.entry(tc, CLASS_NAME + "checkTopicAccess", new Object[] { authenticatedSubject, destinationName, operationType });
        checkIfUserIsAuthenticated(authenticatedSubject);
        String userName = null;
        String user = authenticatedSubject.getPrincipals().iterator().next().getName();
        
        Map<String, TopicPermission> mq = messagingSecurityService.getTopicPermissions();
        roles = messagingSecurityService.getDestinationRoles(mq, destinationName, user);
        SibTr.debug(tc, "checkTopicAccess, roles: " + Arrays.toString(roles));
        
        try {
            userName = MessagingSecurityUtility.getUniqueUserName(authenticatedSubject);
        } catch (MessagingSecurityException e) {
            if (auditManager != null && auditManager.getJMSConversationMetaData() != null) {
                ConversationMetaData cmd = (ConversationMetaData) auditManager.getJMSConversationMetaData();

                Audit.audit(Audit.EventID.SECURITY_JMS_AUTHZ_01, user, cmd.getRemoteAddress().getHostAddress(), new Integer(cmd.getRemotePort()).toString(),
                            cmd.getChainName(), busName, messagingEngine, destinationName, operationType, roles, resource,
                            Integer.valueOf("201"));
            } else {
                Audit.audit(Audit.EventID.SECURITY_JMS_AUTHZ_01, user, null, null, null, busName, messagingEngine, destinationName, operationType, 
                            roles, resource, Integer.valueOf("201"));
            }

            throw new MessagingAuthorizationException(Tr.formatMessage(tc, "USER_NOT_AUTHORIZED_MSE1010", userName, operationType, destinationName), e);
        }
        Map<String, TopicPermission> topicPermissions = messagingSecurityService.getTopicPermissions();
        TopicPermission permission = getTopicPermission(topicPermissions, destinationName);
        boolean result = checkPermission(permission, operationType, userName);
        if (!result) {
            if (auditManager != null && auditManager.getJMSConversationMetaData() != null) {
                ConversationMetaData cmd = (ConversationMetaData) auditManager.getJMSConversationMetaData();

                Audit.audit(Audit.EventID.SECURITY_JMS_AUTHZ_01, user, cmd.getRemoteAddress().getHostAddress(), new Integer(cmd.getRemotePort()).toString(),
                            cmd.getChainName(), busName, messagingEngine, destinationName, operationType, roles, resource,
                            Integer.valueOf("201"));
            } else {
                Audit.audit(Audit.EventID.SECURITY_JMS_AUTHZ_01, user, null, null, null, busName, messagingEngine, destinationName, operationType, 
                            roles, resource, Integer.valueOf("201"));
            }

            SibTr.debug(tc, "USER_NOT_AUTHORIZED_MSE1010",
                        new Object[] { userName, operationType, destinationName });
            throw new MessagingAuthorizationException(Tr.formatMessage(tc, "USER_NOT_AUTHORIZED_MSE1010", userName, operationType, destinationName));
        } else {
            if (auditManager != null && auditManager.getJMSConversationMetaData() != null) {
                ConversationMetaData cmd = (ConversationMetaData) auditManager.getJMSConversationMetaData();

                Audit.audit(Audit.EventID.SECURITY_JMS_AUTHZ_01, user, cmd.getRemoteAddress().getHostAddress(), new Integer(cmd.getRemotePort()).toString(),
                            cmd.getChainName(), busName, messagingEngine, destinationName, operationType, roles, resource,
                            Integer.valueOf("200"));
            } else {
                Audit.audit(Audit.EventID.SECURITY_JMS_AUTHZ_01, user, null, null, null, busName, messagingEngine, destinationName, operationType, 
                            roles, resource, Integer.valueOf("200"));
            }
        }

        SibTr.exit(tc, CLASS_NAME + "checkTopicAccess", result);
        return result;
    }
1188037
public <T extends Throwable> T throwing(T throwable) {
        if (instanceofLAL) {
            ((LocationAwareLogger) logger).log(THROWING_MARKER, FQCN, LocationAwareLogger.ERROR_INT, "throwing", null, throwable);
        }
        return throwable;
    }
402430
public static String printResult(final JoinPoint joinPoint, final Object object) {
        return printResult(joinPoint, object, LoggingAspectConfig.DEFAULT_RESULT_DETAILS);
    }
720345
@Override
    public void sendAppException(Throwable throwable) {
        checkState();
        SofaResponse response = new SofaResponse();
        response.setAppResponse(throwable);
        sendSofaResponse(response, null);
    }
327296
@Override
	public void snapshotState(FunctionSnapshotContext context) throws Exception {
		Preconditions.checkState(this.checkpointedState != null,
			"The " + getClass().getSimpleName() + " has not been properly initialized.");

		if (LOG.isDebugEnabled()) {
			LOG.debug("{} checkpointing: Messages: {}, checkpoint id: {}, timestamp: {}",
				idsForCurrentCheckpoint, context.getCheckpointId(), context.getCheckpointTimestamp());
		}

		pendingCheckpoints.addLast(new Tuple2<>(context.getCheckpointId(), idsForCurrentCheckpoint));
		idsForCurrentCheckpoint = new HashSet<>(64);

		this.checkpointedState.clear();
		this.checkpointedState.add(SerializedCheckpointData.fromDeque(pendingCheckpoints, idSerializer));
	}