Search in sources :

Example 1 with SetPermissionsAction

use of com.sun.enterprise.security.permissionsxml.SetPermissionsAction in project Payara by payara.

the class EjbJarHandler method getClassLoader.

public ClassLoader getClassLoader(final ClassLoader parent, DeploymentContext context) {
    ASURLClassLoader cloader = AccessController.doPrivileged(new PrivilegedAction<ASURLClassLoader>() {

        @Override
        public ASURLClassLoader run() {
            return new ASURLClassLoader(parent);
        }
    });
    try {
        String compatProp = context.getAppProps().getProperty(COMPATIBILITY);
        // let's see if it's defined in glassfish-ejb-jar.xml
        if (compatProp == null) {
            compatProp = new GFEjbJarXMLParser(context.getSource()).getCompatibilityValue();
            if (compatProp != null) {
                context.getAppProps().put(COMPATIBILITY, compatProp);
            }
        }
        // let's see if it's defined in sun-ejb-jar.xml
        if (compatProp == null) {
            compatProp = new SunEjbJarXMLParser(context.getSourceDir()).getCompatibilityValue();
            if (compatProp != null) {
                context.getAppProps().put(DeploymentProperties.COMPATIBILITY, compatProp);
            }
        }
        // compatibility of v2 jar visibility
        if (compatProp != null && compatProp.equals("v2")) {
            List<URL> moduleRootLibraries = ASClassLoaderUtil.getURLsAsList(null, new File[] { context.getSourceDir() }, true);
            for (URL url : moduleRootLibraries) {
                cloader.addURL(url);
            }
        }
        cloader.addURL(context.getSource().getURI().toURL());
        cloader.addURL(context.getScratchDir("ejb").toURI().toURL());
        // Add libraries referenced from manifest
        for (URL url : getManifestLibraries(context)) {
            cloader.addURL(url);
        }
        try {
            doPrivileged(new SetPermissionsAction(CommponentType.ejb, context, cloader));
        } catch (PrivilegedActionException e) {
            throw new SecurityException(e.getException());
        }
    } catch (Exception e) {
        _logger.severe(e.getMessage());
        throw new RuntimeException(e);
    }
    return cloader;
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) URL(java.net.URL) XMLStreamException(javax.xml.stream.XMLStreamException) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ASURLClassLoader(com.sun.enterprise.loader.ASURLClassLoader) SetPermissionsAction(com.sun.enterprise.security.permissionsxml.SetPermissionsAction)

Example 2 with SetPermissionsAction

use of com.sun.enterprise.security.permissionsxml.SetPermissionsAction in project Payara by payara.

the class RarHandler method getClassLoader.

/**
 * {@inheritDoc}
 */
public ClassLoader getClassLoader(ClassLoader parent, DeploymentContext context) {
    try {
        String moduleDir = context.getSource().getURI().getPath();
        String moduleName = context.getSource().getName();
        List<URI> appLibs = null;
        try {
            appLibs = context.getAppLibs();
            if (_logger.isLoggable(Level.FINEST)) {
                _logger.log(Level.FINEST, "installed libraries (--applibs and EXTENSTION_LIST) for rar " + "[ " + moduleName + " ] :  " + appLibs);
            }
        } catch (URISyntaxException e) {
            throw new RuntimeException(e);
        }
        ClassLoader carCL;
        if (isEmbedded(context)) {
            String applicationName = ConnectorsUtil.getApplicationName(context);
            String embeddedRarName = ConnectorsUtil.getEmbeddedRarModuleName(applicationName, moduleName);
            // ear's classloader hierarchy is : module-CL -> ear-CL (contains all ejb module classpath)
            // -> embedded-RAR-CL -> ear-lib-CL.
            // parent provided here is ear-CL, we need to use
            // ear-lib-CL as parent for embedded-RAR module-CL
            carCL = loader.createRARClassLoader(moduleDir, parent.getParent().getParent(), embeddedRarName, appLibs);
        } else {
            carCL = loader.createRARClassLoader(moduleDir, null, moduleName, appLibs);
        }
        try {
            doPrivileged(new SetPermissionsAction(CommponentType.rar, context, carCL));
        } catch (PrivilegedActionException e) {
            throw new SecurityException(e.getException());
        }
        return carCL;
    } catch (ConnectorRuntimeException e) {
        throw new RuntimeException(e);
    }
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) PrivilegedActionException(java.security.PrivilegedActionException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) SetPermissionsAction(com.sun.enterprise.security.permissionsxml.SetPermissionsAction)

