本文整理匯總了Java中java.security.PrivilegedActionException.getCause方法的典型用法代碼示例。如果您正苦於以下問題:Java PrivilegedActionException.getCause方法的具體用法?Java PrivilegedActionException.getCause怎麽用?Java PrivilegedActionException.getCause使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.security.PrivilegedActionException
的用法示例。
在下文中一共展示了PrivilegedActionException.getCause方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createJobClassLoader
import java.security.PrivilegedActionException; //導入方法依賴的package包/類
private static ClassLoader createJobClassLoader(final String appClasspath,
final String[] systemClasses) throws IOException {
try {
return AccessController.doPrivileged(
new PrivilegedExceptionAction<ClassLoader>() {
@Override
public ClassLoader run() throws MalformedURLException {
return new ApplicationClassLoader(appClasspath,
MRApps.class.getClassLoader(), Arrays.asList(systemClasses));
}
});
} catch (PrivilegedActionException e) {
Throwable t = e.getCause();
if (t instanceof MalformedURLException) {
throw (MalformedURLException) t;
}
throw new IOException(e);
}
}
示例2: getConstructor
import java.security.PrivilegedActionException; //導入方法依賴的package包/類
/**
* Obtains the Constructor specified from the given Class and argument types
*/
private static <T> Constructor<T> getConstructor(final Class<T> clazz, final Class<?>... argumentTypes)
throws NoSuchMethodException {
try {
return AccessController.doPrivileged(
(PrivilegedExceptionAction<Constructor<T>>) () -> clazz.getDeclaredConstructor(argumentTypes));
}
// Unwrap
catch (final PrivilegedActionException pae) {
final Throwable t = pae.getCause();
// Rethrow
if (t instanceof NoSuchMethodException) {
throw (NoSuchMethodException) t;
} else {
// No other checked Exception thrown by Class.getConstructor
try {
throw (RuntimeException) t;
}
// Just in case we've really messed up
catch (final ClassCastException cce) {
throw new RuntimeException("Obtained unchecked Exception; this code should never be reached", t);
}
}
}
}
示例3: doNewClient
import java.security.PrivilegedActionException; //導入方法依賴的package包/類
@Override
RMIConnection doNewClient(final Object credentials) throws IOException {
if (callerACC == null) {
throw new SecurityException("AccessControlContext cannot be null");
}
try {
return AccessController.doPrivileged(
new PrivilegedExceptionAction<RMIConnection>() {
public RMIConnection run() throws IOException {
return superDoNewClient(credentials);
}
}, callerACC);
} catch (PrivilegedActionException pae) {
throw (IOException) pae.getCause();
}
}
示例4: parse
import java.security.PrivilegedActionException; //導入方法依賴的package包/類
/**
* parses with tika, throwing any exception hit while parsing the document
*/
// only package private for testing!
static String parse(final byte content[], final Metadata metadata, final int limit) throws TikaException, IOException {
// check that its not unprivileged code like a script
SpecialPermission.check();
try {
return AccessController.doPrivileged((PrivilegedExceptionAction<String>)
() -> TIKA_INSTANCE.parseToString(new ByteArrayInputStream(content), metadata, limit), RESTRICTED_CONTEXT);
} catch (PrivilegedActionException e) {
// checked exception from tika: unbox it
Throwable cause = e.getCause();
if (cause instanceof TikaException) {
throw (TikaException) cause;
} else if (cause instanceof IOException) {
throw (IOException) cause;
} else {
throw new AssertionError(cause);
}
}
}
示例5: loadClassMaybePrivileged
import java.security.PrivilegedActionException; //導入方法依賴的package包/類
protected Class<?> loadClassMaybePrivileged(final String className, final ClassLoader classLoader) throws ClassNotFoundException {
Class<?> clazz;
if (SecurityUtil.isPackageProtectionEnabled()) {
try {
clazz = AccessController.doPrivileged(new PrivilegedExceptionAction<Class<?>>() {
@Override
public Class<?> run() throws Exception {
return loadClass(className, classLoader);
}
});
} catch (PrivilegedActionException e) {
Throwable t = e.getCause();
if (t instanceof ClassNotFoundException) {
throw (ClassNotFoundException) t;
}
throw new RuntimeException(t);
}
} else {
clazz = loadClass(className, classLoader);
}
checkAccess(clazz);
return clazz;
}
示例6: getConstructor
import java.security.PrivilegedActionException; //導入方法依賴的package包/類
/**
* Obtains the Constructor specified from the given Class and argument types
* @param clazz
* @param argumentTypes
* @return
* @throws NoSuchMethodException
*/
static <T> Constructor<T> getConstructor(final Class<T> clazz, final Class<?>... argumentTypes)
throws NoSuchMethodException
{
try
{
return AccessController.doPrivileged(new PrivilegedExceptionAction<Constructor<T>>()
{
public Constructor<T> run() throws NoSuchMethodException
{
return clazz.getDeclaredConstructor(argumentTypes);
}
});
}
// Unwrap
catch (final PrivilegedActionException pae)
{
final Throwable t = pae.getCause();
// Rethrow
if (t instanceof NoSuchMethodException)
{
throw (NoSuchMethodException) t;
}
else
{
// No other checked Exception thrown by Class.getConstructor
try
{
throw (RuntimeException) t;
}
// Just in case we've really messed up
catch (final ClassCastException cce)
{
throw new RuntimeException("Obtained unchecked Exception; this code should never be reached", t);
}
}
}
}
示例7: invokeFactoryMethod
import java.security.PrivilegedActionException; //導入方法依賴的package包/類
/**
* Invokes the provider's "provider" method to instantiate a provider.
* When running with a security manager then the method runs with
* permissions that are restricted by the security context of whatever
* created this loader.
*/
private S invokeFactoryMethod() {
Object result = null;
Throwable exc = null;
if (acc == null) {
try {
result = factoryMethod.invoke(null);
} catch (Throwable x) {
exc = x;
}
} else {
PrivilegedExceptionAction<?> pa = new PrivilegedExceptionAction<>() {
@Override
public Object run() throws Exception {
return factoryMethod.invoke(null);
}
};
// invoke factory method with permissions restricted by acc
try {
result = AccessController.doPrivileged(pa, acc);
} catch (PrivilegedActionException pae) {
exc = pae.getCause();
}
}
if (exc != null) {
if (exc instanceof InvocationTargetException)
exc = exc.getCause();
fail(service, factoryMethod + " failed", exc);
}
if (result == null) {
fail(service, factoryMethod + " returned null");
}
@SuppressWarnings("unchecked")
S p = (S) result;
return p;
}
示例8: initSystemClassLoader
import java.security.PrivilegedActionException; //導入方法依賴的package包/類
private static synchronized void initSystemClassLoader() {
if (!sclSet) {
if (scl != null)
throw new IllegalStateException("recursive invocation");
sun.misc.Launcher l = sun.misc.Launcher.getLauncher();
if (l != null) {
Throwable oops = null;
scl = l.getClassLoader();
try {
scl = AccessController.doPrivileged(
new SystemClassLoaderAction(scl));
} catch (PrivilegedActionException pae) {
oops = pae.getCause();
if (oops instanceof InvocationTargetException) {
oops = oops.getCause();
}
}
if (oops != null) {
if (oops instanceof Error) {
throw (Error) oops;
} else {
// wrap the exception
throw new Error(oops);
}
}
}
sclSet = true;
}
}
示例9: getServiceDetails
import java.security.PrivilegedActionException; //導入方法依賴的package包/類
@Override
public HostedServiceGetDetailedResponse getServiceDetails() {
SpecialPermission.check();
try {
return AccessController.doPrivileged((PrivilegedExceptionAction<HostedServiceGetDetailedResponse>)
() -> client.getHostedServicesOperations().getDetailed(serviceName));
} catch (PrivilegedActionException e) {
throw new AzureServiceRemoteException("can not get list of azure nodes", e.getCause());
}
}
示例10: doPrivilegedException
import java.security.PrivilegedActionException; //導入方法依賴的package包/類
public static <T> T doPrivilegedException(PrivilegedExceptionAction<T> operation) throws StorageException, URISyntaxException {
SpecialPermission.check();
try {
return AccessController.doPrivileged(operation);
} catch (PrivilegedActionException e) {
throw (StorageException) e.getCause();
}
}
示例11: PipeImpl
import java.security.PrivilegedActionException; //導入方法依賴的package包/類
PipeImpl(final SelectorProvider sp) throws IOException {
try {
AccessController.doPrivileged(new Initializer(sp));
} catch (PrivilegedActionException x) {
throw (IOException)x.getCause();
}
}
示例12: doPrivilegedIOException
import java.security.PrivilegedActionException; //導入方法依賴的package包/類
public static <T> T doPrivilegedIOException(PrivilegedExceptionAction<T> operation) throws IOException {
SpecialPermission.check();
try {
return AccessController.doPrivileged(operation);
} catch (PrivilegedActionException e) {
throw (IOException) e.getCause();
}
}
示例13: getConstructor
import java.security.PrivilegedActionException; //導入方法依賴的package包/類
/**
* Obtains the Constructor specified from the given Class and argument types
*
* @param clazz
* @param argumentTypes
* @return
* @throws NoSuchMethodException
*/
private static <T> Constructor<T> getConstructor(final Class<T> clazz, final Class<?>... argumentTypes)
throws NoSuchMethodException {
try {
return AccessController.doPrivileged(new PrivilegedExceptionAction<Constructor<T>>() {
public Constructor<T> run() throws NoSuchMethodException {
return clazz.getDeclaredConstructor(argumentTypes);
}
});
}
// Unwrap
catch (final PrivilegedActionException pae) {
final Throwable t = pae.getCause();
// Rethrow
if (t instanceof NoSuchMethodException) {
throw (NoSuchMethodException) t;
} else {
// No other checked Exception thrown by Class.getConstructor
try {
throw (RuntimeException) t;
}
// Just in case we've really messed up
catch (final ClassCastException cce) {
throw new RuntimeException("Obtained unchecked Exception; this code should never be reached", t);
}
}
}
}
示例14: setRequestMethodViaJreBugWorkaround
import java.security.PrivilegedActionException; //導入方法依賴的package包/類
/**
* Workaround for a bug in {@code HttpURLConnection.setRequestMethod(String)}
* The implementation of Sun/Oracle is throwing a {@code ProtocolException}
* when the method is other than the HTTP/1.1 default methods. So to use {@code PROPFIND}
* and others, we must apply this workaround.
*/
private static void setRequestMethodViaJreBugWorkaround(final HttpURLConnection httpURLConnection,
final String method) {
try {
httpURLConnection.setRequestMethod(method); // Check whether we are running on a buggy JRE
} catch (final ProtocolException pe) {
try {
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
@Override
public Object run() throws NoSuchFieldException, IllegalAccessException {
final Object target;
if (httpURLConnection instanceof HttpsURLConnection) {
final Field delegate = httpURLConnection.getClass().getDeclaredField("delegate");
delegate.setAccessible(true);
target = delegate.get(httpURLConnection);
} else {
target = httpURLConnection;
}
final Field methodField = HttpURLConnection.class.getDeclaredField("method");
methodField.setAccessible(true);
methodField.set(target, method);
return null;
}
});
} catch (final PrivilegedActionException e) {
final Throwable cause = e.getCause();
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
} else {
throw new RuntimeException(cause);
}
}
}
}
示例15: getCalendarProperties
import java.security.PrivilegedActionException; //導入方法依賴的package包/類
/**
* Returns a {@link Properties} loaded from lib/calendars.properties.
*
* @return a {@link Properties} loaded from lib/calendars.properties
* @throws IOException if an error occurred when reading from the input stream
* @throws IllegalArgumentException if the input stream contains any malformed
* Unicode escape sequences
*/
public static Properties getCalendarProperties() throws IOException {
Properties calendarProps = null;
try {
String homeDir = AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("java.home"));
final String fname = homeDir + File.separator + "lib" + File.separator
+ "calendars.properties";
calendarProps = AccessController.doPrivileged(new PrivilegedExceptionAction<Properties>() {
@Override
public Properties run() throws IOException {
Properties props = new Properties();
try (FileInputStream fis = new FileInputStream(fname)) {
props.load(fis);
}
return props;
}
});
} catch (PrivilegedActionException e) {
Throwable cause = e.getCause();
if (cause instanceof IOException) {
throw (IOException) cause;
} else if (cause instanceof IllegalArgumentException) {
throw (IllegalArgumentException) cause;
}
// Should not happen
throw new InternalError(cause);
}
return calendarProps;
}