List of usage examples for java.security PrivilegedAction PrivilegedAction
PrivilegedAction
From source file:org.apache.tajo.master.TaskRunnerLauncherImpl.java
protected ContainerManager getCMProxy(ContainerId containerID, final String containerManagerBindAddr, ContainerToken containerToken) throws IOException { String[] hosts = containerManagerBindAddr.split(":"); final InetSocketAddress cmAddr = new InetSocketAddress(hosts[0], Integer.parseInt(hosts[1])); UserGroupInformation user = UserGroupInformation.getCurrentUser(); if (UserGroupInformation.isSecurityEnabled()) { Token<ContainerTokenIdentifier> token = ProtoUtils.convertFromProtoFormat(containerToken, cmAddr); // the user in createRemoteUser in this context has to be ContainerID user = UserGroupInformation.createRemoteUser(containerID.toString()); user.addToken(token);// w w w. ja va2s .c o m } ContainerManager proxy = user.doAs(new PrivilegedAction<ContainerManager>() { @Override public ContainerManager run() { return (ContainerManager) yarnRPC.getProxy(ContainerManager.class, cmAddr, getConfig()); } }); return proxy; }
From source file:com.ikon.module.jcr.stuff.JCRUtils.java
/** * Get JCR Session// w w w.j a va 2 s . c o m */ public static Session getSession() throws javax.jcr.LoginException, javax.jcr.RepositoryException, DatabaseException { Subject subject = null; Object obj = null; // Resolve subject // Subject userSubject=(Subject)PolicyContext.getContext("javax.security.auth.Subject.container"); if (EnvironmentDetector.isServerJBoss()) { try { InitialContext ctx = new InitialContext(); subject = (Subject) ctx.lookup("java:/comp/env/security/subject"); ctx.close(); } catch (NamingException e) { throw new javax.jcr.LoginException(e.getMessage()); } } else if (EnvironmentDetector.isServerTomcat()) { subject = Subject.getSubject(AccessController.getContext()); } // Obtain JCR session if (subject != null) { obj = Subject.doAs(subject, new PrivilegedAction<Object>() { public Object run() { Session s = null; try { s = JcrRepositoryModule.getRepository().login(); } catch (javax.jcr.LoginException e) { return e; } catch (javax.jcr.RepositoryException e) { return e; } return s; } }); } // Validate JCR session if (obj instanceof javax.jcr.LoginException) { throw (javax.jcr.LoginException) obj; } else if (obj instanceof javax.jcr.RepositoryException) { throw (javax.jcr.RepositoryException) obj; } else if (obj instanceof javax.jcr.Session) { Session session = (javax.jcr.Session) obj; log.debug("#{} - {} Create session {} from {}", new Object[] { ++sessionCreationCount, ++activeSessions, session, StackTraceUtils.whoCalledMe() }); JcrAuthModule.loadUserData(session); return session; } else { return null; } }
From source file:org.apache.phoenix.end2end.HttpParamImpersonationQueryServerIT.java
private static void startQueryServer() throws Exception { PQS = new QueryServer(new String[0], UTIL.getConfiguration()); // Get the SPNEGO ident for PQS to use final UserGroupInformation ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(SPNEGO_PRINCIPAL, KEYTAB.getAbsolutePath());/*from www . jav a2 s . co m*/ PQS_EXECUTOR = Executors.newSingleThreadExecutor(); // Launch PQS, doing in the Kerberos login instead of letting PQS do it itself (which would // break the HBase/HDFS logins also running in the same test case). PQS_EXECUTOR.submit(new Runnable() { @Override public void run() { ugi.doAs(new PrivilegedAction<Void>() { @Override public Void run() { PQS.run(); return null; } }); } }); PQS.awaitRunning(); PQS_PORT = PQS.getPort(); PQS_URL = ThinClientUtil.getConnectionUrl("localhost", PQS_PORT) + ";authentication=SPNEGO"; }
From source file:org.apache.cxf.common.logging.LogUtils.java
private static ClassLoader getClassLoader(final Class<?> clazz) { final SecurityManager sm = System.getSecurityManager(); if (sm != null) { return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { public ClassLoader run() { return clazz.getClassLoader(); }//from w ww. j a v a 2s .c om }); } return clazz.getClassLoader(); }
From source file:org.apache.struts2.jasper.runtime.PageContextImpl.java
public int getAttributesScope(final String name) { if (name == null) { throw new NullPointerException(Localizer.getMessage("jsp.error.attribute.null_name")); }/*from w w w . j a va 2 s. c om*/ if (SecurityUtil.isPackageProtectionEnabled()) { return ((Integer) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { return new Integer(doGetAttributeScope(name)); } })).intValue(); } else { return doGetAttributeScope(name); } }
From source file:org.apache.jasper.runtime.PageContextImpl.java
public void setAttribute(final String name, final Object o, final int scope) { if (name == null) { throw new NullPointerException(Localizer.getMessage("jsp.error.attribute.null_name")); }/*ww w .j av a 2s. com*/ if (System.getSecurityManager() != null) { AccessController.doPrivileged(new PrivilegedAction() { public Object run() { doSetAttribute(name, o, scope); return null; } }); } else { doSetAttribute(name, o, scope); } }
From source file:org.commonjava.sshwrap.config.DefaultSSHConfiguration.java
static String userName() { return AccessController.doPrivileged(new PrivilegedAction<String>() { @Override/*from w w w . j av a 2 s . co m*/ public String run() { return System.getProperty("user.name"); } }); }
From source file:com.scaleoutsoftware.soss.hserver.hadoop.DistributedCacheManager.java
/** * Creates a class loader that includes the designated * files and archives./*from www.java2 s . c o m*/ */ public ClassLoader makeClassLoader(final ClassLoader parent) throws MalformedURLException { final URL[] urls = new URL[localClasspaths.size()]; for (int i = 0; i < localClasspaths.size(); ++i) { urls[i] = new File(localClasspaths.get(i)).toURI().toURL(); LOG.info(urls[i]); } return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { @Override public ClassLoader run() { return new URLClassLoader(urls, parent); } }); }
From source file:org.pepstock.jem.springbatch.tasks.utilities.MainLauncherTasklet.java
/** * Loads java class from className and for classpath * @param className classname to be loaded * @return class object loaded from classpath * @throws IOException if any error occurs * @throws ClassNotFoundException if any error occurs *//* w w w .j av a 2 s. c o m*/ private Class<?> loadCustomClass(String classNam) throws IOException, ClassNotFoundException { // CLASSPATH has been set therefore it an try to load the plugin by // a custom classloader // collection of all file of classpath Collection<File> files = new LinkedList<File>(); for (String classPathFile : classPath) { classPathFile = FilenameUtils.normalize(classPathFile, true); // checks if a item contains more than 1 path String[] paths = null; if (classPathFile.contains(File.pathSeparator)) { // substitute variables if there are and split paths = StringUtils.split(JobsProperties.getInstance().replacePlaceHolders(classPathFile), File.pathSeparator); } else if (classPathFile.contains(";")) { // substitute variables if there are and split paths = StringUtils.split(JobsProperties.getInstance().replacePlaceHolders(classPathFile), ";"); } else { // substitute variables if there are and assign paths = new String[] { JobsProperties.getInstance().replacePlaceHolders(classPathFile) }; } if (paths != null) { for (String path : paths) { // creates the file File file = new File(path); // if file ends with * could be only this folder or all folders // in cascade if (path.endsWith(ClassLoaderUtil.ALL_FOLDER)) { // checks if is all folders in cascade boolean cascade = path.endsWith(ClassLoaderUtil.ALL_FOLDER_IN_CASCADE); // gets the parent and asks for all JAR files File parent = file.getParentFile(); Collection<File> newFiles = FileUtils.listFiles(parent, ClassLoaderUtil.EXTENSIONS.toArray(new String[0]), cascade); // loads to the collection files.addAll(newFiles); } else if (file.isDirectory() && file.exists()) { // if here, we have a directory // adds the directory to collection files.add(file); } else if (file.isFile() && file.exists()) { // if here, a file has been indicated // adds the directory to collection files.add(file); } } } } // checks if the collection is empty. // if yes, all classpath definiton is wrong and no files have been // loaded if (!files.isEmpty()) { // gets where the class is located // because it must be added to classpath CodeSource codeSource = JavaMainClassLauncher.class.getProtectionDomain().getCodeSource(); if (codeSource != null) { // gets URL URL url = codeSource.getLocation(); if (url != null) { // adds URL to classpath files.add(FileUtils.toFile(url)); } } // exports files in URLs, for our classloader final URL[] urls = FileUtils.toURLs(files.toArray(new File[files.size()])); // loads a our classloader by access controller ClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { public ClassLoader run() { return new ReverseURLClassLoader(urls, MainLauncherTasklet.class.getClassLoader(), false); } }); // loads the plugin from classloader return loader.loadClass(className); } else { throw new IOException(UtilMessage.JEMB009E.toMessage().getMessage()); } }
From source file:org.apache.axis2.util.Utils.java
public static ConfigurationContext getNewConfigurationContext(String repositry) throws Exception { final File file = new File(repositry); boolean exists = exists(file); if (!exists) { throw new Exception("repository directory " + file.getAbsolutePath() + " does not exists"); }/* w ww .java 2 s . c o m*/ File axis2xml = new File(file, "axis.xml"); String axis2xmlString = null; if (exists(axis2xml)) { axis2xmlString = axis2xml.getName(); } String path = (String) org.apache.axis2.java.security.AccessController .doPrivileged(new PrivilegedAction<String>() { public String run() { return file.getAbsolutePath(); } }); return ConfigurationContextFactory.createConfigurationContextFromFileSystem(path, axis2xmlString); }