Java Code Examples for java.security.PrivilegedActionException.getException()

The following are Jave code examples for showing how to use getException() of the java.security.PrivilegedActionException class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: aries-jpa   File: TempBundleDelegatingClassLoader.java   View Source Code Vote up 6 votes
private Enumeration<URL> findResourcesInBundle(final String resName, final Bundle inBundle) throws IOException {
    Enumeration<URL> resources = null;
    try {
        // Bundle.getResources requires privileges that the client may not
        // have but we need
        // use a doPriv so that only this bundle needs the privileges
        resources = AccessController.doPrivileged(new PrivilegedExceptionAction<Enumeration<URL>>() {
            @Override
            public Enumeration<URL> run() throws IOException {
                return inBundle.getResources(resName);
            }
        });
    } catch (PrivilegedActionException pae) {
        // thrownException can never be a RuntimeException, as that would escape the doPriv normally
        Exception thrownException = pae.getException();
        if (thrownException instanceof IOException) {
            throw (IOException)thrownException;
        } else {
            LOG.warn("Exception during findResourcesInBundle", pae);
        }
    }
    return resources;
}
 
Example 2
Project: tomcat7   File: StandardManager.java   View Source Code Vote up 6 votes
@Override
public void load() throws ClassNotFoundException, IOException {
    if (SecurityUtil.isPackageProtectionEnabled()){
        try{
            AccessController.doPrivileged( new PrivilegedDoLoad() );
        } catch (PrivilegedActionException ex){
            Exception exception = ex.getException();
            if (exception instanceof ClassNotFoundException) {
                throw (ClassNotFoundException)exception;
            } else if (exception instanceof IOException) {
                throw (IOException)exception;
            }
            if (log.isDebugEnabled()) {
                log.debug("Unreported exception in load() ", exception);
            }
        }
    } else {
        doLoad();
    }
}
 
Example 3
Project: jdk8u-jdk   File: ObjectInputStream.java   View Source Code Vote up 6 votes
/**
 * Invokes all registered callbacks and clears the callback list.
 * Callbacks with higher priorities are called first; those with equal
 * priorities may be called in any order.  If any of the callbacks
 * throws an InvalidObjectException, the callback process is terminated
 * and the exception propagated upwards.
 */
void doCallbacks() throws InvalidObjectException {
    try {
        while (list != null) {
            AccessController.doPrivileged(
                new PrivilegedExceptionAction<Void>()
            {
                public Void run() throws InvalidObjectException {
                    list.obj.validateObject();
                    return null;
                }
            }, list.acc);
            list = list.next;
        }
    } catch (PrivilegedActionException ex) {
        list = null;
        throw (InvalidObjectException) ex.getException();
    }
}
 
Example 4
Project: OpenJSharp   File: HttpURLConnection.java   View Source Code Vote up 6 votes
protected void plainConnect()  throws IOException {
    synchronized (this) {
        if (connected) {
            return;
        }
    }
    SocketPermission p = URLtoSocketPermission(this.url);
    if (p != null) {
        try {
            AccessController.doPrivileged(
                new PrivilegedExceptionAction<Void>() {
                    public Void run() throws IOException {
                        plainConnect0();
                        return null;
                    }
                }, null, p
            );
        } catch (PrivilegedActionException e) {
                throw (IOException) e.getException();
        }
    } else {
        // run without additional permission
        plainConnect0();
    }
}
 
Example 5
Project: tomcat7   File: PageContextImpl.java   View Source Code Vote up 6 votes
@Override
public void include(final String relativeUrlPath, final boolean flush)
        throws ServletException, IOException {
    if (SecurityUtil.isPackageProtectionEnabled()) {
        try {
            AccessController.doPrivileged(
                    new PrivilegedExceptionAction<Void>() {
                @Override
                public Void run() throws Exception {
                    doInclude(relativeUrlPath, flush);
                    return null;
                }
            });
        } catch (PrivilegedActionException e) {
            Exception ex = e.getException();
            if (ex instanceof IOException) {
                throw (IOException) ex;
            } else {
                throw (ServletException) ex;
            }
        }
    } else {
        doInclude(relativeUrlPath, flush);
    }
}
 
Example 6
Project: jdk8u-jdk   File: HttpURLConnection.java   View Source Code Vote up 6 votes
protected void plainConnect()  throws IOException {
    synchronized (this) {
        if (connected) {
            return;
        }
    }
    SocketPermission p = URLtoSocketPermission(this.url);
    if (p != null) {
        try {
            AccessController.doPrivilegedWithCombiner(
                new PrivilegedExceptionAction<Void>() {
                    public Void run() throws IOException {
                        plainConnect0();
                        return null;
                    }
                }, null, p
            );
        } catch (PrivilegedActionException e) {
                throw (IOException) e.getException();
        }
    } else {
        // run without additional permission
        plainConnect0();
    }
}
 
