Developing OAM Access Client 11GR2

An Access Client is a custom Webgate that has been developed using the 11g Access SDK and APIs. This post explains the steps for developing OAM Access client 11gR2.

Developing OAM Access Client 11GR2 steps

Before writing the code, we need to set up the environment locally.

1. Download “Oracle Access Manager Access SDK 11.1.2.0.0″ from Oracle edelivery.

2. Create a folder and extract the contents for the downloaded zip file into this folder (in my case it is “C:/AccessSDK11g”)

3. Create a Java project and add all the jars in the zip file to the class path of that project.

4. In the same folder ” C:/AccessSDK11g”, copy the below list of files

Developing OAM Access Client 11GR2 300x72 Developing OAM Access Client 11GR2

All these files will be available in OAM installed path(except “jps-config” which comes along with downloaded zip)

5. copy the below code into a class file of the project and execute  the below code.

 

import java.util.Hashtable;
import java.util.Properties;
import oracle.security.am.asdk.*;

public class JAccessClient{
public static void main(String args[]) {
AccessClient ac = null;
UserSession session = null;

String ms_resource = “//abcd.example.com/identity”;
String ms_protocol = “http”;
String ms_method = “GET”;
String ms_login = “username”;
String ms_passwd = “password”;
try {

System.setProperty(“oracle.security.jps.config”,
“C:/AccessSDK11g/jps-config.xml”);
System.setProperty(“OAM_ASDK_CONFIG_DIR”, “C:/AccessSDK11g”);
System.out.println(“System Property jps::”
+ System.getProperty(“oracle.security.jps.config”));
System.out.println(“System Property ASDK::”
+ System.getProperty(“OAM_ASDK_CONFIG_DIR”));
ac = AccessClient
.createDefaultInstance(AccessClient.CompatibilityMode.OAM_11G);

ResourceRequest rrq = new ResourceRequest(ms_protocol, ms_resource,
ms_method);
if (rrq.isProtected()) {
System.out.println(“Resource is protected.”);
AuthenticationScheme authnScheme = new AuthenticationScheme(rrq);
if (authnScheme.isForm()) {
System.out.println(“Form Authentication Scheme”);
Hashtable creds = new Hashtable();
creds.put(“userid”, ms_login);
creds.put(“password”, ms_passwd);

try {
System.out.println(“In try”);
session = new UserSession(rrq, creds);
System.out.println(“session status is::”
+ session.getStatus());
System.out.println(“session error is::”
+ session.getError());
System.out.println(“session error message is::”
+ session.getErrorMessage());
System.out.println(“session Identity is::”
+ session.getUserIdentity());

} catch (Exception e) {
System.out.println(“In catch of Exception”);
e.printStackTrace();
System.out.println(“Exception message is::”
+ e.getMessage());
}

if (session.getStatus() == session.LOGGEDIN) {
if (session.isAuthorized(rrq)) {
System.out
.println(“User ”
+ ms_login
+ ” with password ”
+ ms_passwd
+ ” is logged in and authorized for the”
+ ” request at level ”
+ session.getLevel());
session.logoff();
System.out.println(“User is logged off”);
} else {
System.out
.println(“User is logged in but NOT authorized”);
}
} else {
System.out.println(“User is NOT logged in”);
if ((session.getError() == session.ERR_PASSWORD_EXPIRED))
System.out.println(“Expired password”);
else if ((session.getError() == session.ERR_NO_USER)
|| (session.getError() == session.ERR_WRONG_PASSWORD))
System.out.println(“Invalid UserID/Password”);
else if (session.getError() == session.ERR_USER_LOCKED_OUT)
System.out.println(“Account Locked”);

}

} else
System.out.println(“non-Form Authentication Scheme.”);
} else
System.out.println(“Resource is not protected”);
} catch (AccessException ae) {
System.out.println(“Access Exception: ” + ae.getMessage());
}
session.clearActions();
System.out.println(“Session cleared”);
ac.shutdown();

}
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>