axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gdani...@apache.org
Subject cvs commit: xml-axis/java/src/org/apache/axis/utils Admin.java
Date Mon, 30 Jul 2001 02:29:28 GMT
gdaniels    01/07/29 19:29:28

  Modified:    java/src/org/apache/axis AxisEngine.java
               java/src/org/apache/axis/client AdminClient.java
                        AxisClient.java
               java/src/org/apache/axis/message EnvelopeBuilder.java
               java/src/org/apache/axis/server AxisServer.java
               java/src/org/apache/axis/transport/http AdminServlet.java
               java/src/org/apache/axis/utils Admin.java
  Log:
  Add an optional "basePath" param to the AxisEngine constructor.  This
  allows us to default the location of the axis.properties and config.xml
  files.  The AdminServlet sets this to the webapp's WEB-INF directory
  now.  Default is still ".".
  
  Sketch in some support for limiting access to the Admin service.  Right
  now this means not letting any non-local IP address access the service.
  Also added an "admin password" property which in the future could be
  shipping with a default value, then no admin activity would be allowed
  on the server until the user first changed the password.
  
  Revision  Changes    Path
  1.27      +45 -5     xml-axis/java/src/org/apache/axis/AxisEngine.java
  
  Index: AxisEngine.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/AxisEngine.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- AxisEngine.java	2001/07/18 22:17:52	1.26
  +++ AxisEngine.java	2001/07/30 02:29:28	1.27
  @@ -84,9 +84,12 @@
       public static final String PROP_DEBUG_LEVEL = "debugLevel";
       public static final String PROP_DEBUG_FILE = "debugFile";
       public static final String PROP_DOMULTIREFS = "sendMultiRefs";
  -    
  +    public static final String PROP_PASSWORD = "adminPassword";
  +
  +    protected String sep = System.getProperty("file.separator");
       
       protected String engineConfigFilename = "engine-config.xml";
  +    protected String engineBasePath;
       
       /** The handler registry this Engine uses. */
       protected HandlerRegistry _handlerRegistry = new SupplierRegistry();
  @@ -103,6 +106,9 @@
       
       protected Properties props = new Properties();
       
  +    /** Has the user changed the password yet? */
  +    protected boolean _hasSafePassword = false;
  +    
       //protected SupplierRegistry listenerRegistry = new SupplierRegistry();
       
       /**
  @@ -123,8 +129,12 @@
           Debug.Print( 1, "Exit: AxisEngine no-arg constructor");
       }
       
  -    public AxisEngine(String fileName)
  +    public AxisEngine(String basePath, String fileName)
       {
  +        if ((basePath == null) || (basePath.equals("")))
  +            basePath = ".";
  +        
  +        engineBasePath = basePath;
           engineConfigFilename = fileName;
           init();
       }
  @@ -137,7 +147,8 @@
           * set ASAP.
           */
           try {
  -            File propFile = new File("axis.properties");
  +            File propFile = new File(engineBasePath + sep +
  +                                     "axis.properties");
               if (propFile.exists()) {
                   FileInputStream propFileInputStream =
                                                  new FileInputStream(propFile);
  @@ -163,6 +174,16 @@
           propVal = props.getProperty(PROP_DOMULTIREFS, "true");
           addOption(PROP_DOMULTIREFS, new Boolean(propVal.equals("true")));
           
  +        // The admin password (if it hasn't been set, we're "unsafe", and
  +        // we shouldn't do anything in the admin but change it)
  +        propVal = props.getProperty(PROP_PASSWORD);
  +        if (propVal != null) {
  +            addOption(PROP_PASSWORD, propVal);
  +            _hasSafePassword = true;
  +        } else {
  +            addOption(PROP_PASSWORD, "admin");
  +        }
  +        
           _typeMappingRegistry.setParent(SOAPTypeMappingRegistry.getSingleton());
           
           Debug.Print( 1, "Enter: AxisEngine::init" );
  @@ -190,7 +211,8 @@
       {
           InputStream is;
           try {
  -            is = new FileInputStream(engineConfigFilename);
  +            is = new FileInputStream(engineBasePath + sep +
  +                                     engineConfigFilename);
           } catch (Exception e) {
               is = getResourceStream(engineConfigFilename);
           }
  @@ -220,9 +242,15 @@
       {
           try {
               Document doc = Admin.listConfig(this);
  -            FileOutputStream fos = new FileOutputStream(engineConfigFilename);
  +            FileOutputStream fos = new FileOutputStream(
  +                                            engineBasePath + sep +
  +                                            engineConfigFilename);
               XMLUtils.DocumentToStream(doc, fos);
               fos.close();
  +            
  +            props.store(new FileOutputStream(engineBasePath + sep +
  +                                             "axis.properties"),
  +                        "Axis engine properties");
           } catch (Exception e) {
               System.err.println("Coudn't write engine config!");
               e.printStackTrace();
  @@ -234,6 +262,18 @@
           return this.getClass().getResourceAsStream(name);
       }
       
  +    public boolean hasSafePassword()
  +    {
  +        return _hasSafePassword;
  +    }
  +    
  +    public void setAdminPassword(String pw)
  +    {
  +        addOption(PROP_PASSWORD, pw);
  +        props.put(PROP_PASSWORD, pw);
  +        _hasSafePassword = true;
  +        saveConfiguration();
  +    }
   
       public HandlerRegistry getHandlerRegistry()
       {
  
  
  
  1.27      +11 -0     xml-axis/java/src/org/apache/axis/client/AdminClient.java
  
  Index: AdminClient.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/client/AdminClient.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- AdminClient.java	2001/07/12 15:03:23	1.26
  +++ AdminClient.java	2001/07/30 02:29:28	1.27
  @@ -106,6 +106,17 @@
                       System.out.println("Doing a quit");
                       String str = "<m:quit xmlns:m=\"AdminService\"/>";
                       input = new ByteArrayInputStream(str.getBytes());
  +                } else if (args[i].equals("passwd")) {
  +                    System.out.println("Changing admin password");
  +                    if (args[i + 1] == null) {
  +                        System.err.println("Must specify a password!");
  +                        return;
  +                    }
  +                    String str = "<m:passwd xmlns:m=\"AdminService\">";
  +                    str += args[i + 1];
  +                    str += "</m:passwd>";
  +                    input = new ByteArrayInputStream(str.getBytes());
  +                    i++;
                   }
                   else {
                       System.out.println( "Processing file: " + args[i] );
  
  
  
  1.20      +6 -1      xml-axis/java/src/org/apache/axis/client/AxisClient.java
  
  Index: AxisClient.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/client/AxisClient.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- AxisClient.java	2001/07/10 22:52:47	1.19
  +++ AxisClient.java	2001/07/30 02:29:28	1.20
  @@ -76,7 +76,12 @@
   {
       public AxisClient()
       {
  -        super(Constants.CLIENT_CONFIG_FILE);
  +        super(null, Constants.CLIENT_CONFIG_FILE);
  +    }
  +    
  +    public AxisClient(String basePath)
  +    {
  +        super(basePath, Constants.CLIENT_CONFIG_FILE);
       }
       
       /**
  
  
  
  1.3       +2 -1      xml-axis/java/src/org/apache/axis/message/EnvelopeBuilder.java
  
  Index: EnvelopeBuilder.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/EnvelopeBuilder.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- EnvelopeBuilder.java	2001/07/16 17:37:02	1.2
  +++ EnvelopeBuilder.java	2001/07/30 02:29:28	1.3
  @@ -29,7 +29,8 @@
           throws SAXException
       {
           if (!namespace.equals(Constants.URI_SOAP_ENV))
  -            throw new SAXException("Bad envelope namespace " + namespace);
  +            throw new SAXException("Bad envelope namespace '" + namespace +
  +                                         "'");
           
           if (!localName.equals(Constants.ELEM_ENVELOPE))
               throw new SAXException("Bad envelope tag " + localName);
  
  
  
  1.32      +14 -3     xml-axis/java/src/org/apache/axis/server/AxisServer.java
  
  Index: AxisServer.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/server/AxisServer.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- AxisServer.java	2001/07/12 15:04:19	1.31
  +++ AxisServer.java	2001/07/30 02:29:28	1.32
  @@ -85,16 +85,27 @@
       
       public AxisServer()
       {
  -        super(Constants.SERVER_CONFIG_FILE);
  +        super(null, Constants.SERVER_CONFIG_FILE);
       }
       
  +    public AxisServer(String basePath)
  +    {
  +        super(basePath, Constants.SERVER_CONFIG_FILE);
  +    }
  +    
       /** Lifecycle routines for managing a static AxisServer
        */
       private static AxisServer singleton = null;
  +    private static String basePath = null;
  +    
  +    public static void setBasePath(String path)
  +    {
  +        basePath = path;
  +    }
       public static synchronized AxisServer getSingleton()
       {
           if (singleton == null) {
  -            singleton = new AxisServer();
  +            singleton = new AxisServer(basePath);
           }
           return singleton;
       }
  @@ -128,7 +139,7 @@
        */
       public synchronized AxisEngine getClientEngine () {
           if (clientEngine == null) {
  -            clientEngine = new AxisClient();
  +            clientEngine = new AxisClient(basePath);
           }
           return clientEngine;
       }
  
  
  
  1.3       +3 -0      xml-axis/java/src/org/apache/axis/transport/http/AdminServlet.java
  
  Index: AdminServlet.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/transport/http/AdminServlet.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AdminServlet.java	2001/07/12 15:04:35	1.2
  +++ AdminServlet.java	2001/07/30 02:29:28	1.3
  @@ -75,6 +75,9 @@
       private AxisServer server;
       
       public void init() {
  +        // Set the base path for the AxisServer to our WEB-INF directory
  +        // (so the config files can't get snooped by a browser)
  +        AxisServer.setBasePath(getServletContext().getRealPath("WEB-INF"));
           server = AxisServer.getSingleton();
       }
   
  
  
  
  1.55      +44 -2     xml-axis/java/src/org/apache/axis/utils/Admin.java
  
  Index: Admin.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/utils/Admin.java,v
  retrieving revision 1.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- Admin.java	2001/07/12 15:04:52	1.54
  +++ Admin.java	2001/07/30 02:29:28	1.55
  @@ -56,6 +56,7 @@
   package org.apache.axis.utils ;
   
   import java.io.* ;
  +import java.net.*;
   import java.util.* ;
   import org.apache.axis.* ;
   import org.apache.axis.registries.* ;
  @@ -67,8 +68,10 @@
   import org.apache.axis.client.AxisClient;
   import org.apache.axis.client.Transport;
   import org.apache.axis.server.AxisServer;
  +import org.apache.axis.transport.http.HTTPConstants;
   
   import org.w3c.dom.* ;
  +import javax.servlet.http.*;
   
   /**
    * Handy static utility functions for turning XML into
  @@ -258,11 +261,50 @@
   
               if ( !action.equals("clientdeploy") && !action.equals("deploy") &&
                    !action.equals("undeploy") &&
  -                 !action.equals("list") && !action.equals("quit") )
  +                 !action.equals("list") &&
  +                 !action.equals("quit") &&
  +                 !action.equals("passwd"))
                   throw new AxisFault( "Admin.error",
                       "Root element must be 'clientdeploy', 'deploy', 'undeploy', " +
  -                    "'list', or 'quit'",
  +                    "'list', 'passwd', or 'quit'",
                       null, null );
  +            
  +            /** Might do something like this once security is a little more
  +             * integrated.
  +            if (!engine.hasSafePassword() &&
  +                !action.equals("passwd"))
  +                throw new AxisFault("Server.MustSetPassword",
  +              "You must change the admin password before administering Axis!",
  +                                     null, null);
  +             */
  +            
  +            /** For now, though - make sure we can only admin from our own
  +             * IP.
  +             */
  +            HttpServletRequest req =
  +                     (HttpServletRequest)msgContext.
  +                          getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);
  +            if (req != null) {
  +                String remoteIP = req.getRemoteAddr();
  +                if (!remoteIP.equals("127.0.0.1")) {
  +                    InetAddress myAddr = InetAddress.getLocalHost();
  +                    InetAddress remoteAddr = InetAddress.getByName(remoteIP);
  +             
  +                    if (!myAddr.equals(remoteAddr))
  +                        throw new AxisFault("Server.Unauthorized",
  +                            "Remote admin access is not allowed! ",
  +                            null, null);
  +                }
  +            }
  +            
  +            if (action.equals("passwd")) {
  +                String newPassword = root.getFirstChild().getNodeValue();
  +                engine.setAdminPassword(newPassword);
  +                doc = XMLUtils.newDocument();
  +                doc.appendChild( root = doc.createElement( "Admin" ) );
  +                root.appendChild( doc.createTextNode( "Done processing" ) );
  +                return doc;
  +            }
   
               if (action.equals("quit")) {
                   System.err.println("Admin service requested to quit, quitting.");
  
  
  

Mime
View raw message