java.security.PrivilegedActionException#getException ( )源码实例Demo

下面列出了java.security.PrivilegedActionException#getException ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jdk8u-jdk   文件: HttpURLConnection.java
@Override
public synchronized OutputStream getOutputStream() throws IOException {
    connecting = true;
    SocketPermission p = URLtoSocketPermission(this.url);

    if (p != null) {
        try {
            return AccessController.doPrivileged(
                new PrivilegedExceptionAction<OutputStream>() {
                    public OutputStream run() throws IOException {
                        return getOutputStream0();
                    }
                }, null, p
            );
        } catch (PrivilegedActionException e) {
            throw (IOException) e.getException();
        }
    } else {
        return getOutputStream0();
    }
}
 
源代码2 项目: Tomcat7.0.67   文件: PersistentManagerBase.java
/**
 * Remove this Session from the active Sessions for this Manager,
 * and from the Store.
 *
 * @param id Session's id to be removed
 */    
protected void removeSession(String id){
    try {
        if (SecurityUtil.isPackageProtectionEnabled()){
            try{
                AccessController.doPrivileged(new PrivilegedStoreRemove(id));
            }catch(PrivilegedActionException ex){
                Exception exception = ex.getException();
                log.error("Exception in the Store during removeSession: "
                          + exception, exception);
            }
        } else {
             store.remove(id);
        }               
    } catch (IOException e) {
        log.error("Exception removing session  " + e.getMessage(), e);
    }        
}
 
源代码3 项目: TencentKona-8   文件: VersionHelper12.java
NamingEnumeration<InputStream> getResources(final ClassLoader cl,
        final String name) throws IOException {
    Enumeration<URL> urls;
    try {
        urls = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Enumeration<URL>>() {
                public Enumeration<URL> run() throws IOException {
                    return (cl == null)
                        ? ClassLoader.getSystemResources(name)
                        : cl.getResources(name);
                }
            }
        );
    } catch (PrivilegedActionException e) {
        throw (IOException)e.getException();
    }
    return new InputStreamEnumeration(urls);
}
 
源代码4 项目: openjdk-jdk8u-backup   文件: Executors.java
public T call() throws Exception {
    try {
        return AccessController.doPrivileged(
            new PrivilegedExceptionAction<T>() {
                public T run() throws Exception {
                    Thread t = Thread.currentThread();
                    ClassLoader cl = t.getContextClassLoader();
                    if (ccl == cl) {
                        return task.call();
                    } else {
                        t.setContextClassLoader(ccl);
                        try {
                            return task.call();
                        } finally {
                            t.setContextClassLoader(cl);
                        }
                    }
                }
            }, acc);
    } catch (PrivilegedActionException e) {
        throw e.getException();
    }
}
 
源代码5 项目: openjdk-jdk8u   文件: ActivationID.java
/**
 * Activate the object for this id.
 *
 * @param force if true, forces the activator to contact the group
 * when activating the object (instead of returning a cached reference);
 * if false, returning a cached value is acceptable.
 * @return the reference to the active remote object
 * @exception ActivationException if activation fails
 * @exception UnknownObjectException if the object is unknown
 * @exception RemoteException if remote call fails
 * @since 1.2
 */
public Remote activate(boolean force)
    throws ActivationException, UnknownObjectException, RemoteException
{
    try {
        MarshalledObject<? extends Remote> mobj =
            activator.activate(this, force);
        return AccessController.doPrivileged(
            new PrivilegedExceptionAction<Remote>() {
                public Remote run() throws IOException, ClassNotFoundException {
                    return mobj.get();
                }
            }, NOPERMS_ACC);
    } catch (PrivilegedActionException pae) {
        Exception ex = pae.getException();
        if (ex instanceof RemoteException) {
            throw (RemoteException) ex;
        } else {
            throw new UnmarshalException("activation failed", ex);
        }
    }

}
 
源代码6 项目: jdk1.8-source-analysis   文件: SecuritySupport.java
static FileInputStream getFileInputStream(final File file)
throws FileNotFoundException
{
    try {
        return (FileInputStream)
        AccessController.doPrivileged(new PrivilegedExceptionAction() {
            public Object run() throws FileNotFoundException {
                return new FileInputStream(file);
            }
        });
    } catch (PrivilegedActionException e) {
        throw (FileNotFoundException)e.getException();
    }
}
 
