Search in sources :

Example 41 with PrivilegedActionException

use of java.security.PrivilegedActionException in project jdk8u_jdk by JetBrains.

the class EmptyInputStream method getInputStream.

@Override
public synchronized InputStream getInputStream() throws IOException {
    connecting = true;
    SocketPermission p = URLtoSocketPermission(this.url);
    if (p != null) {
        try {
            return AccessController.doPrivilegedWithCombiner(new PrivilegedExceptionAction<InputStream>() {

                public InputStream run() throws IOException {
                    return getInputStream0();
                }
            }, null, p);
        } catch (PrivilegedActionException e) {
            throw (IOException) e.getException();
        }
    } else {
        return getInputStream0();
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) ChunkedInputStream(sun.net.www.http.ChunkedInputStream) SocketPermission(java.net.SocketPermission)

Example 42 with PrivilegedActionException

use of java.security.PrivilegedActionException in project jdk8u_jdk by JetBrains.

the class EmptyInputStream method getOutputStream.

/*
     * Allowable input/output sequences:
     * [interpreted as request entity]
     * - get output, [write output,] get input, [read input]
     * - get output, [write output]
     * [interpreted as GET]
     * - get input, [read input]
     * Disallowed:
     * - get input, [read input,] get output, [write output]
     */
@Override
public synchronized OutputStream getOutputStream() throws IOException {
    connecting = true;
    SocketPermission p = URLtoSocketPermission(this.url);
    if (p != null) {
        try {
            return AccessController.doPrivilegedWithCombiner(new PrivilegedExceptionAction<OutputStream>() {

                public OutputStream run() throws IOException {
                    return getOutputStream0();
                }
            }, null, p);
        } catch (PrivilegedActionException e) {
            throw (IOException) e.getException();
        }
    } else {
        return getOutputStream0();
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) SocketPermission(java.net.SocketPermission) ChunkedOutputStream(sun.net.www.http.ChunkedOutputStream) PosterOutputStream(sun.net.www.http.PosterOutputStream)

Example 43 with PrivilegedActionException

use of java.security.PrivilegedActionException in project jdk8u_jdk by JetBrains.

the class PollingWatchService method register.

/**
     * Register the given file with this watch service
     */
@Override
WatchKey register(final Path path, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) throws IOException {
    // check events - CCE will be thrown if there are invalid elements
    final Set<WatchEvent.Kind<?>> eventSet = new HashSet<WatchEvent.Kind<?>>(events.length);
    for (WatchEvent.Kind<?> event : events) {
        // standard events
        if (event == StandardWatchEventKinds.ENTRY_CREATE || event == StandardWatchEventKinds.ENTRY_MODIFY || event == StandardWatchEventKinds.ENTRY_DELETE) {
            eventSet.add(event);
            continue;
        }
        // OVERFLOW is ignored
        if (event == StandardWatchEventKinds.OVERFLOW) {
            continue;
        }
        // null/unsupported
        if (event == null)
            throw new NullPointerException("An element in event set is 'null'");
        throw new UnsupportedOperationException(event.name());
    }
    if (eventSet.isEmpty())
        throw new IllegalArgumentException("No events to register");
    // A modifier may be used to specify the sensitivity level
    SensitivityWatchEventModifier sensivity = SensitivityWatchEventModifier.MEDIUM;
    if (modifiers.length > 0) {
        for (WatchEvent.Modifier modifier : modifiers) {
            if (modifier == null)
                throw new NullPointerException();
            if (modifier instanceof SensitivityWatchEventModifier) {
                sensivity = (SensitivityWatchEventModifier) modifier;
                continue;
            }
            throw new UnsupportedOperationException("Modifier not supported");
        }
    }
    // check if watch service is closed
    if (!isOpen())
        throw new ClosedWatchServiceException();
    // attributes of the entries in the directory.
    try {
        final SensitivityWatchEventModifier s = sensivity;
        return AccessController.doPrivileged(new PrivilegedExceptionAction<PollingWatchKey>() {

            @Override
            public PollingWatchKey run() throws IOException {
                return doPrivilegedRegister(path, eventSet, s);
            }
        });
    } catch (PrivilegedActionException pae) {
        Throwable cause = pae.getCause();
        if (cause != null && cause instanceof IOException)
            throw (IOException) cause;
        throw new AssertionError(pae);
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) SensitivityWatchEventModifier(com.sun.nio.file.SensitivityWatchEventModifier)

Example 44 with PrivilegedActionException

use of java.security.PrivilegedActionException in project jdk8u_jdk by JetBrains.

the class ActivationGroupImpl method newInstance.

/**
     * Creates a new instance of an activatable remote object. The
     * <code>Activator</code> calls this method to create an activatable
     * object in this group. This method should be idempotent; a call to
     * activate an already active object should return the previously
     * activated object.
     *
     * Note: this method assumes that the Activator will only invoke
     * newInstance for the same object in a serial fashion (i.e.,
     * the activator will not allow the group to see concurrent requests
     * to activate the same object.
     *
     * @param id the object's activation identifier
     * @param desc the object's activation descriptor
     * @return a marshalled object containing the activated object's stub
     */
public MarshalledObject<? extends Remote> newInstance(final ActivationID id, final ActivationDesc desc) throws ActivationException, RemoteException {
    RegistryImpl.checkAccess("ActivationInstantiator.newInstance");
    if (!groupID.equals(desc.getGroupID()))
        throw new ActivationException("newInstance in wrong group");
    try {
        acquireLock(id);
        synchronized (this) {
            if (groupInactive == true)
                throw new InactiveGroupException("group is inactive");
        }
        ActiveEntry entry = active.get(id);
        if (entry != null)
            return entry.mobj;
        String className = desc.getClassName();
        final Class<? extends Remote> cl = RMIClassLoader.loadClass(desc.getLocation(), className).asSubclass(Remote.class);
        Remote impl = null;
        final Thread t = Thread.currentThread();
        final ClassLoader savedCcl = t.getContextClassLoader();
        ClassLoader objcl = cl.getClassLoader();
        final ClassLoader ccl = covers(objcl, savedCcl) ? objcl : savedCcl;
        /*
             * Fix for 4164971: allow non-public activatable class
             * and/or constructor, create the activatable object in a
             * privileged block
             */
        try {
            /*
                 * The code below is in a doPrivileged block to
                 * protect against user code which code might have set
                 * a global socket factory (in which case application
                 * code would be on the stack).
                 */
            impl = AccessController.doPrivileged(new PrivilegedExceptionAction<Remote>() {

                public Remote run() throws InstantiationException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
                    Constructor<? extends Remote> constructor = cl.getDeclaredConstructor(ActivationID.class, MarshalledObject.class);
                    constructor.setAccessible(true);
                    try {
                        /*
                               * Fix for 4289544: make sure to set the
                               * context class loader to be the class
                               * loader of the impl class before
                               * constructing that class.
                               */
                        t.setContextClassLoader(ccl);
                        return constructor.newInstance(id, desc.getData());
                    } finally {
                        t.setContextClassLoader(savedCcl);
                    }
                }
            });
        } catch (PrivilegedActionException pae) {
            Throwable e = pae.getException();
            // narrow the exception's type and rethrow it
            if (e instanceof InstantiationException) {
                throw (InstantiationException) e;
            } else if (e instanceof NoSuchMethodException) {
                throw (NoSuchMethodException) e;
            } else if (e instanceof IllegalAccessException) {
                throw (IllegalAccessException) e;
            } else if (e instanceof InvocationTargetException) {
                throw (InvocationTargetException) e;
            } else if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
            } else if (e instanceof Error) {
                throw (Error) e;
            }
        }
        entry = new ActiveEntry(impl);
        active.put(id, entry);
        return entry.mobj;
    } catch (NoSuchMethodException | NoSuchMethodError e) {
        /* user forgot to provide activatable constructor?
             * or code recompiled and user forgot to provide
             *  activatable constructor?
             */
        throw new ActivationException("Activatable object must provide an activation" + " constructor", e);
    } catch (InvocationTargetException e) {
        throw new ActivationException("exception in object constructor", e.getTargetException());
    } catch (Exception e) {
        throw new ActivationException("unable to activate object", e);
    } finally {
        releaseLock(id);
        checkInactiveGroup();
    }
}
Also used : ActivationException(java.rmi.activation.ActivationException) PrivilegedActionException(java.security.PrivilegedActionException) Remote(java.rmi.Remote) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchObjectException(java.rmi.NoSuchObjectException) ActivationException(java.rmi.activation.ActivationException) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException) UnknownObjectException(java.rmi.activation.UnknownObjectException) RMIClassLoader(java.rmi.server.RMIClassLoader)

