Search in sources :

Example 81 with PrivilegedAction

use of java.security.PrivilegedAction in project Payara by payara.

the class BaseContainerCallbackHandler method processGroupPrincipal.

private void processGroupPrincipal(GroupPrincipalCallback gpCallback) {
    final Subject fs = gpCallback.getSubject();
    final String[] groups = gpCallback.getGroups();
    if (groups != null && groups.length > 0) {
        AppservAccessController.doPrivileged(new PrivilegedAction() {

            public java.lang.Object run() {
                for (String group : groups) {
                    fs.getPrincipals().add(new Group(group));
                }
                return fs;
            }
        });
    } else if (groups == null) {
        AppservAccessController.doPrivileged(new PrivilegedAction() {

            public java.lang.Object run() {
                Set<Principal> principalSet = fs.getPrincipals();
                principalSet.removeAll(fs.getPrincipals(Group.class));
                return fs;
            }
        });
    }
}
Also used : Group(org.glassfish.security.common.Group) PrivilegedAction(java.security.PrivilegedAction) Subject(javax.security.auth.Subject) WebPrincipal(com.sun.enterprise.security.web.integration.WebPrincipal) Principal(java.security.Principal) X500Principal(javax.security.auth.x500.X500Principal)

Example 82 with PrivilegedAction

use of java.security.PrivilegedAction in project Payara by payara.

the class LoggerFactoryJDK14 method createLogger.

/**
 * Create a new Logger.  create a logger for the named component.
 * The bundle name and class loader are passed to allow the implementation
 * to properly find and construct the internationalization bundle.
 * This operation is executed as a privileged action to allow
 * permission access for the following operations:
 *
 * LogManager.getLogManager().addLogger - this might do checkAccess.
 * new FileHandler
 * FileHandler.setLevel
 * FileHandler.setFormatter
 * Logger.addHandler
 *
 * @param absoluteLoggerName the absolute name of this logger
 * @param bundleName the fully qualified name of the resource bundle
 * @param loader the class loader used to load the resource bundle, or null
 * @return the logger
 */
protected Logger createLogger(final String absoluteLoggerName, final String bundleName, final ClassLoader loader) {
    return (Logger) AccessController.doPrivileged(new PrivilegedAction() {

        public Object run() {
            LoggerJDK14 logger = null;
            ClassLoader pushed = Thread.currentThread().getContextClassLoader();
            if (loader != null) {
                setContextClassLoader(loader);
            }
            try {
                logger = createLogger(absoluteLoggerName, bundleName);
                LogManager.getLogManager().addLogger(logger);
                configureFileHandler(logger);
                return logger;
            } catch (Exception ex) {
                MessageFormat messageFormat = new MessageFormat(getMessages().getString("errorlogger.create.exception"));
                getErrorLogger().log(Logger.SEVERE, messageFormat.format(new String[] { absoluteLoggerName }), ex);
            } finally {
                setContextClassLoader(pushed);
            }
            return logger;
        }
    });
}
Also used : MessageFormat(java.text.MessageFormat) PrivilegedAction(java.security.PrivilegedAction) IOException(java.io.IOException)

Example 83 with PrivilegedAction

use of java.security.PrivilegedAction in project Payara by payara.

the class ResourceGateway method initializeCustomResourceGatewayInPrivilegedMode.

private static ResourceGateway initializeCustomResourceGatewayInPrivilegedMode(final String className) throws PoolingException {
    Object result = AccessController.doPrivileged(new PrivilegedAction() {

        public Object run() {
            Object result = null;
            try {
                result = initializeCustomResourceGateway(className);
            } catch (Exception e) {
                _logger.log(Level.WARNING, "pool.resource.gateway.init.failure", className);
                _logger.log(Level.WARNING, "pool.resource.gateway.init.failure", e);
            }
            return result;
        }
    });
    if (result != null) {
        return (ResourceGateway) result;
    } else {
        throw new PoolingException("Unable to initalize custom ResourceGateway : " + className);
    }
}
Also used : PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) PrivilegedAction(java.security.PrivilegedAction) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException)

Example 84 with PrivilegedAction

use of java.security.PrivilegedAction in project Payara by payara.

the class DataStructureFactory method initializeCustomDataStructureInPrivilegedMode.

