我花了几天的时间来尝试使用Spring应用程序进行Inspektr审核(https://github.com/dima767/inspektr/wiki/Inspektr-Auditing)。我可以找到的所有示例似乎都涉及CAS,但是我的应用程序使用spring安全性进行身份验证。

目前,我只是想在添加整个代码的其余部分的审计语句之前进行一个小的测试。但是,当我运行测试时,没有输出,没有错误,而且我的想法已经用完了。如果您不使用CAS,是否可以使用Inspektr?我正在用一个简单的JUnit进行测试(以允许在Eclipse中进行快速测试)-该junit只是创建了可审计类并调用了可审计方法。该类本身运行良好-我只是没有得到任何输出。

我真的希望有人能提供帮助!

这是我的xml(这是我的第一篇文章,因此如果格式不正确,我们深表歉意):

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:c="http://www.springframework.org/schema/c"
        xmlns:util="http://www.springframework.org/schema/util"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
                http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
                http://www.springframework.org/schema/aop
                http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
                http://www.springframework.org/schema/tx
                http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
                http://www.springframework.org/schema/util
                http://www.springframework.org/schema/util/spring-util-3.2.xsd">

<!-- Entry for Inspektr Audit Logging Functionality -->
    <aop:aspectj-autoproxy />

    <!-- ***************AUDIT TRAIL MANAGERS*************** -->
    <bean id="loggingAuditTrailManager" class="com.github.inspektr.audit.support.Slf4jLoggingAuditTrailManager"/>
    <bean id="consoleAuditTrailManager" class="com.github.inspektr.audit.support.ConsoleAuditTrailManager"/>
    <bean id="jdbcAuditTrailManager" class="com.github.inspektr.audit.support.JdbcAuditTrailManager">
        <constructor-arg index="0" ref="inspektrTransactionTemplate" />
        <property name="dataSource" ref="dataSource" />
    </bean>

    <util:list id="auditTrailManagers" value-type="java.lang.String">
        <ref bean="loggingAuditTrailManager"/>
        <ref bean="consoleAuditTrailManager"/>
        <ref bean="jdbcAuditTrailManager"/>
    </util:list>


    <!-- ***************AUDIT ACTION RESOLVERS*************** -->
    <bean id="defaultActionResolver" class="com.github.inspektr.audit.spi.support.DefaultAuditActionResolver">
        <constructor-arg index="0" value="_SUCCEEDED"/>
        <constructor-arg index="1" value="_FAILED"/>
    </bean>


    <util:map id="auditActionResolversMap">
        <entry key="DEFAULT_ACTION_RESOLVER" value-ref="defaultActionResolver" />
    </util:map>


    <!-- ***************AUDIT RESOURCE RESOLVERS -->
    <util:map id="auditResourceResolversMap">
        <entry key="DEFAULT_RESOURCE_RESOLVER">
            <bean
                class="com.github.inspektr.audit.spi.support.ReturnValueAsStringResourceResolver" />
        </entry>
    </util:map>

    <!-- ***************PRINCIPAL RESOLVERS*************** -->
    <bean id="anonymousPrincipalResolver" class="myapp.service.helper.AnonymousPrincipalResolver"/>
<!--     <bean id="springSecurityAuditablePrincipalResolver" class="org.inspektr.audit.spi.support.SpringSecurityAuditablePrincipalResolver"/> -->


    <!-- ***************SETTINGS REQUIRED FOR JDBC AUDIT MANAGER -->
    <bean id="inspektrTransactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">
        <property name="transactionManager" ref="inspektrTransactionManager" />
        <property name="timeout" value="5" />
    </bean>

    <bean id="inspektrTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>

    <bean id="isolationReadCommitted" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
        <property name="staticField" value="org.springframework.transaction.TransactionDefinition.ISOLATION_READ_COMMITTED"/>
    </bean>


    <!-- ***************MAIN AUDIT ASPECT*************** -->
    <bean id="auditTrailManagementAspect" class="com.github.inspektr.audit.AuditTrailManagementAspect"
        c:applicationCode="MYAPP_WEB_APPLICATION"
        c:auditablePrincipalResolver-ref="anonymousPrincipalResolver"
        c:auditTrailManagers-ref="auditTrailManagers"
        c:auditActionResolverMap-ref="auditActionResolversMap"
        c:auditResourceResolverMap-ref="auditResourceResolversMap" />

    <!-- ***************DEFINE AUDITABLE BEANS*************** -->
    <bean id="simpleService" class="myapp.service.helper.SimpleAuditExample"/>


</beans>


这是试图获取审核记录的类:

package myapp.service.helper;

import com.github.inspektr.audit.annotation.Audit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.TransactionDefinition;

public class SimpleAuditExample {

    private static final Logger logger = LoggerFactory.getLogger(SimpleAuditExample.class);

    public SimpleAuditExample() {

    }

    @Audit(action = "SIMPLE_ACTION", actionResolverName = "DEFAULT_ACTION_RESOLVER", resourceResolverName = "DEFAULT_RESOURCE_RESOLVER")
    public String performAuditableActionGetString() {
        return "Well, here is some simple value";
    }
}

最佳答案

将您的auditTrailManagementAspect修改为类似以下内容:

<bean id="auditTrailManagementAspect" class="com.github.inspektr.audit.AuditTrailManagementAspect">
        <!-- String applicationCode -->
        <constructor-arg index="0" value="MY_aPPLICATION"/>

        <!-- PrincipalResolver -->
        <constructor-arg index="1" ref="anonymousPrincipalResolver"/>

        <!-- List<AuditTrailManager> auditTrailManagers -->
        <constructor-arg index="2">
            <list>

                <ref bean="jdbcAuditTrailManager"/>
                <ref bean="consoleAuditTrailManager"/>
            </list>
        </constructor-arg>


        <!-- Map<String,AuditActionResolver> auditActionResolverMap -->
        <constructor-arg index="3">
            <map>
                <entry key="DEFAULT_ACTION_RESOLVER">
                    <ref local="defaultActionResolver"/>
                </entry>
            </map>
        </constructor-arg>

        <!-- Map<String,AuditResourceResolver> auditResourceResolverMap -->
        <constructor-arg index="4">
            <map>
                <entry key="DEFAULT_RESOURCE_RESOLVER">
                    <bean class="com.github.inspektr.audit.spi.support.ObjectToStringResourceResolver"/>
                </entry>
            </map>
        </constructor-arg>
    </bean>


除了这种检查,还希望您的数据库中有一个名为COM_AUDIT_TRAIL的数据库表。有关更多参考,请查看以下链接:
https://wiki.jasig.org/display/CASUM/Auditing+and+Statistics+Via+Inspektr

07-26 01:09