use of org.eclipse.persistence.internal.security.PrivilegedClassForName in project eclipselink by eclipse-ee4j.
the class EntityManagerSetupImpl method addBeanValidationListeners.
/**
* If Bean Validation is enabled, bootstraps Bean Validation on descriptors.
* @param puProperties merged properties for this persistence unit
*/
private void addBeanValidationListeners(Map puProperties, ClassLoader appClassLoader) {
ValidationMode validationMode = getValidationMode(persistenceUnitInfo, puProperties);
if (validationMode == ValidationMode.AUTO || validationMode == ValidationMode.CALLBACK) {
// BeanValidationInitializationHelper contains static reference to jakarta.validation.* classes. We need to support
// environment where these classes are not available.
// To guard against some vms that eagerly resolve, reflectively load class to prevent any static reference to it
String helperClassName = "org.eclipse.persistence.internal.jpa.deployment.BeanValidationInitializationHelper$BeanValidationInitializationHelperImpl";
Class<?> helperClass;
try {
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
try {
helperClass = AccessController.doPrivileged(new PrivilegedClassForName<>(helperClassName, true, appClassLoader));
} catch (Throwable t) {
// Try the ClassLoader that loaded Eclipselink classes
ClassLoader eclipseLinkClassLoader = EntityManagerSetupImpl.class.getClassLoader();
helperClass = AccessController.doPrivileged(new PrivilegedClassForName<>(helperClassName, true, eclipseLinkClassLoader));
}
} else {
try {
helperClass = PrivilegedAccessHelper.getClassForName(helperClassName, true, appClassLoader);
} catch (Throwable t) {
// Try the ClassLoader that loaded Eclipselink classes
ClassLoader eclipseLinkClassLoader = EntityManagerSetupImpl.class.getClassLoader();
helperClass = PrivilegedAccessHelper.getClassForName(helperClassName, true, eclipseLinkClassLoader);
}
}
BeanValidationInitializationHelper beanValidationInitializationHelper = (BeanValidationInitializationHelper) helperClass.getConstructor().newInstance();
beanValidationInitializationHelper.bootstrapBeanValidation(puProperties, session, appClassLoader);
} catch (Throwable e) {
// Catching Throwable to catch any linkage errors on vms that resolve eagerly
if (validationMode == ValidationMode.CALLBACK) {
throw PersistenceUnitLoadingException.exceptionObtainingRequiredBeanValidatorFactory(e);
}
// else validationMode == ValidationMode.AUTO. Log a message, Ignore the exception
this.session.log(SessionLog.FINEST, SessionLog.JPA, "validation_factory_not_initialized", new Object[] { e.getMessage() });
}
}
}
use of org.eclipse.persistence.internal.security.PrivilegedClassForName in project eclipselink by eclipse-ee4j.
the class DBWSBuilder method getConnection.
public Connection getConnection() {
if (conn == null) {
String driverClassName = getDriver();
try {
@SuppressWarnings("unused") Class<?> driverClass = null;
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
driverClass = AccessController.doPrivileged(new PrivilegedClassForName<>(driverClassName));
} else {
driverClass = PrivilegedAccessHelper.getClassForName(driverClassName);
}
Properties props = new Properties();
props.put("user", getUsername());
props.put("password", getPassword());
if (getPlatformClassname().contains("MySQL")) {
props.put("useInformationSchema", "true");
}
conn = DriverManager.getConnection(getUrl(), props);
} catch (Exception e) {
logMessage(SEVERE, "JDBC driver error: " + driverClassName, e);
}
}
return conn;
}
use of org.eclipse.persistence.internal.security.PrivilegedClassForName in project eclipselink by eclipse-ee4j.
the class MissingDescriptorListener method missingDescriptor.
@Override
public void missingDescriptor(SessionEvent event) {
String name = ((Class<?>) event.getResult()).getName();
DatabaseSession session = (DatabaseSession) ((AbstractSession) event.getSession()).getRootSession(null);
Project project = session.getProject();
String namespaceXPath = "";
NamespaceResolverWithPrefixes namespaceResolverWithPrefixes;
if (project instanceof NamespaceResolvableProject) {
// this should always be true
NamespaceResolvableProject nrpProject = (NamespaceResolvableProject) project;
namespaceXPath = nrpProject.getPrimaryNamespaceXPath();
namespaceResolverWithPrefixes = nrpProject.getNamespaceResolver();
} else {
// this shouldn't happen - but if it does, build a new (empty) NamespaceResolverWithPrefixes
namespaceResolverWithPrefixes = new NamespaceResolverWithPrefixes();
}
DirectToXMLTypeMappingHelper.getInstance().addXDBDescriptors(name, (DatabaseSessionImpl) session, namespaceResolverWithPrefixes);
if (name.equals(EIS_DESCRIPTOR_CLASS) || name.equals(XML_INTERACTION_CLASS) || name.equals(EIS_LOGIN_CLASS)) {
try {
Class<?> javaClass;
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
try {
javaClass = AccessController.doPrivileged(new PrivilegedClassForName<>(XML_INTERACTION_CLASS));
} catch (PrivilegedActionException ex) {
if (ex.getCause() instanceof ClassNotFoundException) {
throw (ClassNotFoundException) ex.getCause();
}
throw (RuntimeException) ex.getCause();
}
} else {
javaClass = PrivilegedAccessHelper.getClassForName(XML_INTERACTION_CLASS);
}
session.getDescriptor(Call.class).getInheritancePolicy().addClassIndicator(javaClass, namespaceXPath + "xml-interaction");
} catch (Exception classLoadFailure) {
throw ValidationException.fatalErrorOccurred(classLoadFailure);
}
session.addDescriptors(new EISObjectPersistenceXMLProject(namespaceResolverWithPrefixes));
}
if (name.equals(XML_BINARY_MAPPING_CLASS) || name.equals(XML_BINARY_COLLECTION_MAPPING_CLASS)) {
session.addDescriptors(new OXMObjectPersistenceRuntimeXMLProject(namespaceResolverWithPrefixes));
}
}
use of org.eclipse.persistence.internal.security.PrivilegedClassForName in project eclipselink by eclipse-ee4j.
the class AbstractColumnMapping method convertClassNamesToClasses.
/**
* INTERNAL:
* Convert all the class-name-based settings in this mapping to actual class-based settings
* This method is implemented by subclasses as necessary.
*/
@Override
public void convertClassNamesToClasses(ClassLoader classLoader) {
super.convertClassNamesToClasses(classLoader);
// Field may have a type name that needs to be initialize.
if (field != null) {
field.convertClassNamesToClasses(classLoader);
}
// Convert and any Converter class names.
convertConverterClassNamesToClasses(converter, classLoader);
// Instantiate any custom converter class
if (converterClassName != null) {
Class<?> converterClass;
Converter converter;
try {
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
try {
converterClass = AccessController.doPrivileged(new PrivilegedClassForName<>(converterClassName, true, classLoader));
} catch (PrivilegedActionException exception) {
throw ValidationException.classNotFoundWhileConvertingClassNames(converterClassName, exception.getException());
}
try {
converter = (Converter) AccessController.doPrivileged(new PrivilegedNewInstanceFromClass(converterClass));
} catch (PrivilegedActionException exception) {
throw ValidationException.classNotFoundWhileConvertingClassNames(converterClassName, exception.getException());
}
} else {
converterClass = PrivilegedAccessHelper.getClassForName(converterClassName, true, classLoader);
converter = (Converter) PrivilegedAccessHelper.newInstanceFromClass(converterClass);
}
} catch (ClassNotFoundException exc) {
throw ValidationException.classNotFoundWhileConvertingClassNames(converterClassName, exc);
} catch (Exception e) {
// Catches IllegalAccessException and InstantiationException
throw ValidationException.classNotFoundWhileConvertingClassNames(converterClassName, e);
}
setConverter(converter);
}
}
use of org.eclipse.persistence.internal.security.PrivilegedClassForName in project eclipselink by eclipse-ee4j.
the class DirectCollectionMapping method convertClassNamesToClasses.
/**
* INTERNAL:
* Convert all the class-name-based settings in this mapping to actual class-based
* settings
* This method is implemented by subclasses as necessary.
*/
@Override
public void convertClassNamesToClasses(ClassLoader classLoader) {
super.convertClassNamesToClasses(classLoader);
// Tell the direct field to convert any class names (type name).
directField.convertClassNamesToClasses(classLoader);
// Convert and any Converter class names.
convertConverterClassNamesToClasses(valueConverter, classLoader);
// Instantiate any custom converter class
if (valueConverterClassName != null) {
Class<?> valueConverterClass;
Converter valueConverter;
try {
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
try {
valueConverterClass = AccessController.doPrivileged(new PrivilegedClassForName<>(valueConverterClassName, true, classLoader));
} catch (PrivilegedActionException exception) {
throw ValidationException.classNotFoundWhileConvertingClassNames(valueConverterClassName, exception.getException());
}
try {
valueConverter = (Converter) AccessController.doPrivileged(new PrivilegedNewInstanceFromClass<>(valueConverterClass));
} catch (PrivilegedActionException exception) {
throw ValidationException.classNotFoundWhileConvertingClassNames(valueConverterClassName, exception.getException());
}
} else {
valueConverterClass = PrivilegedAccessHelper.getClassForName(valueConverterClassName, true, classLoader);
valueConverter = (Converter) PrivilegedAccessHelper.newInstanceFromClass(valueConverterClass);
}
} catch (ClassNotFoundException exc) {
throw ValidationException.classNotFoundWhileConvertingClassNames(valueConverterClassName, exc);
} catch (Exception e) {
// Catches IllegalAccessException and InstantiationException
throw ValidationException.classNotFoundWhileConvertingClassNames(valueConverterClassName, e);
}
setValueConverter(valueConverter);
}
// Check if the attribute classification is set (either directly or through a type conversion converter)
if (attributeClassification == null) {
// Look for an attribute classification name
if (attributeClassificationName != null) {
try {
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
try {
attributeClassification = AccessController.doPrivileged(new PrivilegedClassForName<>(attributeClassificationName, true, classLoader));
} catch (PrivilegedActionException pae) {
throw ValidationException.classNotFoundWhileConvertingClassNames(attributeClassificationName, pae.getException());
}
} else {
attributeClassification = PrivilegedAccessHelper.getClassForName(attributeClassificationName, true, classLoader);
}
} catch (Exception exception) {
throw ValidationException.classNotFoundWhileConvertingClassNames(attributeClassificationName, exception);
}
} else {
// Still nothing, default to the type from the direct field.
attributeClassification = getDirectField().getType();
}
}
}
Aggregations