Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > CVS update: joist/java/org/joist/session SessionManager.java

Project highlights: Architectural Overview

joist
Discussion topic

Back to topic list

CVS update: joist/java/org/joist/session SessionManager.java

Author manoj
Full name Manoj Kasichainula
Date 2000-11-09 16:20:16 PST
Message User: manoj
  Date: 00/11/09 16:20:16

  Modified: java/org/joist/session SessionManager.java
  Log:
  Add a method that logs in a user without explicitly checking the
  password. This is useful when you are authenticating users using a
  different scheme than the standard Tigris one.
  
  Also, some common code was spliced out into another method.
  
  Revision Changes Path
  1.21 +87 -22 joist/java/org/joist​/session/SessionMana​ger.java
  
  Index: SessionManager.java
  ====================​====================​====================​=======
  RCS file: /cvs/joist/java/org/​joist/session/Sessio​nManager.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- SessionManager.java 2000/11/07 01:18:34 1.20
  +++ SessionManager.java 2000/11/10 00:20:16 1.21
  @@ -69,7 +69,7 @@
    * Manages information cached in the session.
    *
    * @author David C. Pellegrini <A HREF="mailto:davidp@​dataweb-systems.com"​>davidp@dataweb-s​ystems.com</A>​
  - * @version $Revision: 1.20 $
  + * @version $Revision: 1.21 $
    *
    * Copyright (c) 1999 dataweb systems, inc.
    * Copyright (c) 1999, 2000 CollabNet, Inc.
  @@ -343,6 +343,89 @@
       }
   
       /**
  + * Takes a ResultSet (cursor pointing at the appropriate record) from a
  + * user lookup and caches it
  + *
  + * @param context the WebContext
  + * @param rset the data from the user lookup
  + * @exception SQLException
  + */
  + protected void cacheLoginParameters(WebContext context, ResultSet rset)
  + throws SQLException
  + {
  + setUserName(rset.get​String("name"));
  + setUserID(rset.getSt​ring("userID"));
  + setEmail(rset.getStr​ing("email"));
  + setLoginID(rset.getS​tring("loginID"));
  +
  + // Put values into the context
  +
  + // Real name, e.g. "Brian Behlendorf"
  + context.put("UserName", userName);
  +
  + // Numeric uid, e.g. "42"
  + context.put("loginUserID", userID);
  +
  + // E-mail address
  + context.put("email", email);
  +
  + // loginID, a.k.a. username, e.g. "brian"
  + context.put("loginID", loginID);
  + }
  +
  +
  + /**
  + * Takes a loginID, retrieves user information, and caches it in the
  + * session and context. Does NOT verify password; use this method with
  + * care.
  + *
  + * @param connection a JDBC connection
  + * @param context the WebContext
  + * @param identify the user's login ID
  + * @return A variable of type boolean
  + * @exception SQLException
  + */
  + public boolean cacheLogin(Connection connection, WebContext context,
  + String identify) throws SQLException
  + {
  + Statement stmt = null;
  +
  + // Retrieve the User information based on the login id
  + // If no record is retrieved, then the login is invalid.
  + try
  + {
  + StringBuffer selectStmt = new StringBuffer(
  + "select name, userID, email, loginID from User where loginID=");
  + selectStmt.append(Qu​otedString.from(
  + EscapedString.from(i​dentify.trim())));
  + selectStmt.append(";");
  +
  + stmt = connection.createStatement();
  +
  + ResultSet rset = stmt.executeQuery(se​lectStmt.toString())​;
  + if (rset.next())
  + {
  + cacheLoginParameters(context, rset);
  +
  + // Record that a successful login has occurred
  + isLoggedIn = Boolean.TRUE;
  + }
  + }
  + catch (Exception e)
  + {
  + log.exception(e);
  + }
  + finally
  + {
  + if (stmt != null) stmt.close();
  + }
  +
  + context.put("isLoggedIn", isLoggedIn);
  +
  + return isLoggedIn.booleanValue();
  + }
  +
  + /**
        * Checks that the loginID and password combination is valid.
        * Retrieves User information and caches it in the session and context.
        *
  @@ -376,16 +459,7 @@
               ResultSet rset1 = stmt.executeQuery(se​lectStmt.toString())​;
               if (rset1.next())
               {
  - setUserName(rset1.ge​tString(1));
  - setUserID(rset1.getString(2));
  - setEmail(rset1.getString(3));
  - setLoginID(rset1.getString(4));
  -
  - // Put the user's name, ID and email into the context
  - context.put("UserName", userName);
  - context.put("loginUserID", userID);
  - context.put("email", email);
  - context.put("loginID", loginID);
  + cacheLoginParameters(context, rset1);
   
                   // Record that a successful login has occurred
                   isLoggedIn = Boolean.TRUE;
  @@ -403,17 +477,8 @@
                   rset1 = stmt.executeQuery(se​lectStmt.toString())​;
                   if (rset1.next())
                   {
  - setUserName(rset1.ge​tString(1));
  - setUserID(rset1.getString(2));
  - setEmail(rset1.getString(3));
  - setLoginID(rset1.getString(4));
  -
  - // Put the user's name, ID and email into the context
  - context.put("UserName", userName);
  - context.put("loginUserID", userID);
  - context.put("email", email);
  - context.put("loginID", loginID);
  -
  + cacheLoginParameters(context, rset1);
  +
                           // Record that a successful login has occurred
                       isLoggedIn = Boolean.TRUE;
                   }

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

CVS update: joist/java/org/joist/session SessionManager.java manoj Manoj Kasichainula 2000-11-09 16:20:16 PST
Messages per page: