java.security.PrivilegedActionException Java Examples

The following examples show how to use java.security.PrivilegedActionException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StreamFileContainer.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private synchronized OutputStream privGetOutputStream(StorageFile file)
    throws FileNotFoundException
{
    actionCode = STORAGE_FILE_GET_OUTPUT_STREAM_ACTION;
    actionStorageFile = file;

    try
    {
        return (OutputStream) AccessController.doPrivileged( this);
    }catch( PrivilegedActionException pae) 
    { 
        throw (FileNotFoundException)pae.getException();
    } 
    finally
    {
        actionStorageFile = null;
    }
}
 
Example #2
Source File: RMIConnectionImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public boolean isRegistered(ObjectName name,
                            Subject delegationSubject) throws IOException {
    try {
        final Object params[] = new Object[] { name };
        return ((Boolean)
            doPrivilegedOperation(
              IS_REGISTERED,
              params,
              delegationSubject)).booleanValue();
    } catch (PrivilegedActionException pe) {
        Exception e = extractException(pe);
        if (e instanceof IOException)
            throw (IOException) e;
        throw newIOException("Got unexpected server exception: " + e, e);
    }
}
 
Example #3
Source File: ErrorStreamTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private static void assertNotEmpty(final File f) throws IOException {
    try {
        AccessController.doPrivileged (new PrivilegedExceptionAction() {
            public Object run() throws IOException {
                assertTrue("assertNotEmpty failed: " + f.getCanonicalPath()
                      + " does not exist.", f.exists());
                FileInputStream fis = new FileInputStream(f);
                int result = fis.read();
                fis.close();
                assertTrue("assertNotEmpty failed: " + f.getCanonicalPath()
                      + " is empty.", -1 != result);
                return null;
            }
        });
    } catch (PrivilegedActionException e) {
        // e.getException() should be an instance of IOException.
        throw (IOException) e.getException();
    }
}
 
Example #4
Source File: HttpURLConnection.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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 #5
Source File: HttpURLConnection.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public synchronized InputStream getInputStream() throws IOException {
    connecting = true;
    SocketPermission p = URLtoSocketPermission(this.url);

    if (p != null) {
        try {
            return AccessController.doPrivilegedWithCombiner(
                new PrivilegedExceptionAction<>() {
                    public InputStream run() throws IOException {
                        return getInputStream0();
                    }
                }, null, p
            );
        } catch (PrivilegedActionException e) {
            throw (IOException) e.getException();
        }
    } else {
        return getInputStream0();
    }
}
 
Example #6
Source File: RMIIIOPServerImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@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();
    }
}
 
Example #7
Source File: RMIConnectionImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private ClassLoader getClassLoader(final ObjectName name)
    throws InstanceNotFoundException {
    try {
        return
            AccessController.doPrivileged(
                new PrivilegedExceptionAction<ClassLoader>() {
                    public ClassLoader run() throws InstanceNotFoundException {
                        return mbeanServer.getClassLoader(name);
                    }
                },
                withPermissions(new MBeanPermission("*", "getClassLoader"))
        );
    } catch (PrivilegedActionException pe) {
        throw (InstanceNotFoundException) extractException(pe);
    }
}
 
Example #8
Source File: Context.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public Context impersonate(final String someone) throws Exception {
    try {
        GSSCredential creds = Subject.doAs(s, new PrivilegedExceptionAction<GSSCredential>() {
            @Override
            public GSSCredential run() throws Exception {
                GSSManager m = GSSManager.getInstance();
                GSSName other = m.createName(someone, GSSName.NT_USER_NAME);
                if (Context.this.cred == null) {
                    Context.this.cred = m.createCredential(GSSCredential.INITIATE_ONLY);
                }
                return ((ExtendedGSSCredential)Context.this.cred).impersonate(other);
            }
        });
        Context out = new Context();
        out.s = s;
        out.cred = creds;
        out.name = name + " as " + out.cred.getName().toString();
        return out;
    } catch (PrivilegedActionException pae) {
        throw pae.getException();
    }
}
 
