Revision 930
Added by Jing Tao almost 23 years ago
src/edu/ucsb/nceas/metacat/AuthLdap.java | ||
---|---|---|
68 | 68 |
private String ldapsUrl; |
69 | 69 |
private String ldapBase; |
70 | 70 |
private String referral; |
71 |
private Context referralContext;
|
|
71 |
private Context referralContext;
|
|
72 | 72 |
Hashtable env = new Hashtable(11); |
73 | 73 |
private Context rContext; |
74 |
private String userName; |
|
75 |
private String userPassword; |
|
74 | 76 |
ReferralException refExc; |
75 | 77 |
|
76 | 78 |
/** |
... | ... | |
109 | 111 |
|
110 | 112 |
// Check the usename as passed in |
111 | 113 |
authenticated = ldapAuthenticate(identifier, password); |
112 |
System.out.println("Identifier: "+ identifier); |
|
114 |
//System.out.println("Identifier: "+ identifier);
|
|
113 | 115 |
|
114 | 116 |
// if not found, try looking up a valid DN then auth again |
115 | 117 |
//Because identifier already has url and idapbase information, |
... | ... | |
161 | 163 |
if (identifier != null && !password.equals("")) |
162 | 164 |
{ |
163 | 165 |
|
164 |
// Identify service provider to use |
|
166 |
//Pass the username and password to run() |
|
167 |
userName=identifier; |
|
168 |
userPassword=password; |
|
169 |
// Identify service provider to use |
|
165 | 170 |
Hashtable env = new Hashtable(11); |
166 | 171 |
env.put(Context.INITIAL_CONTEXT_FACTORY, |
167 | 172 |
"com.sun.jndi.ldap.LdapCtxFactory"); |
... | ... | |
179 | 184 |
variable. it is hard coded to 'throw'. Matt: Is it ok to do this |
180 | 185 |
only here and not in every method? |
181 | 186 |
*/ |
182 |
System.out.println("ldapsUrl: " + ldapsUrl + " ldapBase: " + ldapBase); |
|
187 |
//System.out.println("ldapsUrl: " + ldapsUrl + " ldapBase: " + ldapBase);
|
|
183 | 188 |
env.put(Context.PROVIDER_URL, ldapsUrl + ldapBase); |
184 | 189 |
if ( !ldapsUrl.equals(ldapUrl) ) |
185 | 190 |
{ |
... | ... | |
188 | 193 |
env.put(Context.SECURITY_PROTOCOL, "ssl"); |
189 | 194 |
} |
190 | 195 |
env.put(Context.SECURITY_AUTHENTICATION, "simple"); |
191 |
System.out.println("provider_url: "+env.get(Context.PROVIDER_URL)); |
|
196 |
//System.out.println("provider_url: "+env.get(Context.PROVIDER_URL));
|
|
192 | 197 |
env.put(Context.SECURITY_PRINCIPAL, identifier); |
193 | 198 |
//System.out.println("Trying DN: " + identifier); |
194 | 199 |
env.put(Context.SECURITY_CREDENTIALS, password); |
... | ... | |
198 | 203 |
try |
199 | 204 |
{ |
200 | 205 |
double startTime = System.currentTimeMillis(); |
201 |
System.out.println("Before creating ctx"); |
|
206 |
//System.out.println("Before creating ctx");
|
|
202 | 207 |
//Here to check the autheration |
203 | 208 |
ctx = new InitialDirContext(env); |
204 | 209 |
//Keep track the value of provider url |
205 |
System.out.println("I am before getEnvironment()"); |
|
206 |
System.out.println("Here is the provider url from enviroment: "+ |
|
207 |
(ctx.getEnvironment()).get("Context.PROVIDER_URL")); |
|
210 |
//System.out.println("I am before getEnvironment()");
|
|
211 |
//System.out.println("Here is the provider url from enviroment: "+
|
|
212 |
//(ctx.getEnvironment()).get("Context.PROVIDER_URL"));
|
|
208 | 213 |
|
209 |
System.out.println("After creating ctx"); |
|
214 |
//System.out.println("After creating ctx");
|
|
210 | 215 |
double stopTime = System.currentTimeMillis(); |
211 | 216 |
System.out.println("Connection time thru " + ldapsUrl + " was: " + |
212 | 217 |
(stopTime-startTime)/1000 + " seconds."); |
... | ... | |
220 | 225 |
catch (AuthenticationException ae) |
221 | 226 |
{ |
222 | 227 |
//To keep tracking Jing Tao, 02/06/02 |
223 |
System.out.println("AuthernticationException happened!"); |
|
228 |
//System.out.println("AuthernticationException happened!");
|
|
224 | 229 |
authenticated = false; |
225 | 230 |
if ( ctx != null ) |
226 | 231 |
{ |
... | ... | |
1044 | 1049 |
{ |
1045 | 1050 |
referralContext = null; |
1046 | 1051 |
DirContext refDirContext=null; |
1047 |
try |
|
1048 |
{ |
|
1049 |
System.out.println("running thread...."); |
|
1050 |
//Revise environment variable |
|
1051 |
env.put(Context.PROVIDER_URL, refExc.getReferralInfo()); |
|
1052 |
env.put(Context.INITIAL_CONTEXT_FACTORY, |
|
1052 |
boolean moreReferrals=true; |
|
1053 |
while(moreReferrals) |
|
1054 |
{ |
|
1055 |
try |
|
1056 |
{ |
|
1057 |
System.out.println("running thread...."); |
|
1058 |
//Revise environment variable |
|
1059 |
env.put(Context.PROVIDER_URL, refExc.getReferralInfo()); |
|
1060 |
env.put(Context.INITIAL_CONTEXT_FACTORY, |
|
1053 | 1061 |
"com.sun.jndi.ldap.LdapCtxFactory"); |
1054 |
env.put(Context.REFERRAL, "throw"); |
|
1055 |
//Get a context object for referral in the new envriment |
|
1056 |
rContext = refExc.getReferralContext(env); |
|
1057 |
System.out.println("After revsing env, referral povider_url: "+ |
|
1058 |
env.get(Context.PROVIDER_URL)); |
|
1059 |
//refExc.retryReferral(); |
|
1060 |
System.out.println("Here is environment for rContext: "); |
|
1061 |
System.out.println(rContext.getEnvironment()); |
|
1062 |
System.out.println("here is rContext full name:"); |
|
1063 |
System.out.println(rContext.getNameInNamespace()); |
|
1064 |
//Casting the context to dircontext and hopelly will create a |
|
1065 |
//autherntication exception if DN and password is incorrect |
|
1066 |
referralContext=rContext; |
|
1067 |
refDirContext=(DirContext)rContext; |
|
1068 |
System.out.println("Why?"); |
|
1069 |
//refDirContext=new InitialDirContext(env); |
|
1070 |
refDirContext.close(); |
|
1071 |
//referralContext = handleReferral(env, rContext); |
|
1072 |
//System.out.println("rContext.PROVIDER_URL: "+rContext.PROVIDER_URL); |
|
1073 |
//Hashtable tempenv=rContext.getEnvironment(); |
|
1074 |
//If running the above line, we will get a java.long.NullPointerException |
|
1075 |
System.out.println("exiting thread..."); |
|
1076 |
} |
|
1077 |
//Jing Tao |
|
1078 |
catch(AuthenticationException ae) |
|
1079 |
{ |
|
1080 |
System.out.println("In referral authentication exception"); |
|
1081 |
System.out.println("Error running referral handler thread: " + |
|
1062 |
env.put(Context.SECURITY_PRINCIPAL, userName); |
|
1063 |
env.put(Context.SECURITY_CREDENTIALS, userPassword); |
|
1064 |
env.put(Context.REFERRAL, "throw"); |
|
1065 |
//Get a context object for referral in the new envriment |
|
1066 |
rContext = refExc.getReferralContext(env); |
|
1067 |
/*System.out.println("After revsing env, referral povider_url: "+ |
|
1068 |
env.get(Context.PROVIDER_URL));*/ |
|
1069 |
/*System.out.println("Here is environment for rContext: "); |
|
1070 |
System.out.println(rContext.getEnvironment());*/ |
|
1071 |
//Casting the context to dircontext and hopelly will create a |
|
1072 |
//autherntication or naming exception if DN and password is incorrect |
|
1073 |
referralContext=rContext; |
|
1074 |
refDirContext=(DirContext)rContext; |
|
1075 |
refDirContext.close(); |
|
1076 |
//Get context and jump out the while loop |
|
1077 |
moreReferrals=false; |
|
1078 |
//System.out.println("rContext.PROVIDER_URL: "+rContext.PROVIDER_URL); |
|
1079 |
//Hashtable tempenv=rContext.getEnvironment(); |
|
1080 |
//If running the above line, we will get a java.long.NullPointerException |
|
1081 |
System.out.println("exiting thread..."); |
|
1082 |
}//try |
|
1083 |
//If referral have a referral excption |
|
1084 |
catch(ReferralException re) |
|
1085 |
{ |
|
1086 |
//Keep running in while loop |
|
1087 |
moreReferrals=true; |
|
1088 |
//Assign refExc to new referral exception re |
|
1089 |
refExc=re; |
|
1090 |
//System.out.println("Referral Exception again"); |
|
1091 |
}//catch ref |
|
1092 |
//catch a authentication exception |
|
1093 |
catch(AuthenticationException ae) |
|
1094 |
{ |
|
1095 |
System.out.println("In referral authentication exception"); |
|
1096 |
System.out.println("Error running referral handler thread: " + |
|
1082 | 1097 |
ae.getMessage()); |
1083 |
ae.printStackTrace(); |
|
1084 |
referralContext = null; |
|
1085 |
|
|
1086 |
} |
|
1087 |
//Jing Tao |
|
1088 |
catch(NamingException ne) |
|
1089 |
{ |
|
1090 |
System.out.println("Error running referral handler thread: " + |
|
1098 |
//ae.printStackTrace(); |
|
1099 |
//Jump out the while loop |
|
1100 |
moreReferrals=false; |
|
1101 |
//Don't get the context |
|
1102 |
referralContext = null; |
|
1103 |
}//catch ather exception |
|
1104 |
//catch a naming exception |
|
1105 |
catch(NamingException ne) |
|
1106 |
{ |
|
1107 |
System.out.println("Error running referral handler thread: " + |
|
1091 | 1108 |
ne.getMessage()); |
1092 |
ne.printStackTrace(); |
|
1093 |
referralContext = null; |
|
1094 |
} |
|
1095 |
catch(Exception e) |
|
1096 |
{ |
|
1097 |
System.out.println("Error running referral handler thread: " + |
|
1098 |
e.getMessage()); |
|
1099 |
e.printStackTrace(); |
|
1100 |
referralContext = null; |
|
1101 |
} |
|
1102 |
} |
|
1109 |
//ne.printStackTrace(); |
|
1110 |
//Jump out the loop |
|
1111 |
moreReferrals=false; |
|
1112 |
//Don't get context |
|
1113 |
referralContext = null; |
|
1114 |
}//catch naming exception |
|
1115 |
}//while |
|
1116 |
//System.out.println("Out of while loop!"); |
|
1117 |
}//run() |
|
1103 | 1118 |
} |
Also available in: Unified diff
Authentication bug was fixed (bug 408).
However, it needs to test if referral cotaining a referral.