We help IT Professionals succeed at work.
Get Started

Test for oracle.ldap.util.User object Existence in Oracle Internet Directory

1,232 Views
Last Modified: 2013-12-01
Hi,

I need to query the Oracle Internet Directory LDAP server for a User object.  If the User is not found, an exception is thrown.   I need to be able to test for the User object's existence in OID withouth an excpetion being thrown.

This is what I have right now:

   sub = roc.getSubscriber(ctx, Util.IDTYPE_DEFAULT, null, new String[] { "*" });

   User myUser = null;

   myUser = sub.getUser(ctx, Util.IDTYPE_DN, p.getName(), new String[] { });

Again, if myUser is not found, an exception is thrown.  I need to be able to test if myUser exists for a if - else conditional, i.e.

   IF (myUser == null  //this doesn't work - exception thrown before I get here) {
         do something
   } ELSE {
         do something else
   }

Here's more of the code I have right now:

                RootOracleContext roc = null;
                Subscriber sub = null;

                roc = new RootOracleContext(ctx);

                try {
                    // Using RootOracleContext to fetch the default realm
                    sub = roc.getSubscriber(ctx, Util.IDTYPE_DEFAULT, null, new String[] { "*" });
                } catch (UtilException ue) {
                    out.println("Exception encountered when fetching Subscriber");
                    throw ue;
                }
                User myUser = null;

                try {
                    // ctx - the DirContext
                    // Util.IDTYPE_SIMPLE - indicates the criteria used to look
                    //                      up the user.
                    //                      IDTYPE_SIMPLE = nickname
                    //                      IDTYPE_DN     = DN
                    //                      IDTYPE_GUID   = GUID of user
                    myUser =
                            sub.getUser(ctx, Util.IDTYPE_DN, p.getName(), new String[] { });

                } catch (UtilException e) {
                            System.out.println(e.getMessage());
                }
                           
TIA,

Jim
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE