audit4j / audit4j-core

An open source auditing framework.
http://audit4j.org
Apache License 2.0
126 stars 76 forks source link

Limit of records in audit table. #16

Closed msamichev closed 8 years ago

msamichev commented 8 years ago

Hi. I have included the audit4j(core/spring/db) into my project. Everything works, but when the count of records in the audit table become equal 14, new record is not created. What it can be?

Thanks

janithb commented 8 years ago

Please share the configuration you are using.

msamichev commented 8 years ago

Of course:

Maven:

    ...
    <!-- Audit4j -->
    <audit4j.version>2.4.0-alpha3</audit4j.version>
    <audit4j-spring.version>2.4.0-alpha3</audit4j-spring.version>
    <audit4j-db.version>2.3.1</audit4j-db.version>

    ...
    <!-- Audit4j -->
    <dependency>
        <groupId>org.audit4j</groupId>
        <artifactId>audit4j-core</artifactId>
        <version>${audit4j.version}</version>
        <exclusions>
            <exclusion>
                <groupId>javassist</groupId>
                <artifactId>javassist</artifactId>
            </exclusion>
            <exclusion>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.audit4j</groupId>
        <artifactId>audit4j-spring</artifactId>
        <version>${audit4j-spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.audit4j</groupId>
        <artifactId>audit4j-db</artifactId>
        <version>${audit4j-db.version}</version>
    </dependency>

Spring:

    <bean id="layout" class="org.audit4j.core.layout.SimpleLayout"></bean>
    <bean id="metaData" class="ru.atc.tmon.core.audit.AuditMetaData"></bean>
    <bean id="consoleAuditHandler" class="org.audit4j.core.handler.ConsoleAuditHandler"></bean>
    <bean id="databaseAuditHandler" class="org.audit4j.handler.db.DatabaseAuditHandler">
        <property name="embedded" value="false"></property>
        <property name="db_connection_type" value="pooled"></property>
        <property name="db_driver" value="${jdbc.driverClassName}"/>
        <property name="db_url" value="${jdbc.url}"/>
        <property name="db_user" value="${jdbc.username}"/>
        <property name="db_password" value="${jdbc.password}"/>
    </bean>
    <bean id="auditconfig" class="org.audit4j.integration.spring.SpringAudit4jConfig">
        <property name="layout" ref="layout"></property>
        <property name="metaData" ref="metaData"></property>
        <property name="handlers">
            <list>
                <ref bean="consoleAuditHandler"/>
                <ref bean="databaseAuditHandler"/>
            </list>
        </property>
    </bean>

    <bean id="auditAspect" class="org.audit4j.integration.spring.AuditAspect" />

    <aop:aspectj-autoproxy>
        <aop:include name="auditAspect" />
    </aop:aspectj-autoproxy>

MetaData:

public class AuditMetaData implements MetaData {
    private static final long serialVersionUID = -991195007439661187L;

    @Override
    public String getOrigin() {
        try {
            return ((ServletRequest)((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest()).getRemoteAddr();
        }catch(Exception e){
            System.out.println(e);
        }
        return null;
    }

    @Override
    public String getActor() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (authentication != null && authentication.getPrincipal() instanceof LoggedUser) {
            return ((LoggedUser) authentication.getPrincipal()).getUsername();
        }

        return "anonymous";
    }
}

Something else?

msamichev commented 8 years ago

Only 14 records and no one new :( image

janithb commented 8 years ago

Hi @msamichev Is there any exception in console log? Are those audit records available in the console which are logged through console handler?

msamichev commented 8 years ago

No errors. But my second question, I don't see any audit information in console :(.

msamichev commented 8 years ago

And after restart tomcat new 14 records are created in table.

janithb commented 8 years ago

Please remove the database handler from the configurations and share the console log. I want to check whether the issue is in the database handler.

msamichev commented 8 years ago

commented out db-handler and console started work:


     _             _ _ _   _  _   _ 
    / \  _   _  __| (_) |_| || | (_)
   / _ \| | | |/ _` | | __| || |_| |
  / ___ \ |_| | (_| | | |_|__   _| |
 /_/   \_\__,_|\__,_|_|\__|  |_|_/ |
                               |__/ 
 ===========================(v2.4.0-alpha3)

Audit4j:INFO Initializing Audit4j...
Audit4j:INFO Loading Configurations...
Audit4j:INFO Validating Configurations...
Audit4j:INFO Initializing Handlers...
Audit4j:INFO org.audit4j.core.handler.ConsoleAuditHandler Initialized.
Audit4j:INFO Initializing Layout...
Audit4j:INFO org.audit4j.core.layout.SimpleLayout Initialized.
Audit4j:INFO Initializing Streams...
Audit4j:INFO Audit Streams Initialized.
Audit4j:INFO Executing Schedulers...
Audit4j:INFO Audit4j initialized. Total time: 447ms
...
10/22/2015 12:50:00|anonymous|null|loadUserByUsername==>arg0 java.lang.String:admin,
10/22/2015 12:50:00|admin|0:0:0:0:0:0:0:1|getCurrentUser==>
10/22/2015 12:51:18|admin|0:0:0:0:0:0:0:1|getCurrentUser==>
10/22/2015 12:51:26|admin|0:0:0:0:0:0:0:1|getAll==>
10/22/2015 12:52:01|admin|0:0:0:0:0:0:0:1|get==>arg0 java.lang.Integer:100004,
10/22/2015 12:52:01|admin|0:0:0:0:0:0:0:1|save==>arg0 ru.atc.tmon.core.model.user.User:User{id=100004, name='oke', email='oke@mail.ru', password='$2a$10$g5EgGlW5XpCuR7yi3bQzKOaXSmqzAqAr/QD97kRjdoKGSmb1eO7yy', enabled=true, ldap=false, userProfile=UserProfile{id=500004, lastName='Краскин', firstName='Олег', middleName=''}, registered=2015-10-22 12:49:44.801, roles=[Role{id=200002, name='ROLE_INSPECTOR', description='налоговый инспектор', permissions='[Permission{id=400000, name='SELECT'}]'}, Role{id=200000, name='ROLE_USER', description='сотрудник налогоплательщика', permissions='[Permission{id=400000, name='SELECT'}]'}], groups=[]},
10/22/2015 12:52:01|admin|0:0:0:0:0:0:0:1|getAll==>
10/22/2015 12:52:02|admin|0:0:0:0:0:0:0:1|getAll==>
10/22/2015 12:52:54|admin|0:0:0:0:0:0:0:1|get==>arg0 java.lang.Integer:100004,
10/22/2015 12:52:54|admin|0:0:0:0:0:0:0:1|save==>arg0 ru.atc.tmon.core.model.user.User:User{id=100004, name='oke', email='oke@mail.ru', password='$2a$10$g5EgGlW5XpCuR7yi3bQzKOaXSmqzAqAr/QD97kRjdoKGSmb1eO7yy', enabled=true, ldap=false, userProfile=UserProfile{id=500004, lastName='Краскин', firstName='Олег', middleName=''}, registered=2015-10-22 12:49:44.801, roles=[], groups=[]},
10/22/2015 12:52:54|admin|0:0:0:0:0:0:0:1|getAll==>
10/22/2015 12:52:54|admin|0:0:0:0:0:0:0:1|getAll==>
10/22/2015 12:53:37|admin|0:0:0:0:0:0:0:1|delete==>arg0 java.lang.Integer:100004,
10/22/2015 12:53:37|admin|0:0:0:0:0:0:0:1|getAll==>
10/22/2015 12:53:37|admin|0:0:0:0:0:0:0:1|getAll==>
10/22/2015 12:53:37|admin|0:0:0:0:0:0:0:1|delete==>arg0 java.lang.Integer:100004,
10/22/2015 12:53:37|admin|0:0:0:0:0:0:0:1|getAll==>
10/22/2015 12:53:37|admin|0:0:0:0:0:0:0:1|getAll==>
10/22/2015 12:54:07|admin|0:0:0:0:0:0:0:1|get==>arg0 java.lang.Integer:100005,
10/22/2015 12:54:07|admin|0:0:0:0:0:0:0:1|save==>arg0 ru.atc.tmon.core.model.user.User:User{id=100005, name='vsmys', email='vsmys@mail.ru', password='$2a$10$BJvYcfI.ZUxod9AjrRLv2uwLfbBtaA6HyvFhfsmmQmghXoYTtj2La', enabled=true, ldap=false, userProfile=UserProfile{id=500005, lastName='Смыслов', firstName='Василий', middleName=''}, registered=2015-10-22 12:49:44.801, roles=[Role{id=200001, name='ROLE_ADMIN', description='администратор', permissions='[Permission{id=400001, name='CREATE'}, Permission{id=400003, name='DELETE'}, Permission{id=400000, name='SELECT'}, Permission{id=400002, name='UPDATE'}]'}, Role{id=200002, name='ROLE_INSPECTOR', description='налоговый инспектор', permissions='[Permission{id=400000, name='SELECT'}]'}], groups=[]},
10/22/2015 12:54:07|admin|0:0:0:0:0:0:0:1|getAll==>
10/22/2015 12:54:07|admin|0:0:0:0:0:0:0:1|getAll==>
janithb commented 8 years ago

I think there will be an issue in database handler. I suspect that the connections in the database pool are not releasing again to the pool after consume by the application. Can you switch it to single connection mode or jndi mode for now and let me know how it is going. I will fix this issue later.

msamichev commented 8 years ago

Put single mode - it works(both handlers), thanks.

when can we expect a version with pool mode?

janithb commented 8 years ago

We will release this in database handler 2.4.0 version by next week.

msamichev commented 8 years ago

cool. will wait ;)

msamichev commented 8 years ago

One request - can you add datasource property in db-handler or it is difficult?

janithb commented 8 years ago

Yes. It is pretty straight forward but we have to test it since the handlers are working outside the application context scope because of the asynchronous nature. I will add this to our milestone and plan a release in next major version.

janithb commented 8 years ago

Fixed issue in Audit4j-DB 2.4.0-alpha1 and currently available in maven central repository. Added external data source support.