private static DataStructure initializeCustomDataStructureInPrivilegedMode(final String className, final String parameters, final int maxPoolSize, final ResourceHandler handler, final String strategyClass) throws PoolingException {
    Object result = AccessController.doPrivileged(new PrivilegedAction() {

        public Object run() {
            Object result = null;
            try {
                result = initializeDataStructure(className, parameters, maxPoolSize, handler, strategyClass);
            } catch (Exception e) {
                _logger.log(Level.WARNING, "pool.datastructure.init.failure", className);
                _logger.log(Level.WARNING, "pool.datastructure.init.failure.exception", e);
            }
            return result;
        }
    });
    if (result != null) {
        return (DataStructure) result;
    } else {
        throw new PoolingException("Unable to initalize custom DataStructure : " + className);
    }
}
Also used : PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) PrivilegedAction(java.security.PrivilegedAction) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException)

Example 85 with PrivilegedAction

use of java.security.PrivilegedAction in project Payara by payara.

the class DeploymentFactoryInstaller method installDeploymentFactory.

protected void installDeploymentFactory(final File installedDM) throws IOException {
    if (deplLogger.isLoggable(Level.FINE)) {
        deplLogger.fine("Installing Deployment factory = " + installedDM.getAbsolutePath());
    }
    // let's check first that we indeed have a valid
    // deployment manager implementation
    /*
         *Declare the JarFile and Manifest but populate them inside the first try block.  This way the 
         *jar file can be closed right away to conserve resources.
         */
    Manifest m = null;
    JarFile jarFile = new JarFile(installedDM);
    try {
        m = jarFile.getManifest();
    } finally {
        jarFile.close();
    }
    String className = m.getMainAttributes().getValue(J2EE_DEPLOYMENT_MANAGER);
    final URL[] urls = new URL[] { installedDM.toURI().toURL() };
    URLClassLoader urlClassLoader;
    urlClassLoader = AccessController.doPrivileged(new PrivilegedAction<URLClassLoader>() {

        public URLClassLoader run() {
            return new java.net.URLClassLoader(urls, getClass().getClassLoader());
        }
    });
    Class factory = null;
    try {
        factory = urlClassLoader.loadClass(className);
    } catch (ClassNotFoundException cnfe) {
        deplLogger.log(Level.SEVERE, NO_DEPLOYMENT_MANAGER, className);
        throw new IllegalArgumentException(className + " is not present in the " + installedDM.getName());
    }
    // Ok we have the class, let's instanciate it, check it and
    // if everything is fine, register it to the DeploymentFactoryManager
    Object df = null;
    try {
        df = factory.newInstance();
    } catch (Exception ie) {
        LogRecord lr = new LogRecord(Level.SEVERE, NO_DEPLOYMENT_MANAGER);
        Object[] args = { className };
        lr.setParameters(args);
        lr.setThrown(ie);
        deplLogger.log(lr);
        throw new IllegalArgumentException("Cannot install " + installedDM.getName());
    }
    if (df instanceof DeploymentFactory) {
        DeploymentFactoryManager.getInstance().registerDeploymentFactory((DeploymentFactory) df);
    } else {
        throw new IllegalArgumentException("The " + className + " declared as a DeploymentFactory does implement the DeploymentFactory interface");
    }
}
Also used : DeploymentFactory(javax.enterprise.deploy.spi.factories.DeploymentFactory) Manifest(java.util.jar.Manifest) JarFile(java.util.jar.JarFile) URL(java.net.URL) IOException(java.io.IOException) PrivilegedAction(java.security.PrivilegedAction) LogRecord(java.util.logging.LogRecord) URLClassLoader(java.net.URLClassLoader)

Aggregations

PrivilegedAction (java.security.PrivilegedAction)190 IOException (java.io.IOException)44 Subject (javax.security.auth.Subject)28 File (java.io.File)19 AccessControlContext (java.security.AccessControlContext)18 Method (java.lang.reflect.Method)13 InputStream (java.io.InputStream)12 URL (java.net.URL)11 LoginException (com.sun.enterprise.security.auth.login.common.LoginException)10 Field (java.lang.reflect.Field)10 URLClassLoader (java.net.URLClassLoader)10 Principal (java.security.Principal)10 Set (java.util.Set)9 PrivilegedActionException (java.security.PrivilegedActionException)8 Iterator (java.util.Iterator)8 PasswordCredential (com.sun.enterprise.security.auth.login.common.PasswordCredential)7 InvalidOperationException (com.sun.enterprise.security.auth.realm.InvalidOperationException)7 NoSuchRealmException (com.sun.enterprise.security.auth.realm.NoSuchRealmException)7 NoSuchUserException (com.sun.enterprise.security.auth.realm.NoSuchUserException)7 URISyntaxException (java.net.URISyntaxException)7