Example #9
Source File: HijrahChronology.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return the configuration properties from the resource.
 * <p>
 * The default location of the variant configuration resource is:
 * <pre>
 *   "$java.home/lib/" + resource-name
 * </pre>
 *
 * @param resource the name of the calendar property resource
 * @return a Properties containing the properties read from the resource.
 * @throws Exception if access to the property resource fails
 */
private static Properties readConfigProperties(final String resource) throws Exception {
    try {
        return AccessController
                .doPrivileged((java.security.PrivilegedExceptionAction<Properties>)
                    () -> {
                    String libDir = System.getProperty("java.home") + File.separator + "lib";
                    File file = new File(libDir, resource);
                    Properties props = new Properties();
                    try (InputStream is = new FileInputStream(file)) {
                        props.load(is);
                    }
                    return props;
                });
    } catch (PrivilegedActionException pax) {
        throw pax.getException();
    }
}
 
Example #10
Source File: SpnegoAuthInterceptor.java    From knox with Apache License 2.0 6 votes vote down vote up
private static <T> T doAs(Subject subject, GssSupplier<T> action) throws GSSException {
  try {
    return Subject.doAs(subject, (PrivilegedExceptionAction<T>) action::get);
  } catch (PrivilegedActionException e) {
    Throwable t = e.getCause();
    if (t instanceof GSSException) {
      throw (GSSException)t;
    } else if (t instanceof Error) {
      throw (Error)t;
    } else if (t instanceof RuntimeException) {
      throw (RuntimeException)t;
    } else {
      throw new RuntimeException(t);
    }
  }
}
 
Example #11
Source File: RMIConnectionImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public boolean isRegistered(ObjectName name,
                            Subject delegationSubject) throws IOException {
    try {
        final Object params[] = new Object[] { name };
        return ((Boolean)
            doPrivilegedOperation(
              IS_REGISTERED,
              params,
              delegationSubject)).booleanValue();
    } catch (PrivilegedActionException pe) {
        Exception e = extractException(pe);
        if (e instanceof IOException)
            throw (IOException) e;
        throw newIOException("Got unexpected server exception: " + e, e);
    }
}
 
Example #12
Source File: Utils.java    From deprecated-security-advanced-modules with Apache License 2.0 6 votes vote down vote up
public static Map<String, Object> byteArrayToMutableJsonMap(byte[] jsonBytes) throws IOException {

        final SecurityManager sm = System.getSecurityManager();

        if (sm != null) {
            sm.checkPermission(new SpecialPermission());
        }

        try {
            return AccessController.doPrivileged(new PrivilegedExceptionAction<Map<String, Object>>() {
                @Override
                public Map<String, Object> run() throws Exception {
                    return internalMapper.readValue(jsonBytes, new TypeReference<Map<String, Object>>() {});
                }
            });
        } catch (final PrivilegedActionException e) {
            if (e.getCause() instanceof IOException) {
                throw (IOException) e.getCause();
            } else if (e.getCause() instanceof RuntimeException) {
                throw (RuntimeException) e.getCause();
            } else {
                throw new RuntimeException(e.getCause());
            }
        }
    }
 
Example #13
Source File: HttpURLConnection.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@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();
    }
}
 
Example #14
Source File: RMIIIOPServerImpl.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
@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();
    }
}
 
Example #15
Source File: RawStore.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private synchronized boolean privExists( File file)
{
    actionCode = REGULAR_FILE_EXISTS_ACTION;
    actionRegularFile = file;

    try
    {
        Object ret = AccessController.doPrivileged( this);
        return ((Boolean) ret).booleanValue();
    }
    catch( PrivilegedActionException pae) { return false;} // does not throw an exception
    finally
    {
        actionRegularFile = null;
    }
}
 
Example #16
Source File: Executors.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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();
    }
}
 
Example #17
Source File: LoginContext.java    From AndroidPNClient with Apache License 2.0 6 votes vote down vote up
public void handle(final Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    try {
        AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
            public Void run() throws IOException, UnsupportedCallbackException {
                hiddenHandlerRef.handle(callbacks);
                return null;
            }
        }, userContext);
    } catch (PrivilegedActionException ex) {
        if (ex.getCause() instanceof UnsupportedCallbackException) {
            throw (UnsupportedCallbackException) ex.getCause();
        }
        throw (IOException) ex.getCause();
    }
}
 