@Override
public Configuration[] listConfigurations(final String filterString)
    throws IOException, InvalidSyntaxException
{
  Configuration[] configurations = null;

  try {
    configurations =
      AccessController
          .doPrivileged(new PrivilegedExceptionAction<Configuration[]>() {
            @Override
            public Configuration[] run()
                throws IOException, InvalidSyntaxException
            {
              return ConfigurationAdminFactory.this
                  .listConfigurations(filterString,
                                      ConfigurationAdminImpl.this.callingBundle,
                                      true);
            }
          });
  } catch (final PrivilegedActionException e) {
    final Exception ee = e.getException();
    // Android don't supply nested exception
    if (ee != null) {
      if (ee instanceof InvalidSyntaxException) {
        throw (InvalidSyntaxException) ee;
      }
      throw (IOException) ee;
    } else {
      throw new IOException("Failed to handle CM data");
    }
  }
  return configurations;
}
 
源代码8 项目: jdk8u60   文件: DOMKeyValue.java
EC(PublicKey key) throws KeyException {
    super(key);
    ECPublicKey ecKey = (ECPublicKey)key;
    ECPoint ecPoint = ecKey.getW();
    ecParams = ecKey.getParams();
    try {
        AccessController.doPrivileged(
            new PrivilegedExceptionAction<Void>() {
                public Void run() throws
                    ClassNotFoundException, NoSuchMethodException
                {
                    getMethods();
                    return null;
                }
            }
        );
    } catch (PrivilegedActionException pae) {
        throw new KeyException("ECKeyValue not supported",
                                pae.getException());
    }
    Object[] args = new Object[] { ecPoint, ecParams.getCurve() };
    try {
        ecPublicKey = (byte[])encodePoint.invoke(null, args);
    } catch (IllegalAccessException iae) {
        throw new KeyException(iae);
    } catch (InvocationTargetException ite) {
        throw new KeyException(ite);
    }
}
 
源代码9 项目: openjdk-8   文件: SecuritySupport.java
FileInputStream getFileInputStream(final File file)
throws FileNotFoundException
{
    try {
        return (FileInputStream)
        AccessController.doPrivileged(new PrivilegedExceptionAction() {
            public Object run() throws FileNotFoundException {
                return new FileInputStream(file);
            }
        });
    } catch (PrivilegedActionException e) {
        throw (FileNotFoundException)e.getException();
    }
}
 
源代码10 项目: openjdk-jdk8u-backup   文件: Context.java
/**
 * Does something using the Subject inside
 * @param action the action
 * @param in the input byte
 * @return the output byte
 * @throws java.lang.Exception
 */
public byte[] doAs(final Action action, final byte[] in) throws Exception {
    try {
        return Subject.doAs(s, new PrivilegedExceptionAction<byte[]>() {

            @Override
            public byte[] run() throws Exception {
                return action.run(Context.this, in);
            }
        });
    } catch (PrivilegedActionException pae) {
        throw pae.getException();
    }
}
 
源代码11 项目: jdk8u-dev-jdk   文件: AtomicIntegerFieldUpdater.java
AtomicIntegerFieldUpdaterImpl(final Class<T> tclass,
                              final String fieldName,
                              final Class<?> caller) {
    final Field field;
    final int modifiers;
    try {
        field = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Field>() {
                public Field run() throws NoSuchFieldException {
                    return tclass.getDeclaredField(fieldName);
                }
            });
        modifiers = field.getModifiers();
        sun.reflect.misc.ReflectUtil.ensureMemberAccess(
            caller, tclass, null, modifiers);
        ClassLoader cl = tclass.getClassLoader();
        ClassLoader ccl = caller.getClassLoader();
        if ((ccl != null) && (ccl != cl) &&
            ((cl == null) || !isAncestor(cl, ccl))) {
          sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass);
        }
    } catch (PrivilegedActionException pae) {
        throw new RuntimeException(pae.getException());
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    Class<?> fieldt = field.getType();
    if (fieldt != int.class)
        throw new IllegalArgumentException("Must be integer type");

    if (!Modifier.isVolatile(modifiers))
        throw new IllegalArgumentException("Must be volatile type");

    this.cclass = (Modifier.isProtected(modifiers) &&
                   caller != tclass) ? caller : null;
    this.tclass = tclass;
    offset = unsafe.objectFieldOffset(field);
}
 
