private static ClassLoader identifyClassLoader() { ClassLoader classLoader = WildFlySecurityManager.isChecking() ? AccessController.doPrivileged(GetContextClassLoaderAction.getInstance()) : GetContextClassLoaderAction.getInstance().run(); return classLoader != null ? classLoader : ClassLoader.getSystemClassLoader(); }
protected TransactionIntegration getTransactionIntegration() { if (! WildFlySecurityManager.isChecking()) { currentThread().setContextClassLoader(TransactionIntegration.class.getClassLoader()); } else { doPrivileged(new SetContextClassLoaderFromClassAction(TransactionIntegration.class)); } try { return transactionIntegrationValue.getValue(); } finally { doPrivileged(ClearContextClassLoaderAction.getInstance()); } }
static ModuleClassLoader getModuleClassLoader() throws ModuleLoadException { if (! WildFlySecurityManager.isChecking()) { return (ModuleClassLoader) SecurityActions.class.getClassLoader(); } else { return (ModuleClassLoader) doPrivileged(new GetClassLoaderAction(SecurityActions.class)); } }
private static void checkPDPermission(Class<?> clazz, Permission permission) { final ProtectionDomain protectionDomain; final ClassLoader classLoader; if (getSecurityManager() instanceof WildFlySecurityManager) { protectionDomain = clazz.getProtectionDomain(); classLoader = clazz.getClassLoader(); } else { protectionDomain = doPrivileged(new GetProtectionDomainAction(clazz)); classLoader = doPrivileged(new GetClassLoaderAction(clazz)); } if (protectionDomain.implies(permission)) { return; } access.accessCheckFailed(permission, protectionDomain.getCodeSource(), classLoader); if (! LOG_ONLY) { throw access.accessControlException(permission, permission, protectionDomain.getCodeSource(), classLoader); } }
/** * Get a property, doing a faster permission check that skips having to execute a privileged action frame. * * @param name the property name * @param def the default value if the property is not found * @return the property value, or the default value */ public static String getPropertyPrivileged(String name, String def) { final SecurityManager sm = getSecurityManager(); if (sm == null) { return getProperty(name, def); } if (sm instanceof WildFlySecurityManager) { final Context ctx = CTX.get(); if (! ctx.checking) { return getProperty(name, def); } ctx.checking = false; try { checkPropertyReadPermission(getCallerClass(2), name); return getProperty(name, def); } finally { ctx.checking = true; } } else { checkPropertyReadPermission(getCallerClass(2), name); return doPrivileged(new ReadPropertyAction(name, def)); } }
static ModuleClassLoader getModuleClassLoader(final String moduleSpec) throws ModuleLoadException { ModuleLoader loader = Module.getCallerModuleLoader(); final Module module = loader.loadModule(ModuleIdentifier.fromString(moduleSpec)); GetModuleClassLoaderAction action = new GetModuleClassLoaderAction(module); return WildFlySecurityManager.isChecking() ? doPrivileged(action) : action.run(); }
/** * Get the current thread's context class loader, doing a faster permission check that skips having to execute a * privileged action frame. * * @return the context class loader */ public static ClassLoader getCurrentContextClassLoaderPrivileged() { final SecurityManager sm = System.getSecurityManager(); if (sm == null) { return currentThread().getContextClassLoader(); } if (sm instanceof WildFlySecurityManager) { final Context ctx = CTX.get(); if (! ctx.checking) { return currentThread().getContextClassLoader(); } ctx.checking = false; try { checkPDPermission(getCallerClass(2), GET_CLASS_LOADER_PERMISSION); return currentThread().getContextClassLoader(); } finally { ctx.checking = true; } } else { checkPDPermission(getCallerClass(2), GET_CLASS_LOADER_PERMISSION); return doPrivileged(GetContextClassLoaderAction.getInstance()); } }
static ModuleClassLoader getModuleClassLoader(final ModuleLoader loader, final String moduleSpec) throws ModuleLoadException { final Module module = loader.loadModule(ModuleIdentifier.fromString(moduleSpec)); return WildFlySecurityManager.isChecking() ? doPrivileged(new GetModuleClassLoaderAction(module)) : module.getClassLoader(); }
/** * Set a property, doing a faster permission check that skips having to execute a privileged action frame. * * @param name the property name * @param value the value ot set * @return the previous property value, or {@code null} if there was none */ public static String setPropertyPrivileged(String name, String value) { final SecurityManager sm = getSecurityManager(); if (sm == null) { return setProperty(name, value); } if (sm instanceof WildFlySecurityManager) { final Context ctx = CTX.get(); if (! ctx.checking) { return setProperty(name, value); } ctx.checking = false; try { checkPropertyWritePermission(getCallerClass(2), name); return setProperty(name, value); } finally { ctx.checking = true; } } else { checkPropertyWritePermission(getCallerClass(2), name); return doPrivileged(new WritePropertyAction(name, value)); } }
/** * Get an environmental property, doing a faster permission check that skips having to execute a privileged action frame. * * @param name the property name * @param def the default value if the property is not found * @return the property value, or the default value */ public static String getEnvPropertyPrivileged(String name, String def) { final SecurityManager sm = getSecurityManager(); if (sm == null) { return getenv(name); } if (sm instanceof WildFlySecurityManager) { final Context ctx = CTX.get(); if (! ctx.checking) { return def(getenv(name), def); } ctx.checking = false; try { checkEnvPropertyReadPermission(getCallerClass(2), name); return def(getenv(name), def); } finally { ctx.checking = true; } } else { checkEnvPropertyReadPermission(getCallerClass(2), name); return doPrivileged(new ReadEnvironmentPropertyAction(name, def)); } }
/** * Clear a property, doing a faster permission check that skips having to execute a privileged action frame. * * @param name the property name * @return the previous property value, or {@code null} if there was none */ public static String clearPropertyPrivileged(String name) { final SecurityManager sm = getSecurityManager(); if (sm == null) { return clearProperty(name); } if (sm instanceof WildFlySecurityManager) { final Context ctx = CTX.get(); if (! ctx.checking) { return clearProperty(name); } ctx.checking = false; try { checkPropertyWritePermission(getCallerClass(2), name); return clearProperty(name); } finally { ctx.checking = true; } } else { checkPropertyWritePermission(getCallerClass(2), name); return doPrivileged(new ClearPropertyAction(name)); } }
/** * Get the system properties map, doing a faster permission check that skips having to execute a privileged action * frame. * * @return the system property map */ public static Properties getSystemPropertiesPrivileged() { final SecurityManager sm = System.getSecurityManager(); if (sm == null) { return getProperties(); } if (sm instanceof WildFlySecurityManager) { final Context ctx = CTX.get(); if (! ctx.checking) { return getProperties(); } ctx.checking = false; try { checkPDPermission(getCallerClass(2), PROPERTIES_PERMISSION); return getProperties(); } finally { ctx.checking = true; } } else { checkPDPermission(getCallerClass(2), PROPERTIES_PERMISSION); return doPrivileged(GetSystemPropertiesAction.getInstance()); } }
/** * Get the system environment map, doing a faster permission check that skips having to execute a privileged action * frame. * * @return the system environment map */ public static Map<String, String> getSystemEnvironmentPrivileged() { final SecurityManager sm = System.getSecurityManager(); if (sm == null) { return getenv(); } if (sm instanceof WildFlySecurityManager) { final Context ctx = CTX.get(); if (! ctx.checking) { return getenv(); } ctx.checking = false; try { checkPDPermission(getCallerClass(2), ENVIRONMENT_PERMISSION); return getenv(); } finally { ctx.checking = true; } } else { checkPDPermission(getCallerClass(2), ENVIRONMENT_PERMISSION); return doPrivileged(GetEnvironmentAction.getInstance()); } }
/** * <p> * Creates a thread with the specified {@code Runnable} and name. * </p> * * @param runnable the {@code Runnable} to be set in the new {@code Thread}. * @param threadName the name of the new {@code Thread}. * @return the construct {@code Thread} instance. */ static Thread createThread(final Runnable runnable, final String threadName) { return ! WildFlySecurityManager.isChecking() ? new Thread(runnable, threadName) : doPrivileged(new CreateThreadAction(runnable, threadName)); } }
private static void checkPropertyWritePermission(Class<?> clazz, String propertyName) { final ProtectionDomain protectionDomain; final ClassLoader classLoader; if (getSecurityManager() instanceof WildFlySecurityManager) { protectionDomain = clazz.getProtectionDomain(); classLoader = clazz.getClassLoader(); } else { protectionDomain = doPrivileged(new GetProtectionDomainAction(clazz)); classLoader = doPrivileged(new GetClassLoaderAction(clazz)); } if (protectionDomain.implies(PROPERTIES_PERMISSION)) { return; } final PropertyPermission permission = new PropertyPermission(propertyName, "write"); if (protectionDomain.implies(permission)) { return; } access.accessCheckFailed(permission, protectionDomain.getCodeSource(), classLoader); if (! LOG_ONLY) { throw access.accessControlException(permission, permission, protectionDomain.getCodeSource(), classLoader); } }
private ClassLoader driverClassLoader() { if(classLoader != null) { return classLoader; } final Class<? extends Driver> clazz = driverValue.getValue().getClass(); return ! WildFlySecurityManager.isChecking() ? clazz.getClassLoader() : doPrivileged(new GetClassLoaderAction(clazz)); }
@Override public TransactionIntegration getTransactionIntegration() { if (! WildFlySecurityManager.isChecking()) { currentThread().setContextClassLoader(TransactionIntegration.class.getClassLoader()); } else { doPrivileged(new SetContextClassLoaderFromClassAction(TransactionIntegration.class)); } try { return transactionIntegrationValue.getValue(); } finally { if (! WildFlySecurityManager.isChecking()) { currentThread().setContextClassLoader(null); } else { doPrivileged(ClearContextClassLoaderAction.getInstance()); } } }
private static void checkEnvPropertyReadPermission(Class<?> clazz, String propertyName) { final ProtectionDomain protectionDomain; final ClassLoader classLoader; if (getSecurityManager() instanceof WildFlySecurityManager) { protectionDomain = clazz.getProtectionDomain(); classLoader = clazz.getClassLoader(); } else { protectionDomain = doPrivileged(new GetProtectionDomainAction(clazz)); classLoader = doPrivileged(new GetClassLoaderAction(clazz)); } if (protectionDomain.implies(ENVIRONMENT_PERMISSION)) { return; } final RuntimePermission permission = new RuntimePermission("getenv." + propertyName); if (protectionDomain.implies(permission)) { return; } access.accessCheckFailed(permission, protectionDomain.getCodeSource(), classLoader); if (! LOG_ONLY) { throw access.accessControlException(permission, permission, protectionDomain.getCodeSource(), classLoader); } }
@Override protected TransactionManager getTransactionManager() { if (! WildFlySecurityManager.isChecking()) { currentThread().setContextClassLoader(TransactionIntegration.class.getClassLoader()); } else { doPrivileged(new SetContextClassLoaderFromClassAction(TransactionIntegration.class)); } try { return getTxIntegration().getValue().getTransactionManager(); } finally { if (! WildFlySecurityManager.isChecking()) { currentThread().setContextClassLoader(null); } else { doPrivileged(ClearContextClassLoaderAction.getInstance()); } } }
private static void checkPropertyReadPermission(Class<?> clazz, String propertyName) { final ProtectionDomain protectionDomain; final ClassLoader classLoader; if (getSecurityManager() instanceof WildFlySecurityManager) { protectionDomain = clazz.getProtectionDomain(); classLoader = clazz.getClassLoader(); } else { protectionDomain = doPrivileged(new GetProtectionDomainAction(clazz)); classLoader = doPrivileged(new GetClassLoaderAction(clazz)); } if (protectionDomain.implies(PROPERTIES_PERMISSION)) { return; } final PropertyPermission permission = new PropertyPermission(propertyName, "read"); if (protectionDomain.implies(permission)) { return; } access.accessCheckFailed(permission, protectionDomain.getCodeSource(), classLoader); if (! LOG_ONLY) { throw access.accessControlException(permission, permission, protectionDomain.getCodeSource(), classLoader); } }