You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by am...@apache.org on 2005/11/21 20:13:50 UTC
svn commit: r347956 - in /geronimo/trunk:
applications/console-standard/src/java/org/apache/geronimo/console/databasemanager/wizard/
applications/console-standard/src/webapp/WEB-INF/view/dbwizard/
modules/converter/src/java/org/apache/geronimo/converte...
Author: ammulder
Date: Mon Nov 21 11:13:41 2005
New Revision: 347956
URL: http://svn.apache.org/viewcvs?rev=347956&view=rev
Log:
Add a link to show usage directions for a database pool.
Add a custom import process for WebLogic pools that decrypts the
stored passwords.
Clean out a personal test method that snuck in
Added:
geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/dbwizard/usage.jsp (with props)
geronimo/trunk/modules/converter/src/java/org/apache/geronimo/converter/bea/Weblogic81Utils.java (with props)
Modified:
geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/databasemanager/wizard/DatabasePoolPortlet.java
geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/dbwizard/importUpload.jsp
geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/dbwizard/list.jsp
geronimo/trunk/modules/converter/src/java/org/apache/geronimo/converter/bea/WebLogic81DatabaseConverter.java
Modified: geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/databasemanager/wizard/DatabasePoolPortlet.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/databasemanager/wizard/DatabasePoolPortlet.java?rev=347956&r1=347955&r2=347956&view=diff
==============================================================================
--- geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/databasemanager/wizard/DatabasePoolPortlet.java (original)
+++ geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/databasemanager/wizard/DatabasePoolPortlet.java Mon Nov 21 11:13:41 2005
@@ -121,6 +121,7 @@
private static final String SHOW_PLAN_VIEW = "/WEB-INF/view/dbwizard/showPlan.jsp";
private static final String IMPORT_UPLOAD_VIEW = "/WEB-INF/view/dbwizard/importUpload.jsp";
private static final String IMPORT_STATUS_VIEW = "/WEB-INF/view/dbwizard/importStatus.jsp";
+ private static final String USAGE_VIEW = "/WEB-INF/view/dbwizard/usage.jsp";
private static final String LIST_MODE = "list";
private static final String EDIT_MODE = "edit";
private static final String SELECT_RDBMS_MODE = "rdbms";
@@ -135,6 +136,8 @@
private static final String IMPORT_UPLOAD_MODE = "importUpload";
private static final String IMPORT_STATUS_MODE = "importStatus";
private static final String IMPORT_COMPLETE_MODE = "importComplete";
+ private static final String WEBLOGIC_IMPORT_MODE = "weblogicImport";
+ private static final String USAGE_MODE = "usage";
private static final String IMPORT_EDIT_MODE = "importEdit";
private static final String MODE_KEY = "mode";
@@ -148,6 +151,7 @@
private PortletRequestDispatcher planView;
private PortletRequestDispatcher importUploadView;
private PortletRequestDispatcher importStatusView;
+ private PortletRequestDispatcher usageView;
public void init(PortletConfig portletConfig) throws PortletException {
super.init(portletConfig);
@@ -161,6 +165,7 @@
planView = portletConfig.getPortletContext().getRequestDispatcher(SHOW_PLAN_VIEW);
importUploadView = portletConfig.getPortletContext().getRequestDispatcher(IMPORT_UPLOAD_VIEW);
importStatusView = portletConfig.getPortletContext().getRequestDispatcher(IMPORT_STATUS_VIEW);
+ usageView = portletConfig.getPortletContext().getRequestDispatcher(USAGE_VIEW);
}
public void destroy() {
@@ -174,6 +179,7 @@
planView = null;
importUploadView = null;
importStatusView = null;
+ usageView = null;
super.destroy();
}
@@ -344,6 +350,18 @@
data.adapterDisplayName = "TranQL Generic JDBC Resource Adapter";
}
actionResponse.setRenderParameter(MODE_KEY, mode);
+ } else if(mode.equals(WEBLOGIC_IMPORT_MODE)) {
+ String domainDir = actionRequest.getParameter("weblogicDomainDir");
+ String libDir = actionRequest.getParameter("weblogicLibDir");
+ try {
+ DatabaseConversionStatus status = WebLogic81DatabaseConverter.convert(libDir, domainDir);
+ actionRequest.getPortletSession(true).setAttribute("ImportStatus", new ImportStatus(status));
+ actionResponse.setRenderParameter(MODE_KEY, IMPORT_STATUS_MODE);
+ } catch (Exception e) {
+ log.error("Unable to import", e);
+ actionResponse.setRenderParameter("from", actionRequest.getParameter("from"));
+ actionResponse.setRenderParameter(MODE_KEY, IMPORT_START_MODE);
+ }
} else if(mode.equals(IMPORT_START_MODE)) {
actionResponse.setRenderParameter("from", actionRequest.getParameter("from"));
actionResponse.setRenderParameter(MODE_KEY, mode);
@@ -616,12 +634,18 @@
renderImportUploadForm(renderRequest, renderResponse);
} else if(mode.equals(IMPORT_STATUS_MODE)) {
renderImportStatus(renderRequest, renderResponse);
+ } else if(mode.equals(USAGE_MODE)) {
+ renderUsage(renderRequest, renderResponse);
}
} catch (Throwable e) {
log.error("Unable to render portlet", e);
}
}
+ private void renderUsage(RenderRequest request, RenderResponse response) throws IOException, PortletException {
+ usageView.include(request, response);
+ }
+
private void renderImportStatus(RenderRequest request, RenderResponse response) throws IOException, PortletException {
request.setAttribute("status", getImportStatus(request));
populatePoolList(request);
@@ -1082,6 +1106,7 @@
private String adapterDescription;
private String rarPath;
private String importSource;
+ private Map objectNameMap; // generated as needed, don't need to read/write it
public void load(PortletRequest request) {
name = request.getParameter("name");
@@ -1292,6 +1317,19 @@
public String getImportSource() {
return importSource;
+ }
+
+ public Map getObjectNameMap() {
+ if(objectName == null) return Collections.EMPTY_MAP;
+ if(objectNameMap != null) return objectNameMap;
+ try {
+ ObjectName name = new ObjectName(objectName);
+ objectNameMap = new HashMap(name.getKeyPropertyList());
+ objectNameMap.put("domain", name.getDomain());
+ return objectNameMap;
+ } catch (MalformedObjectNameException e) {
+ return Collections.EMPTY_MAP;
+ }
}
}
Modified: geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/dbwizard/importUpload.jsp
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/dbwizard/importUpload.jsp?rev=347956&r1=347955&r2=347956&view=diff
==============================================================================
--- geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/dbwizard/importUpload.jsp (original)
+++ geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/dbwizard/importUpload.jsp Mon Nov 21 11:13:41 2005
@@ -32,6 +32,53 @@
</table>
</form>
+<c:if test="${pool.importSource eq 'WebLogic 8.1'}">
+<br />
+<br />
+<br />
+<form name="<portlet:namespace/>WebLogicImportForm" action="<portlet:actionURL/>">
+ <input type="hidden" name="mode" value="weblogicImport" />
+ <input type="hidden" name="importSource" value="${pool.importSource}" />
+ <input type="hidden" name="from" value="${from}" />
+ <table width="100%">
+ <tr>
+ <td class="DarkBackground" colspan="2">Alternate ${pool.importSource} Import</td>
+ </tr>
+ <tr>
+ <td colspan="2">If WebLogic 8.1 is installed on the same machine as Geronimo, and the
+WebLogic domain directory is readable by the user running Geronimo, you
+can also point directly to the WebLogic installation and domain directories.
+This has the advantage that the import process can read the database
+passwords, whereas if you just import a <tt>config.xml</tt> above you'll
+need to re-enter all the passwords.</td>
+ </tr>
+ <tr>
+ <th align="right">Domain directory path:</th>
+ <td><input type="text" name="weblogicDomainDir" size="40" /></td>
+ </tr>
+ <tr>
+ <td></td>
+ <td>Please enter the full path to the WebLogic domain directory (containing the
+ <tt>config.xml</tt> file) for your WebLogic domain (e.g. C:\bea\user_projects\domains\mydomain).</td>
+ </tr>
+ <tr>
+ <th align="right"><tt>weblogic81/server/lib</tt> path:</th>
+ <td><input type="text" name="weblogicLibDir" size="40" /></td>
+ </tr>
+ <tr>
+ <td></td>
+ <td>Please enter the full path to the <tt>weblogic81/server/lib</tt> directory
+ for your WebLogic 8.1 installation (e.g. C:\bea\weblogic81\server\lib).</td>
+ </tr>
+ <!-- SUBMIT BUTTON -->
+ <tr>
+ <td></td>
+ <td><input type="submit" value="Next" /></td>
+ </tr>
+ </table>
+</form>
+</c:if>
+
<p><a href="<portlet:actionURL portletMode="view">
<portlet:param name="mode" value="list" />
Modified: geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/dbwizard/list.jsp
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/dbwizard/list.jsp?rev=347956&r1=347955&r2=347956&view=diff
==============================================================================
--- geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/dbwizard/list.jsp (original)
+++ geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/dbwizard/list.jsp Mon Nov 21 11:13:41 2005
@@ -54,6 +54,11 @@
<portlet:param name="adapterObjectName" value="${pool.adapterObjectName}" />
<portlet:param name="objectName" value="${pool.factoryObjectName}" />
</portlet:actionURL>">edit</a>
+ <a href="<portlet:actionURL portletMode="view">
+ <portlet:param name="mode" value="usage" />
+ <portlet:param name="name" value="${pool.name}" />
+ <portlet:param name="objectName" value="${pool.factoryObjectName}" />
+ </portlet:actionURL>">usage</a>
<%--<a href="<portlet:actionURL portletMode="view">
<portlet:param name="mode" value="delete" />
<portlet:param name="name" value="${info.objectName}" />
Added: geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/dbwizard/usage.jsp
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/dbwizard/usage.jsp?rev=347956&view=auto
==============================================================================
--- geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/dbwizard/usage.jsp (added)
+++ geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/dbwizard/usage.jsp Mon Nov 21 11:13:41 2005
@@ -0,0 +1,125 @@
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
+<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet"%>
+<portlet:defineObjects/>
+
+<p>This page talks about how to use the database pool ${pool.name} from a J2EE application.
+ The example here is a web application, but other application modules would work in
+ the same way.</p>
+
+
+<p><b>WEB-INF/web.xml</b></p>
+
+<p>The <tt>web.xml</tt> should have a <tt>resource-ref</tt> section declaring the database pool,
+like this. Note the <tt>res-ref-name</tt>, which is what we'll need to map the reference
+to a pool, and also what the application will need in order to access the pool.</p>
+
+<pre>
+<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
+ http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
+ version="2.4">
+
+ <!-- servlets and mappings and normal web.xml stuff here -->
+
+ <resource-ref>
+ <res-ref-name><b>jdbc/MyDataSource</b></res-ref-name>
+ <res-type>javax.sql.DataSource</res-type>
+ <res-auth>Container</res-auth>
+ <res-sharing-scope>Shareable</res-sharing-scope>
+ </resource-ref>
+</web-app>
+</pre>
+
+<p><b>WEB-INF/geronimo-web.xml</b></p>
+
+<p>To point the resource reference to a specific database pool in Gernimo, the web application
+needs to have a <tt>geronimo-web.xml</tt> deployment plan. That may be packaged in the WAR
+in the <tt>WEB-INF</tt> directory, or it may be provided separately on the command line to
+the deploy tool. The <tt>geronimo-web.xml</tt> plan should have a <tt>resource-ref</tt>
+block corresponding to the one above, which maps the resource reference to a specific database
+pool. In that block, the <tt>ref-name</tt> must match the <tt>res-ref-name</tt> from
+the <tt>web.xml</tt> (above) and the <tt>resource-link</tt> must point to the database
+pool.</p>
+
+<p><i>If you have only one pool named ${pool.name} deployed in Geronimo, you can point to it
+like this.</i></p>
+
+<pre>
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app
+ xmlns="http://geronimo.apache.org/xml/ns/web"
+ xmlns:naming="http://geronimo.apache.org/xml/ns/naming"
+ configId="MyConfigName"
+ parentId="org/apache/geronimo/Server">
+
+ <context-root>/MyWebApp</context-root>
+ <context-priority-classloader>true</context-priority-classloader>
+
+ <!-- security settings, if any, go here -->
+
+ <naming:resource-ref>
+ <naming:ref-name><b>jdbc/MyDataSource</b></naming:ref-name>
+ <b><naming:resource-link>${pool.name}</naming:resource-link></b>
+ </naming:resource-ref>
+</web-app>
+</pre>
+
+<p>That will search for a pool named ${pool.name} in both the current application and
+as a server-wide pool.</p>
+
+<p><i>If you have more than one pool named ${pool.name} (for example, one as a server-wide
+pool and one deployed within an application EAR), then you can specify the pool to use
+more explicitly like this:</i></p>
+
+<pre>
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app
+ xmlns="http://geronimo.apache.org/xml/ns/web"
+ xmlns:naming="http://geronimo.apache.org/xml/ns/naming"
+ configId="MyConfigName"
+ parentId="org/apache/geronimo/Server">
+
+ <context-root>/MyWebApp</context-root>
+ <context-priority-classloader>true</context-priority-classloader>
+
+ <!-- security settings, if any, go here -->
+
+ <naming:resource-ref>
+ <naming:ref-name><b>jdbc/MyDataSource</b></naming:ref-name>
+ <b><naming:domain>${pool.objectNameMap['domain']}</naming:domain>
+ <naming:server>${pool.objectNameMap['J2EEServer']}</naming:server>
+ <naming:application>${pool.objectNameMap['J2EEApplication']}</naming:application>
+ <naming:module>${pool.objectNameMap['JCAResource']}</naming:module>
+ <naming:type>${pool.objectNameMap['j2eeType']}</naming:type>
+ <naming:name>${pool.objectNameMap['name']}</naming:name></b>
+ </naming:resource-ref>
+</web-app>
+</pre>
+
+<p><b>Application Code</b></p>
+
+<p>To get a reference to the database pool, your application can use code like this. Note that
+the JNDI lookup string is <tt>java:comp/env/</tt> plus the <tt>res-ref-name</tt> used in
+<tt>web.xml</tt> (above).</p>
+
+<pre>
+protected void doGet(HttpServletRequest request, HttpServletResponse response) {
+ try {
+ InitialContext ctx = new InitialContext();
+ DataSource ds = ctx.lookup("java:comp/env/<b>jdbc/MyDataSource</b>");
+ Connection con = ds.getConnection();
+ } catch(NamingException e) {
+ ...
+ } catch(SQLException e) {
+ ...
+ }
+}
+</pre>
+
+<hr />
+
+<p><a href="<portlet:actionURL portletMode="view">
+ <portlet:param name="mode" value="list" />
+ </portlet:actionURL>">Return to list</a></p>
Propchange: geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/dbwizard/usage.jsp
------------------------------------------------------------------------------
svn:eol-style = native
Modified: geronimo/trunk/modules/converter/src/java/org/apache/geronimo/converter/bea/WebLogic81DatabaseConverter.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/converter/src/java/org/apache/geronimo/converter/bea/WebLogic81DatabaseConverter.java?rev=347956&r1=347955&r2=347956&view=diff
==============================================================================
--- geronimo/trunk/modules/converter/src/java/org/apache/geronimo/converter/bea/WebLogic81DatabaseConverter.java (original)
+++ geronimo/trunk/modules/converter/src/java/org/apache/geronimo/converter/bea/WebLogic81DatabaseConverter.java Mon Nov 21 11:13:41 2005
@@ -18,14 +18,13 @@
import java.io.Reader;
import java.io.IOException;
-import java.io.FileReader;
-import java.io.File;
-import java.io.FilenameFilter;
+import java.io.StringReader;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.Properties;
+import java.util.Iterator;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
@@ -47,6 +46,12 @@
* @version $Rev: 46019 $ $Date: 2004-09-14 05:56:06 -0400 (Tue, 14 Sep 2004) $
*/
public class WebLogic81DatabaseConverter extends DOMUtils {
+ public static DatabaseConversionStatus convert(String libDir, String domainDir) throws IOException {
+ Weblogic81Utils utils = new Weblogic81Utils(libDir, domainDir);
+ String config = utils.getConfigXML();
+ return convert(new StringReader(config));
+ }
+
public static DatabaseConversionStatus convert(Reader configXml) throws IOException {
List status = new ArrayList();
List noTx = new ArrayList();
@@ -59,7 +64,7 @@
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(new InputSource(configXml));
configXml.close();
- parseDocument(doc, status, noTx, local, xa);
+ parseDocument(doc, status, local, xa);
} catch (ParserConfigurationException e) {
throw (IOException)new IOException().initCause(e);
} catch (SAXException e) {
@@ -74,7 +79,7 @@
return result;
}
- private static void parseDocument(Document doc, List status, List noTx, List local, List xa) {
+ private static void parseDocument(Document doc, List status, List local, List xa) {
Element domain = doc.getDocumentElement();
if(!domain.getNodeName().equalsIgnoreCase("Domain")) {
status.add("ERROR: Unrecognized file beginning with "+domain.getNodeName()+" element. Expected a WebLogic config.xml file.");
@@ -110,6 +115,15 @@
}
}
}
+ if(pools.size() > 0) {
+ for (Iterator it = pools.values().iterator(); it.hasNext();) {
+ ConnectionPool pool = (ConnectionPool) it.next();
+ if(pool.getPassword() != null && pool.getPassword().startsWith("{")) {
+ status.add("NOTE: When importing from WebLogic, typically database passwords cannot be recovered, and will need to be re-entered.");
+ break;
+ }
+ }
+ }
processPools((ConnectionPool[]) pools.values().toArray(new ConnectionPool[0]),
status, local, xa);
}
@@ -174,7 +188,10 @@
result.setConnectionProperties(pool.getProperties());
result.setDriverClass(pool.getDriverName());
result.setJdbcURL(pool.getUrl());
- result.setPassword(pool.getPassword());
+ // Don't bother putting encrypted passwords into the pool
+ if(pool.getPassword() != null && !pool.getPassword().startsWith("{")) {
+ result.setPassword(pool.getPassword());
+ }
result.setUsername(pool.getUsername());
return result;
}
@@ -216,8 +233,9 @@
readProperties(pool.getProperties(), root.getAttribute("Properties"), status);
pool.setUsername(pool.getProperties().getProperty("user"));
pool.getProperties().remove("user");
- pool.setPassword(root.getAttribute("Password"));
- if(pool.getPassword() == null) {
+ if(root.hasAttribute("Password")) {
+ pool.setPassword(root.getAttribute("Password"));
+ } else if(root.hasAttribute("PasswordEncrypted")) {
pool.setPassword(root.getAttribute("PasswordEncrypted"));
}
pool.setReserveTimeoutSecs(getInteger(root.getAttribute("ConnectionReserveTimeoutSeconds")));
@@ -466,33 +484,6 @@
public void setUrl(String url) {
this.url = url;
- }
- }
-
-
- public static void main(String[] args) {
- File dir = new File("/Users/ammulder/temp/");
- File[] files = dir.listFiles(new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return name.indexOf("config.xml") > -1;
- }
- });
- for (int i = 0; i < files.length; i++) {
- File file = files[i];
- System.out.println("Reading "+file.getName());
- try {
- FileReader reader = new FileReader(file);
- DatabaseConversionStatus status = WebLogic81DatabaseConverter.convert(reader);
- for (int j = 0; j < status.getMessages().length; j++) {
- String message = status.getMessages()[j];
- System.out.println(" "+message);
- }
- System.out.println(" FOUND "+status.getNoTXPools().length+" NoTX Pools");
- System.out.println(" FOUND "+status.getJdbcPools().length+" JDBC Pools");
- System.out.println(" FOUND "+status.getXaPools().length+" XA Pools");
- } catch (IOException e) {
- e.printStackTrace();
- }
}
}
}
Added: geronimo/trunk/modules/converter/src/java/org/apache/geronimo/converter/bea/Weblogic81Utils.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/converter/src/java/org/apache/geronimo/converter/bea/Weblogic81Utils.java?rev=347956&view=auto
==============================================================================
--- geronimo/trunk/modules/converter/src/java/org/apache/geronimo/converter/bea/Weblogic81Utils.java (added)
+++ geronimo/trunk/modules/converter/src/java/org/apache/geronimo/converter/bea/Weblogic81Utils.java Mon Nov 21 11:13:41 2005
@@ -0,0 +1,176 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.converter.bea;
+
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
+import java.util.Properties;
+import java.util.Iterator;
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.StringWriter;
+import java.io.PrintWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URLClassLoader;
+import java.net.URL;
+
+/**
+ * Reads information out of the WebLogic domain directory.
+ * Needs access to the WebLogic JARs in the weblogic81/server/lib directory.
+ *
+ * @version $Rev: 46019 $ $Date: 2004-09-14 05:56:06 -0400 (Tue, 14 Sep 2004) $
+ */
+public class Weblogic81Utils {
+ private final static Pattern ENCRYPTED_STRING = Pattern.compile("\\\"\\{\\S+\\}\\S+?\\\"");
+ private Object decoder;
+ private Method decode;
+ private Object decrypter;
+ private Method decrypt;
+ private File domainDir;
+
+ public Weblogic81Utils(String libDirPath, String domainDirPath) {
+ File libDir = new File(libDirPath);
+ if(!libDir.exists() || !libDir.canRead() || !libDir.isDirectory()) throw new IllegalArgumentException("Bad weblogic lib dir");
+ File weblogicJar = new File(libDir, "weblogic.jar");
+ File securityJar = new File(libDir, "jsafeFIPS.jar");
+ if(!weblogicJar.canRead()) throw new IllegalArgumentException("Cannot find JARs in provided lib dir");
+ domainDir = new File(domainDirPath);
+ if(!domainDir.exists() || !domainDir.canRead() || !domainDir.isDirectory()) throw new IllegalArgumentException("Bad domain directory");
+ File state = new File(domainDir, "SerializedSystemIni.dat");
+ if(!state.canRead()) throw new IllegalArgumentException("Cannot find serialized state in domain directory");
+ try {
+ ClassLoader loader = new URLClassLoader(securityJar.exists() ? new URL[]{weblogicJar.toURL(), securityJar.toURL()} : new URL[]{weblogicJar.toURL()}, Weblogic81Utils.class.getClassLoader());
+ initialize(loader, state);
+ } catch (Exception e) {
+ throw (RuntimeException)new IllegalArgumentException("Unable to initialize encryption routines from provided arguments").initCause(e);
+ }
+ }
+
+ public Properties getBootProperties() {
+ File boot = new File(domainDir, "boot.properties");
+ FileInputStream bootIn = null;
+ try {
+ bootIn = new FileInputStream(boot);
+ } catch (FileNotFoundException e) {
+ return null;
+ }
+ try {
+ Properties props = new Properties();
+ props.load(bootIn);
+ bootIn.close();
+ for (Iterator it = props.keySet().iterator(); it.hasNext();) {
+ String key = (String) it.next();
+ String value = props.getProperty(key);
+ if(value != null && value.startsWith("{")) props.setProperty(key, decryptString(value));
+ }
+ return props;
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ public String getConfigXML() throws FileNotFoundException {
+ File config = new File(domainDir, "config.xml");
+ BufferedReader in = new BufferedReader(new FileReader(config));
+ StringWriter string = new StringWriter();
+ PrintWriter out = new PrintWriter(string);
+ String line;
+ Matcher m = ENCRYPTED_STRING.matcher("");
+ try {
+ while((line = in.readLine()) != null) {
+ m.reset(line);
+ int last = -1;
+ while(m.find()) {
+ out.print(line.substring(last+1, m.start()));
+ String s = line.substring(m.start(), m.end());
+ out.print("\"");
+ out.print(decryptString(s.substring(1, s.length()-1)));
+ out.print("\"");
+ last = m.end()-1;
+ }
+ if(last == -1) {
+ out.println(line);
+ } else {
+ if(line.length() > last+1) {
+ out.print(line.substring(last+1));
+ }
+ out.println();
+ }
+ out.flush();
+ }
+ in.close();
+ out.close();
+ } catch (Exception e) {
+ return null;
+ }
+ return string.getBuffer().toString();
+ }
+
+ private void initialize(ClassLoader loader, File state) throws IOException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, ClassNotFoundException, InstantiationException {
+ byte[] salt = null, key = null;
+ FileInputStream in = new FileInputStream(state);
+ salt = readBytes(in);
+ int i = in.read();
+ if(i != -1) {
+ if(i != 1) throw new IllegalStateException();
+ key = readBytes(in);
+ }
+ in.close();
+ decrypter = getEncryptionService(loader, salt, key);
+ decoder = loader.loadClass("weblogic.utils.encoders.BASE64Decoder").newInstance();
+ decode = decoder.getClass().getMethod("decodeBuffer", new Class[]{String.class});
+ decrypt = decrypter.getClass().getMethod("decryptString", new Class[]{byte[].class});
+ }
+
+ private static byte[] readBytes(InputStream in) throws IOException {
+ int len = in.read();
+ if(len < 0)
+ throw new IOException("stream is empty");
+ byte result[] = new byte[len];
+ int index = 0;
+ while(true) {
+ if(index >= len) {
+ break;
+ }
+ int count = in.read(result, index, len - index);
+ if(count == -1)
+ break;
+ index += count;
+ }
+ return result;
+ }
+
+ private String decryptString(String string) throws IllegalAccessException, InvocationTargetException {
+ if(string.indexOf('}') > -1) {
+ string = string.substring(string.indexOf("}")+1);
+ }
+ return (String) decrypt.invoke(decrypter, new Object[]{decode.invoke(decoder, new Object[]{string})});
+ }
+
+ static Object getEncryptionService(ClassLoader loader, byte salt[], byte key[]) throws NoSuchMethodException, ClassNotFoundException, IllegalAccessException, InvocationTargetException {
+ String magic = "0xccb97558940b82637c8bec3c770f86fa3a391a56";
+ Object factory = loader.loadClass("weblogic.security.internal.encryption.JSafeEncryptionServiceImpl").getMethod("getFactory", new Class[0]).invoke(null, null);
+ Method getter = factory.getClass().getMethod("getEncryptionService", new Class[]{byte[].class, String.class, byte[].class});
+ return getter.invoke(factory, new Object[]{salt, magic, key});
+ }
+}
Propchange: geronimo/trunk/modules/converter/src/java/org/apache/geronimo/converter/bea/Weblogic81Utils.java
------------------------------------------------------------------------------
svn:eol-style = native