Project

General

Profile

« Previous | Next » 

Revision 927

Added by Jing Tao over 22 years ago

In order to fix bug 408 (authentication), some important variables' values
were followed.

View differences:

src/edu/ucsb/nceas/metacat/AuthLdap.java
109 109
   
110 110
        // Check the usename as passed in
111 111
        authenticated = ldapAuthenticate(identifier, password);
112
				System.out.println("Identifier: "+ identifier);
112 113

  
113 114
        // if not found, try looking up a valid DN then auth again
114
        if (!authenticated) {
115
        //Because identifier already has url and idapbase information,
116
				//we don't need check again.
117
				/*if (!authenticated) 
118
				{
119
	    			
120
	    			System.out.println("Check  againg!");
121
            System.out.println("idenfier: "+identifier);
122
						System.out.println("ldapUrl: "+ldapUrl);
123
						System.out.println("ldapBase: "+ldapBase);
115 124
            identifier = getIdentifyingName(identifier,ldapUrl,ldapBase);
125
					
126
						System.out.println("In Check again and after getIdenName, identifier: "+identifier+","
127
						+ldapBase);
116 128
            authenticated = ldapAuthenticate(identifier+","+ldapBase, password);
117
        }
129
        }*/
118 130

  
119 131
    } catch (NullPointerException e) {
120 132
      util.debugMessage("NullPointerException b' password is null");
......
146 158
  {
147 159
    double totStartTime = System.currentTimeMillis();
148 160
    boolean authenticated = false;
149
    if (identifier != null && !password.equals("")) {
161
    if (identifier != null && !password.equals("")) 
162
		{
150 163
    
151 164
        // Identify service provider to use
152 165
        Hashtable env = new Hashtable(11);
......
157 170
        // Now that we have the dn, we can authenticate, so
158 171
        // authenticate this time when opening the DirContext
159 172
        //System.out.println("referral=throw");
173
        
174
        //Change the vaule of Context.REFERRAL from "throw" to "follow"
175
        //Jing Tao 02/06/02
176
        //env.put(Context.REFERRAL, "follow");
160 177
        env.put(Context.REFERRAL, "throw");
161 178
        /*CB:  Note that the above env.put statement does not use the referral 
162 179
          variable.  it is hard coded to 'throw'.  Matt: Is it ok to do this
163 180
          only here and not in every method?
164 181
        */
165
        //System.out.println("ldapsUrl: " + ldapsUrl + " ldapBase: " + ldapBase);
182
        System.out.println("ldapsUrl: " + ldapsUrl + " ldapBase: " + ldapBase);
166 183
        env.put(Context.PROVIDER_URL, ldapsUrl + ldapBase);
167
        if ( !ldapsUrl.equals(ldapUrl) ) {
184
        if ( !ldapsUrl.equals(ldapUrl) ) 
185
				{
168 186
          // ldap is set on default port 389
169 187
          // ldaps is set on second port - 636 by default
170 188
          env.put(Context.SECURITY_PROTOCOL, "ssl");
171 189
        }
172 190
        env.put(Context.SECURITY_AUTHENTICATION, "simple");
191
				System.out.println("provider_url: "+env.get(Context.PROVIDER_URL));
173 192
        env.put(Context.SECURITY_PRINCIPAL, identifier);
174 193
        //System.out.println("Trying DN: " + identifier);
175 194
        env.put(Context.SECURITY_CREDENTIALS, password);
195
				
176 196
        // If our auth credentials are invalid, an exception will be thrown
177 197
        DirContext ctx = null;
178
        try {
198
        try 
199
        {
179 200
          double startTime = System.currentTimeMillis();
201
          System.out.println("Before creating ctx");
202
          //Here to check the autheration
180 203
          ctx = new InitialDirContext(env);
204
					//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"));
208
					
209
          System.out.println("After creating ctx");
181 210
          double stopTime = System.currentTimeMillis();
182 211
          System.out.println("Connection time thru " + ldapsUrl + " was: " +
183 212
                             (stopTime-startTime)/1000 + " seconds.");
......
187 216
          this.ldapUrl = ldapUrl;
188 217
          this.ldapBase = ldapBase;
189 218
          //break;
190
        } catch (AuthenticationException ae) {
219
        } 
220
        catch (AuthenticationException ae) 
221
        {
222
          //To keep tracking Jing Tao, 02/06/02
223
          System.out.println("AuthernticationException happened!");
191 224
          authenticated = false;
192
          if ( ctx != null ) {
225
          if ( ctx != null ) 
226
          {
193 227
            ctx.close();
194 228
          }
195 229
        } 
......
200 234
        catch(javax.naming.ReferralException re) 
201 235
        {
202 236
          System.out.println("referral during authentication");
237
					System.out.println("Referral information: "+re.getReferralInfo());
203 238
	        try
204 239
          {
205 240
            refExc = re;
241
						
206 242
            Thread t = new Thread(this);
207
            //System.out.println("Starting thread...");
243
            System.out.println("Starting thread...");
208 244
            t.start();
209 245
            System.out.println("sleeping for 5 seconds.");
210 246
            Thread.sleep(5000); //this is a manual override of ldap's 
211 247
                                //hideously long time out period.
212
            //System.out.println("Awake after 5 seconds.");
248
            System.out.println("Awake after 5 seconds.");
213 249
            if(referralContext == null)
214 250
            {
215
              //System.out.println("killing thread....not authenticated.");
251
              System.out.println("killing thread....not authenticated.");
216 252
              t.interrupt();
217
              //System.out.println("thread killed.");
253
              System.out.println("thread killed.");
218 254
              authenticated = false;
219 255
            }
220 256
            else
221 257
            {
222 258
              authenticated = true;
259
							
223 260
            }
224 261
          }
225 262
          catch(Exception e)
......
227 264
            authenticated = false;
228 265
          }
229 266
        }
230
    } else { 
267
    } 
268
		else 
269
		{ 
231 270
        util.debugMessage("User not found");
232 271
    }
233 272
    double totStopTime = System.currentTimeMillis();
......
243 282
  private Context handleReferral(Hashtable env, Context rContext) throws
244 283
                                                                  Exception
245 284
  {
246
    System.out.println("referral to : " + rContext.toString());
285
    System.out.println("Referral to(rContext) : " + rContext.toString());
247 286
    boolean referralSuccess = false;
248 287
    while(referralSuccess != true)
249 288
    {
......
1006 1045
    referralContext = null;
1007 1046
    try
1008 1047
    {
1009
      //System.out.println("running thread....");
1048
      System.out.println("running thread....");
1010 1049
      rContext = refExc.getReferralContext(env);
1050
			System.out.println("Before handling referral povider_url: "+
1051
			env.get(Context.PROVIDER_URL));
1011 1052
      referralContext = handleReferral(env, rContext);
1012
      //System.out.println("exiting thread...");
1053
			System.out.println("rContext.PROVIDER_URL: "+rContext.PROVIDER_URL);
1054
			//Hashtable tempenv=rContext.getEnvironment();
1055
			//If running the above line, we will get a java.long.NullPointerException
1056
			System.out.println("After handling refferal povider_url: "+
1057
			env.get(Context.PROVIDER_URL));
1058
      System.out.println("exiting thread...");
1013 1059
    }
1014 1060
    catch(Exception e)
1015 1061
    {

Also available in: Unified diff