Disable User in OIM through SCIM/Rest Services-
-----------------------------------------------------------------------------------
Required Jar File-
java-json.jar
sun.misc.BASE64Decoder.jar
apache-httpcomponents-httpcore.jar
apache-jakarta-commons-httpclient.jar
commons-codec-1.9.jar
commons-logging.jar
commons-httpclient-3.1.jar
===============================================
package oracle.iam.webservice;
public class OIMUserManagementBySCIM
{
/*
Operation-4: Disable User Method
*/
public void disableUser()
{
//1. Define URL with User Key
org.apache.commons.httpclient.methods.PostMethod m = new org.apache.commons.httpclient.methods.PostMethod("http://oimhost:14000/idaas/im/scim/v1/Users/13337")
{
@Override
//2. Calling PATCH Operation
public String getName()
{
System.out.println(" After PATCH ");
return "PATCH";
}
};
//3. Define Authorization
System.out.println(" Passing Credential ");
String userCredentials = "xelsysadm:password";
new com.sun.xml.internal.messaging.saaj.util.Base64();
String basicAuth = "Basic " + new String(com.sun.xml.internal.messaging.saaj.util.Base64.encode(userCredentials.getBytes()));
m.setRequestHeader("Authorization", basicAuth);
try
{
//4. Creating Object
org.json.JSONObject request_body = new org.json.JSONObject();
org.json.JSONArray request_body_schemas = new org.json.JSONArray();
//5. Passing SChema
request_body_schemas.put("urn:ietf:params:scim:api:messages:2.0:PatchOp");
request_body.put("schemas", request_body_schemas);
org.json.JSONArray request_body_operation= new org.json.JSONArray();
//6. Enable User
org.json.JSONObject request_body_disable= new org.json.JSONObject();
request_body_disable.put("op", "replace");
request_body_disable.put("path", "urn:ietf:params:scim:schemas:core:2.0:User:active");
request_body_disable.put("value", false);
request_body_operation.put(request_body_disable);
request_body.put("Operations", request_body_operation);
System.out.println("JSON Object: "+request_body);
//6. Sending Data in OIM
m.setRequestEntity(new org.apache.commons.httpclient.methods.StringRequestEntity(request_body.toString(), "application/scim+json", "UTF-8"));
org.apache.commons.httpclient.HttpClient c = new org.apache.commons.httpclient.HttpClient();
int sc = c.executeMethod(m);
System.out.println("PATCH call returned a Disable status code ::" + sc);
}
catch (java.net.ProtocolException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (java.net.MalformedURLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (java.io.IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (org.json.JSONException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String args[])
{
OIMUserManagementBySCIM usermgmt=new OIMUserManagementBySCIM();
usermgmt.disableUser();
}
}
-----------------------------------------------------------------------------------
Required Jar File-
java-json.jar
sun.misc.BASE64Decoder.jar
apache-httpcomponents-httpcore.jar
apache-jakarta-commons-httpclient.jar
commons-codec-1.9.jar
commons-logging.jar
commons-httpclient-3.1.jar
===============================================
package oracle.iam.webservice;
public class OIMUserManagementBySCIM
{
/*
Operation-4: Disable User Method
*/
public void disableUser()
{
//1. Define URL with User Key
org.apache.commons.httpclient.methods.PostMethod m = new org.apache.commons.httpclient.methods.PostMethod("http://oimhost:14000/idaas/im/scim/v1/Users/13337")
{
@Override
//2. Calling PATCH Operation
public String getName()
{
System.out.println(" After PATCH ");
return "PATCH";
}
};
//3. Define Authorization
System.out.println(" Passing Credential ");
String userCredentials = "xelsysadm:password";
new com.sun.xml.internal.messaging.saaj.util.Base64();
String basicAuth = "Basic " + new String(com.sun.xml.internal.messaging.saaj.util.Base64.encode(userCredentials.getBytes()));
m.setRequestHeader("Authorization", basicAuth);
try
{
//4. Creating Object
org.json.JSONObject request_body = new org.json.JSONObject();
org.json.JSONArray request_body_schemas = new org.json.JSONArray();
//5. Passing SChema
request_body_schemas.put("urn:ietf:params:scim:api:messages:2.0:PatchOp");
request_body.put("schemas", request_body_schemas);
org.json.JSONArray request_body_operation= new org.json.JSONArray();
//6. Enable User
org.json.JSONObject request_body_disable= new org.json.JSONObject();
request_body_disable.put("op", "replace");
request_body_disable.put("path", "urn:ietf:params:scim:schemas:core:2.0:User:active");
request_body_disable.put("value", false);
request_body_operation.put(request_body_disable);
request_body.put("Operations", request_body_operation);
System.out.println("JSON Object: "+request_body);
//6. Sending Data in OIM
m.setRequestEntity(new org.apache.commons.httpclient.methods.StringRequestEntity(request_body.toString(), "application/scim+json", "UTF-8"));
org.apache.commons.httpclient.HttpClient c = new org.apache.commons.httpclient.HttpClient();
int sc = c.executeMethod(m);
System.out.println("PATCH call returned a Disable status code ::" + sc);
}
catch (java.net.ProtocolException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (java.net.MalformedURLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (java.io.IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (org.json.JSONException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String args[])
{
OIMUserManagementBySCIM usermgmt=new OIMUserManagementBySCIM();
usermgmt.disableUser();
}
}
No comments:
Post a Comment