openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From allee8...@apache.org
Subject svn commit: r799013 - in /openjpa/trunk: openjpa-lib/pom.xml openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java openjpa-persistence/src/main/java/org/apache/openjpa/persistence/validation/ValidatorImpl.java
Date Wed, 29 Jul 2009 18:58:01 GMT
Author: allee8285
Date: Wed Jul 29 18:58:00 2009
New Revision: 799013

URL: http://svn.apache.org/viewvc?rev=799013&view=rev
Log:
OENJPA-1206 - Enable Java 2 security on BV validate call.

Modified:
    openjpa/trunk/openjpa-lib/pom.xml
    openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/validation/ValidatorImpl.java

Modified: openjpa/trunk/openjpa-lib/pom.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/pom.xml?rev=799013&r1=799012&r2=799013&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/pom.xml (original)
+++ openjpa/trunk/openjpa-lib/pom.xml Wed Jul 29 18:58:00 2009
@@ -65,6 +65,11 @@
             <groupId>net.sourceforge.serp</groupId>
             <artifactId>serp</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-validation_1.0_spec</artifactId>
+            <scope>provided</scope>
+        </dependency>        
     </dependencies>
     <build>
         <plugins>

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java?rev=799013&r1=799012&r2=799013&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java
(original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java
Wed Jul 29 18:58:00 2009
@@ -42,8 +42,12 @@
 import java.security.PrivilegedExceptionAction;
 import java.util.Enumeration;
 import java.util.Properties;
+import java.util.Set;
 import java.util.zip.ZipFile;
 
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+
 import serp.bytecode.BCClass;
 import serp.bytecode.BCClassLoader;
 import serp.bytecode.BCField;
@@ -106,6 +110,7 @@
  * <li>AnnotatedElement.getAnnotations
  * <li>AnnotatedElement.getDeclaredAnnotations
  * <li>AnnotatedElement.isAnnotationPresent
+ * <li>javax.validationValidator.validate
  * </ul>
  * 
  * If these methods are used, the following sample usage patterns should be
@@ -1178,4 +1183,18 @@
             }
         };
     }
+    
+    /**
+     * Return a PrivilegeAction object for javax.validationValidator.validate().
+     * 
+     * Requires security policy: 'permission java.lang.RuntimePermission "*";'
+     */
+    public static final <T> PrivilegedAction<Set<ConstraintViolation<T>>>
validateAction(
+        final Validator validator, final T arg0, final Class<?>[] groups) {
+        return new PrivilegedAction<Set<ConstraintViolation<T>>>() {
+            public Set<ConstraintViolation<T>> run() {
+                return validator.validate(arg0, groups);
+            }
+        };
+    }
 }

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/validation/ValidatorImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/validation/ValidatorImpl.java?rev=799013&r1=799012&r2=799013&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/validation/ValidatorImpl.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/validation/ValidatorImpl.java
Wed Jul 29 18:58:00 2009
@@ -18,6 +18,7 @@
  */
 package org.apache.openjpa.persistence.validation;
 
+import java.security.AccessController;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
@@ -33,6 +34,7 @@
 import org.apache.openjpa.conf.OpenJPAConfiguration;
 import org.apache.openjpa.event.LifecycleEvent;
 import org.apache.openjpa.lib.conf.Configuration;
+import org.apache.openjpa.lib.util.J2DoPrivHelper;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.validation.AbstractValidator;
 import org.apache.openjpa.validation.ValidationException;
@@ -286,8 +288,9 @@
     public <T> ValidationException validate(T arg0, int event) { 
         if (!isValidating(event))
             return null;
-        Set<ConstraintViolation<T>> violations = 
-            _validator.validate(arg0, getValidationGroup(event));
+        Set<ConstraintViolation<T>> violations = AccessController.doPrivileged(
+                J2DoPrivHelper.validateAction(_validator, arg0, getValidationGroup(event)));
+
         if (violations != null && violations.size() > 0) {
             return new ValidationException(
                 new ConstraintViolationException(



Mime
View raw message