当前位置: 首页>>代码示例>>Java>>正文


Java PrivilegedActionException.getCause方法代码示例

本文整理汇总了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);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:20,代码来源:MRApps.java

示例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);
            }
        }
    }
}
 
开发者ID:arquillian,项目名称:smart-testing,代码行数:28,代码来源:SecurityUtils.java

示例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();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:RMIIIOPServerImpl.java

示例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);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:TikaImpl.java

示例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;
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:25,代码来源:DefaultInstanceManager.java

示例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);
         }
      }
   }
}
 
开发者ID:arquillian,项目名称:arquillian-reporter,代码行数:45,代码来源:SecurityActions.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:42,代码来源:ServiceLoader.java

示例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;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:30,代码来源:ClassLoader.java

示例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());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:AzureComputeServiceImpl.java

示例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();
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:SocketAccess.java

示例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();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:PipeImpl.java

示例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();
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:Access.java

示例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);
            }
        }
    }
}
 
开发者ID:arquillian,项目名称:arquillian-reporter,代码行数:36,代码来源:Reporter.java

示例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);
            }
        }
    }
}
 
开发者ID:jenkinsci,项目名称:gitea-plugin,代码行数:40,代码来源:DefaultGiteaConnection.java

示例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;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:38,代码来源:CalendarSystem.java


注:本文中的java.security.PrivilegedActionException.getCause方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。