Example 7
Project: incubator-netbeans   File: TopSecurityManager.java   View Source Code Vote up 5 votes
private static void check(PrivilegedCheck action) {
    try {
        AccessController.doPrivileged(action);
    } catch (PrivilegedActionException e) {
        Exception orig = e.getException();
        if (orig instanceof RuntimeException) {
            throw ((RuntimeException) orig);
        }
        orig.printStackTrace();
    }
}
 
Example 8
Project: openjdk-jdk10   File: ConfigFile.java   View Source Code Vote up 5 votes
public Spi(final Configuration.Parameters params) throws IOException {

            // call in a doPrivileged
            //
            // we have already passed the Configuration.getInstance
            // security check.  also this class is not freely accessible
            // (it is in the "sun" package).

            try {
                AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
                    public Void run() throws IOException {
                        if (params == null) {
                            init();
                        } else {
                            if (!(params instanceof URIParameter)) {
                                throw new IllegalArgumentException
                                        ("Unrecognized parameter: " + params);
                            }
                            URIParameter uriParam = (URIParameter)params;
                            url = uriParam.getURI().toURL();
                            init();
                        }
                        return null;
                    }
                });
            } catch (PrivilegedActionException pae) {
                throw (IOException)pae.getException();
            }

            // if init() throws some other RuntimeException,
            // let it percolate up naturally.
        }
 
Example 9
Project: openjdk-jdk10   File: Context.java   View Source Code Vote up 5 votes
/**
 * 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();
    }
}
 
Example 10
Project: lams   File: PersistentManagerBase.java   View Source Code Vote up 5 votes
/**
 * Write the provided session to the Store without modifying
 * the copy in memory or triggering passivation events. Does
 * nothing if the session is invalid or past its expiration.
 */
protected void writeSession(Session session) throws IOException {

    if (store == null || !session.isValid()) {
        return;
    }

    try {
        if (SecurityUtil.isPackageProtectionEnabled()){
            try{
                AccessController.doPrivileged(new PrivilegedStoreSave(session));
            }catch(PrivilegedActionException ex){
                Exception exception = ex.getException();
                log.error("Exception in the Store during writeSession: "
                          + exception);
                exception.printStackTrace();                        
            }
        } else {
             store.save(session);
        }   
    } catch (IOException e) {
        log.error(sm.getString
            ("persistentManager.serializeError", session.getIdInternal(), e));
        throw e;
    }

}
 
Example 11
Project: keycloak-remote-ejb   File: SecurityActions.java   View Source Code Vote up 5 votes
@Override
public ContextStateCache pushIdentity(final Principal principal, final Object credential) throws Exception {
    try {
        return AccessController.doPrivileged(new PrivilegedExceptionAction<ContextStateCache>() {

            @Override
            public ContextStateCache run() throws Exception {
                return NON_PRIVILEGED.pushIdentity(principal, credential);
            }
        });
    } catch (PrivilegedActionException e) {
        throw e.getException();
    }
}
 
Example 12
Project: jdk8u-jdk   File: FileSystemPreferences.java   View Source Code Vote up 5 votes
protected void syncSpi() throws BackingStoreException {
    try {
        AccessController.doPrivileged(
            new PrivilegedExceptionAction<Void>() {
            public Void run() throws BackingStoreException {
                syncSpiPrivileged();
                return null;
            }
        });
    } catch (PrivilegedActionException e) {
        throw (BackingStoreException) e.getException();
    }
}
 
Example 13
Project: openjdk-jdk10   File: FileSystemPreferences.java   View Source Code Vote up 5 votes
/**
 * Called with file lock held (in addition to node locks).
 */
protected void removeNodeSpi() throws BackingStoreException {
    try {
        AccessController.doPrivileged(
            new PrivilegedExceptionAction<Void>() {
            public Void run() throws BackingStoreException {
                if (changeLog.contains(nodeCreate)) {
                    changeLog.remove(nodeCreate);
                    nodeCreate = null;
                    return null;
                }
                if (!dir.exists())
                    return null;
                prefsFile.delete();
                tmpFile.delete();
                // dir should be empty now.  If it's not, empty it
                File[] junk = dir.listFiles();
                if (junk.length != 0) {
                    getLogger().warning(
                       "Found extraneous files when removing node: "
                        + Arrays.asList(junk));
                    for (int i=0; i<junk.length; i++)
                        junk[i].delete();
                }
                if (!dir.delete())
                    throw new BackingStoreException("Couldn't delete dir: "
                                                                     + dir);
                return null;
            }
        });
    } catch (PrivilegedActionException e) {
        throw (BackingStoreException) e.getException();
    }
}
 