源代码12 项目: rome   文件: SecuritySupport.java
FileInputStream getFileInputStream(final File file) throws FileNotFoundException {
    try {
        final PrivilegedExceptionAction<FileInputStream> action = new PrivilegedExceptionAction<FileInputStream>() {
            @Override
            public FileInputStream run() throws FileNotFoundException {
                return new FileInputStream(file);
            }
        };
        return AccessController.doPrivileged(action);
    } catch (final PrivilegedActionException e) {
        throw (FileNotFoundException) e.getException();
    }
}
 
源代码13 项目: cxf   文件: JAXBEncoderDecoder.java
public static Object unmarshall(final Unmarshaller u,
                                final Object source,
                                final QName elName,
                                final Class<?> clazz,
                                final boolean unwrap) {
    try {
        return AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
            public Object run() throws Exception {
                return doUnmarshal(u, source, elName, clazz, unwrap);
            }
        });
    } catch (PrivilegedActionException e) {
        Exception ex = e.getException();
        if (ex instanceof Fault) {
            throw (Fault)ex;
        }
        if (ex instanceof javax.xml.bind.UnmarshalException) {
            javax.xml.bind.UnmarshalException unmarshalEx = (javax.xml.bind.UnmarshalException)ex;
            if (unmarshalEx.getLinkedException() != null) {
                throw new Fault(new Message("UNMARSHAL_ERROR", LOG,
                                        unmarshalEx.getLinkedException().getMessage()), ex);
            }
            throw new Fault(new Message("UNMARSHAL_ERROR", LOG,
                                        unmarshalEx.getMessage()), ex);
        }
        throw new Fault(new Message("UNMARSHAL_ERROR", LOG, ex.getMessage()), ex);
    }
}
 
源代码14 项目: spliceengine   文件: ErrorStreamTest.java
private static void assertNotDirectory(final File f) throws IOException {
    try {
        AccessController.doPrivileged (new PrivilegedExceptionAction() {
            public Object run() throws IOException {
                assertFalse("assertNotDirectory failed: " +
                      f.getCanonicalPath(), f.isDirectory());
                return null;
            }
        });
    } catch (PrivilegedActionException e) {
        // e.getException() should be an instance of IOException.
        throw (IOException) e.getException();
    }
}
 
源代码15 项目: jdk8u-jdk   文件: AtomicIntegerFieldUpdater.java
AtomicIntegerFieldUpdaterImpl(final Class<T> tclass,
                              final String fieldName,
                              final Class<?> caller) {
    final Field field;
    final int modifiers;
    try {
        field = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Field>() {
                public Field run() throws NoSuchFieldException {
                    return tclass.getDeclaredField(fieldName);
                }
            });
        modifiers = field.getModifiers();
        sun.reflect.misc.ReflectUtil.ensureMemberAccess(
            caller, tclass, null, modifiers);
        ClassLoader cl = tclass.getClassLoader();
        ClassLoader ccl = caller.getClassLoader();
        if ((ccl != null) && (ccl != cl) &&
            ((cl == null) || !isAncestor(cl, ccl))) {
            sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass);
        }
    } catch (PrivilegedActionException pae) {
        throw new RuntimeException(pae.getException());
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    if (field.getType() != int.class)
        throw new IllegalArgumentException("Must be integer type");

    if (!Modifier.isVolatile(modifiers))
        throw new IllegalArgumentException("Must be volatile type");

    // Access to protected field members is restricted to receivers only
    // of the accessing class, or one of its subclasses, and the
    // accessing class must in turn be a subclass (or package sibling)
    // of the protected member's defining class.
    // If the updater refers to a protected field of a declaring class
    // outside the current package, the receiver argument will be
    // narrowed to the type of the accessing class.
    this.cclass = (Modifier.isProtected(modifiers) &&
                   tclass.isAssignableFrom(caller) &&
                   !isSamePackage(tclass, caller))
                  ? caller : tclass;
    this.tclass = tclass;
    this.offset = U.objectFieldOffset(field);
}
 
