nacho 00/12/03 14:29:43 Modified: src/share/org/apache/tomcat/modules/server Ajp12.java Ajp12Interceptor.java Http10.java src/share/org/apache/tomcat/request JDBCRealm.java SimpleRealm.java Removed: src/share/org/apache/tomcat/service JNIEndpoint.java JNIEndpointConnector.java PoolTcpConnector.java package.html src/share/org/apache/tomcat/service/connector Ajp12ConnectionHandler.java Ajp13ConnectionHandler.java Ajp13ConnectorRequest.java Ajp13ConnectorResponse.java JNIConnectionHandler.java MsgBuffer.java MsgConnector.java TcpConnector.java package.html src/share/org/apache/tomcat/service/http HttpConnectionHandler.java HttpInterceptor.java HttpRequestAdapter.java HttpResponseAdapter.java package.html Log: service package was obsolete, this functionality is now , in org.apache.tomcat.modules.server Revision Changes Path 1.8 +13 -2 jakarta-tomcat/src/share/org/apache/tomcat/modules/server/Ajp12.java Index: Ajp12.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/server/Ajp12.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- Ajp12.java 2000/11/30 04:58:45 1.7 +++ Ajp12.java 2000/12/03 22:29:38 1.8 @@ -75,6 +75,7 @@ Socket socket; InputStream sin; BufferedInputStream ajpin; + private boolean TomcatAuthentication=true; boolean shutdown=false; boolean isPing=false; boolean doLog; @@ -145,8 +146,10 @@ req.queryString().setString( readString(ajpin, null)); req.setRemoteAddr(readString(ajpin, "")); req.setRemoteHost( readString(ajpin, "")); - req.setRemoteUser( readString(ajpin, null)); - req.setAuthType(readString(ajpin, null)); + if (isTomcatAuthentication()) + dummy=readString(ajpin, null); + else req.setRemoteUser( readString(ajpin, null)); + req.setAuthType(readString(ajpin, null)); //remote port dummy = readString(ajpin, null); req.method().setString( readString(ajpin, null)); @@ -364,6 +367,14 @@ p = p+r; } return new String(b, CHARSET); + } + + public boolean isTomcatAuthentication() { + return TomcatAuthentication; + } + + public void setTomcatAuthentication(boolean newTomcatAuthentication) { + TomcatAuthentication = newTomcatAuthentication; } 1.6 +22 -2 jakarta-tomcat/src/share/org/apache/tomcat/modules/server/Ajp12Interceptor.java Index: Ajp12Interceptor.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/server/Ajp12Interceptor.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- Ajp12Interceptor.java 2000/11/19 15:54:29 1.5 +++ Ajp12Interceptor.java 2000/12/03 22:29:38 1.6 @@ -75,8 +75,8 @@ /* */ public class Ajp12Interceptor extends PoolTcpConnector - implements TcpConnectionHandler -{ + implements TcpConnectionHandler{ + private boolean TomcatAuthentication=true; public Ajp12Interceptor() { super(); } @@ -125,10 +125,15 @@ resA=(AJP12Response)thData[1]; if( reqA!=null ) reqA.recycle(); if( resA!=null ) resA.recycle(); +//XXX Need to revert the tomcat auth state? if yes put it into recycle and +// and uncomment here +// ((AJP12Request)reqA).setTomcatAuthentication(isTomcatAuthtentication()); } if( reqA==null || resA==null ) { reqA = new AJP12Request(); + ((AJP12Request)reqA).setTomcatAuthentication( + isTomcatAuthentication()); resA=new AJP12Response(); cm.initRequest( reqA, resA ); } @@ -147,6 +152,14 @@ log("HANDLER THREAD PROBLEM", e); } } + + public boolean isTomcatAuthentication() { + return TomcatAuthentication; + } + + public void setTomcatAuthentication(boolean newTomcatAuthentication) { + TomcatAuthentication = newTomcatAuthentication; + } } class AJP12Request extends Request { @@ -176,6 +189,13 @@ return ajp12.doRead( b,off,len); } + public boolean isTomcatAuthentication() { + return ajp12.isTomcatAuthentication(); + } + + public void setTomcatAuthentication(boolean newTomcatAuthentication) { + ajp12.setTomcatAuthentication(newTomcatAuthentication); + } } 1.4 +2 -2 jakarta-tomcat/src/share/org/apache/tomcat/modules/server/Http10.java Index: Http10.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/server/Http10.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- Http10.java 2000/09/29 07:01:17 1.3 +++ Http10.java 2000/12/03 22:29:38 1.4 @@ -170,7 +170,7 @@ // XXX this does not currently handle headers which // are folded to take more than one line. - if( ! parseHeaderFiled(headers, buf, start, off - start) ) { + if( ! parseHeaderField(headers, buf, start, off - start) ) { // error parsing header return 200; } @@ -185,7 +185,7 @@ * @param len the length of the bytes * @exception IllegalArgumentException if the header format was invalid */ - public final boolean parseHeaderFiled(MimeHeaders headers, byte[] b, + public final boolean parseHeaderField(MimeHeaders headers, byte[] b, int off, int len) { int start = off; 1.25 +27 -32 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.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- JDBCRealm.java 2000/11/06 15:10:27 1.24 +++ JDBCRealm.java 2000/12/03 22:29:39 1.25 @@ -1,7 +1,7 @@ /* - * $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 $ + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/JDBCRealm.java,v 1.25 2000/12/03 22:29:39 nacho Exp $ + * $Revision: 1.25 $ + * $Date: 2000/12/03 22:29:39 $ * * The Apache Software License, Version 1.1 * @@ -355,7 +355,7 @@ // Log the problem for posterity log(sm.getString("jdbcRealm.checkPasswordSQLException", - username)); + username),ex); // Clean up the JDBC objects so that they get recreated next time if (preparedAuthenticate != null) { @@ -383,12 +383,11 @@ private boolean checkConnection(){ try { if( (dbConnection == null) || dbConnection.isClosed() ) { + Class.forName(driverName); log(sm.getString("jdbcRealm.checkConnectionDBClosed")); if ((connectionName == null || connectionName.equals("")) && (connectionPassword == null || connectionPassword.equals(""))) { - dbConnection = DriverManager.getConnection(connectionURL); - } else { dbConnection = DriverManager.getConnection(connectionURL, connectionName, @@ -401,9 +400,12 @@ } return true; }catch (SQLException ex){ - log(sm.getString("jdbcRealm.checkConnectionSQLException")); + log(sm.getString("jdbcRealm.checkConnectionSQLException"),ex); return false; } + catch( ClassNotFoundException ex ) { + throw new RuntimeException("JDBCRealm.contextInit: " + ex); + } } public synchronized String[] getUserRoles(String username) { @@ -436,10 +438,8 @@ return res; } - for(int i=0 ; i<vrol.size() ; i++ ) res[i]=(String)vrol.elementAt(i); - return res; } catch( SQLException ex ) { @@ -477,16 +477,19 @@ public void contextShutdown(Context ctx) throws org.apache.tomcat.core.TomcatException { + shutdown(); + } + + public void shutdown() + throws org.apache.tomcat.core.TomcatException { // Validate and update our current component state if (started) { - if( dbConnection != null ) { - try { + try { + if( dbConnection != null && !dbConnection.isClosed()) dbConnection.close(); - } - catch( SQLException ex ) { - log("dbConnection.close Exception!!!"); - } - } + }catch( SQLException ex ) { + log("dbConnection.close Exception!!!",ex); + } } } @@ -594,7 +597,6 @@ /** Called when the ContextManger is started */ public void engineInit(ContextManager cm) throws TomcatException { - //TODO: Override this org.apache.tomcat.core.BaseInterceptor method super.engineInit(cm); init(cm); } @@ -604,15 +606,6 @@ 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 , "required.roles"); @@ -623,13 +616,15 @@ 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); - } } + } + + /** Called before the ContextManager is stoped. + * You need to stop any threads and remove any resources. + */ + public void engineShutdown(ContextManager cm) throws TomcatException { + //TODO: Override this org.apache.tomcat.core.BaseInterceptor method + shutdown(); } 1.13 +96 -113 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.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- SimpleRealm.java 2000/11/06 15:10:28 1.12 +++ SimpleRealm.java 2000/12/03 22:29:39 1.13 @@ -84,7 +84,6 @@ public class SimpleRealm extends BaseInterceptor { MemoryRealm memoryRealm; - ContextManager cm; int reqRolesNote=-1; int reqRealmSignNote=-1; String filename; @@ -95,7 +94,6 @@ throws TomcatException { super.contextInit(ctx); - ContextManager cm=ctx.getContextManager(); init(cm,ctx); try { // XXX make the name a "global" static - @@ -177,13 +175,13 @@ /** Called when the ContextManger is started */ public void engineInit(ContextManager cm) throws TomcatException { - super.engineInit(cm); +// super.engineInit(cm); init(cm,null); } void init(ContextManager cm,Context ctx) { if( memoryRealm==null) { - memoryRealm = new MemoryRealm(cm,null,filename); + memoryRealm = new MemoryRealm(filename,cm.getHome()); try { memoryRealm.readMemoryRealm(); } catch(Exception ex ) { @@ -192,124 +190,109 @@ } } } -} -class MemoryRealm { - // String user -> password - Hashtable passwords=new Hashtable(); - // String role -> Vector users - Hashtable roles=new Hashtable(); - // user -> roles - Hashtable userRoles= new Hashtable(); - String filename; - Context ctx; - Logger log; - int debug=0; - ContextManager cm; - - MemoryRealm(Context ctx,String fn) { - 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(); + class MemoryRealm { + // String user -> password + Hashtable passwords=new Hashtable(); + // String role -> Vector users + Hashtable roles=new Hashtable(); + // user -> roles + Hashtable userRoles= new Hashtable(); + String filename; + String home; + + MemoryRealm(String fn,String home) { + this.home=home; + filename=fn; } - - } - public Hashtable getRoles() { - return roles; - } - - public void addUser(String name, String pass, String groups ) { - if( debug > 0 ) log.log( "Add user " + name + " " + pass + " " + groups ); - passwords.put( name, pass ); - groups += ","; - while (true) { - int comma = groups.indexOf(","); - if (comma < 0) - break; - addRole( groups.substring(0, comma).trim(), name); - groups = groups.substring(comma + 1); - } - } + public Hashtable getRoles() { + return roles; + } - public void addRole( String role, String user ) { - Vector users=(Vector)roles.get(role); - if(users==null) { - users=new Vector(); - roles.put(role, users ); - } - users.addElement( user ); + public void addUser(String name, String pass, String groups ) { + if( debug > 0 ) log( "Add user " + name + " " + pass + " " + groups ); + passwords.put( name, pass ); + groups += ","; + while (true) { + int comma = groups.indexOf(","); + if (comma < 0) + break; + addRole( groups.substring(0, comma).trim(), name); + groups = groups.substring(comma + 1); + } + } - Vector thisUserRoles=(Vector)userRoles.get( user ); - if( thisUserRoles == null ) { - thisUserRoles = new Vector(); - userRoles.put( user, thisUserRoles ); - } - thisUserRoles.addElement( role ); - } + public void addRole( String role, String user ) { + Vector users=(Vector)roles.get(role); + if(users==null) { + users=new Vector(); + roles.put(role, users ); + } + users.addElement( user ); + + Vector thisUserRoles=(Vector)userRoles.get( user ); + if( thisUserRoles == null ) { + thisUserRoles = new Vector(); + userRoles.put( user, thisUserRoles ); + } + thisUserRoles.addElement( role ); + } - public boolean checkPassword( String user, String pass ) { - if( user==null ) return false; - if( debug > 0 ) log.log( "check " + user+ " " + pass + " " + passwords.get( user )); - return pass.equals( (String)passwords.get( user ) ); - } + public boolean checkPassword( String user, String pass ) { + if( user==null ) return false; + if( debug > 0 ) log( "check " + user+ " " + pass + " " + passwords.get( user )); + return pass.equals( (String)passwords.get( user ) ); + } - public String[] getUserRoles( String user ) { - Vector v=(Vector)userRoles.get( user ); - if( v==null) return null; - String roles[]=new String[v.size()]; - for( int i=0; i<roles.length; i++ ) { - roles[i]=(String)v.elementAt( i ); - } - return roles; - } + public String[] getUserRoles( String user ) { + Vector v=(Vector)userRoles.get( user ); + if( v==null) return null; + String roles[]=new String[v.size()]; + for( int i=0; i<roles.length; i++ ) { + roles[i]=(String)v.elementAt( i ); + } + return roles; + } - public boolean userInRole( String user, String role ) { - Vector users=(Vector)roles.get(role); - if( debug > 0 ) log.log( "check role " + user+ " " + role + " " ); - if(users==null) return false; - return users.indexOf( user ) >=0 ; - } - 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() ) { - log.log( "File not found " + f ); - return; - } - XmlMapper xh=new XmlMapper(); - if( debug > 5 ) xh.setDebug( 2 ); + public boolean userInRole( String user, String role ) { + Vector users=(Vector)roles.get(role); + if( debug > 0 ) log( "check role " + user+ " " + role + " " ); + if(users==null) return false; + return users.indexOf( user ) >=0 ; + } + void readMemoryRealm() throws Exception { + File f; + if (filename != null) + f=new File( home + File.separator + filename ); + else + f=new File( home + "/conf/tomcat-users.xml"); + + if( ! f.exists() ) { + log( "File not found " + f ); + return; + } + XmlMapper xh=new XmlMapper(); + if( debug > 5 ) xh.setDebug( 2 ); + + // call addUser using attributes as parameters + xh.addRule("tomcat-users/user", + new XmlAction() { + public void start(SaxContext sctx) throws Exception { + int top=sctx.getTagCount()-1; + MemoryRealm mr=(MemoryRealm)sctx.getRoot(); + AttributeList attributes = sctx.getAttributeList( top ); + String user=attributes.getValue("name"); + String pass=attributes.getValue("password"); + String group=attributes.getValue("roles"); + mr.addUser( user, pass, group ); + } + } + ); - // call addUser using attributes as parameters - xh.addRule("tomcat-users/user", - new XmlAction() { - public void start(SaxContext sctx) throws Exception { - int top=sctx.getTagCount()-1; - MemoryRealm mr=(MemoryRealm)sctx.getRoot(); - AttributeList attributes = sctx.getAttributeList( top ); - String user=attributes.getValue("name"); - String pass=attributes.getValue("password"); - String group=attributes.getValue("roles"); - mr.addUser( user, pass, group ); - } - } - ); - - xh.readXml( f, this ); + xh.readXml( f, this ); + } } + }