Example 14
Project: jdk8u-jdk   File: Executors.java   View Source Code Vote up 5 votes
public T call() throws Exception {
    try {
        return AccessController.doPrivileged(
            new PrivilegedExceptionAction<T>() {
                public T run() throws Exception {
                    return task.call();
                }
            }, acc);
    } catch (PrivilegedActionException e) {
        throw e.getException();
    }
}
 
Example 15
Project: openjdk-jdk10   File: Executors.java   View Source Code Vote up 5 votes
public T call() throws Exception {
    try {
        return AccessController.doPrivileged(
            new PrivilegedExceptionAction<T>() {
                public T run() throws Exception {
                    return task.call();
                }
            }, acc);
    } catch (PrivilegedActionException e) {
        throw e.getException();
    }
}
 
Example 16
Project: apache-tomcat-7.0.73-with-comment   File: CoyoteInputStream.java   View Source Code Vote up 5 votes
@Override
public int read(final byte[] b, final int off, final int len)
    throws IOException {

    if (SecurityUtil.isPackageProtectionEnabled()){
        try{
            Integer result =
                AccessController.doPrivileged(
                    new PrivilegedExceptionAction<Integer>(){

                        @Override
                        public Integer run() throws IOException{
                            Integer integer =
                                Integer.valueOf(ib.read(b, off, len));
                            return integer;
                        }

            });
            return result.intValue();
        } catch(PrivilegedActionException pae){
            Exception e = pae.getException();
            if (e instanceof IOException){
                throw (IOException)e;
            } else {
                throw new RuntimeException(e.getMessage(), e);
            }
        }
    } else {
        return ib.read(b, off, len);
    }
}
 
Example 17
Project: jdk8u-jdk   File: AtomicReferenceFieldUpdater.java   View Source Code Vote up 4 votes
AtomicReferenceFieldUpdaterImpl(final Class<T> tclass,
                                final Class<V> vclass,
                                final String fieldName,
                                final Class<?> caller) {
    final Field field;
    final Class<?> fieldClass;
    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);
        }
        fieldClass = field.getType();
    } catch (PrivilegedActionException pae) {
        throw new RuntimeException(pae.getException());
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    if (vclass != fieldClass)
        throw new ClassCastException();
    if (vclass.isPrimitive())
        throw new IllegalArgumentException("Must be reference 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.vclass = vclass;
    this.offset = U.objectFieldOffset(field);
}
 
Example 18
Project: openjdk-jdk10   File: AtomicLongFieldUpdater.java   View Source Code Vote up 4 votes
CASUpdater(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() != 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);
}
 
Example 19
Project: jdk8u-jdk   File: JMXPluggableAuthenticator.java   View Source Code Vote up 4 votes
/**
 * Creates an instance of <code>JMXPluggableAuthenticator</code>
 * and initializes it with a {@link LoginContext}.
 *
 * @param env the environment containing configuration properties for the
 *            authenticator. Can be null, which is equivalent to an empty
 *            Map.
 * @exception SecurityException if the authentication mechanism cannot be
 *            initialized.
 */
public JMXPluggableAuthenticator(Map<?, ?> env) {

    String loginConfigName = null;
    String passwordFile = null;

    if (env != null) {
        loginConfigName = (String) env.get(LOGIN_CONFIG_PROP);
        passwordFile = (String) env.get(PASSWORD_FILE_PROP);
    }

    try {

        if (loginConfigName != null) {
            // use the supplied JAAS login configuration
            loginContext =
                new LoginContext(loginConfigName, new JMXCallbackHandler());

        } else {
            // use the default JAAS login configuration (file-based)
            SecurityManager sm = System.getSecurityManager();
            if (sm != null) {
                sm.checkPermission(
                        new AuthPermission("createLoginContext." +
                                           LOGIN_CONFIG_NAME));
            }

            final String pf = passwordFile;
            try {
                loginContext = AccessController.doPrivileged(
                    new PrivilegedExceptionAction<LoginContext>() {
                        public LoginContext run() throws LoginException {
                            return new LoginContext(
                                            LOGIN_CONFIG_NAME,
                                            null,
                                            new JMXCallbackHandler(),
                                            new FileLoginConfig(pf));
                        }
                    });
            } catch (PrivilegedActionException pae) {
                throw (LoginException) pae.getException();
            }
        }

    } catch (LoginException le) {
        authenticationFailure("authenticate", le);

    } catch (SecurityException se) {
        authenticationFailure("authenticate", se);
    }
}
 
Example 20
Project: OpenJSharp   File: ExtensionDependency.java   View Source Code Vote up 4 votes
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;
}