Example 45 with PrivilegedActionException

use of java.security.PrivilegedActionException in project jdk8u_jdk by JetBrains.

the class GSSUtil method searchSubject.

/**
     * Searches the private credentials of current Subject with the
     * specified criteria and returns the matching GSSCredentialSpi
     * object out of Sun's impl of GSSCredential. Returns null if
     * no Subject present or a Vector which contains 0 or more
     * matching GSSCredentialSpi objects.
     */
public static <T extends GSSCredentialSpi> Vector<T> searchSubject(final GSSNameSpi name, final Oid mech, final boolean initiate, final Class<? extends T> credCls) {
    debug("Search Subject for " + getMechStr(mech) + (initiate ? " INIT" : " ACCEPT") + " cred (" + (name == null ? "<<DEF>>" : name.toString()) + ", " + credCls.getName() + ")");
    final AccessControlContext acc = AccessController.getContext();
    try {
        Vector<T> creds = AccessController.doPrivileged(new PrivilegedExceptionAction<Vector<T>>() {

            public Vector<T> run() throws Exception {
                Subject accSubj = Subject.getSubject(acc);
                Vector<T> result = null;
                if (accSubj != null) {
                    result = new Vector<T>();
                    Iterator<GSSCredentialImpl> iterator = accSubj.getPrivateCredentials(GSSCredentialImpl.class).iterator();
                    while (iterator.hasNext()) {
                        GSSCredentialImpl cred = iterator.next();
                        debug("...Found cred" + cred);
                        try {
                            GSSCredentialSpi ce = cred.getElement(mech, initiate);
                            debug("......Found element: " + ce);
                            if (ce.getClass().equals(credCls) && (name == null || name.equals((Object) ce.getName()))) {
                                result.add(credCls.cast(ce));
                            } else {
                                debug("......Discard element");
                            }
                        } catch (GSSException ge) {
                            debug("...Discard cred (" + ge + ")");
                        }
                    }
                } else
                    debug("No Subject");
                return result;
            }
        });
        return creds;
    } catch (PrivilegedActionException pae) {
        debug("Unexpected exception when searching Subject:");
        if (DEBUG)
            pae.printStackTrace();
        return null;
    }
}
Also used : AccessControlContext(java.security.AccessControlContext) GSSCredentialSpi(sun.security.jgss.spi.GSSCredentialSpi) PrivilegedActionException(java.security.PrivilegedActionException) Iterator(java.util.Iterator) Vector(java.util.Vector) LoginException(javax.security.auth.login.LoginException) PrivilegedActionException(java.security.PrivilegedActionException) Subject(javax.security.auth.Subject)

Aggregations

PrivilegedActionException (java.security.PrivilegedActionException)135 IOException (java.io.IOException)58 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)56 Subject (javax.security.auth.Subject)23 LoginContext (javax.security.auth.login.LoginContext)14 LoginException (javax.security.auth.login.LoginException)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)11 Method (java.lang.reflect.Method)11 URISyntaxException (java.net.URISyntaxException)11 HashSet (java.util.HashSet)11 ServletException (javax.servlet.ServletException)11 AccessControlContext (java.security.AccessControlContext)10 Principal (java.security.Principal)9 GSSException (org.ietf.jgss.GSSException)9 Field (java.lang.reflect.Field)8 SolrServerException (org.apache.solr.client.solrj.SolrServerException)7 GSSManager (org.ietf.jgss.GSSManager)7 MalformedURLException (java.net.MalformedURLException)6 ArrayList (java.util.ArrayList)6 YardException (org.apache.stanbol.entityhub.servicesapi.yard.YardException)6