1 55 56 package org.jboss.axis.utils; 57 58 import org.jboss.axis.AxisEngine; 59 import org.jboss.axis.AxisFault; 60 import org.jboss.axis.Constants; 61 import org.jboss.axis.EngineConfiguration; 62 import org.jboss.axis.Handler; 63 import org.jboss.axis.MessageContext; 64 import org.jboss.axis.WSDDEngineConfiguration; 65 import org.jboss.axis.client.AxisClient; 66 import org.jboss.axis.deployment.wsdd.WSDDConstants; 67 import org.jboss.axis.deployment.wsdd.WSDDDeployment; 68 import org.jboss.axis.deployment.wsdd.WSDDDocument; 69 import org.jboss.axis.encoding.SerializationContext; 70 import org.jboss.axis.encoding.SerializationContextImpl; 71 import org.jboss.axis.server.AxisServer; 72 import org.jboss.logging.Logger; 73 import org.w3c.dom.Document ; 74 import org.w3c.dom.Element ; 75 import org.xml.sax.InputSource ; 76 77 import java.io.FileInputStream ; 78 import java.io.StringReader ; 79 import java.io.StringWriter ; 80 import java.net.InetAddress ; 81 import java.net.UnknownHostException ; 82 83 90 public class Admin 91 { 92 private static Logger log = Logger.getLogger(Admin.class.getName()); 93 94 97 public Element [] AdminService(Element [] xml) 98 throws Exception 99 { 100 log.debug("Enter: Admin::AdminService"); 101 MessageContext msgContext = MessageContext.getCurrentContext(); 102 Document doc = process(msgContext, xml[0]); 103 Element [] result = new Element [1]; 104 result[0] = doc.getDocumentElement(); 105 log.debug("Exit: Admin::AdminService"); 106 return result; 107 } 108 109 protected static Document processWSDD(MessageContext msgContext, 110 AxisEngine engine, 111 Element root) 112 throws Exception 113 { 114 Document doc = null; 115 116 String action = root.getLocalName(); 117 if (action.equals("passwd")) 118 { 119 String newPassword = root.getFirstChild().getNodeValue(); 120 engine.setAdminPassword(newPassword); 121 doc = XMLUtils.newDocument(); 122 doc.appendChild(root = doc.createElementNS("", "Admin")); 123 root.appendChild(doc.createTextNode(Messages.getMessage("done00"))); 124 return doc; 125 } 126 127 if (action.equals("quit")) 128 { 129 log.error(Messages.getMessage("quitRequest00")); 130 if (msgContext != null) 131 { 132 msgContext.setProperty(MessageContext.QUIT_REQUESTED, "true"); 135 } 136 doc = XMLUtils.newDocument(); 137 doc.appendChild(root = doc.createElementNS("", "Admin")); 138 root.appendChild(doc.createTextNode(Messages.getMessage("quit00", ""))); 139 return doc; 140 } 141 142 if (action.equals("list")) 143 { 144 return listConfig(engine); 145 } 146 147 if (action.equals("clientdeploy")) 148 { 149 engine = engine.getClientEngine(); 151 } 152 153 WSDDDocument wsddDoc = new WSDDDocument(root); 154 EngineConfiguration config = engine.getConfig(); 155 if (config instanceof WSDDEngineConfiguration) 156 { 157 WSDDDeployment deployment = 158 ((WSDDEngineConfiguration)config).getDeployment(); 159 wsddDoc.deploy(deployment); 160 } 161 engine.refreshGlobalOptions(); 162 163 engine.saveConfiguration(); 164 165 doc = XMLUtils.newDocument(); 166 doc.appendChild(root = doc.createElementNS("", "Admin")); 167 root.appendChild(doc.createTextNode(Messages.getMessage("done00"))); 168 169 return doc; 170 } 171 172 protected void preProcessWSDD(MessageContext msgContext, AxisEngine engine, Element root) 173 { 174 } 176 177 185 public Document process(MessageContext msgContext, Element root) 186 throws Exception 187 { 188 190 198 199 202 Handler serviceHandler = msgContext.getService(); 203 if (serviceHandler != null && 204 !JavaUtils.isTrueExplicitly(serviceHandler.getOption("enableRemoteAdmin"))) 205 { 206 207 String remoteIP = msgContext.getStrProp(Constants.MC_REMOTE_ADDR); 208 if (remoteIP != null && 209 !remoteIP.equals("127.0.0.1")) 210 { 211 212 try 213 { 214 InetAddress myAddr = InetAddress.getLocalHost(); 215 InetAddress remoteAddr = 216 InetAddress.getByName(remoteIP); 217 if (log.isDebugEnabled()) 218 { 219 log.debug("Comparing remote caller " + remoteAddr + " to " + myAddr); 220 } 221 222 223 if (!myAddr.equals(remoteAddr)) 224 { 225 log.error(Messages.getMessage("noAdminAccess01", 226 remoteAddr.toString())); 227 throw new AxisFault("Server.Unauthorized", 228 Messages.getMessage("noAdminAccess00"), 229 null, null); 230 } 231 } 232 catch (UnknownHostException e) 233 { 234 throw new AxisFault("Server.UnknownHost", 235 Messages.getMessage("unknownHost00"), 236 null, null); 237 } 238 } 239 } 240 241 String rootNS = root.getNamespaceURI(); 242 AxisEngine engine = msgContext.getAxisEngine(); 243 244 if (rootNS != null && rootNS.equals(WSDDConstants.URI_WSDD)) 246 { 247 preProcessWSDD(msgContext, engine, root); 248 return processWSDD(msgContext, engine, root); 249 } 250 251 throw new Exception ("FIXME"); 254 } 255 256 266 public static Document listConfig(AxisEngine engine) 267 throws AxisFault 268 { 269 StringWriter writer = new StringWriter (); 270 SerializationContext context = new SerializationContextImpl(writer, null); 271 context.setPretty(true); 272 try 273 { 274 EngineConfiguration config = engine.getConfig(); 275 276 if (config instanceof WSDDEngineConfiguration) 277 { 278 WSDDDeployment deployment = 279 ((WSDDEngineConfiguration)config).getDeployment(); 280 deployment.writeToContext(context); 281 } 282 } 283 catch (Exception e) 284 { 285 288 throw new AxisFault(Messages.getMessage("noEngineWSDD")); 289 } 290 291 try 292 { 293 writer.close(); 294 return XMLUtils.newDocument(new InputSource (new StringReader (writer.getBuffer().toString()))); 295 } 296 catch (Exception e) 297 { 298 log.error("exception00", e); 299 return null; 300 } 301 } 302 303 public static void main(String args[]) throws Exception 304 { 305 int i = 0; 306 307 if (args.length < 2 || !(args[0].equals("client") || 308 args[0].equals("server"))) 309 { 310 log.error(Messages.getMessage("usage00", "Admin client|server <xml-file>")); 311 312 log.error(Messages.getMessage("where00", "<xml-file>")); 313 log.error("<deploy>"); 314 318 log.error(" <handler name=a class=className/>"); 319 log.error(" <chain name=a flow=\"a,b,c\" />"); 320 log.error(" <chain name=a request=\"a,b,c\" pivot=\"d\""); 321 log.error(" response=\"e,f,g\" />"); 322 log.error(" <service name=a handler=b />"); 323 log.error("</deploy>"); 324 log.error("<undeploy>"); 325 log.error(" <handler name=a/>"); 326 log.error(" <chain name=a/>"); 327 log.error(" <service name=a/>"); 328 log.error("</undeploy>"); 329 log.error("<list/>"); 330 331 332 throw new IllegalArgumentException (Messages.getMessage("usage00", 335 "Admin client|server <xml-file>")); 336 } 338 339 Admin admin = new Admin(); 340 341 AxisEngine engine; 342 if (args[0].equals("client")) 343 engine = new AxisClient(); 344 else 345 engine = new AxisServer(); 346 engine.setShouldSaveConfig(true); 347 engine.init(); 348 MessageContext msgContext = new MessageContext(engine); 349 350 try 351 { 352 for (i = 1; i < args.length; i++) 353 { 354 if (log.isDebugEnabled()) 355 log.debug(Messages.getMessage("process00", args[i])); 356 357 Document doc = XMLUtils.newDocument(new FileInputStream (args[i])); 358 admin.process(msgContext, doc.getDocumentElement()); 359 } 360 } 361 catch (Exception e) 362 { 363 log.error(Messages.getMessage("errorProcess00", args[i]), e); 364 throw e; 366 } 367 } 368 } 369 | Popular Tags |