Question about maxAgeDays in CAS JDBC audit

23 views
Skip to first unread message

Andy Ng

unread,
Aug 8, 2019, 11:32:01 PM8/8/19
to CAS Community
Hi all,


I tried to use the maxAgeDays config from CAS JDBC audit but failed in CAS 5.3.x / 6.0.x, which is listed here:


I use maxAgeDays like this in my cas.yml:

   url: jdbc:mariadb://example.jdbc.com/place
   user: myuser
   password: mypassword
   driverClass: org.mariadb.jdbc.Driver
   dialect: org.hibernate.dialect.MariaDBDialect
   ddlAuto: 
   cas.audit.jdbc.maxAgeDays: 1


And the database is as follows:

CREATE TABLE `COM_AUDIT_TRAIL` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `AUD_ACTION` varchar(255) DEFAULT NULL,
  `APPLIC_CD` varchar(255) DEFAULT NULL,
  `AUD_CLIENT_IP` varchar(255) DEFAULT NULL,
  `AUD_DATE` datetime NOT NULL,
  `AUD_RESOURCE` varchar(255) DEFAULT NULL,
  `AUD_SERVER_IP` varchar(255) DEFAULT NULL,
  `AUD_USER` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)


But the logs kept is more than 1 days, in fact it seems like it never remove the audit logs in my DB.

I have no idea why this failed, so I looked into the code and found the maxAgeDays  logic trace to this delete statement here:


where maxAgeDays is used as pass as the clean up parameter to make DELETE FROM COM_AUDIT_TRAIL AUD_DATE > maxAgeDay

This all triggered inside the clean() function.

However, when I serach for the keyword clean(), I didn't find anywhere this was being used, so my question is:

1. Does anybody make maxAgeDays workds before? If so can you share the config?
2. If not, does anybody knows where does the clean() function, trigger? So I can continue my debugging on why this doesn't work,

Thanks.

Cheers!
- Andy

Andy Ng

unread,
Aug 9, 2019, 4:50:44 AM8/9/19
to CAS Community
Hi all, 

After seraching for a while, seems to me that maxAgeDays wasn't implemented at all in CAS 5 / 6.....

Anyway, I figure to just copy the ticket cleaner and implement that myself, I copied my implementation here to other can reference :D

Config file

package net.mycompany.cas.audit.cleaner;

import org.apereo.cas.configuration.CasConfigurationProperties;
import org.apereo.inspektr.audit.support.JdbcAuditTrailManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@Configuration("mycompanyJdbcAuditTrailSchedulingConfiguration")
@EnableConfigurationProperties(CasConfigurationProperties.class)
@EnableScheduling
@EnableAsync
@EnableTransactionManagement(proxyTargetClass = true)
//@AutoConfigureAfter(CasSupportJdbcAuditConfiguration.class)
public class MyCompanyJdbcAuditTrailSchedulingConfiguration {
    private static final Logger LOGGER = LoggerFactory.getLogger(MyCompanyJdbcAuditTrailSchedulingConfiguration.class);

    
    @ConditionalOnMissingBean(name = "jdbcAuditTrailCleanerScheduler")
    @Bean
    @Autowired
    @RefreshScope
    public JdbcAuditCleanerScheduler jdbcAuditTrailCleanerScheduler(@Qualifier("jdbcAuditTrailManager") final JdbcAuditTrailManager jdbcAuditTrailManager) {
        return new JdbcAuditCleanerScheduler(jdbcAuditTrailManager);
    }


    /**
     * The Ticket registry cleaner scheduler. Because the cleaner itself is marked
     * with {@link org.springframework.transaction.annotation.Transactional},
     * we need to create a separate scheduler component that simply invokes it
     * so that {@link Scheduled} annotations can be processed and not interfere
     * with transaction semantics of the cleaner.
     */
    public static class JdbcAuditCleanerScheduler {
        private final JdbcAuditTrailManager jdbcAuditTrailManager;

        public JdbcAuditCleanerScheduler(final JdbcAuditTrailManager jdbcAuditTrailManager) {
            this.jdbcAuditTrailManager = jdbcAuditTrailManager;
        }

        // Every day, 1:01 a.m.
        @Scheduled(cron = "0 1 1 * * ?")
        public void run() {
            try {
            LOGGER.debug("Jdbc Audit Trail clean performed");
                this.jdbcAuditTrailManager.clean();
            } catch (final Exception e) {
                LOGGER.error(e.getMessage(), e);
            }
        }
    }

}

spring.factories
org.springframework.boot.autoconfigure.EnableAutoConfiguration=net.mycompany.cas.audit.cleaner.MyCompanyJdbcAuditTrailSchedulingConfiguration 


Cheers!
- Andy
Reply all
Reply to author
Forward
0 new messages