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;
}
});
}
}
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;
}
});
}
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);
}
}
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);
}
}
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");
}
}
Aggregations