源代码16 项目: jdk8u-jdk   文件: URLJarFile.java
/**
 * Given a URL, retrieves a JAR file, caches it to disk, and creates a
 * cached JAR file object.
 */
 private static JarFile retrieve(final URL url, final URLJarFileCloseController closeController) throws IOException {
    /*
     * See if interface is set, then call retrieve function of the class
     * that implements URLJarFileCallBack interface (sun.plugin - to
     * handle the cache failure for JARJAR file.)
     */
    if (callback != null)
    {
        return callback.retrieve(url);
    }

    else
    {

        JarFile result = null;

        /* get the stream before asserting privileges */
        try (final InputStream in = url.openConnection().getInputStream()) {
            result = AccessController.doPrivileged(
                new PrivilegedExceptionAction<JarFile>() {
                    public JarFile run() throws IOException {
                        Path tmpFile = Files.createTempFile("jar_cache", null);
                        try {
                            Files.copy(in, tmpFile, StandardCopyOption.REPLACE_EXISTING);
                            JarFile jarFile = new URLJarFile(tmpFile.toFile(), closeController);
                            tmpFile.toFile().deleteOnExit();
                            return jarFile;
                        } catch (Throwable thr) {
                            try {
                                Files.delete(tmpFile);
                            } catch (IOException ioe) {
                                thr.addSuppressed(ioe);
                            }
                            throw thr;
                        }
                    }
                });
        } catch (PrivilegedActionException pae) {
            throw (IOException) pae.getException();
        }

        return result;
    }
}
 
源代码17 项目: jdk8u-jdk   文件: AtomicLongFieldUpdater.java
LockedUpdater(final Class<T> tclass, final String fieldName,
              final Class<?> caller) {
    Field field = null;
    int modifiers = 0;
    try {
        field = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Field>() {
                public Field run() throws NoSuchFieldException {
                    return tclass.getDeclaredField(fieldName);
                }
            });
        modifiers = field.getModifiers();
        sun.reflect.misc.ReflectUtil.ensureMemberAccess(
            caller, tclass, null, modifiers);
        ClassLoader cl = tclass.getClassLoader();
        ClassLoader ccl = caller.getClassLoader();
        if ((ccl != null) && (ccl != cl) &&
            ((cl == null) || !isAncestor(cl, ccl))) {
            sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass);
        }
    } catch (PrivilegedActionException pae) {
        throw new RuntimeException(pae.getException());
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    if (field.getType() != long.class)
        throw new IllegalArgumentException("Must be long type");

    if (!Modifier.isVolatile(modifiers))
        throw new IllegalArgumentException("Must be volatile type");

    // Access to protected field members is restricted to receivers only
    // of the accessing class, or one of its subclasses, and the
    // accessing class must in turn be a subclass (or package sibling)
    // of the protected member's defining class.
    // If the updater refers to a protected field of a declaring class
    // outside the current package, the receiver argument will be
    // narrowed to the type of the accessing class.
    this.cclass = (Modifier.isProtected(modifiers) &&
                   tclass.isAssignableFrom(caller) &&
                   !isSamePackage(tclass, caller))
                  ? caller : tclass;
    this.tclass = tclass;
    this.offset = U.objectFieldOffset(field);
}
 
源代码18 项目: jdk-1.7-annotated   文件: Calendar.java
/**
 * Reconstitutes this object from a stream (i.e., deserialize it).
 */
private void readObject(ObjectInputStream stream)
     throws IOException, ClassNotFoundException
{
    final ObjectInputStream input = stream;
    input.defaultReadObject();

    stamp = new int[FIELD_COUNT];

    // Starting with version 2 (not implemented yet), we expect that
    // fields[], isSet[], isTimeSet, and areFieldsSet may not be
    // streamed out anymore.  We expect 'time' to be correct.
    if (serialVersionOnStream >= 2)
    {
        isTimeSet = true;
        if (fields == null) fields = new int[FIELD_COUNT];
        if (isSet == null) isSet = new boolean[FIELD_COUNT];
    }
    else if (serialVersionOnStream >= 0)
    {
        for (int i=0; i<FIELD_COUNT; ++i)
            stamp[i] = isSet[i] ? COMPUTED : UNSET;
    }

    serialVersionOnStream = currentSerialVersion;

    // If there's a ZoneInfo object, use it for zone.
    ZoneInfo zi = null;
    try {
        zi = AccessController.doPrivileged(
                new PrivilegedExceptionAction<ZoneInfo>() {
                    public ZoneInfo run() throws Exception {
                        return (ZoneInfo) input.readObject();
                    }
                },
                CalendarAccessControlContext.INSTANCE);
    } catch (PrivilegedActionException pae) {
        Exception e = pae.getException();
        if (!(e instanceof OptionalDataException)) {
            if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
            } else if (e instanceof IOException) {
                throw (IOException) e;
            } else if (e instanceof ClassNotFoundException) {
                throw (ClassNotFoundException) e;
            }
            throw new RuntimeException(e);
        }
    }
    if (zi != null) {
        zone = zi;
    }

    // If the deserialized object has a SimpleTimeZone, try to
    // replace it with a ZoneInfo equivalent (as of 1.4) in order
    // to be compatible with the SimpleTimeZone-based
    // implementation as much as possible.
    if (zone instanceof SimpleTimeZone) {
        String id = zone.getID();
        TimeZone tz = TimeZone.getTimeZone(id);
        if (tz != null && tz.hasSameRules(zone) && tz.getID().equals(id)) {
            zone = tz;
        }
    }
}
 
