cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject cvs commit: xml-cocoon2/src/org/apache/cocoon/acting DatabaseAuthenticatorAction.java
Date Thu, 19 Jul 2001 19:07:47 GMT
bloritsch    01/07/19 12:07:47

  Modified:    src/org/apache/cocoon/acting Tag: cocoon_20_branch
                        DatabaseAuthenticatorAction.java
  Log:
  Fix incorrect connection handling by DBauthenticatorAction
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.3.2.2   +58 -40    xml-cocoon2/src/org/apache/cocoon/acting/DatabaseAuthenticatorAction.java
  
  Index: DatabaseAuthenticatorAction.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/acting/DatabaseAuthenticatorAction.java,v
  retrieving revision 1.3.2.1
  retrieving revision 1.3.2.2
  diff -u -r1.3.2.1 -r1.3.2.2
  --- DatabaseAuthenticatorAction.java	2001/07/13 13:37:28	1.3.2.1
  +++ DatabaseAuthenticatorAction.java	2001/07/19 19:07:47	1.3.2.2
  @@ -1,4 +1,4 @@
  -// $Id: DatabaseAuthenticatorAction.java,v 1.3.2.1 2001/07/13 13:37:28 dims Exp $
  +// $Id: DatabaseAuthenticatorAction.java,v 1.3.2.2 2001/07/19 19:07:47 bloritsch Exp $
   package org.apache.cocoon.acting;
   
   import java.sql.Connection;
  @@ -51,7 +51,7 @@
    * not verified.
    *
    * @author Martin Man <Martin.Man@seznam.cz>
  - * @version CVS $Revision: 1.3.2.1 $ $Date: 2001/07/13 13:37:28 $
  + * @version CVS $Revision: 1.3.2.2 $ $Date: 2001/07/19 19:07:47 $
    */
   public class DatabaseAuthenticatorAction extends AbstractDatabaseAction
   {
  @@ -62,19 +62,24 @@
               Parameters parameters) throws Exception {
           DataSourceComponent datasource = null;
           Connection conn = null;
  +        Statement st = null;
  +        ResultSet rs = null;
   
  -	// read global parameter settings
  -	boolean reloadable = Constants.DESCRIPTOR_RELOADABLE_DEFAULT;
  -	if (this.settings.containsKey("reloadable"))
  -	    reloadable = Boolean.getBoolean((String) this.settings.get("reloadable"));
  -	// read local settings
  +        // read global parameter settings
  +        boolean reloadable = Constants.DESCRIPTOR_RELOADABLE_DEFAULT;
  +
  +        if (this.settings.containsKey("reloadable")) {
  +            reloadable = Boolean.getBoolean((String) this.settings.get("reloadable"));
  +        }
  +
  +        // read local settings
           try {
               Configuration conf = this.getConfiguration (
  -                    parameters.getParameter ("descriptor", (String) this.settings.get("descriptor")),

  -		    parameters.getParameterAsBoolean("reloadable",reloadable));
  +                    parameters.getParameter ("descriptor", (String) this.settings.get("descriptor")),
  +            parameters.getParameterAsBoolean("reloadable",reloadable));
               boolean cs = true;
  -            String create_session = parameters.getParameter ("create-session", 
  -							     (String) this.settings.get("create-session"));
  +            String create_session = parameters.getParameter ("create-session",
  +                                 (String) this.settings.get("create-session"));
               if (create_session != null &&
                       ("no".equals (create_session.trim ()) || "false".equals (create_session.trim
()))) {
                   cs = false;
  @@ -90,44 +95,57 @@
                   return null;
               }
   
  -
               String query = this.getAuthQuery (conf, req);
               if (query == null) {
                   getLogger ().debug ("DBAUTH: have not got query");
                   return null;
               }
   
  -            try {
  -                getLogger ().debug ("DBAUTH: quuery is: " + query);
  -                Statement st = conn.createStatement ();
  -                ResultSet rs = st.executeQuery (query);
  -                if (rs.next ()) {
  -                    getLogger ().debug ("DBAUTH: authorized successfully");
  -                    Session session = null;
  -                    if (cs) {
  -                        session = req.getSession (false);
  -                        if (session != null)
  -                            session.invalidate ();
  -                        session = req.getSession (true);
  -                        if (session == null)
  -                            return null;
  -                        getLogger ().debug ("DBAUTH: session created");
  -                    } else {
  -                        getLogger ().debug ("DBAUTH: leaving session untouched");
  -                    }
  -                    HashMap actionMap = this.propagateParameters (conf, rs,
  -                            session);
  -                    rs.close ();
  -                    st.close ();
  -                    return Collections.unmodifiableMap (actionMap);
  +            getLogger ().debug ("DBAUTH: quuery is: " + query);
  +            Statement st = conn.createStatement ();
  +            ResultSet rs = st.executeQuery (query);
  +
  +            if (rs.next ()) {
  +                getLogger ().debug ("DBAUTH: authorized successfully");
  +                Session session = null;
  +
  +                if (cs) {
  +                    session = req.getSession (false);
  +                    if (session != null)
  +                        session.invalidate ();
  +                    session = req.getSession (true);
  +                    if (session == null)
  +                        return null;
  +                    getLogger ().debug ("DBAUTH: session created");
  +                } else {
  +                    getLogger ().debug ("DBAUTH: leaving session untouched");
                   }
  -                getLogger ().debug ("DBAUTH: no results for query");
  -            } catch (Exception e) {
  -                getLogger ().debug ("exception: ", e);
  -                return null;
  +
  +                HashMap actionMap = this.propagateParameters (conf, rs,
  +                        session);
  +
  +                conn.commit();
  +                return Collections.unmodifiableMap (actionMap);
               }
  +
  +            conn.rollback();
  +            getLogger ().debug ("DBAUTH: no results for query");
           } catch (Exception e) {
  +            if (conn != null) {
  +                try {
  +                    conn.rollback();
  +                } catch (Exception e) {/* ignore */}
  +            }
               getLogger().debug ("exception: ", e);
  +            return null;
  +        } finally {
  +            if (rs != null) rs.close();
  +            if (st != null) st.close();
  +            if (conn != null) {
  +                try {
  +                    conn.close();
  +                } catch (Exception e) {/* ignore */}
  +            }
           }
           return null;
       }
  @@ -231,5 +249,5 @@
       }
   }
   
  -// $Id: DatabaseAuthenticatorAction.java,v 1.3.2.1 2001/07/13 13:37:28 dims Exp $
  +// $Id: DatabaseAuthenticatorAction.java,v 1.3.2.2 2001/07/19 19:07:47 bloritsch Exp $
   // vim: set et ts=4 sw=4:
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message