nacho 00/11/06 07:10:29 Modified: src/share/org/apache/tomcat/request JDBCRealm.java SimpleRealm.java Log: Adapting code to new start order. Revision Changes Path 1.24 +36 -31 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.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- JDBCRealm.java 2000/11/02 00:38:02 1.23 +++ JDBCRealm.java 2000/11/06 15:10:27 1.24 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/JDBCRealm.java,v 1.23 2000/11/02 00:38:02 nacho Exp $ - * $Revision: 1.23 $ - * $Date: 2000/11/02 00:38:02 $ + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/JDBCRealm.java,v 1.24 2000/11/06 15:10:27 nacho Exp $ + * $Revision: 1.24 $ + * $Date: 2000/11/06 15:10:27 $ * * The Apache Software License, Version 1.1 * @@ -470,28 +470,9 @@ public void contextInit(Context ctx) throws org.apache.tomcat.core.TomcatException { + super.contextInit(ctx); + init(ctx.getContextManager()); // Validate and update our current component state - if (!started) { - started = true; - // set-up a per/container note for maps - try { - Class.forName(driverName); - if ((connectionName == null || connectionName.equals("")) && - (connectionPassword == null || connectionPassword.equals(""))) { - dbConnection = DriverManager.getConnection(connectionURL); - } else { - dbConnection = DriverManager.getConnection(connectionURL, - connectionName, - connectionPassword); - } - } - catch( ClassNotFoundException ex ) { - throw new RuntimeException("JDBCRealm.contextInit: " + ex); - } - catch( SQLException ex ) { - throw new RuntimeException("JDBCRealm.contextInit: " + ex); - } - } } public void contextShutdown(Context ctx) @@ -615,16 +596,40 @@ public void engineInit(ContextManager cm) throws TomcatException { //TODO: Override this org.apache.tomcat.core.BaseInterceptor method super.engineInit(cm); - try { + init(cm); + } + + void init(ContextManager cm) { + if (!started) { + started = true; + // set-up a per/container note for maps + try { + Class.forName(driverName); + if ((connectionName == null || connectionName.equals("")) && + (connectionPassword == null || connectionPassword.equals(""))) { + dbConnection = DriverManager.getConnection(connectionURL); + } else { + dbConnection = DriverManager.getConnection(connectionURL, + connectionName, + connectionPassword); + } // XXX make the name a "global" static - after everything is stable! - reqRolesNote = cm.getNoteId( ContextManager.REQUEST_NOTE + reqRolesNote = cm.getNoteId( ContextManager.REQUEST_NOTE , "required.roles"); - reqRealmSignNote = cm.getNoteId( ContextManager.REQUEST_NOTE + reqRealmSignNote = cm.getNoteId( ContextManager.REQUEST_NOTE , "realm.sign"); - } catch( TomcatException ex ) { - log("setting up note for " + cm, ex); - throw new RuntimeException( "Invalid state "); - } + } + catch( TomcatException ex ) { + log("setting up note for " + cm, ex); + throw new RuntimeException( "Invalid state "); + } + catch( ClassNotFoundException ex ) { + throw new RuntimeException("JDBCRealm.contextInit: " + ex); + } + catch( SQLException ex ) { + throw new RuntimeException("JDBCRealm.contextInit: " + ex); + } + } } 1.12 +51 -31 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.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- SimpleRealm.java 2000/11/02 00:38:02 1.11 +++ SimpleRealm.java 2000/11/06 15:10:28 1.12 @@ -63,6 +63,7 @@ import org.apache.tomcat.core.*; import org.apache.tomcat.util.*; +import org.apache.tomcat.util.log.*; import org.apache.tomcat.helper.*; import org.apache.tomcat.util.xml.*; import java.io.*; @@ -84,8 +85,8 @@ MemoryRealm memoryRealm; ContextManager cm; - int reqRolesNote; - int reqRealmSignNote; + int reqRolesNote=-1; + int reqRealmSignNote=-1; String filename; public SimpleRealm() { } @@ -93,15 +94,19 @@ public void contextInit(Context ctx) throws TomcatException { - if( memoryRealm==null) { - memoryRealm = new MemoryRealm(ctx,filename); - try { - memoryRealm.readMemoryRealm(ctx); - } catch(Exception ex ) { - log("initting " + ctx, ex); - memoryRealm=null; - } - } + super.contextInit(ctx); + ContextManager cm=ctx.getContextManager(); + init(cm,ctx); + try { + // XXX make the name a "global" static - + reqRolesNote = cm.getNoteId( ContextManager.REQUEST_NOTE, + "required.roles"); + reqRealmSignNote = cm.getNoteId( ContextManager.REQUEST_NOTE + , "realm.sign"); + } catch( TomcatException ex ) { + log("getting note for " + cm, ex); + throw new RuntimeException( "Invalid state "); + } } public int authenticate( Request req, Response response ) @@ -173,17 +178,19 @@ */ public void engineInit(ContextManager cm) throws TomcatException { super.engineInit(cm); - // set-up a per/container note for maps - try { - // XXX make the name a "global" static - - reqRolesNote = cm.getNoteId( ContextManager.REQUEST_NOTE, - "required.roles"); - reqRealmSignNote = cm.getNoteId( ContextManager.REQUEST_NOTE - , "realm.sign"); - } catch( TomcatException ex ) { - log("getting note for " + cm, ex); - throw new RuntimeException( "Invalid state "); - } + init(cm,null); + } + + void init(ContextManager cm,Context ctx) { + if( memoryRealm==null) { + memoryRealm = new MemoryRealm(cm,null,filename); + try { + memoryRealm.readMemoryRealm(); + } catch(Exception ex ) { + log("initting " + cm, ex); + memoryRealm=null; + } + } } } @@ -196,11 +203,25 @@ Hashtable userRoles= new Hashtable(); String filename; Context ctx; + Logger log; int debug=0; + ContextManager cm; MemoryRealm(Context ctx,String fn) { - this.ctx=ctx; + this(ctx.getContextManager(),ctx,fn); + } + + MemoryRealm(ContextManager cm,Context ctx,String fn) { + this.cm=cm; filename=fn; + if(ctx==null){ + log=cm.getLogger(); + debug=cm.getDebug(); + }else { + log=ctx.getLog().getLogger(); + debug=ctx.getDebug(); + } + } public Hashtable getRoles() { @@ -208,7 +229,7 @@ } public void addUser(String name, String pass, String groups ) { - if( ctx.getDebug() > 0 ) ctx.log( "Add user " + name + " " + pass + " " + groups ); + if( debug > 0 ) log.log( "Add user " + name + " " + pass + " " + groups ); passwords.put( name, pass ); groups += ","; while (true) { @@ -238,7 +259,7 @@ public boolean checkPassword( String user, String pass ) { if( user==null ) return false; - if( debug > 0 ) ctx.log( "check " + user+ " " + pass + " " + passwords.get( user )); + if( debug > 0 ) log.log( "check " + user+ " " + pass + " " + passwords.get( user )); return pass.equals( (String)passwords.get( user ) ); } @@ -254,25 +275,24 @@ public boolean userInRole( String user, String role ) { Vector users=(Vector)roles.get(role); - if( debug > 0 ) ctx.log( "check role " + user+ " " + role + " " ); + if( debug > 0 ) log.log( "check role " + user+ " " + role + " " ); if(users==null) return false; return users.indexOf( user ) >=0 ; } - void readMemoryRealm(Context ctx) throws Exception { - ContextManager cm=ctx.getContextManager(); + void readMemoryRealm() throws Exception { String home=cm.getHome(); File f; if (filename != null) f=new File( home + File.separator + filename ); else f=new File( home + "/conf/tomcat-users.xml"); - + if( ! f.exists() ) { - ctx.log( "File not found " + f ); + log.log( "File not found " + f ); return; } XmlMapper xh=new XmlMapper(); - if( ctx.getDebug() > 5 ) xh.setDebug( 2 ); + if( debug > 5 ) xh.setDebug( 2 ); // call addUser using attributes as parameters xh.addRule("tomcat-users/user", --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]