Project

General

Profile

« Previous | Next » 

Revision 5374

Added by berkley almost 14 years ago

refactored the sessionService to use a correct singleton initialization scheme. Added true authentication to ResourceHandler.

View differences:

ResourceHandler.java
58 58
import edu.ucsb.nceas.metacat.McdbDocNotFoundException;
59 59
import edu.ucsb.nceas.metacat.MetacatHandler;
60 60
import edu.ucsb.nceas.metacat.dataone.CrudService;
61
import edu.ucsb.nceas.metacat.service.SessionService;
61 62
import edu.ucsb.nceas.metacat.util.RequestUtil;
62 63
import edu.ucsb.nceas.metacat.util.SessionData;
63 64

  
......
203 204
    private static final String FUNCTION_NAME_GETNEXTOBJ = "getnextobject";
204 205
    private static final String FUNCTION_NAME_INSERT = "insert";
205 206
    private static final String FUNCTION_NAME_UPDATE = "update";
207
    private static final String FUNCTION_NAME_GENERATE_MISSING_SYSTEM_METADATA = "generatemissingsystemmetadata";
206 208

  
207 209
    private ServletContext servletContext;
208 210
    private Logger logMetacat;
......
225 227
    }
226 228

  
227 229
    /**
228
     *  copies request parameters to a hashtable which is given as argument to native metacathandler functions  
229
     */
230
    private void initParams() {
231

  
232
        String name = null;
233
        String[] value = null;
234
        Enumeration paramlist = request.getParameterNames();
235
        while (paramlist.hasMoreElements()) {
236
            name = (String) paramlist.nextElement();
237
            value = request.getParameterValues(name);
238
            //System.out.println("adding param: " + name + " = " + value);
239
            params.put(name, value);
240
        }
241

  
242
    }
243

  
244
    /**
245
     * 
246
     * Load user details of metacat session from the request 
247
     * 
248
     */
249
    private void loadSessionData() {
250
        SessionData sessionData = RequestUtil.getSessionData(request);
251

  
252
        // TODO: validate the session before allowing these values to be set
253
        username = sessionData.getUserName();
254
        password = sessionData.getPassword();
255
        groupNames = sessionData.getGroupNames();
256
        sessionId = sessionData.getId();
257
        //System.out.println("setting sessionid to " + sessionId);
258
        
259
        if (username == null) {
260
            username = "public";
261
        }
262
    }
263

  
264
    /**
265 230
     * This function is called from REST APU servlet and handles each request to the servlet 
266 231
     * 
267 232
     * @param httpVerb (GET, POST, PUT or DELETE)
......
302 267
                            //System.out.println("done setting access");
303 268
                        }
304 269
                    } else if (resource.equals(RESOURCE_META)) {
305
                        loadSessionData();
306
                        String objectId = request.getPathInfo();
307
                        if (objectId != null && objectId.length() > 1) 
270
                        if(params.get(FUNCTION_KEYWORD)[0].equals(FUNCTION_NAME_GENERATE_MISSING_SYSTEM_METADATA))
271
                        { //generate system metadata for any object that is
272
                          //a) not system metadata itself
273
                          //b) does not already have a system metadata id in the systemmetadata table
274
                          //c) not a BIN object (data)
275
                            generateMissingSystemMetadata();
276
                            status = true;
277
                        }
278
                        else
308 279
                        {
309
                            objectId = request.getPathInfo().substring(1);
280
                            loadSessionData();
281
                            String objectId = request.getPathInfo();
282
                            if (objectId != null && objectId.length() > 1) 
283
                            {
284
                                objectId = request.getPathInfo().substring(1);
285
                            }
286
                            getSystemMetadataObject(objectId);
287
                            status = true;
310 288
                        }
311
                        getSystemMetadataObject(objectId);
312
                        status = true;
313 289
                            
314 290
                    } else if (resource.equals(RESOURCE_OBJECTS)) {
315 291
                    logMetacat.debug("D1 Rest: Starting resource processing...");
......
383 359
            e.printStackTrace();
384 360
        }
385 361
    }
362
    
363
    /**
364
     *  copies request parameters to a hashtable which is given as argument to native metacathandler functions  
365
     */
