use of org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass in project eclipselink by eclipse-ee4j.
the class PersistenceUnitProcessor method getArchiveFactory.
public static ArchiveFactory getArchiveFactory(ClassLoader loader, Map properties) {
if (ARCHIVE_FACTORY != null) {
return ARCHIVE_FACTORY;
}
ArchiveFactory factory = null;
String factoryClassName = PrivilegedAccessHelper.shouldUsePrivilegedAccess() ? AccessController.doPrivileged(new PrivilegedGetSystemProperty(SystemProperties.ARCHIVE_FACTORY)) : System.getProperty(SystemProperties.ARCHIVE_FACTORY);
if (factoryClassName == null && properties != null) {
Object name = properties.get(SystemProperties.ARCHIVE_FACTORY);
if (name instanceof String) {
factoryClassName = (String) name;
}
}
if (factoryClassName == null) {
return new ArchiveFactoryImpl();
} else {
try {
if (loader != null) {
Class<?> archiveClass = loader.loadClass(factoryClassName);
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
try {
factory = (ArchiveFactory) AccessController.doPrivileged(new PrivilegedNewInstanceFromClass(archiveClass));
} catch (PrivilegedActionException exception) {
throw PersistenceUnitLoadingException.exceptionCreatingArchiveFactory(factoryClassName, exception);
}
} else {
factory = (ArchiveFactory) PrivilegedAccessHelper.newInstanceFromClass(archiveClass);
}
}
} catch (ClassNotFoundException cnfe) {
throw PersistenceUnitLoadingException.exceptionCreatingArchiveFactory(factoryClassName, cnfe);
} catch (IllegalAccessException iae) {
throw PersistenceUnitLoadingException.exceptionCreatingArchiveFactory(factoryClassName, iae);
} catch (InstantiationException ie) {
throw PersistenceUnitLoadingException.exceptionCreatingArchiveFactory(factoryClassName, ie);
}
}
return factory;
}
use of org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass in project eclipselink by eclipse-ee4j.
the class SessionsFactory method processSessionConfig.
/**
* INTERNAL:
* Process the common elements from a SessionConfig.
*/
protected void processSessionConfig(SessionConfig sessionConfig, AbstractSession session) {
// Name
session.setName(sessionConfig.getName().trim());
// Session Event Manager
processSessionEventManagerConfig(sessionConfig.getSessionEventManagerConfig(), session);
// server platform
((DatabaseSessionImpl) session).setServerPlatform(buildServerPlatformConfig(sessionConfig.getServerPlatformConfig(), (DatabaseSessionImpl) session));
// Session Log - BUG# 3442865, don't set the log if it is null
SessionLog log = buildSessionLog(sessionConfig.getLogConfig(), session);
if (log != null) {
session.setSessionLog(log);
}
// Remote command manager
buildRemoteCommandManagerConfig(sessionConfig.getRemoteCommandManagerConfig(), session);
// Profiler - XML Schema default is null
if (sessionConfig.getProfiler() != null) {
if (sessionConfig.getProfiler().equals("eclipselink")) {
session.setProfiler(new PerformanceProfiler());
}
}
// Exception handler
String exceptionHandlerClassName = sessionConfig.getExceptionHandlerClass();
if (exceptionHandlerClassName != null) {
try {
@SuppressWarnings({ "unchecked" }) Class<ExceptionHandler> exceptionHandlerClass = (Class<ExceptionHandler>) m_classLoader.loadClass(exceptionHandlerClassName);
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
session.setExceptionHandler(AccessController.doPrivileged(new PrivilegedNewInstanceFromClass<>(exceptionHandlerClass)));
} else {
session.setExceptionHandler(PrivilegedAccessHelper.newInstanceFromClass(exceptionHandlerClass));
}
} catch (Exception e) {
throw SessionLoaderException.failedToLoadTag("exception-handler-class", exceptionHandlerClassName, e);
}
}
// Session customizer will be processed in the buildSessions method.
// Ensures it is run last.
}
use of org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass in project eclipselink by eclipse-ee4j.
the class SessionsFactory method processStructConverterConfig.
/**
* INTERNAL:
*/
@SuppressWarnings({ "unchecked" })
protected void processStructConverterConfig(StructConverterConfig converterClassConfig, DatabaseLogin login) {
if (converterClassConfig != null) {
Platform platform = login.getDatasourcePlatform();
if (platform instanceof DatabasePlatform) {
Iterator<String> i = converterClassConfig.getStructConverterClasses().iterator();
while (i.hasNext()) {
String converterClassName = i.next();
try {
Class<StructConverter> converterClass = (Class<StructConverter>) m_classLoader.loadClass(converterClassName);
StructConverter converter = null;
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
try {
converter = AccessController.doPrivileged(new PrivilegedNewInstanceFromClass<>(converterClass));
} catch (PrivilegedActionException ex) {
throw (Exception) ex.getCause();
}
} else {
converter = PrivilegedAccessHelper.newInstanceFromClass(converterClass);
}
((DatabasePlatform) platform).addStructConverter(converter);
} catch (Exception exception) {
throw SessionLoaderException.failedToLoadTag("struct-converter", converterClassName, exception);
}
}
}
}
}
use of org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass in project eclipselink by eclipse-ee4j.
the class SessionsFactory method loadProjectConfig.
/**
* INTERNAL:
* Load a projectConfig from the session.xml file. This method will determine
* the proper loading scheme, that is, for a class or xml project.
*/
@SuppressWarnings({ "unchecked" })
protected Project loadProjectConfig(ProjectConfig projectConfig) {
Project project = null;
String projectString = projectConfig.getProjectString().trim();
if (projectConfig.isProjectClassConfig()) {
try {
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
project = AccessController.doPrivileged(new PrivilegedNewInstanceFromClass<>((Class<Project>) m_classLoader.loadClass(projectString)));
} else {
project = PrivilegedAccessHelper.newInstanceFromClass((Class<Project>) m_classLoader.loadClass(projectString));
}
} catch (Exception exception) {
throw SessionLoaderException.failedToLoadProjectClass(projectString, exception);
}
} else {
try {
project = XMLProjectReader.read(projectString, m_classLoader);
} catch (ValidationException validationException) {
if (validationException.getErrorCode() == ValidationException.PROJECT_XML_NOT_FOUND) {
try {
project = XMLProjectReader.read(projectString);
} catch (Exception e) {
throw SessionLoaderException.failedToLoadProjectXml(projectString, validationException);
}
} else {
throw SessionLoaderException.failedToLoadProjectXml(projectString, validationException);
}
}
}
return project;
}
use of org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass in project eclipselink by eclipse-ee4j.
the class SessionsFactory method buildUserDefinedTransportManagerConfig.
/**
* INTERNAL:
*/
protected void buildUserDefinedTransportManagerConfig(UserDefinedTransportManagerConfig tmConfig, RemoteCommandManager rcm) {
TransportManager tm = null;
// Transport class
String transportManagerClassName = tmConfig.getTransportClass();
if (transportManagerClassName != null) {
try {
@SuppressWarnings({ "unchecked" }) Class<TransportManager> transportManagerClass = (Class<TransportManager>) m_classLoader.loadClass(transportManagerClassName);
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
tm = AccessController.doPrivileged(new PrivilegedNewInstanceFromClass<>(transportManagerClass));
} else {
tm = PrivilegedAccessHelper.newInstanceFromClass(transportManagerClass);
}
} catch (Exception exception) {
throw SessionLoaderException.failedToLoadTag("transport-class", transportManagerClassName, exception);
}
// Set the transport manager. This will initialize the DiscoveryManager
rcm.setTransportManager(tm);
// Process the common elements in TransportManagerConfig
processTransportManagerConfig(tmConfig, tm);
}
}
Aggregations