Search in sources :

Example 1 with PrivilegedNewInstanceFromClass

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;
}
Also used : ArchiveFactory(org.eclipse.persistence.jpa.ArchiveFactory) PrivilegedNewInstanceFromClass(org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass) PrivilegedActionException(java.security.PrivilegedActionException) PrivilegedGetSystemProperty(org.eclipse.persistence.internal.security.PrivilegedGetSystemProperty)

Example 2 with PrivilegedNewInstanceFromClass

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.
}
Also used : ExceptionHandler(org.eclipse.persistence.exceptions.ExceptionHandler) DefaultSessionLog(org.eclipse.persistence.logging.DefaultSessionLog) SessionLog(org.eclipse.persistence.logging.SessionLog) PerformanceProfiler(org.eclipse.persistence.tools.profiler.PerformanceProfiler) DatabaseSessionImpl(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl) PrivilegedNewInstanceFromClass(org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass) PrivilegedNewInstanceFromClass(org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass) ValidationException(org.eclipse.persistence.exceptions.ValidationException) PrivilegedActionException(java.security.PrivilegedActionException) SessionLoaderException(org.eclipse.persistence.exceptions.SessionLoaderException)

Example 3 with PrivilegedNewInstanceFromClass

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);
                }
            }
        }
    }
}
Also used : Platform(org.eclipse.persistence.internal.databaseaccess.Platform) DatasourcePlatform(org.eclipse.persistence.internal.databaseaccess.DatasourcePlatform) ServerPlatform(org.eclipse.persistence.platform.server.ServerPlatform) DatabasePlatform(org.eclipse.persistence.internal.databaseaccess.DatabasePlatform) NoServerPlatform(org.eclipse.persistence.platform.server.NoServerPlatform) StructConverter(org.eclipse.persistence.platform.database.converters.StructConverter) PrivilegedNewInstanceFromClass(org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass) PrivilegedActionException(java.security.PrivilegedActionException) PrivilegedNewInstanceFromClass(org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass) DatabasePlatform(org.eclipse.persistence.internal.databaseaccess.DatabasePlatform) ValidationException(org.eclipse.persistence.exceptions.ValidationException) PrivilegedActionException(java.security.PrivilegedActionException) SessionLoaderException(org.eclipse.persistence.exceptions.SessionLoaderException)

Example 4 with PrivilegedNewInstanceFromClass

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;
}
Also used : Project(org.eclipse.persistence.sessions.Project) ValidationException(org.eclipse.persistence.exceptions.ValidationException) PrivilegedNewInstanceFromClass(org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass) PrivilegedNewInstanceFromClass(org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass) ValidationException(org.eclipse.persistence.exceptions.ValidationException) PrivilegedActionException(java.security.PrivilegedActionException) SessionLoaderException(org.eclipse.persistence.exceptions.SessionLoaderException)

Example 5 with PrivilegedNewInstanceFromClass

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);
    }
}
Also used : PrivilegedNewInstanceFromClass(org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass) PrivilegedNewInstanceFromClass(org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass) JMSPublishingTransportManager(org.eclipse.persistence.sessions.coordination.jms.JMSPublishingTransportManager) TransportManager(org.eclipse.persistence.sessions.coordination.TransportManager) JMSTopicTransportManager(org.eclipse.persistence.sessions.coordination.jms.JMSTopicTransportManager) RMITransportManager(org.eclipse.persistence.sessions.coordination.rmi.RMITransportManager) ValidationException(org.eclipse.persistence.exceptions.ValidationException) PrivilegedActionException(java.security.PrivilegedActionException) SessionLoaderException(org.eclipse.persistence.exceptions.SessionLoaderException)

Aggregations

PrivilegedNewInstanceFromClass (org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass)15 PrivilegedActionException (java.security.PrivilegedActionException)10 ValidationException (org.eclipse.persistence.exceptions.ValidationException)9 SessionLoaderException (org.eclipse.persistence.exceptions.SessionLoaderException)6 UnmappedContentHandler (org.eclipse.persistence.internal.oxm.unmapped.UnmappedContentHandler)3 PrivilegedClassForName (org.eclipse.persistence.internal.security.PrivilegedClassForName)3 EclipseLinkException (org.eclipse.persistence.exceptions.EclipseLinkException)2 DatasourcePlatform (org.eclipse.persistence.internal.databaseaccess.DatasourcePlatform)2 XPathFragment (org.eclipse.persistence.internal.oxm.XPathFragment)2 DefaultSequence (org.eclipse.persistence.sequencing.DefaultSequence)2 NativeSequence (org.eclipse.persistence.sequencing.NativeSequence)2 Sequence (org.eclipse.persistence.sequencing.Sequence)2 TableSequence (org.eclipse.persistence.sequencing.TableSequence)2 UnaryTableSequence (org.eclipse.persistence.sequencing.UnaryTableSequence)2 SAXParseException (org.xml.sax.SAXParseException)2 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 NamingException (javax.naming.NamingException)1 QName (javax.xml.namespace.QName)1 Version (org.eclipse.persistence.Version)1