源代码19 项目: jdk8u-jdk   文件: ExtensionDependency.java
protected boolean checkExtensionAgainst(String extensionName,
                                        Attributes attr,
                                        final File file)
    throws IOException,
           FileNotFoundException,
           ExtensionInstallationException
{

    debug("Checking extension " + extensionName +
          " against " + file.getName());

    // Load the jar file ...
    Manifest man;
    try {
        man = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Manifest>() {
                public Manifest run()
                        throws IOException, FileNotFoundException {
                     if (!file.exists())
                         throw new FileNotFoundException(file.getName());
                     JarFile jarFile =  new JarFile(file);
                     return jarFile.getManifest();
                 }
             });
    } catch(PrivilegedActionException e) {
        if (e.getException() instanceof FileNotFoundException)
            throw (FileNotFoundException) e.getException();
        throw (IOException) e.getException();
    }

    // Construct the extension information object
    ExtensionInfo reqInfo = new ExtensionInfo(extensionName, attr);
    debug("Requested Extension : " + reqInfo);

    int isCompatible = ExtensionInfo.INCOMPATIBLE;
    ExtensionInfo instInfo = null;

    if (man != null) {
        Attributes instAttr = man.getMainAttributes();
        if (instAttr != null) {
            instInfo = new ExtensionInfo(null, instAttr);
            debug("Extension Installed " + instInfo);
            isCompatible = instInfo.isCompatibleWith(reqInfo);
            switch(isCompatible) {
            case ExtensionInfo.COMPATIBLE:
                debug("Extensions are compatible");
                return true;

            case ExtensionInfo.INCOMPATIBLE:
                debug("Extensions are incompatible");
                return false;

            default:
                // everything else
                debug("Extensions require an upgrade or vendor switch");
                return installExtension(reqInfo, instInfo);

            }
        }
    }
    return false;
}
 
源代码20 项目: JDKSourceCode1.8   文件: Init.java
/**
 * Dynamically initialise the library by registering the default algorithms/implementations
 */
private static void dynamicInit() {
    //
    // Load the Resource Bundle - the default is the English resource bundle.
    // To load another resource bundle, call I18n.init(...) before calling this
    // method.
    //
    I18n.init("en", "US");

    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Registering default algorithms");
    }
    try {
        AccessController.doPrivileged(new PrivilegedExceptionAction<Void>(){
            @Override public Void run() throws XMLSecurityException {
                //
                // Bind the default prefixes
                //
                ElementProxy.registerDefaultPrefixes();

                //
                // Set the default Transforms
                //
                Transform.registerDefaultAlgorithms();

                //
                // Set the default signature algorithms
                //
                SignatureAlgorithm.registerDefaultAlgorithms();

                //
                // Set the default JCE algorithms
                //
                JCEMapper.registerDefaultAlgorithms();

                //
                // Set the default c14n algorithms
                //
                Canonicalizer.registerDefaultAlgorithms();

                //
                // Register the default resolvers
                //
                ResourceResolver.registerDefaultResolvers();

                //
                // Register the default key resolvers
                //
                KeyResolver.registerDefaultResolvers();

                return null;
            }
       });
    } catch (PrivilegedActionException ex) {
        XMLSecurityException xse = (XMLSecurityException)ex.getException();
        log.log(java.util.logging.Level.SEVERE, xse.getMessage(), xse);
        xse.printStackTrace();
    }
}