Project

General

Profile

« Previous | Next » 

Revision 251

Added by bojilova over 24 years ago

finished user auth & session tracking

View differences:

src/edu/ucsb/nceas/metacat/MetaCatServlet.java
219 219
// Jivka added 
220 220
    // handle login action
221 221
    if (action.equals("Login")) {
222
      //out.println("here is Login"); 
223 222
      handleLoginAction(out, params, request, response);
224 223
    // handle logout action  
225 224
    } else if (action.equals("Logout")) {
226 225
      HttpSession sess = request.getSession(false);
227
      if (sess != null) {
228
        sess.invalidate();
229
        response.sendRedirect("/xmltodb/lib/login.html"); 
226
      if (sess != null) { sess.invalidate();  }    
227
      response.sendRedirect("/xmltodb/lib/login.html"); 
228
    // aware of session expiration on every request  
229
    } else {    
230
      HttpSession sess = request.getSession(false);
231
      if (sess == null) { 
232
        // session expired or has not been stored b/w user requests
233
        // redirect to session expiration message page
234
        response.sendRedirect("/xmltodb/lib/sexpire.html"); 
230 235
      }
231
    // aware of session expiration on every request  
232
//    } else {    
233
//      HttpSession sess = request.getSession(false);
234
//      if (sess == null) { 
235
//        out.println("Session expired. " +
236
//                    "You will be redirected to Login page again.");
237
//        response.sendRedirect("/xmltodb/lib/login.html"); 
238
//      }
239 236
    }    
240 237
// End of Jivka added
241 238

  
......
257 254
      handleValidateAction(out, params, response);  
258 255
    } else if (action.equals("getdatadoc")) {
259 256
      handleGetDataDocumentAction(out, params, response);  
257
    } else if (action.equals("Login")) {
260 258
    } else {
261 259
      out.println("Error: action not registered.  Please report this error.");
262 260
    }
......
273 271

  
274 272
  private void handleLoginAction(PrintWriter out, Hashtable params, 
275 273
               HttpServletRequest request, HttpServletResponse response) {
274

  
276 275
    String un = ((String[])params.get("username"))[0];
277 276
    String pw = ((String[])params.get("password"))[0];
278
 out.println("Username:" + un);
279
 out.println("Password:" + pw);
277

  
280 278
    MetaCatSession sess = new MetaCatSession(request, un, pw);
281
 out.println("SRB Host: " + sess.srbHost);
282
 out.println("SRB Port: " + sess.srbPort);
283 279
 
284 280
    try {  
285 281
        if (sess.userAuth(pw)) {
......
294 290
            }                
295 291
                
296 292
        } else {
297
 out.println("SRB Host: " + sess.srbHost);
298
 out.println("SRB Port: " + sess.srbPort);
299 293
            sess.disconnect();            
300 294
            out.println("SRB Connection failed. " +
301 295
                        "SRB RMI Server is not running now or " +
......
559 553
        valtext = docreader.readXMLDocument(docid);
560 554

  
561 555
      } catch (NullPointerException npe) {
562
        response.setContentType("text/xml");
563
        out.println("<error>Error getting document ID: " + docid + "</error>");
556
        response.setContentType("text/html");
557
        out.println("Error getting document ID: " + docid );
564 558
      }
565 559
    }
566 560

  
567 561
    try {
568
      DBValidate valobj = new DBValidate(saxparser,conn);
562
      DBValidate valobj = new DBValidate(saxparser,xmlcatalogfile);
569 563
      boolean valid = valobj.validateString(valtext);
570 564

  
571 565
      // set content type and other response header fields first
572
      response.setContentType("text/xml");
573
      out.println(valobj.returnErrors());
574

  
566
      response.setContentType("text/html");
567
      out.println("<html>");
568
      out.println("<head><link rel=\"stylesheet\" type=\"text/css\" " +
569
                  "href=\"/xmltodb/rowcol.css\" /></head>");
570
      out.println("<body class=\"emlbody\">");
571
  
572
      if (valid) {
573
        out.println("The input XML is VALID!");
574
      } else {
575
        out.println("The input XML is NOT VALID<br />\n<pre>\n" 
576
                    + valobj.returnErrors() + "\n</pre>\n");
577
      } 
578
      out.println("</body></html>");
575 579
    } catch (NullPointerException npe2) {
576 580
      // set content type and other response header fields first
577
      response.setContentType("text/xml");
578
      out.println("<error>Error validating document.</error>"); 
581
      response.setContentType("text/html");
582
      out.println("Error validating document."); 
579 583
    }
580 584
  }
581 585

  
......
637 641

  
638 642
/**
639 643
 * '$Log$
640
 * 'Revision 1.48  2000/06/29 20:04:51  bojilova
641
 * 'testing login
642
 * '
643 644
 * 'Revision 1.36  2000/06/28 02:36:26  jones
644 645
 * 'Added feature to now ouput COMMENTs and PIs when the document is
645 646
 * 'read from the database with DBReader.

Also available in: Unified diff