Personal tools
You are here: Home Oracle Checking for a User in OID

 

Document Actions

Checking for a User in OID

by Mark Allen last modified 2008-02-16 20:49

Test to see if a user is already in OID

The following java code checks to see if there is a user in OID, returning true if they are there.


import oracle.ldap.util.*;

import oracle.ldap.util.jndi.*;
import java.io.*;


import java.util.*;


import javax.naming.*;

import javax.naming.directory.*;


public class Application1 {

    InitialDirContext ctx;


    public Application1() throws NamingException {


        // Create InitialDirContext

        try {

             ctx  = ConnectionUtil.getDefaultDirCtx("linux02", "389", "cn=orcladmin", "orcladmin1");

         } catch (NamingException e) {

             throw e;

         }

    }


    public static void main(String[] args) throws NamingException {

        Application1 appl1 = new Application1();

        if (appl1.exec("cn=mark.allen,cn=Users,dc=markcallen,dc=com"))

            System.out.println("Found mark.allen");

        if (! appl1.exec("cn=unknown,cn=Users,dc=markcallen,dc=com"))

            System.out.println("Could not find unknown");


    }


    public boolean exec(String userId) {

        try {

            Util.getUserDn(ctx, userId, Util.IDTYPE_DN, null);


        } catch (oracle.ldap.util.NoSuchUserException e) {

            return false;

        }

        catch (UtilException e) {

            throw e;

        }

        return true;

    }

}


Ads
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: