You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by na...@locus.apache.org on 2000/08/18 00:22:30 UTC

cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/resources LocalStrings.properties LocalStrings_es.properties

nacho       00/08/17 15:22:29

  Modified:    src/share/org/apache/tomcat/request JDBCRealm.java
                        SimpleRealm.java
               src/share/org/apache/tomcat/resources
                        LocalStrings.properties LocalStrings_es.properties
  Log:
  * Some cleaing and cosmethic changes to JDBCRealm
  
  * made the realms compatible with being various in the
  interceptor list. Mainly now a user can have 0 roles
  and nul roles, this last is the case for a realm is using
  a user authenticated by another realm in the list.
  
  Revision  Changes    Path
  1.16      +93 -63    jakarta-tomcat/src/share/org/apache/tomcat/request/JDBCRealm.java
  
  Index: JDBCRealm.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/JDBCRealm.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- JDBCRealm.java	2000/08/15 23:29:33	1.15
  +++ JDBCRealm.java	2000/08/17 22:22:24	1.16
  @@ -175,11 +175,15 @@
        */
       private boolean started = false;
   
  -
       /**
  -     * The property change support for this component.
  +     *
  +     * Encode used in passwords that sane values acceepted by MessageDigest
  +     * plus "No" ( no encode ) that is the default
  +     *
        */
   
  +    private String encode="No";
  +
   
       // ------------------------------------------------------------- Properties
   
  @@ -264,8 +268,30 @@
       public void setRoleNameCol( String roleNameCol ) {
           this.roleNameCol = roleNameCol;
       }
  +    /**
  +     * Gets the encode used for credentials in the database
  +     * could be the same that MessageDigest accepts
  +     * and "No" that is the Default
  +     *
  +     */
  +
  +    public String getEncode() {
  +        return encode;
  +    }
   
       /**
  +     * Sets the ncode used for credentials in the database
  +     * could be the same that MessageDigest accepts
  +     * and "No" that is the Default
  +     *
  +     * @param newEncode the Encode type
  +     */
  +
  +    public void setEncode(String newEncode) {
  +        encode = newEncode;
  +    }
  +
  +    /**
        * If there are any errors with the JDBC connection, executing
        * the query or anything we return false (don't authenticate). This
        * event is also logged.
  @@ -282,27 +308,8 @@
       public synchronized boolean checkPassword(String username
               , String credentials) {
           try {
  -
  -            // Establish the database connection if necessary
  -            if ((dbConnection == null) || dbConnection.isClosed()) {
  -                log(sm.getString("jdbcRealm.authDBClosed"));
  -
  -                if ((connectionName == null || connectionName.equals("")) &&
  -                    (connectionPassword == null || connectionPassword.equals(""))) {
  -                      dbConnection = DriverManager.getConnection(connectionURL);
  -                } else {
  -                     dbConnection = DriverManager.getConnection(connectionURL,
  -                                                                connectionName,
  -                                                                connectionPassword);
  -                }
  -
  -
  -                if( (dbConnection == null) || dbConnection.isClosed() ) {
  -                    log(sm.getString("jdbcRealm.authDBReOpenFail"));
  -                    return false;
  -                }
  -            }
  -
  +            if (!checkConnection())
  +                return false;
               // Create the authentication search prepared statement if necessary
               if (preparedAuthenticate == null) {
                   String sql = "SELECT " + userCredCol + " FROM " + userTable +
  @@ -317,11 +324,16 @@
               ResultSet rs1 = preparedAuthenticate.executeQuery();
               boolean found = false;
               if (rs1.next()) {
  -                if (credentials.equals(rs1.getString(1))) {
  -                    if (debug >= 2)
  -                        log(sm.getString("jdbcRealm.authenticateSuccess",
  -                                 username));
  -                    return true;
  +                if (encode.equals("No")) {
  +                    if (credentials.equals(rs1.getString(1))) {
  +                        if (debug >= 2)
  +                            log(sm.getString("jdbcRealm.authenticateSuccess",
  +                                     username));
  +                        return true;
  +                    }
  +                } else {
  +                // FixMe:  Test if the password is expected encoded
  +                // for now only the place marked
                   }
               }
               rs1.close();
  @@ -333,7 +345,7 @@
           } catch( SQLException ex ) {
   
               // Log the problem for posterity
  -            log(sm.getString("jdbcRealm.authenticateSQLException",
  +            log(sm.getString("jdbcRealm.checkPasswordSQLException",
                        username));
   
               // Clean up the JDBC objects so that they get recreated next time
  @@ -359,55 +371,71 @@
           }
       }
   
  -    public synchronized String[] getUserRoles(String username) {
  +    private boolean checkConnection(){
           try {
  -          if( (dbConnection == null) || dbConnection.isClosed() ) {
  -            log(sm.getString("jdbcRealm.getUserRolesDBClosed"));
  +            if( (dbConnection == null) || dbConnection.isClosed() ) {
  +                log(sm.getString("jdbcRealm.checkConnectionDBClosed"));
  +                if ((connectionName == null || connectionName.equals("")) &&
  +                        (connectionPassword == null || connectionPassword.equals(""))) {
   
  -            if ((connectionName == null || connectionName.equals("")) &&
  -                (connectionPassword == null || connectionPassword.equals(""))) {
  -                dbConnection = DriverManager.getConnection(connectionURL);
  -            } else {
  -                dbConnection = DriverManager.getConnection(connectionURL,
  -                                                           connectionName,
  -                                                           connectionPassword);
  -            }
  +                        dbConnection = DriverManager.getConnection(connectionURL);
   
  -            if( dbConnection == null || dbConnection.isClosed() ) {
  -              log(sm.getString("jdbcRealm.getUserRolesDBReOpenFail"));
  -              return null;
  +                } else {
  +                        dbConnection = DriverManager.getConnection(connectionURL,
  +                                                                   connectionName,
  +                                                                   connectionPassword);
  +                }
  +                if( dbConnection == null || dbConnection.isClosed() ) {
  +                  log(sm.getString("jdbcRealm.checkConnectionDBReOpenFail"));
  +                  return false;
  +                }
               }
  -          }
  -          if (preparedRoles == null) {
  +            return true;
  +        }catch (SQLException ex){
  +            log(sm.getString("jdbcRealm.checkConnectionSQLException"));
  +            return false;
  +        }
  +    }
  +
  +    public synchronized String[] getUserRoles(String username) {
  +        try {
  +            if ( !checkConnection() )
  +                return null;
  +            if (preparedRoles == null) {
                   String sql = "SELECT " + roleNameCol + " FROM " +
                       userRoleTable + " WHERE " + userNameCol + " = ?";
                   if (debug >= 1)
                       log("JDBCRealm.roles: " + sql);
                   preparedRoles = dbConnection.prepareStatement(sql);
  -          }
  -
  -          preparedRoles.clearParameters();
  -          preparedRoles.setString(1, username);
  +            }
  +            preparedRoles.clearParameters();
  +            preparedRoles.setString(1, username);
   
  -          ResultSet rs = preparedRoles.executeQuery();
  +            ResultSet rs = preparedRoles.executeQuery();
   
  -          // Next we convert the resultset into a String[]
  -          Vector vrol=new Vector();
  +            // Next we convert the resultset into a String[]
  +            Vector vrol=new Vector();
   
  -          while (rs.next()) {
  +            while (rs.next()) {
                 vrol.addElement(rs.getString(1));
  -          }
  +            }
  +            String[] res=new String[vrol.size() > 0 ? vrol.size() : 1 ];
   
  -          String[] res=new String[vrol.size()];
  +            // no roles case
  +            if( vrol.size() == 0 ){
  +                res[0]="";
  +                return res;
  +            }
  +
   
  -          for(int i=0 ; i<vrol.size() ; i++ )
  +            for(int i=0 ; i<vrol.size() ; i++ )
                 res[i]=(String)vrol.elementAt(i);
   
  -          return res;
  +            return res;
           }
           catch( SQLException ex ) {
  -          // Set the connection to null.
  -          // Next time we will try to get a new connection.
  +            // Set the connection to null.
  +            // Next time we will try to get a new connection.
               log(sm.getString("jdbcRealm.getUserRolesSQLException",
                        username));
               if (preparedRoles != null) {
  @@ -424,10 +452,10 @@
                   } catch (Throwable t) {
                       ;
                   }
  -            dbConnection = null;
  +                dbConnection = null;
               }
           }
  -	    return null;
  +        return null;
       }
   
   
  @@ -448,10 +476,10 @@
               }
             }
             catch( ClassNotFoundException ex ) {
  -            throw new RuntimeException("JDBCRealm.start.readXml: " + ex);
  +            throw new RuntimeException("JDBCRealm.contextInit: " + ex);
             }
             catch( SQLException ex ) {
  -            throw new RuntimeException("JDBCRealm.start.readXml: " + ex);
  +            throw new RuntimeException("JDBCRealm.contextInit: " + ex);
             }
         }
       }
  @@ -521,6 +549,8 @@
                    + req.getContainer() );
   
   	userRoles = getUserRoles( user );
  +        if( userRoles == null )
  +              return 0;
   	req.setUserRoles( userRoles );
   
           if( debug > 0 ) log( "Auth ok, first role=" + userRoles[0] );
  
  
  
  1.7       +2 -0      jakarta-tomcat/src/share/org/apache/tomcat/request/SimpleRealm.java
  
  Index: SimpleRealm.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/SimpleRealm.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SimpleRealm.java	2000/07/11 03:48:51	1.6
  +++ SimpleRealm.java	2000/08/17 22:22:25	1.7
  @@ -155,6 +155,8 @@
   			     req + " " + req.getContainer() );
   
   	userRoles = memoryRealm.getUserRoles( user );
  +        if ( userRoles == null )
  +            return 0;
   	req.setUserRoles( userRoles );
   
   	if( SecurityTools.haveRole( userRoles, roles ))
  
  
  
  1.8       +6 -8      jakarta-tomcat/src/share/org/apache/tomcat/resources/LocalStrings.properties
  
  Index: LocalStrings.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/resources/LocalStrings.properties,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- LocalStrings.properties	2000/08/11 21:20:17	1.7
  +++ LocalStrings.properties	2000/08/17 22:22:28	1.8
  @@ -1,4 +1,4 @@
  -# $Id: LocalStrings.properties,v 1.7 2000/08/11 21:20:17 costin Exp $
  +# $Id: LocalStrings.properties,v 1.8 2000/08/17 22:22:28 nacho Exp $
   #
   
   # Localized strings for package org.apache.tomcat.core
  @@ -134,14 +134,12 @@
   jdbcRealm.alreadyStarted=This Realm has already been started
   jdbcRealm.authenticateFailure=Authentication unsuccessful for user {0}
   jdbcRealm.authenticateSuccess=Authentication successful for user {0}
  -jdbcRealm.authenticateSQLException=There was an SQLException while in authenticate: {0}
  -jdbcRealm.getUserRolesSQLException=There was an SQLException while in getUserRoles: {0}
   jdbcRealm.notStarted=This Realm has not yet been started
  -jdbcRealm.authDBClosed=The database connection is null or was found to be closed. Trying to re-open it.
  -jdbcRealm.authDBReOpenFail=The re-open on the database failed. The database could be down.
  -jdbcRealm.getUserRolesDBClosed=The database connection is null or was found to be closed. Trying to re-open it.
  -jdbcRealm.getUserRolesDBReOpenFail=The re-open on the database failed. The database could be down.
  -
  +jdbcRealm.checkConnectionSQLException=There was an SQLException while in checkConnection: {0}
  +jdbcRealm.checkPasswordSQLException=There was an SQLException while in checkPassword: {0}
  +jdbcRealm.checkConnectionDBClosed=The database connection is null or was found to be closed. Trying to re-open it.
  +jdbcRealm.checkConnectionDBReOpenFail=The re-open on the database failed. The database could be down.
  +jdbcRealm.getUserRolesSQLException=There was an SQLException while in getUserRoles: {0}
   
   # Session
   standardManager.createSession.ise=createSession: Too many active sessions
  
  
  
  1.8       +16 -5     jakarta-tomcat/src/share/org/apache/tomcat/resources/LocalStrings_es.properties
  
  Index: LocalStrings_es.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/resources/LocalStrings_es.properties,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- LocalStrings_es.properties	2000/08/11 21:20:19	1.7
  +++ LocalStrings_es.properties	2000/08/17 22:22:29	1.8
  @@ -1,4 +1,4 @@
  -# $Id: LocalStrings_es.properties,v 1.7 2000/08/11 21:20:19 costin Exp $
  +# $Id: LocalStrings_es.properties,v 1.8 2000/08/17 22:22:29 nacho Exp $
   #
   
   # Localized strings for package org.apache.tomcat.core
  @@ -39,7 +39,7 @@
   #WebXmlReader
   context.getConfig.e=No se puede configurar el servicio web usando "{0}"
   
  -# Core / Facade 
  +# Core / Facade
   scfacade.getresource.npe=La ruta de acceso no existe
   scfacade.getresource.iae=La ruta de acceso {0} no es absoluta para la base de este contexto.
   scfacade.context.iae=La rutas de acceso de Servlet deben comenzar con /: {0}
  @@ -93,7 +93,7 @@
   sc.200=OK
   sc.201=Creado
   sc.202=Aceptado
  -sc.203=Informacion No-Autorizativa 
  +sc.203=Informacion No-Autorizativa
   sc.204=Sin Contenido
   sc.205=Reset Contenido
   sc.206=Contenido Parcial
  @@ -134,8 +134,19 @@
   servletOutputStreamImpl.reset.ise=No puedo reiniciar el buffer despues de escribirlo hacia el cliente
   servletOutputStreamImpl.setbuffer.ise=especificando el buffer despues de escrbirlo al writer
   
  +# JDBC realm
  +jdbcRealm.alreadyStarted=Este reino ha sido ya iniciado
  +jdbcRealm.authenticateFailure=Autentificacion fallida para el usuario {0}
  +jdbcRealm.authenticateSuccess=Autentificacion para el usuario {0}
  +jdbcRealm.notStarted=Este reino no ha sido todavia iniciado
  +jdbcRealm.checkConnectionSQLException=Hubo una SQLException mientras se ejecutaba checkConnection: {0}
  +jdbcRealm.checkPasswordSQLException=Hubo una SQLException mientras se ejecutaba checkPassword: {0}
  +jdbcRealm.checkConnectionDBClosed=La conexion con la base de datos es nula o se encontro cerrada. Intentando reabrirla.
  +jdbcRealm.checkConnectionDBReOpenFail=La reapertura de la base de datos fallo. La Base de datos podria estar parada.
  +jdbcRealm.getUserRolesSQLException=Hubo una SQLException mientras se ejecutaba getUserRoles: {0}
   
  -# Session 
  +
  +# Session
   standardManager.createSession.ise=createSession: Demasiadas sesiones activas
   standardSession.invalidate.ise=invalidate: Sesion ya invalidada
   standardSession.isNew.ise=isNew: Sesion ya invalidada
  @@ -165,4 +176,4 @@
   
   # service/Endpoint
   endpoint.run.ioe=Una IOException ocurrio mientras se aceptaban conexiones en:\n\tinet: {0}\n\tpuerto: {1}\n\t Excepcion: {2}
  -endpoint.err.fatal=El Endpoint {0} fue apagado debido a una excepcion; {1}
  +endpoint.err.fatal=El Endpoint {0} fue parado debido a una excepcion; {1}