Browse Source

fix lib version mismatch and restrict java policy as much as possible

Pi 2 years ago
parent
commit
86cd7e8fe2
4 changed files with 57 additions and 15 deletions
  1. 36 6
      pljava.policy
  2. 2 2
      pom.xml
  3. 10 7
      src/main/java/PlJavaJSword.java
  4. 9 0
      src/test/java/TestPlJavaJSword.java

+ 36 - 6
pljava.policy

@@ -94,9 +94,44 @@ grant codebase "${org.postgresql.pljava.codesource}" {
 // code, or to its specific jar, etc.).
 //
 grant principal org.postgresql.pljava.PLPrincipal$Sandboxed * {
-        //permission java.security.AllPermission;
 	permission java.lang.RuntimePermission
 		"createClassLoader";
+        permission java.lang.RuntimePermission
+                "getClassLoader";
+        permission java.util.PropertyPermission
+        	"user.home", "read";
+        permission java.util.PropertyPermission
+        	"sword.home", "read";
+        permission java.util.PropertyPermission
+        	"jsword.home", "read";
+	permission java.io.FilePermission
+		"/usr/share/sword", "read";
+	permission java.io.FilePermission
+		"/usr/share/sword/-", "read";
+	permission java.io.FilePermission
+		"/usr/share/sword/mods.d", "read,write";
+	permission java.io.FilePermission
+		"/usr/share/sword/mods.d/*", "read,write";
+	permission java.io.FilePermission
+		"/var/lib/postgresql", "read";
+	permission java.io.FilePermission
+		"/var/lib/postgresql/.jsword", "read";
+	permission java.io.FilePermission
+		"/var/lib/postgresql/.jsword/-", "read";
+	permission java.io.FilePermission
+		"/var/lib/postgresql/.sword/-", "read";
+	permission java.io.FilePermission
+		"./sword.conf", "read";
+	permission java.io.FilePermission
+		"./mods.d", "read";
+	permission java.io.FilePermission
+		"../library/mods.d", "read";
+	permission java.io.FilePermission
+		"/etc/sword.conf", "read";
+	permission java.io.FilePermission
+		"/usr/local/etc/sword.conf", "read";
+	//permission java.io.FilePermission
+	//	"<<ALL FILES>>", "read";
 };
 
 
@@ -108,9 +143,6 @@ grant principal org.postgresql.pljava.PLPrincipal$Sandboxed * {
 // to its specific jar, etc.).
 //
 grant principal org.postgresql.pljava.PLPrincipal$Unsandboxed * {
-        //permission java.security.AllPermission;
-	//permission java.lang.RuntimePermission
-	//	"createClassLoader";
 	// Java does not circumvent operating system access controls; this grant
 	// will still be limited to what the OS allows a PostgreSQL backend process
 	// to do.
@@ -129,7 +161,5 @@ grant principal org.postgresql.pljava.PLPrincipal$Unsandboxed * {
 // and DROP LANGUAGE to remove it when undeployed.
 //
 grant principal org.postgresql.pljava.PLPrincipal$Sandboxed "java_tzset" {
-	//permission java.lang.RuntimePermission
-	//	"createClassLoader";
 	permission java.util.PropertyPermission "user.timezone", "write";
 };

+ 2 - 2
pom.xml

@@ -49,9 +49,9 @@
     <dependency>
       <groupId>org.crosswire</groupId>
       <artifactId>jsword</artifactId>
-      <version>2.0-beta</version>
+      <version>2.1-SNAPSHOT</version>
       <scope>system</scope>
-      <systemPath>${pom.basedir}/lib/jsword-2.0-beta.jar</systemPath>
+      <systemPath>${pom.basedir}/lib/jsword-2.1-SNAPSHOT.jar</systemPath>
     </dependency>
     <dependency>
       <groupId>org.junit.jupiter</groupId>

+ 10 - 7
src/main/java/PlJavaJSword.java

@@ -6,7 +6,6 @@ import java.util.Iterator;
 import org.crosswire.jsword.passage.VerseRangeFactory;
 import org.crosswire.jsword.versification.system.SystemDefault;
 import org.crosswire.jsword.versification.BibleBook;
-import org.crosswire.jsword.versification.BibleNames;
 import org.crosswire.jsword.passage.NoSuchVerseException;
 import org.crosswire.jsword.versification.Versification;
 import org.crosswire.jsword.versification.system.Versifications;
@@ -53,10 +52,12 @@ public class PlJavaJSword {
     try {
         Key key = book.getKey(reference);
         String ret = "";
-        for (Iterator<Content> i = book.getOsisIterator(key, false, false); i.hasNext();){
-            ret = ret + i.next().getValue();
+	Iterator<Content> i = book.getOsisIterator(key, false);
+	i.next();
+        while (i.hasNext()){
+            ret = ret + " " + i.next().getValue().trim();
         }
-        return ret;
+        return ret.trim();
     } catch (NoSuchKeyException ex){
         return null;
     }
@@ -70,10 +71,12 @@ public class PlJavaJSword {
     try {
         Key key = book.getKey(reference);
         String ret = "";
-        for (Iterator<Content> i = book.getOsisIterator(key, false, false); i.hasNext();){
-            ret = ret + i.next().getValue();
+	Iterator<Content> i = book.getOsisIterator(key, false);
+	i.next();
+        while (i.hasNext()){
+            ret = ret + " " + i.next().getValue().trim();
         }
-        return ret;
+        return ret.trim();
     } catch (NoSuchKeyException ex){
         return null;
     }

+ 9 - 0
src/test/java/TestPlJavaJSword.java

@@ -5,6 +5,7 @@ import org.junit.jupiter.api.Test;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 public class TestPlJavaJSword {
+  private static final String GEN_1_1_3 = "In the beginning God created the heaven and the earth. And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters. And God said, Let there be light: and there was light.";
   @Test
   public void testIsValidVerseValidVerse(){
     assertEquals(true, PlJavaJSword.isValidVerse("Gen 1:1"));
@@ -18,7 +19,15 @@ public class TestPlJavaJSword {
     assertEquals("In the beginning God created the heaven and the earth.", PlJavaJSword.getText("KJV", "Genesis 1:1"));
   }
   @Test
+  public void testTextMany() throws BookException {
+    assertEquals(GEN_1_1_3, PlJavaJSword.getText("KJV", "Genesis 1:1-3"));
+  }
+  @Test
   public void testDefaultText() throws BookException {
     assertEquals("In the beginning God created the heaven and the earth.", PlJavaJSword.getDefaultText("Genesis 1:1"));
   }
+  @Test
+  public void testDefaultTextMany() throws BookException {
+    assertEquals(GEN_1_1_3, PlJavaJSword.getDefaultText("Genesis 1:1-3"));
+  }
 }