Example #18
Source File: StreamFileContainer.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private synchronized boolean privMkdirs(StorageFile file)
{
    actionCode = STORAGE_FILE_MKDIRS_ACTION;
    actionStorageFile = file;

    try
    {
        Object ret = AccessController.doPrivileged( this);
        return ((Boolean) ret).booleanValue();
    }catch( PrivilegedActionException pae) 
    {
        // method executed under this priveleged block 
        // does not throw an exception
        return false;
    } 
    finally
    {
        actionStorageFile = null;
    }
}
 
Example #19
Source File: FileSecurity.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 
 * @param path
 * @param type
 * @return
 * @throws FileNotFoundException
 * @throws DataException
 */
public static RandomAccessFile createRandomAccessFile( final String path,
		final String type ) throws FileNotFoundException, DataException
{
	try
	{
		return AccessController.doPrivileged( new PrivilegedExceptionAction<RandomAccessFile>( ) {

			public RandomAccessFile run( ) throws FileNotFoundException
			{
				return new RandomAccessFile( path, type );
			}
		} );
	}
	catch ( PrivilegedActionException e )
	{
		Exception typedException = e.getException( );
		if ( typedException instanceof FileNotFoundException )
		{
			throw (FileNotFoundException) typedException;
		}
		throw new DataException( e.getLocalizedMessage( ) );
	}
}
 
Example #20
Source File: JarUtil.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Copy the jar from the externally obtained 
 * input stream into the database
 * @param jarExternalName Name of jar with database structure.
 * @param contents Contents of jar file.
 * @param add true to add, false to replace
 * @param currentGenerationId generation id of existing version, ignored when adding.
 */
 private long setJar(final String jarExternalName,
      final InputStream contents,
        final boolean add,
        final long currentGenerationId)
        throws StandardException {
    try {
        return ((Long) AccessController
                .doPrivileged(new java.security.PrivilegedExceptionAction() {

                    public Object run() throws StandardException {
                        long generationId;
                        
                        if (add)
                            generationId = fr.add(jarExternalName, contents, lcc);
                        else
                            generationId =  fr.replace(jarExternalName,
                                    currentGenerationId, contents, lcc);
                        return Long.valueOf(generationId);
                    }
                })).longValue();
    } catch (PrivilegedActionException e) {
        throw (StandardException) e.getException();
    }
}
 
Example #21
Source File: SecurityUtils.java    From smart-testing with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
            }
        }
    }
}
 
Example #22
Source File: CoyoteInputStream.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Close the stream
 * Since we re-cycle, we can't allow the call to super.close()
 * which would permanently disable us.
 */
@Override
public void close() throws IOException {

    if (SecurityUtil.isPackageProtectionEnabled()){
        try{
            AccessController.doPrivileged(
                new PrivilegedExceptionAction<Void>(){

                    @Override
                    public Void run() throws IOException{
                        ib.close();
                        return null;
                    }

            });
        } catch(PrivilegedActionException pae){
            Exception e = pae.getException();
            if (e instanceof IOException){
                throw (IOException)e;
            } else {
                throw new RuntimeException(e.getMessage(), e);
            }
        }
    } else {
         ib.close();
    }
}
 
Example #23
Source File: JMXManagementService.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Register an mbean with the platform mbean server.
 */
private void jmxRegister(final StandardMBean standardMBean,
        final ObjectName beanName) throws JMException
{
    // Already registered? Can happen if we don't have permission
    // to unregister the MBeans.
    if (mbeanServer.isRegistered(beanName))
        return;
        
    try {

        AccessController
           .doPrivileged(new PrivilegedExceptionAction<Object>() {

                public Object run() throws JMException {
                    mbeanServer.registerMBean(standardMBean, beanName);
                    return null;
                }

            });

    } catch (PrivilegedActionException pae) {
        throw (JMException) pae.getException();
    } catch (SecurityException se) {
        // If we can't register the MBean then so be it.
        // The application can later enabled the MBeans
        // by using com.pivotal.gemfirexd.internal.mbeans.Management
    }
}
 
