Wednesday, October 8, 2014

TIPS: Sample Create User Oracle Identity Manager 11g API code

Sample Code:

import Thor.API.Operations.tcLookupOperationsIntf;

import java.util.HashMap;
import java.util.Hashtable;

import javax.security.auth.login.LoginException;

import oracle.iam.identity.exception.UserAlreadyExistsException;
import oracle.iam.identity.exception.UserCreateException;
import oracle.iam.identity.exception.ValidationFailedException;
import oracle.iam.identity.usermgmt.api.UserManager;
import oracle.iam.identity.usermgmt.vo.User;
import oracle.iam.platform.OIMClient;

public class OIMTestClient
{  
    public static void main(String arg[])
    {
        Hashtable<Object, Object> env = new Hashtable<Object, Object>();
        env.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, "weblogic.jndi.WLInitialContextFactory");
        env.put(OIMClient.JAVA_NAMING_PROVIDER_URL, "t3://pokuri.demo.com:14000");
     
        System.setProperty("java.security.auth.login.config", "/IdentityManagement/Blog/OIM/JDeveloperConfigforOIM/designconsole/config/authwl.conf");
        System.setProperty("OIM.AppServerType", "wls");
        System.setProperty("APPSERVER_TYPE", "wls");
        oracle.iam.platform.OIMClient oimClient = new oracle.iam.platform.OIMClient(env);
     
        try
        {                      
            oimClient.login("xelsysadm", "Abcd1234".toCharArray());
            System.out.print("Successfully Connected with OIM ");
            System.out.println("Before Create User --");
         
         
            HashMap<String, Object> userAttributeValueMap = new HashMap<String, Object>();
            userAttributeValueMap.put("act_key", new Long(1));
            userAttributeValueMap.put("User Login", "sam");
            userAttributeValueMap.put("First Name", "sam");
            userAttributeValueMap.put("Last Name", "peter");
            userAttributeValueMap.put("Email", "speter@abc.com");
            userAttributeValueMap.put("usr_password", "Password123");
            userAttributeValueMap.put("Role", "OTHER");
            User user = new User("sam", userAttributeValueMap);
            UserManager userManager = oimClient.getService(UserManager.class);
            try {
                userManager.create(user);
                System.out.println("\nUser Created");
            } catch (ValidationFailedException e) {
                e.printStackTrace();
            } catch (UserAlreadyExistsException e) {
                e.printStackTrace();
            } catch (UserCreateException e) {
                e.printStackTrace();
            }
            System.out.println("User Created successfully");
        }
        catch (Exception e)
        {
            System.out.print(" Exception"+ e);
        }
    }
}

Sample Oracle Identity Manager 11g API code to Create and add values to Lookup


Note: Before running the code make sure all the below jar files are in class path


Sample Code

import Thor.API.Operations.tcLookupOperationsIntf;
import java.util.Hashtable;
import javax.security.auth.login.LoginException;
import oracle.iam.platform.OIMClient;
public class OIMTestClient
{  
    public static void main(String arg[])
    {
        Hashtable<Object, Object> env = new Hashtable<Object, Object>();
        env.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, "weblogic.jndi.WLInitialContextFactory");
        env.put(OIMClient.JAVA_NAMING_PROVIDER_URL, "t3://pokuri.demo.com:14000");
     
        System.setProperty("java.security.auth.login.config", "/IdentityManagement/Blog/OIM/JDeveloperConfigforOIM/designconsole/config/authwl.conf");
        System.setProperty("OIM.AppServerType", "wls");
        System.setProperty("APPSERVER_TYPE", "wls");
        oracle.iam.platform.OIMClient oimClient = new oracle.iam.platform.OIMClient(env);
        try
        {                      
            oimClient.login("xelsysadm", "Abcd1234".toCharArray());
            System.out.print("Successfully Connected with OIM ");
            System.out.println("Before Lookup add--");
            tcLookupOperationsIntf lookupIntf = oimClient.getService(tcLookupOperationsIntf.class);
         
            // Create Lookup
            lookupIntf.addLookupCode("UserRoles");
            System.out.println("Created Lookup Table");
         
            // Add Values to lookup
            lookupIntf.addLookupValue("UserRoles", "Admin", "Admin", "en", "US");
            lookupIntf.addLookupValue("UserRoles", "End-User", "End-User", "en", "US");
         
            System.out.println("Added Lookup Values succsesfully");
        }
        catch (Exception e)
        {
            System.out.print(" Exception"+ e);
        }
    }
}

-- Siva Pokuri.

Monday, October 6, 2014

Sample JNDI code to connect and get Active Directory Group properties

import java.util.Hashtable;
import java.util.Date;

import javax.naming.*;
import javax.naming.directory.*;

class GetGroupProps
{
public static void main(String[] args)
{
int totalResults = 0;
Hashtable env = new Hashtable(5, 0.75f);
final String ldapSearchBase = "dc=addemo,dc=com";
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://spsolutions.addemo.com:389");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "cn=Administrator,cn=users,dc=addemo,dc=com");
env.put(Context.SECURITY_CREDENTIALS, "Oracle@1234");
try
{
        DirContext ctx = new InitialDirContext(env);
        System.out.println("Login Successful");
        String searchFilter = "(&(objectClass=group)(CN=Administrators))";
        SearchControls searchControls = new SearchControls();
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
NamingEnumeration<SearchResult> results = ctx.search(ldapSearchBase, searchFilter, searchControls);
while (results.hasMoreElements())
{
SearchResult sr = (SearchResult)results.next();
System.out.println(">>>" + sr.getName());
Attributes attrs = sr.getAttributes();
if (attrs != null
{
try 
{
for (NamingEnumeration ae = attrs.getAll();ae.hasMore();) 
{
Attribute attr = (Attribute)ae.next();
System.out.println("Attribute: " + attr.getID());
for (NamingEnumeration e = attr.getAll();e.hasMore();totalResults++) 
{
System.out.println(" " +  totalResults + ". " +  e.next());
}
}
}
catch (NamingException e)    
{
System.err.println("Problem listing membership: " + e);
}
}
}
}
catch(Exception e)
        {
System.out.println("Exception "+ e);
        }
}
}