Refine search
/** * Returns a sun.misc.Unsafe. Suitable for use in a 3rd party package. Replace with a simple call * to Unsafe.getUnsafe when integrating into a jdk. * * @return a sun.misc.Unsafe */ private static sun.misc.Unsafe getUnsafe() { try { return sun.misc.Unsafe.getUnsafe(); } catch (SecurityException tryReflectionInstead) { } try { return java.security.AccessController.doPrivileged( new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() { public sun.misc.Unsafe run() throws Exception { Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class; for (java.lang.reflect.Field f : k.getDeclaredFields()) { f.setAccessible(true); Object x = f.get(null); if (k.isInstance(x)) return k.cast(x); } throw new NoSuchFieldError("the Unsafe"); } }); } catch (java.security.PrivilegedActionException e) { throw new RuntimeException("Could not initialize intrinsics", e.getCause()); } } }
private static String getCurrentSubjectName() { final AccessControlContext acc = AccessController.getContext(); return AccessController.doPrivileged(new PrivilegedAction<String>() { @Override public String run() { Subject subject = Subject.getSubject(acc); if (subject == null) { return null; } Set<Principal> principals = subject.getPrincipals(); if (principals == null) { return null; } for (Principal p : principals) { return p.getName(); } return null; } }); }
static <T> T newConstructorInstance(Class<T> javaClass, Class<?>[] constructorParamTypes, Object... constructorParamInstances) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { if (System.getSecurityManager() != null) { try { return AccessController.doPrivileged(ConstructorNewInstanceAction.of(javaClass, constructorParamTypes, constructorParamInstances)); } catch (PrivilegedActionException e) { throw new WeldException(e.getCause()); } } else { return javaClass.getConstructor(constructorParamTypes).newInstance(constructorParamInstances); } }
public static InetAddress[] allAddressesByName(final String hostname) throws UnknownHostException { try { return AccessController.doPrivileged(new PrivilegedExceptionAction<InetAddress[]>() { @Override public InetAddress[] run() throws UnknownHostException { return InetAddress.getAllByName(hostname); } }); } catch (PrivilegedActionException e) { throw (UnknownHostException) e.getCause(); } }
public static ProtectionDomain getProtectionDomain(final Class source) { if (source == null) { return null; } return (ProtectionDomain) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { return source.getProtectionDomain(); } }); }
@Override @Nullable public Object getValue() throws Exception { final Method readMethod = this.pd.getReadMethod(); if (System.getSecurityManager() != null) { AccessController.doPrivileged((PrivilegedAction<Object>) () -> { ReflectionUtils.makeAccessible(readMethod); return null; }); try { return AccessController.doPrivileged((PrivilegedExceptionAction<Object>) () -> readMethod.invoke(getWrappedInstance(), (Object[]) null), acc); } catch (PrivilegedActionException pae) { throw pae.getException(); } } else { ReflectionUtils.makeAccessible(readMethod); return readMethod.invoke(getWrappedInstance(), (Object[]) null); } }
public Class<?> loadBeanClass(final String className) { try { return (Class<?>) AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { public Object run() throws Exception { return Class.forName(className, true, getClassLoader(this.getClass())); } }); } catch (PrivilegedActionException pae) { throw new WeldException(BeanMessage.CANNOT_LOAD_CLASS, className, pae.getException()); } }
/** * Return the security context for this bean factory. If a security manager * is set, interaction with the user code will be executed using the privileged * of the security context returned by this method. * @see AccessController#getContext() */ protected AccessControlContext getAccessControlContext() { return AccessController.getContext(); }
C:\ReflectionTest>java -Djava.security.manager CallFoo Exception in thread "main" java.security.AccessControlException: access denied (java.lang.reflect.ReflectPermission suppressAccessChecks) at java.security.AccessControlContext.checkPermission(AccessControlContext.java:264) at java.security.AccessController.checkPermission(AccessController.java:427) at java.lang.SecurityManager.checkPermission(SecurityManager.java:532) at java.lang.reflect.AccessibleObject.setAccessible(AccessibleObject.java:107) at CallFoo.main(CallFoo.java:8)
static <T> T newConstructorInstance(Class<T> javaClass, Class<?>[] constructorParamTypes, Object... constructorParamInstances) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { if (System.getSecurityManager() != null) { try { return AccessController.doPrivileged(ConstructorNewInstanceAction.of(javaClass, constructorParamTypes, constructorParamInstances)); } catch (PrivilegedActionException e) { throw new WeldException(e.getCause()); } } else { return javaClass.getConstructor(constructorParamTypes).newInstance(constructorParamInstances); } }
public static InetAddress addressByName(final String hostname) throws UnknownHostException { try { return AccessController.doPrivileged(new PrivilegedExceptionAction<InetAddress>() { @Override public InetAddress run() throws UnknownHostException { return InetAddress.getByName(hostname); } }); } catch (PrivilegedActionException e) { throw (UnknownHostException) e.getCause(); } }
public static SocketAddress localSocketAddress(final ServerSocket socket) { return AccessController.doPrivileged(new PrivilegedAction<SocketAddress>() { @Override public SocketAddress run() { return socket.getLocalSocketAddress(); } }); }
@Override public AccessControlContext getAccessControlContext() { return (this.acc != null ? this.acc : AccessController.getContext()); }
try { if (System.getSecurityManager() != null) { AccessController.checkPermission(fp); check.append("BeanRoot - success for WAR.txt; "); } else try { if (System.getSecurityManager() != null) { AccessController.checkPermission(fp); check.append("BeanRoot - success for EAR.txt; "); } else try { if (System.getSecurityManager() != null) { AccessController.checkPermission(p1); check.append("BeanRoot - success for EJB.txt; "); } else
/** * Returns a sun.misc.Unsafe. Suitable for use in a 3rd party package. Replace with a simple call * to Unsafe.getUnsafe when integrating into a jdk. * * @return a sun.misc.Unsafe */ private static sun.misc.Unsafe getUnsafe() { try { return sun.misc.Unsafe.getUnsafe(); } catch (SecurityException tryReflectionInstead) { } try { return java.security.AccessController.doPrivileged( new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() { public sun.misc.Unsafe run() throws Exception { Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class; for (java.lang.reflect.Field f : k.getDeclaredFields()) { f.setAccessible(true); Object x = f.get(null); if (k.isInstance(x)) return k.cast(x); } throw new NoSuchFieldError("the Unsafe"); } }); } catch (java.security.PrivilegedActionException e) { throw new RuntimeException("Could not initialize intrinsics", e.getCause()); } } }
static <T> T newConstructorInstance(Class<T> javaClass, Class<?>[] constructorParamTypes, Object... constructorParamInstances) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { if (System.getSecurityManager() != null) { try { return AccessController.doPrivileged(ConstructorNewInstanceAction.of(javaClass, constructorParamTypes, constructorParamInstances)); } catch (PrivilegedActionException e) { throw new WeldException(e.getCause()); } } else { return javaClass.getConstructor(constructorParamTypes).newInstance(constructorParamInstances); } }
public static SocketChannel accept(final ServerSocketChannel serverSocketChannel) throws IOException { try { return AccessController.doPrivileged(new PrivilegedExceptionAction<SocketChannel>() { @Override public SocketChannel run() throws IOException { return serverSocketChannel.accept(); } }); } catch (PrivilegedActionException e) { throw (IOException) e.getCause(); } }
public static InetSocketAddress socketAddress(final String hostname, final int port) { return AccessController.doPrivileged(new PrivilegedAction<InetSocketAddress>() { @Override public InetSocketAddress run() { return new InetSocketAddress(hostname, port); } }); }
/** * Return the security context for this bean factory. If a security manager * is set, interaction with the user code will be executed using the privileged * of the security context returned by this method. * @see AccessController#getContext() */ protected AccessControlContext getAccessControlContext() { return AccessController.getContext(); }
try { if (System.getSecurityManager() != null) { AccessController.checkPermission(filePermission); checkReport.append("servlet - success for WAR.txt; "); } else try { if (System.getSecurityManager() != null) { AccessController.checkPermission(filePermission); checkReport.append("servlet - success for EAR.txt; "); } else try { if (System.getSecurityManager() != null) { AccessController.checkPermission(filePermission); checkReport.append("servlet - success for EJB.txt; "); } else