List of usage examples for java.security AccessControlContext checkPermission
public void checkPermission(Permission perm) throws AccessControlException
From source file:org.eclipse.equinox.http.servlet.internal.multipart.MultipartSupportImpl.java
private void checkPermission(File baseStorage, ServletContext servletContext) { BundleContext bundleContext = (BundleContext) servletContext.getAttribute("osgi-bundlecontext"); //$NON-NLS-1$ Bundle bundle = bundleContext.getBundle(); AccessControlContext accessControlContext = bundle.adapt(AccessControlContext.class); if (accessControlContext == null) return;//from w w w . jav a 2 s . com accessControlContext.checkPermission(new FilePermission(baseStorage.getAbsolutePath(), "read,write")); //$NON-NLS-1$ }
From source file:org.elasticsearch.hadoop.script.GroovyScriptEngineService.java
public GroovyScriptEngineService(Settings settings) { super(settings); deprecationLogger.deprecated("[groovy] scripts are deprecated, use [painless] scripts instead"); // Creates the classloader here in order to isolate Groovy-land code final SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new SpecialPermission()); }/*from w w w. ja v a2s . c o m*/ this.loader = AccessController.doPrivileged((PrivilegedAction<ClassLoader>) () -> { // snapshot our context (which has permissions for classes), since the script has none AccessControlContext context = AccessController.getContext(); return new ClassLoader(getClass().getClassLoader()) { @Override protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { if (sm != null) { try { context.checkPermission(new ClassPermission(name)); } catch (SecurityException e) { throw new ClassNotFoundException(name, e); } } return super.loadClass(name, resolve); } }; }); }