Skip to content

Commit

Permalink
HV-912 Adding doPrivileged() block around ClassLoader#loadResource() …
Browse files Browse the repository at this point in the history
…call
  • Loading branch information
gunnarmorling authored and hferentschik committed Jul 24, 2014
1 parent 7796507 commit e59d080
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ public ConstrainedMethod(

this.parameterMetaData = Collections.unmodifiableList( parameterMetaData );
this.hasParameterConstraints = hasParameterConstraints( parameterMetaData );

if ( isConstrained() ) {
run( SetAccessibility.action( method ) );
}
}

private boolean hasParameterConstraints(List<ConstrainedParameter> parameterMetaData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,38 +134,6 @@ private SortedSet<String> getRegisteredMethodsInAlphabeticalOrder() {
return result;
}

private boolean areEqual(Object o1, Object o2) {
return
!o1.getClass().isArray() ? o1.equals( o2 ) :
o1.getClass() == boolean[].class ? Arrays.equals( (boolean[]) o1, (boolean[]) o2 ) :
o1.getClass() == byte[].class ? Arrays.equals( (byte[]) o1, (byte[]) o2 ) :
o1.getClass() == char[].class ? Arrays.equals( (char[]) o1, (char[]) o2 ) :
o1.getClass() == double[].class ? Arrays.equals(
(double[]) o1,
(double[]) o2
) :
o1.getClass() == float[].class ? Arrays.equals(
(float[]) o1,
(float[]) o2
) :
o1.getClass() == int[].class ? Arrays.equals(
(int[]) o1,
(int[]) o2
) :
o1.getClass() == long[].class ? Arrays.equals(
(long[]) o1,
(long[]) o2
) :
o1.getClass() == short[].class ? Arrays.equals(
(short[]) o1,
(short[]) o2
) :
Arrays.equals(
(Object[]) o1,
(Object[]) o2
);
}

/**
* Runs the given privileged action, using a privileged block if required.
* <p>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* 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.hibernate.validator.internal.util.privilegedactions;

import java.net.URL;
import java.security.PrivilegedAction;

/**
* Loads the given resource.
*
* @author Gunnar Morling
*/
public final class GetResource implements PrivilegedAction<URL> {

private final String resourceName;
private final ClassLoader classLoader;

public static GetResource action(ClassLoader classLoader, String resourceName) {
return new GetResource( classLoader, resourceName );
}

private GetResource(ClassLoader classLoader, String resourceName) {
this.classLoader = classLoader;
this.resourceName = resourceName;
}

@Override
public URL run() {
return classLoader.getResource( resourceName );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.hibernate.validator.internal.util.logging.Log;
import org.hibernate.validator.internal.util.logging.LoggerFactory;
import org.hibernate.validator.internal.util.privilegedactions.GetClassLoader;
import org.hibernate.validator.internal.util.privilegedactions.GetResource;
import org.hibernate.validator.internal.util.privilegedactions.LoadClass;
import org.hibernate.validator.internal.util.privilegedactions.NewInstance;

Expand Down Expand Up @@ -246,7 +247,7 @@ private InputStream getInputStreamForPath(String path) {

private Schema getValidationConfigurationSchema() {
ClassLoader loader = run( GetClassLoader.fromClass( ValidationXmlParser.class ) );
URL schemaUrl = loader.getResource( VALIDATION_CONFIGURATION_XSD );
URL schemaUrl = run( GetResource.action( loader, VALIDATION_CONFIGURATION_XSD ) );
SchemaFactory sf = SchemaFactory.newInstance( javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI );
Schema schema = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import org.hibernate.validator.internal.util.privilegedactions.GetDeclaredField;
import org.hibernate.validator.internal.util.privilegedactions.GetMethod;
import org.hibernate.validator.internal.util.privilegedactions.GetMethodFromPropertyName;
import org.hibernate.validator.internal.util.privilegedactions.GetResource;
import org.hibernate.validator.internal.util.privilegedactions.LoadClass;

import static org.hibernate.validator.internal.util.CollectionHelper.newArrayList;
Expand Down Expand Up @@ -602,7 +603,7 @@ private boolean isQualifiedClass(String clazz) {

private Schema getMappingSchema() {
ClassLoader loader = run( GetClassLoader.fromClass( XmlMappingParser.class ) );
URL schemaUrl = loader.getResource( VALIDATION_MAPPING_XSD );
URL schemaUrl = run( GetResource.action( loader, VALIDATION_MAPPING_XSD ) );
SchemaFactory sf = SchemaFactory.newInstance( javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI );
Schema schema = null;
try {
Expand Down

0 comments on commit e59d080

Please sign in to comment.