You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juddi.apache.org by al...@apache.org on 2015/12/05 22:21:56 UTC
juddi git commit: JUDDI-951 merging user submitted patch,
EntityManagerFactory not closed when undeploying juddi
Repository: juddi
Updated Branches:
refs/heads/master fe5dcfab8 -> 776d9081d
JUDDI-951 merging user submitted patch, EntityManagerFactory not closed when undeploying juddi
Project: http://git-wip-us.apache.org/repos/asf/juddi/repo
Commit: http://git-wip-us.apache.org/repos/asf/juddi/commit/776d9081
Tree: http://git-wip-us.apache.org/repos/asf/juddi/tree/776d9081
Diff: http://git-wip-us.apache.org/repos/asf/juddi/diff/776d9081
Branch: refs/heads/master
Commit: 776d9081dc06e07f75c8a79e52b4e6183393a53a
Parents: fe5dcfa
Author: Alex <al...@apache.org>
Authored: Sat Dec 5 16:21:48 2015 -0500
Committer: Alex <al...@apache.org>
Committed: Sat Dec 5 16:21:48 2015 -0500
----------------------------------------------------------------------
.../juddi/adminconsole/StartupServlet.java | 181 ++++++-------
.../juddi/adminconsole/StartupServlet.java | 255 ++++++++++---------
pom.xml | 1 +
3 files changed, 221 insertions(+), 216 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/juddi/blob/776d9081/juddiv3-war-repl/src/main/java/org/apache/juddi/adminconsole/StartupServlet.java
----------------------------------------------------------------------
diff --git a/juddiv3-war-repl/src/main/java/org/apache/juddi/adminconsole/StartupServlet.java b/juddiv3-war-repl/src/main/java/org/apache/juddi/adminconsole/StartupServlet.java
index c600522..b3b90ba 100644
--- a/juddiv3-war-repl/src/main/java/org/apache/juddi/adminconsole/StartupServlet.java
+++ b/juddiv3-war-repl/src/main/java/org/apache/juddi/adminconsole/StartupServlet.java
@@ -16,12 +16,12 @@
*/
package org.apache.juddi.adminconsole;
+import javax.servlet.ServletContextEvent;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
-import javax.servlet.ServletContextEvent;
/**
* This startup servlet's job is to generate an encryption key which will be
@@ -31,101 +31,102 @@ import javax.servlet.ServletContextEvent;
*/
public class StartupServlet implements javax.servlet.ServletContextListener {
- static final Logger log = Logger.getLogger(StartupServlet.class.getCanonicalName());
+ static final Logger log = Logger.getLogger(StartupServlet.class.getCanonicalName());
- /**
- * creates a new AES key and stores it to the properties files
- *
- * @param sce
- */
- public void contextInitialized(ServletContextEvent sce) {
- log.info("juddi-admin gui startup");
- FileOutputStream fos = null;
- try {
- //URL resource = sce.getServletContext().getResource("/META-INF/config.properties");
- Properties p = new Properties();
+ /**
+ * creates a new AES key and stores it to the properties files
+ *
+ * @param sce
+ */
+ @Override
+ public void contextInitialized(ServletContextEvent sce) {
+ log.info("juddi-admin gui startup");
+ FileOutputStream fos = null;
+ try {
+ Properties p = new Properties();
+ String key = generateKey();
+ if (key == null) return;
+ p.put("key", key);
+ fos = new FileOutputStream(sce.getServletContext().getRealPath("/WEB-INF/config.properties"));
+ log.log(Level.INFO, "Storing key to " + sce.getServletContext().getRealPath("/WEB-INF/config.properties"));
+ p.store(fos, "No comments");
+ fos.flush();
+ fos.close();
+ } catch (Exception ex) {
+ log.log(Level.WARNING, null, ex);
+ try {
+ if (fos != null) {
+ fos.close();
+ }
+ } catch (Exception e) {
+ }
+ }
+ }
- log.info("Attempting to generate 256 bit AES key");
- boolean ok = false;
- String key = AES.GEN(256);
- if (key == null) {
- ok = false;
- } else {
- if (AES.ValidateKey(key)) {
- log.info("Generation of 256 bit AES key successful");
- ok = true;
- } else {
- log.warning("256 bit key validation failed. To use higher key sizes, try installing the Java Cryptographic Extensions (JCE) Unlimited Strength");
- }
- }
- if (!ok) {
- log.info("Attempting to generate 128 bit AES key");
- key = AES.GEN(128);
- if (key == null) {
- log.log(Level.SEVERE, "128 bit key generation failed! user's won't be able to login!");
- return;
- } else if (AES.ValidateKey(key)) {
- log.info("Generation of 128 bit AES key successful");
- } else {
- log.severe("128 bit key validation failed! giving up, user's won't be able to login! ");
- return;
+ private String generateKey() {
+ String key = generateKey(256);
+ if (key == null) {
+ key = generateKey(128);
+ }
+ if (key == null) {
+ log.severe("128 bit key validation failed! giving up, user's won't be able to login! ");
+ return null;
+ }
+ return key;
+ }
- }
- }
+ private String generateKey(int length) {
+ log.info("Attempting to generate "+length+" bit AES key");
+ String key = AES.GEN(length);
+ if (key != null) {
+ if (AES.ValidateKey(key)) {
+ log.info("Generation of "+length+" bit AES key successful");
+ } else {
+ log.warning(length+" bit key validation failed. To use higher key sizes, try installing the Java Cryptographic Extensions (JCE) Unlimited Strength");
+ return null;
+ }
+ }
+ return key;
+ }
- p.put("key", key);
- fos = new FileOutputStream(sce.getServletContext().getRealPath("/WEB-INF/config.properties"));
+ /**
+ *
+ * @param sce
+ */
+ @Override
+ public void contextDestroyed(ServletContextEvent sce) {
+ removeKeyFromConfigurationFile(sce);
+ }
- log.log(Level.INFO, "Storing key to " + sce.getServletContext().getRealPath("/WEB-INF/config.properties"));
- p.store(fos, "No comments");
- fos.flush();
- fos.close();
- } catch (Exception ex) {
- log.log(Level.WARNING, null, ex);
- try {
- if (fos != null) {
- fos.close();
- }
- } catch (Exception e) {
- }
+ private void removeKeyFromConfigurationFile(ServletContextEvent sce) {
+ FileOutputStream fos = null;
+ try {
+ log.info("Cleaning up juddi-admin");
+ Properties p = new Properties();
+ InputStream is = sce.getServletContext().getResourceAsStream("/WEB-INF/config.properties");
+ p.load(is);
+ p.remove("key");
+ is.close();
+ fos = new FileOutputStream(sce.getServletContext().getRealPath("/WEB-INF/config.properties"));
+ p.store(fos, "No comments");
+ fos.flush();
+ fos.close();
+ } catch (Exception ex) {
+ log.log(Level.WARNING, null, ex);
+ try {
+ if (fos != null) {
+ fos.close();
}
+ } catch (Exception e) {
+ }
}
-
- /**
- * does nothing
- *
- * @param sce
- */
- public void contextDestroyed(ServletContextEvent sce) {
- FileOutputStream fos = null;
- try {
- log.info("Cleaning up juddi-admin");
- Properties p = new Properties();
- InputStream is = sce.getServletContext().getResourceAsStream("/WEB-INF/config.properties");
- p.load(is);
- p.remove("key");
- is.close();
- fos = new FileOutputStream(sce.getServletContext().getRealPath("/WEB-INF/config.properties"));
- p.store(fos, "No comments");
- fos.flush();
- fos.close();
- } catch (Exception ex) {
- log.log(Level.WARNING, null, ex);
- try {
- if (fos != null) {
- fos.close();
- }
- } catch (Exception e) {
- }
- }
- try {
- sce.getServletContext().removeAttribute("username");
- sce.getServletContext().removeAttribute("password");
- sce.getServletContext().removeAttribute("locale");
- sce.getServletContext().removeAttribute("hub");
- } catch (Exception ex) {
- log.log(Level.WARNING, null, ex);
- }
-
+ try {
+ sce.getServletContext().removeAttribute("username");
+ sce.getServletContext().removeAttribute("password");
+ sce.getServletContext().removeAttribute("locale");
+ sce.getServletContext().removeAttribute("hub");
+ } catch (Exception ex) {
+ log.log(Level.WARNING, null, ex);
}
+ }
}
http://git-wip-us.apache.org/repos/asf/juddi/blob/776d9081/juddiv3-war/src/main/java/org/apache/juddi/adminconsole/StartupServlet.java
----------------------------------------------------------------------
diff --git a/juddiv3-war/src/main/java/org/apache/juddi/adminconsole/StartupServlet.java b/juddiv3-war/src/main/java/org/apache/juddi/adminconsole/StartupServlet.java
index 9cbb028..fba35d3 100644
--- a/juddiv3-war/src/main/java/org/apache/juddi/adminconsole/StartupServlet.java
+++ b/juddiv3-war/src/main/java/org/apache/juddi/adminconsole/StartupServlet.java
@@ -1,131 +1,134 @@
-/*
- * Copyright 2001-2008 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.juddi.adminconsole;
+/*
+ * Copyright 2001-2008 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.juddi.adminconsole;
+
+import org.apache.juddi.config.PersistenceManager;
-import java.io.FileOutputStream;
-import java.io.InputStream;
-import java.util.Properties;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import javax.servlet.ServletContextEvent;
-
-/**
- * This startup servlet's job is to generate an encryption key which will be
- * used for encrypting cached user credentials in the http session object
- *
- * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>
- */
-public class StartupServlet implements javax.servlet.ServletContextListener {
-
- static final Logger log = Logger.getLogger(StartupServlet.class.getCanonicalName());
-
- /**
- * creates a new AES key and stores it to the properties files
- *
- * @param sce
- */
- public void contextInitialized(ServletContextEvent sce) {
- log.info("juddi-admin gui startup");
- FileOutputStream fos = null;
- try {
- //URL resource = sce.getServletContext().getResource("/META-INF/config.properties");
- Properties p = new Properties();
-
- log.info("Attempting to generate 256 bit AES key");
- boolean ok = false;
- String key = AES.GEN(256);
- if (key == null) {
- ok = false;
- } else {
- if (AES.ValidateKey(key)) {
- log.info("Generation of 256 bit AES key successful");
- ok = true;
- } else {
- log.warning("256 bit key validation failed. To use higher key sizes, try installing the Java Cryptographic Extensions (JCE) Unlimited Strength");
- }
- }
- if (!ok) {
- log.info("Attempting to generate 128 bit AES key");
- key = AES.GEN(128);
- if (key == null) {
- log.log(Level.SEVERE, "128 bit key generation failed! user's won't be able to login!");
- return;
- } else if (AES.ValidateKey(key)) {
- log.info("Generation of 128 bit AES key successful");
- } else {
- log.severe("128 bit key validation failed! giving up, user's won't be able to login! ");
- return;
-
- }
- }
-
- p.put("key", key);
- fos = new FileOutputStream(sce.getServletContext().getRealPath("/WEB-INF/config.properties"));
-
- log.log(Level.INFO, "Storing key to " + sce.getServletContext().getRealPath("/WEB-INF/config.properties"));
- p.store(fos, "No comments");
- fos.flush();
- fos.close();
- } catch (Exception ex) {
- log.log(Level.WARNING, null, ex);
- try {
- if (fos != null) {
- fos.close();
- }
- } catch (Exception e) {
- }
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * This startup servlet's job is to generate an encryption key which will be
+ * used for encrypting cached user credentials in the http session object
+ *
+ * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>
+ */
+public class StartupServlet implements javax.servlet.ServletContextListener {
+
+ static final Logger log = Logger.getLogger(StartupServlet.class.getCanonicalName());
+
+ /**
+ * creates a new AES key and stores it to the properties files
+ *
+ * @param sce
+ */
+ @Override
+ public void contextInitialized(ServletContextEvent sce) {
+ log.info("juddi-admin gui startup");
+ FileOutputStream fos = null;
+ try {
+ Properties p = new Properties();
+ String key = generateKey();
+ if (key == null) return;
+ p.put("key", key);
+ fos = new FileOutputStream(sce.getServletContext().getRealPath("/WEB-INF/config.properties"));
+ log.log(Level.INFO, "Storing key to " + sce.getServletContext().getRealPath("/WEB-INF/config.properties"));
+ p.store(fos, "No comments");
+ fos.flush();
+ fos.close();
+ } catch (Exception ex) {
+ log.log(Level.WARNING, null, ex);
+ try {
+ if (fos != null) {
+ fos.close();
}
+ } catch (Exception e) {
+ }
}
-
- /**
- * does nothing
- *
- * @param sce
- */
- public void contextDestroyed(ServletContextEvent sce) {
- FileOutputStream fos = null;
- try {
- log.info("Cleaning up juddi-admin");
- Properties p = new Properties();
- InputStream is = sce.getServletContext().getResourceAsStream("/WEB-INF/config.properties");
- p.load(is);
- p.remove("key");
- is.close();
- fos = new FileOutputStream(sce.getServletContext().getRealPath("/WEB-INF/config.properties"));
- p.store(fos, "No comments");
- fos.flush();
- fos.close();
- } catch (Exception ex) {
- log.log(Level.WARNING, null, ex);
- try {
- if (fos != null) {
- fos.close();
- }
- } catch (Exception e) {
- }
- }
- try {
- sce.getServletContext().removeAttribute("username");
- sce.getServletContext().removeAttribute("password");
- sce.getServletContext().removeAttribute("locale");
- sce.getServletContext().removeAttribute("hub");
- } catch (Exception ex) {
- log.log(Level.WARNING, null, ex);
- }
-
+ }
+
+ private String generateKey() {
+ String key = generateKey(256);
+ if (key == null) {
+ key = generateKey(128);
+ }
+ if (key == null) {
+ log.severe("128 bit key validation failed! giving up, user's won't be able to login! ");
+ return null;
+ }
+ return key;
+ }
+
+ private String generateKey(int length) {
+ log.info("Attempting to generate " + length + " bit AES key");
+ String key = AES.GEN(length);
+ if (key != null) {
+ if (AES.ValidateKey(key)) {
+ log.info("Generation of " + length + " bit AES key successful");
+ } else {
+ log.warning(length + " bit key validation failed. To use higher key sizes, try installing the Java Cryptographic Extensions (JCE) Unlimited Strength");
+ return null;
+ }
}
-}
+ return key;
+ }
+
+ /**
+ * @param sce
+ */
+ @Override
+ public void contextDestroyed(ServletContextEvent sce) {
+ removeKeyFromConfigurationFile(sce);
+ PersistenceManager.closeEntityManager();
+ }
+
+ private void removeKeyFromConfigurationFile(ServletContextEvent sce) {
+ FileOutputStream fos = null;
+ try {
+ log.info("Cleaning up juddi-admin");
+ Properties p = new Properties();
+ InputStream is = sce.getServletContext().getResourceAsStream("/WEB-INF/config.properties");
+ p.load(is);
+ p.remove("key");
+ is.close();
+ fos = new FileOutputStream(sce.getServletContext().getRealPath("/WEB-INF/config.properties"));
+ p.store(fos, "No comments");
+ fos.flush();
+ fos.close();
+ } catch (Exception ex) {
+ log.log(Level.WARNING, null, ex);
+ try {
+ if (fos != null) {
+ fos.close();
+ }
+ } catch (Exception e) {
+ }
+ }
+ try {
+ sce.getServletContext().removeAttribute("username");
+ sce.getServletContext().removeAttribute("password");
+ sce.getServletContext().removeAttribute("locale");
+ sce.getServletContext().removeAttribute("hub");
+ } catch (Exception ex) {
+ log.log(Level.WARNING, null, ex);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/juddi/blob/776d9081/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 06b5a18..2b6e01b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -541,6 +541,7 @@ under the License.
<exclude>**/pref-rpt*.txt</exclude>
<exclude>**/asciidoctor.css</exclude>
<exclude>**/Guardfile</exclude>
+ <exclude>**/target/**/*</exclude>
<exclude>**/nb-configuration.xml</exclude>
</excludes>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@juddi.apache.org
For additional commands, e-mail: commits-help@juddi.apache.org