List of usage examples for java.security Policy getPolicy
public static Policy getPolicy()
From source file:org.apache.jxtadoop.security.SecurityUtil.java
/** * Get the current global security policy for Hadoop. * @return the current {@link Policy}//from w w w .ja v a 2 s . c om */ public static Policy getPolicy() { return Policy.getPolicy(); }
From source file:org.ow2.proactive.resourcemanager.utils.RMNodeStarter.java
private void configureSecurityManager() { if (System.getProperty("java.security.policy") == null) { System.setProperty("java.security.policy", RMNodeStarter.class.getResource("/config/security.java.policy-client").toString()); Policy.getPolicy().refresh(); }//from w w w . j av a 2s . co m }
From source file:org.ow2.proactive.resourcemanager.utils.RMStarter.java
private static void configureSecurityManager() { if (System.getProperty("java.security.policy") == null) { System.setProperty("java.security.policy", System.getProperty(PAResourceManagerProperties.RM_HOME.getKey()) + "/config/security.java.policy-server"); Policy.getPolicy().refresh(); }/*from w w w .j av a 2 s .c o m*/ }
From source file:org.springframework.data.hadoop.mapreduce.ExecutionUtils.java
/** * Utility method used before invoking custom code for preventing custom classloader, set as the Thread * context class-loader, to leak (typically through JDK classes). *//* w w w . ja v a2 s . c o m*/ static void preventJreTcclLeaks() { if (log.isDebugEnabled()) { log.debug("Preventing JRE TCCL leaks"); } // get the root CL to be used instead ClassLoader sysLoader = ClassLoader.getSystemClassLoader(); ClassLoader cl = Thread.currentThread().getContextClassLoader(); try { // set the sysCL as the TCCL Thread.currentThread().setContextClassLoader(sysLoader); // // Handle security // // Policy holds the TCCL as static ClassUtils.resolveClassName("javax.security.auth.Policy", sysLoader); // since the class init may be lazy, call the method directly Policy.getPolicy(); // Configuration holds the TCCL as static // call method with minimal side-effects (since just doing class loading doesn't seem to trigger the static init) try { javax.security.auth.login.Configuration.getInstance(null, null, (String) null); } catch (Exception ex) { // ignore } // seems to cause side-effects/exceptions // javax.security.auth.login.Configuration.getConfiguration(); java.security.Security.getProviders(); // load the JDBC drivers (used by Hive and co) DriverManager.getDrivers(); // Initialize // sun.awt.AppContext.getAppContext() ImageIO.getCacheDirectory(); } finally { Thread.currentThread().setContextClassLoader(cl); } }
From source file:org.tinygroup.jspengine.compiler.JspRuntimeContext.java
/** * Method used to initialize SecurityManager data. *///from w w w . j ava2 s . com private void initSecurity() { // Setup the PermissionCollection for this web app context // based on the permissions configured for the root of the // web app context directory, then add a file read permission // for that directory. Policy policy = Policy.getPolicy(); if (policy != null) { try { // Get the permissions for the web app context String docBase = context.getRealPath("/"); if (docBase == null) { docBase = options.getScratchDir().toString(); } String codeBase = docBase; if (!codeBase.endsWith(File.separator)) { codeBase = codeBase + File.separator; } File contextDir = new File(codeBase); URL url = contextDir.getCanonicalFile().toURL(); codeSource = new CodeSource(url, (Certificate[]) null); permissionCollection = policy.getPermissions(codeSource); // Create a file read permission for web app context directory if (!docBase.endsWith(File.separator)) { permissionCollection.add(new FilePermission(docBase, "read")); docBase = docBase + File.separator; } else { permissionCollection .add(new FilePermission(docBase.substring(0, docBase.length() - 1), "read")); } docBase = docBase + "-"; permissionCollection.add(new FilePermission(docBase, "read")); // Create a file read permission for web app tempdir (work) // directory String workDir = options.getScratchDir().toString(); if (!workDir.endsWith(File.separator)) { permissionCollection.add(new FilePermission(workDir, "read")); workDir = workDir + File.separator; } workDir = workDir + "-"; permissionCollection.add(new FilePermission(workDir, "read")); // Allow the JSP to access // org.tinygroup.jspengine.runtime.HttpJspBase permissionCollection .add(new RuntimePermission("accessClassInPackage.org.tinygroup.jspengine.runtime")); if (parentClassLoader instanceof URLClassLoader) { URL[] urls = ((URLClassLoader) parentClassLoader).getURLs(); String jarUrl = null; String jndiUrl = null; for (int i = 0; i < urls.length; i++) { if (jndiUrl == null && urls[i].toString().startsWith("jndi:")) { jndiUrl = urls[i].toString() + "-"; } if (jarUrl == null && urls[i].toString().startsWith("jar:jndi:")) { jarUrl = urls[i].toString(); jarUrl = jarUrl.substring(0, jarUrl.length() - 2); jarUrl = jarUrl.substring(0, jarUrl.lastIndexOf('/')) + "/-"; } } if (jarUrl != null) { permissionCollection.add(new FilePermission(jarUrl, "read")); permissionCollection.add(new FilePermission(jarUrl.substring(4), "read")); } if (jndiUrl != null) permissionCollection.add(new FilePermission(jndiUrl, "read")); } } catch (Exception e) { context.log("Security Init for context failed", e); } } }