cancel
Showing results for 
Search instead for 
Did you mean: 

How can I audit my java methods?

saruqui
Champ in-the-making
Champ in-the-making
I don't know what steps do I need to follow in order to audit my own methods. I've tried this:

public interface WfService {

   
   @Auditable(parameters="node")
   WorkflowPath initWf(NodeRef node) throws Exception;

}


– wfAudit.xml –
<Audit xmlns="http://www.alfresco.org/repo/audit/model/3.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.alfresco.org/repo/audit/model/3.2 alfresco-audit-3.2.xsd">
   <DataExtractors>
      <DataExtractor name="simpleValue" registeredName="auditModel.extractor.simpleValue" />
      <DataExtractor name="nullValue" registeredName="auditModel.extractor.nullValue" />
   </DataExtractors>
   <DataGenerators>
      <DataGenerator name="currentUser" registeredName="auditModel.generator.user" />
   </DataGenerators>
   <PathMappings>
      <PathMap source="/alfresco-api/post/WfService/initWf" target="/InitWf" />
   </PathMappings>
   <Application name="InitWf" key="InitWf">
      <AuditPath key="in">
         <RecordValue key="node" dataExtractor="simpleValue" dataSource="/InitWf/args/node" />
      </AuditPath>
      <AuditPath key="out">
         <RecordValue key="value" dataExtractor="simpleValue" dataSource="/InitWf/result" />
      </AuditPath>

   </Application>
</Audit>

Do I have to add anything else (setup, annotations…)?

The audit configuration setting is enabled so I can audit Alfresco services.

I'm using Alfresco 4.0.2

Thanks in advance

Saru
4 REPLIES 4

afaust
Legendary Innovator
Legendary Innovator
Hello,

please provide your bean definitions for your service. Have you provided separate public and private service beans where the public bean is a proxy factory that has the AuditMethodInterceptor applied?

Regards
Axel

saruqui
Champ in-the-making
Champ in-the-making
Hi,
yes, I fixed it. I forgot to add the interceptor Smiley Frustrated

Thanks for your help Smiley Happy

Regards,
Saru

harryxqb
Champ in-the-making
Champ in-the-making

Hello, I have encountered the same problem, I need to record the ip of the logged in user.

I defined the IpRecordService interface and its implementation class IpRecordServiceImpl

@AlfrescoPublicApi
public interface IpRecordService{
    @Auditable(parameters = {"userName", "ip"}, recordable = {true})
    void recordIp(String userName, String ip);
}

@Service("ipRecordService")
public class IpRecordServiceImpl implements IpRecordService {
@Override
@Auditable(parameters = {"userName", "ip"}, recordable = {true, true})
public void recordIp(String userName, String ip) {
System.out.println("recording---------------------------");
}
}
I defined service beans in service-context.xml.


<bean id="IpRecordService" class="org.springframework.aop.framework.ProxyFactoryBean">
    <property name="proxyInterfaces">
        <list>
            <value>cn.alfresco.jingtai.service.IpRecordService</value>
        </list>
    </property>
    <property name="target">
        <ref bean="ipRecordService"/>
    </property>
    <property name="interceptorNames">
        <list>
            <idref bean="AuditMethodInterceptor"/>
        </list>
    </property>
</bean>

and Below is the ipRecord.xml
<?xml version="1.0" encoding="UTF-8"?>
<Audit xmlns="http://www.alfresco.org/repo/audit/model/3.2"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.alfresco.org/repo/audit/model/3.2
    alfresco-audit-3.2.xsd">

    <DataExtractors>
        <DataExtractor name="simpleValue" registeredName="auditModel.extractor.simpleValue" />
        <DataExtractor name="nullValue" registeredName="auditModel.extractor.nullValue" />
    </DataExtractors>
    <DataGenerators>
        <DataGenerator name="currentUser" registeredName="auditModel.generator.user" />
    </DataGenerators>

    <PathMappings>
        <PathMap source="/alfresco-api/post/IpRecordService/recordIp" target="/ipRecordService/recordIp" />
    </PathMappings>

    <Application name="ipRecordService" key="ipRecordService">
        <AuditPath key="recordIp">
            <RecordValue key="userName" dataExtractor="simpleValue" dataSource="/ipRecordService/recordIp/args/userName"/>
            <RecordValue key="ip" dataExtractor="simpleValue" dataSource="/ipRecordService/recordIp/args/ip"/>
        </AuditPath>
    </Application>
</Audit>
According to the above configuration, my custom audit does not work, is there a problem with my configuration file? Still what steps I missed.
I will be very grateful for any reply.

@saruqui @AxelAxel Faust

harryxqb
Champ in-the-making
Champ in-the-making

Hello, I have encountered the same problem, I need to record the ip of the logged in user.

I defined the IpRecordService interface and its implementation class IpRecordServiceImpl

@AlfrescoPublicApi
public interface IpRecordService{
@Auditable(parameters = {"userName", "ip"}, recordable = {true})
void recordIp(String userName, String ip);
}

@Service("ipRecordService")
public class IpRecordServiceImpl implements IpRecordService {
@Override
@Auditable(parameters = {"userName", "ip"}, recordable = {true, true})
public void recordIp(String userName, String ip) {
System.out.println("recording---------------------------");
}
}
I defined service beans in service-context.xml.


<bean id="IpRecordService" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<list>
<value>cn.alfresco.jingtai.service.IpRecordService</value>
</list>
</property>
<property name="target">
<ref bean="ipRecordService"/>
</property>
<property name="interceptorNames">
<list>
<idref bean="AuditMethodInterceptor"/>
</list>
</property>
</bean>

and Below is the ipRecord.xml
<?xml version="1.0" encoding="UTF-8"?>
<Audit xmlns="http://www.alfresco.org/repo/audit/model/3.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.alfresco.org/repo/audit/model/3.2
alfresco-audit-3.2.xsd">

<DataExtractors>
<DataExtractor name="simpleValue" registeredName="auditModel.extractor.simpleValue" />
<DataExtractor name="nullValue" registeredName="auditModel.extractor.nullValue" />
</DataExtractors>
<DataGenerators>
<DataGenerator name="currentUser" registeredName="auditModel.generator.user" />
</DataGenerators>

<PathMappings>
<PathMap source="/alfresco-api/post/IpRecordService/recordIp" target="/ipRecordService/recordIp" />
</PathMappings>

<Application name="ipRecordService" key="ipRecordService">
<AuditPath key="recordIp">
<RecordValue key="userName" dataExtractor="simpleValue" dataSource="/ipRecordService/recordIp/args/userName"/>
<RecordValue key="ip" dataExtractor="simpleValue" dataSource="/ipRecordService/recordIp/args/ip"/>
</AuditPath>
</Application>
</Audit>
According to the above configuration, my custom audit does not work, is there a problem with my configuration file? Still what steps I missed.
I will be very grateful for any reply.

@saruqui @AxelAxel Faust