Author: sdumitriu
Date: 2008-01-07 13:02:24 +0100 (Mon, 07 Jan 2008)
New Revision: 6638

Modified:
   xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java
   
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/XWikiHibernateBaseStore.java
Log:
XWIKI-348: XWiki does not work with java security on
Fix some code causing exceptions when running under -security


Modified: 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java
===================================================================
--- xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java 
2008-01-07 11:49:58 UTC (rev 6637)
+++ xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java 
2008-01-07 12:02:24 UTC (rev 6638)
@@ -272,18 +272,17 @@
 
         // First try loading from a file.
         File f = new File(configurationLocation);
-        if (f.exists()) {
-            try {
+        try {
+            if (f.exists()) {
                 xwikicfgis = new FileInputStream(f);
-            } catch (Exception e) {
-                // Error loading the file. Most likely, the Security Manager 
prevented it.
-                // We'll try loading it as a resource below.
-                LOG.debug("Failed to load the file [" + configurationLocation 
+ "] using direct "
-                    + "file access. The error was [" + e.getMessage() + "]. 
Trying to load it "
-                    + "as a resource using the Servlet Context...");
             }
+        } catch (Exception e) {
+            // Error loading the file. Most likely, the Security Manager 
prevented it.
+            // We'll try loading it as a resource below.
+            LOG.debug("Failed to load the file [" + configurationLocation + "] 
using direct "
+                + "file access. The error was [" + e.getMessage() + "]. Trying 
to load it "
+                + "as a resource using the Servlet Context...");
         }
-
         // Second, try loading it as a resource using the Servlet Context
         if (xwikicfgis == null) {
             xwikicfgis = econtext.getResourceAsStream(configurationLocation);
@@ -874,16 +873,21 @@
 
     public boolean resourceExists(String name)
     {
-        InputStream ris = null;
         if (getEngineContext() != null) {
             try {
-                if (getResourceAsStream(name) != null)
+                if (getResourceAsStream(name) != null) {
                     return true;
+                }
             } catch (IOException e) {
             }
         }
-        File file = new File(name);
-        return file.exists();
+        try {
+            File file = new File(name);
+            return file.exists();
+        } catch (Exception e) {
+            // Could be running under -security, which prevents calling 
file.exists().
+        }
+        return false;
     }
 
     public XWikiConfig getConfig()
@@ -5453,8 +5457,9 @@
         String pageName = clearName(name, context);
         if (exists(space + "." + pageName, context)) {
             int i = 0;
-            while (exists(space + "." + pageName + "_" + i, context))
+            while (exists(space + "." + pageName + "_" + i, context)) {
                 i++;
+            }
             return pageName + "_" + i;
         }
         return pageName;

Modified: 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/XWikiHibernateBaseStore.java
===================================================================
--- 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/XWikiHibernateBaseStore.java
 2008-01-07 11:49:58 UTC (rev 6637)
+++ 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/XWikiHibernateBaseStore.java
 2008-01-07 12:02:24 UTC (rev 6638)
@@ -62,17 +62,25 @@
      */
     public XWikiHibernateBaseStore(XWiki xwiki, XWikiContext context)
     {
-        String path = xwiki.Param("xwiki.store.hibernate.path", 
"hibernate.cfg.xml");
-        if ((path != null) && ((new File(path).exists() || 
context.getEngineContext() == null))) {
-            setPath(path);
-        } else {
+        String path = xwiki.Param("xwiki.store.hibernate.path", 
"/WEB-INF/hibernate.cfg.xml");
+        log.debug("Hibernate configuration file: [" + path + "]");
+        try {
+            if ((path != null) && ((new File(path).exists() || 
context.getEngineContext() == null))) {
+                setPath(path);
+                return;
+            }
+        } catch (Exception ex) {
+            // Probably running under -security, which prevents calling 
File.exists()
+            log.info("Failed setting the Hibernate configuration path using a 
path string");
+        }
+        try {
+            setHibUrl(context.getEngineContext().getResource(path));
+        } catch (Exception ex) {
+            log.info("Failed setting the Hibernate configuration path using 
getResource");
             try {
-                setHibUrl(context.getEngineContext().getResource(path));
-            } catch (Exception e) {
-                try {
-                    setHibUrl(XWiki.class.getClassLoader().getResource(path));
-                } catch (Exception e2) {
-                }
+                setHibUrl(XWiki.class.getClassLoader().getResource(path));
+            } catch (Exception ex2) {
+                log.error("Failed setting the Hibernate configuration file 
with any method, storage cannot be configured", ex2);
             }
         }
     }

_______________________________________________
notifications mailing list
notifications@xwiki.org
http://lists.xwiki.org/mailman/listinfo/notifications

Reply via email to