Following files are required for this sample tutorial:
SimpleSampleAuditProviderImpl : This is a sample runtime class implementing the AuditProvider and AuditChannel.
SimpleSampleAuditorImpl : This is a sample class that extends the ContextHandlerImpl class to get the supported ActiveContextHandlerEntries
SimpleSampleAuditor : This is a sample Audit configuration Mbean Configuration file used to instantiate the Custome Audit Provider Mbean Type.
We will be following the link give below:
http://download.oracle.com/docs/cd/E12840_01/wls/docs103/dvspisec/aud.html
We will have to do the following things to create the Custom Audit Provider:
- Create Runtime Classes Using the Appropriate SSPIs
- Generate an MBean Type Using the WebLogic MBeanMaker
- Configure the Custom Auditing Provider Using the Administration Console
- So First we will create a runtime class using the appropriate SSPI’s:
Implement the AuditProvider SSPI:
http://download.oracle.com/docs/cd/E12840_01/wls/docs103/javadocs/weblogic/security/spi/AuditProvider.html
weblogic.security.spi Interface AuditProvider.
Implement the AuditChannel SSPI:
http://download.oracle.com/docs/cd/E12840_01/wls/docs103/javadocs/weblogic/security/spi/AuditChannel.html
weblogic.security.spi Interface AuditChannel.
Please use the source file provided as a sample with this post.
File Name: SimpleSampleAuditProviderImpl.java
- Then we will be creating a SimpleSampleAuditorImpl.java file which extends ContextHandlerImpl class.
It is needed to inherit the ContextHandlerMBean's ActiveContextHandlerEntries attribute validator that ensures that the ActiveContextHandlerEntries attribute only contains values from the SupportedContextHandlerEntries attribute.
- Then we will be creating a SimpleSampleAuditor.xml file which specifies the Mbean Type that needs to be instantiated for this Custom Audit Provider.
- Then Using the Source files provided with this post we will generate the Mbean Type and the Mbean Jar file for the Audit Provider using the Weblogic MbeanMaker Utility.
Steps To Follow:
1: Download the Sample Source code provided with at the top of the Post.
2: Then create a directory called Providers and within this directory create another dir called src and place all the provided files in this directory, i.e. :
SimpleSampleAuditProviderImpl.java
SimpleSampleAuditorImpl.java
SimpleSampleAuditor.xml
3: Also create the directories called providerjar and created_files within the Providers directory.
So with the directory structure will become like below:
C:/Providers
C:/Providers/src
C:/Providers/providersjar
C:/Providers/created_files
4: Now open a command prompt and set the environment by executing the setWLSEnv.cmd file on this command prompt:
C:/Providers/src> %WLS_HOME%/wlserver/server/bin/setWLSEnv.cmd ( For windows)
homeProviderssrc$ . ./%WLS_HOME%/wlserver/server/bin/setWLSEnv.sh (for Linux)
5: Then execute the following command on the same prompt:
java -Dfiles=C:/Providers/created_files -DMDF=C:/Providers/src/SimpleSampleAuditor.xml -DMJF=C:/Providers/providersjar/SimpleSampleAuditor.jar -DtargetNameSpace=http://xmlns.oracle.com/oracleas/schema/11/adf/sampleapp/weblogic/providers -DpreserveStubs=true -DcreateStubs=true weblogic.management.commo.WebLogicMBeanMaker
6: With the above command a jar file with name SimpleSampleAuditor.jar will be created in the directory: C:/Providers/providersjar.
7: Place this created Jar file in the %BEA_HOME%wlserver_10.3serverlibmbeantypes directory of WLS installation.
8: Start the Admin Server of your domain and access the Admin Server Console with the browser.
9: Go to : Security realm>>>> myrealm >>> Providers >>> Audit Provider .
Click new tab:
Enter name: MyTestAuditprovider.
Type: SimpleSampleAuditor
Click save.
10: Restart the Admin Server.
11: Now you will be able to use the Custom Audit Provider with this Domain.
If you are facing any issues and errors while developing Custom Security provider then you can post the errors here.
3 comments:
I have been following these steps mentioned here, and I'm getting an error while generating the JAR file
Doing the compile.
D:workspacesCustomAuditProviderprovidercreated_filesdemoMyAuditProviderSimpleSampleAuditorMBeanImpl.java:425: cannot find symbol
symbol : method validateActiveContextHandlerEntries(java.lang.String[])
location: class demo.MyAuditProvider.SimpleSampleAuditorImpl
try { if (!(_customizer.validateActiveContextHandlerEntries(getActiveContextHandlerEntries()))) throw new IllegalArgumentException("The ContextHandler ActiveContextHandlerEntri
es attribute was set to an illegal value."); } catch (javax.management.InvalidAttributeValueException e) { throw new IllegalArgumentException(e.toString()); };
^
Note: D:workspacesCustomAuditProviderprovidercreated_filesdemoMyAuditProviderSimpleSampleAuditorMBeanImpl.java uses or overrides a deprecated API.
I'm using WebLogic10.3.2
I had the same error but managed to resolve the issue.
The version of SimpleSampleAuditorImpl.java in the created_files directory is auto-generated by WebLogicMBeanMaker.
Need to copy the version of SimpleSampleAuditorImpl.java from the src directory into the created_files directory, i.e. overwrite this file, as per the comment in the source file:
public class SimpleSampleAuditorImpl extends ContextHandlerImpl
// Note: extend ContextHandlerImpl instead of AuditorImpl to inherit
// the ActiveContextHandlerEntries attribute validator.
The auto-generated version extends AuditorImpl which is incorrect.
Also, I found it is necessary to copy the SimpleSampleAuditProviderImpl.java from the src directory into the created_files directory.
I then re-ran WebLogicMBeanMaker from the command line as per the instructions, the build completed successfully and the resulting audit provider jar file loaded and logged audit messages correctly.
Hi Sandeep
I was trying to create a Custom Audit Provider and while searching in google. I saw your article http://weblogictips.wordpress.com/2010/05/03/how-to-develop-weblogic-custom-audit-provider/
I tried the same example. I was having a small issue and would like to get your suggestion to proceed further.
The problem I am facing is I am not getting the Handler Names and Values . I don’t know where I need to configure this. Is this needs to be configured in the MBean Attributes ?
ContextHandler handler = auditContext.getContext();
log.println(“>”+ handler.getValue(“com.bea.contextelement.servlet.HttpServletRequest”));
I am getting the handler.getNames().length = 0
Post a Comment