Link to home
Start Free TrialLog in
Avatar of aquatone282
aquatone282

asked on

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

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
Avatar of Jaax
Jaax
Flag of India image

...
   User myUser = null;
   Subscriber sub = nulll;

  try{
   sub = roc.getSubscriber(ctx, Util.IDTYPE_DEFAULT, null, new String[] { "*" });
    myUser = sub.getUser(ctx, Util.IDTYPE_DN, p.getName(), new String[] { });
}catch(UtilException ue)){
   ue.printStackTrace();
}catch(Exception e){
  e.printStackTrace();
}

 if(myUser != null){
   //Your Logic - If
 }else{
  //Your Logic - Else
 }
Avatar of aquatone282
aquatone282

ASKER

No, it still throws the exception (LDAP Code 32 - No Object Found) when I try

 if(myUser != null){
   //Your Logic - If
 }else{
  //Your Logic - Else
 }

Any other ideas?
>>if(myUser != null){

You mean it throws the exception is thrown at the above line ?
That is rather strange !!
ASKER CERTIFIED SOLUTION
Avatar of markcallen
markcallen

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Jim,

Any luck in getting this to work?

Mark.