366
    private void initParams() {
386 367

  
368
        String name = null;
369
        String[] value = null;
370
        Enumeration paramlist = request.getParameterNames();
371
        while (paramlist.hasMoreElements()) {
372
            name = (String) paramlist.nextElement();
373
            value = request.getParameterValues(name);
374
            //System.out.println("adding param: " + name + " = " + value);
375
            params.put(name, value);
376
        }
377

  
378
    }
379

  
387 380
    /**
388
     *  Earthgrid API > Identifier Service > isRegistered Function : calls MetacatHandler > handleIdIsRegisteredAction
381
     * 
382
     * Load user details of metacat session from the request 
383
     * 
384
     */
385
    private void loadSessionData()
386
      throws Exception
387
    {
388
        SessionData sessionData = RequestUtil.getSessionData(request);
389
        try
390
        {
391
            username = null;
392
            password = null;
393
            groupNames = null;
394
            sessionId = null;
395
            
396
            boolean validSession = false;
397
            SessionService ss = SessionService.getInstance();
398
            //validate the session
399
            if(ss.isSessionRegistered(sessionData.getId()))
400
            {
401
                validSession = true;
402
            }
403
            
404
            if(validSession)
405
            {
406
                //if the session is valid, set these variables
407
                username = sessionData.getUserName();
408
                password = sessionData.getPassword();
409
                groupNames = sessionData.getGroupNames();
410
                sessionId = sessionData.getId();
411
                //System.out.println("setting sessionid to " + sessionId);
412
            }
413
            
414
            //if the session is not valid or the username is null, set
415
            //username to public
416
            if (username == null) 
417
            {
418
                username = "public";
419
            }
420
        }
421
        catch(Exception e)
422
        {
423
            throw new Exception("Could not load the session data: " + e.getMessage());
424
        }
425
    }
426
    
427
    /**
428
     * generate missing system metadata for any science metadata objects
429
     * that don't already have it. https://trac.dataone.org/ticket/591
430
     */
431
    private void generateMissingSystemMetadata()
432
    {
433
        //generate system metadata for any object that is
434
        //a) not system metadata itself
435
        //b) does not already have a system metadata id in the systemmetadata table
436
        //c) not a BIN object (data)
437
        
438
    }
439

  
440
    /**
441
     *  Earthgrid API > Identifier Service > isRegistered Function : 
442
     *  calls MetacatHandler > handleIdIsRegisteredAction
389 443
     * @param guid
390 444
     * @throws IOException
391 445
     */
......
408 462
    }
409 463

  
410 464
    /**
411
     * Earthgrid API > Identifier Service > getAllDocIds Function : calls MetacatHandler > handleGetAllDocidsAction
465
     * Earthgrid API > Identifier Service > getAllDocIds Function : 
466
     * calls MetacatHandler > handleGetAllDocidsAction
412 467
     * @throws IOException
413 468
     */
414 469
    private void getAllDocIds() throws IOException {
......
418 473
    }
419 474

  
420 475
    /**
421
     * Earthgrid API > Identifier Service > getNextRevision Function : calls MetacatHandler > handleGetRevisionAndDocTypeAction
476
     * Earthgrid API > Identifier Service > getNextRevision Function : 
477
     * calls MetacatHandler > handleGetRevisionAndDocTypeAction
422 478
     * @param guid
423 479
     * @throws IOException
424 480
     */
......
467 523
    }
468 524

  
469 525
    /**
470
     * Earthgrid API > Identifier Service > getNextObject Function : calls MetacatHandler > handleGetMaxDocidAction
526
     * Earthgrid API > Identifier Service > getNextObject Function : 
527
     * calls MetacatHandler > handleGetMaxDocidAction
471 528
     * @throws IOException
472 529
     */
473 530
    private void getNextObject() throws IOException {

Also available in: Unified diff