Example #24
Source File: UNIXProcess.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
UNIXProcess(final byte[] prog,
            final byte[] argBlock, final int argc,
            final byte[] envBlock, final int envc,
            final byte[] dir,
            final int[] fds,
            final boolean redirectErrorStream)
        throws IOException {

    pid = forkAndExec(launchMechanism.value,
                      helperpath,
                      prog,
                      argBlock, argc,
                      envBlock, envc,
                      dir,
                      fds,
                      redirectErrorStream);

    try {
        doPrivileged(new PrivilegedExceptionAction<Void>() {
            public Void run() throws IOException {
                initStreams(fds);
                return null;
            }});
    } catch (PrivilegedActionException ex) {
        throw (IOException) ex.getException();
    }
}
 
Example #25
Source File: ProtectedFunctionMapper.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
/**
    * Creates an instance for this class, and stores the Method for
    * the given EL function prefix and name. This method is used for
    * the case when there is only one function in the EL expression.
    *
    * @param fnQName The EL function qualified name (including prefix)
    * @param c The class containing the Java method
    * @param methodName The name of the Java method
    * @param args The arguments of the Java method
    * @throws RuntimeException if no method with the given signature
    *     could be found.
    */
   public static ProtectedFunctionMapper getMapForFunction(
	String fnQName, final Class<?> c,
               final String methodName, final Class<?>[] args )
   {
       java.lang.reflect.Method method;
       ProtectedFunctionMapper funcMapper;
       if (SecurityUtil.isPackageProtectionEnabled()){
           funcMapper = AccessController.doPrivileged(
               new PrivilegedAction<ProtectedFunctionMapper>(){
               public ProtectedFunctionMapper run() {
                   return new ProtectedFunctionMapper();
               }
           });

           try{
               method = AccessController.doPrivileged(
                   new PrivilegedExceptionAction<Method>(){
                   public Method run() throws Exception{
                       return c.getDeclaredMethod(methodName, args);
                   }
               });
           } catch (PrivilegedActionException ex){
               throw new RuntimeException(
                   "Invalid function mapping - no such method: "
                   + ex.getException().getMessage());
           }
       } else {
    funcMapper = new ProtectedFunctionMapper();
            try {
               method = c.getDeclaredMethod(methodName, args);
           } catch( NoSuchMethodException e ) {
               throw new RuntimeException(
                   "Invalid function mapping - no such method: "
                   + e.getMessage());
           }
       }
       funcMapper.theMethod = method;
return funcMapper;
   }
 
Example #26
Source File: UnboundSSL.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException,
        NoSuchAlgorithmException,LoginException, PrivilegedActionException,
        InterruptedException {
    Security.setProperty("jdk.tls.disabledAlgorithms", "");
    UnboundSSL test = new UnboundSSL();
    test.start(args[0], args[1]);
}
 
Example #27
Source File: FileSystemPreferences.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #28
Source File: DefaultFaultToleranceOperationProvider.java    From smallrye-fault-tolerance with Apache License 2.0 5 votes vote down vote up
protected boolean isMethodDeclaredInHierarchy(Class<?> beanClass, Method method) {
    while (beanClass != null) {
        try {
            for (Method declaredMethod : SecurityActions.getDeclaredMethods(beanClass)) {
                if (declaredMethod.equals(method)) {
                    return true;
                }
            }
        } catch (PrivilegedActionException e) {
            throw new IllegalStateException("Unable to get declared methods of " + beanClass);
        }
        beanClass = beanClass.getSuperclass();
    }
    return false;
}
 
Example #29
Source File: BaseTestCase.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
   * Open the URL for a a test resource, e.g. a policy
   * file or a SQL script.
   * @param url URL obtained from getTestResource
   * @return An open stream
  */
  protected static InputStream openTestResource(final URL url)
      throws PrivilegedActionException
  {
  	return (InputStream)AccessController.doPrivileged
   (new java.security.PrivilegedExceptionAction(){

    public Object run() throws IOException{
	return url.openStream();

    }

}
    );    	
  }
 
Example #30
Source File: UnboundSSLPrincipalProperty.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException,
        NoSuchAlgorithmException,LoginException, PrivilegedActionException,
        InterruptedException {
    Security.setProperty("jdk.tls.disabledAlgorithms", "");
    UnboundSSLPrincipalProperty test = new UnboundSSLPrincipalProperty();
    test.start(args[0], args[1]);
}