Example 3 with SetPermissionsAction

use of com.sun.enterprise.security.permissionsxml.SetPermissionsAction in project Payara by payara.

the class WarHandler method getClassLoader.

@Override
public ClassLoader getClassLoader(final ClassLoader parent, final DeploymentContext context) {
    Application applicationTemp = context.getModuleMetaData(Application.class);
    boolean hotDeploy = context.getCommandParameters(DeployCommandParameters.class).hotDeploy;
    final Application application = applicationTemp == null ? Application.createApplication() : applicationTemp;
    WebappClassLoader cloader = AccessController.doPrivileged(new PrivilegedAction<WebappClassLoader>() {

        @Override
        public WebappClassLoader run() {
            return new WebappClassLoader(parent, application, hotDeploy);
        }
    });
    try {
        WebDirContext r = new WebDirContext();
        File base = new File(context.getSource().getURI());
        r.setDocBase(base.getAbsolutePath());
        cloader.setResources(r);
        cloader.addRepository("WEB-INF/classes/", new File(base, "WEB-INF/classes/"));
        if (context.getScratchDir("ejb") != null) {
            cloader.addRepository(context.getScratchDir("ejb").toURI().toURL().toString().concat("/"));
        }
        if (context.getScratchDir("jsp") != null) {
            cloader.setWorkDir(context.getScratchDir("jsp"));
        }
        // add libraries referenced from manifest
        for (URL url : getManifestLibraries(context)) {
            cloader.addRepository(url.toString());
        }
        WebXmlParser webXmlParser = getWebXmlParser(context.getSource(), application);
        configureLoaderAttributes(cloader, webXmlParser, base);
        configureLoaderProperties(cloader, webXmlParser, base);
        configureContextXmlAttribute(cloader, base, context);
        try {
            doPrivileged(new SetPermissionsAction(CommponentType.war, context, cloader));
        } catch (PrivilegedActionException e) {
            throw new SecurityException(e.getException());
        }
    } catch (XMLStreamException xse) {
        logger.log(SEVERE, xse.getMessage());
        if (logger.isLoggable(FINE)) {
            logger.log(FINE, xse.getMessage(), xse);
        }
        xse.printStackTrace();
    } catch (IOException ioe) {
        logger.log(SEVERE, ioe.getMessage());
        if (logger.isLoggable(FINE)) {
            logger.log(FINE, ioe.getMessage(), ioe);
        }
        ioe.printStackTrace();
    }
    cloader.start();
    return cloader;
}
Also used : WebDirContext(org.apache.naming.resources.WebDirContext) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) URL(java.net.URL) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) WebappClassLoader(org.glassfish.web.loader.WebappClassLoader) XMLStreamException(javax.xml.stream.XMLStreamException) Application(com.sun.enterprise.deployment.Application) JarFile(java.util.jar.JarFile) File(java.io.File) SetPermissionsAction(com.sun.enterprise.security.permissionsxml.SetPermissionsAction)

Aggregations

SetPermissionsAction (com.sun.enterprise.security.permissionsxml.SetPermissionsAction)3 PrivilegedActionException (java.security.PrivilegedActionException)3 IOException (java.io.IOException)2 URL (java.net.URL)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)1 Application (com.sun.enterprise.deployment.Application)1 ASURLClassLoader (com.sun.enterprise.loader.ASURLClassLoader)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 JarFile (java.util.jar.JarFile)1 WebDirContext (org.apache.naming.resources.WebDirContext)1 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)1 WebappClassLoader (org.glassfish.web.loader.WebappClassLoader)1