Search in sources :

Example 36 with PrivilegedActionException

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

the class ProviderImpl method initMapIfNecessary.

private static synchronized void initMapIfNecessary() throws SyncFactoryException {
    // Local implementation class names and keys from Properties
    // file, translate names into Class objects using Class.forName
    // and store mappings
    final Properties properties = new Properties();
    if (implementations == null) {
        implementations = new Hashtable<>();
        try {
            // check if user is supplying his Synchronisation Provider
            // Implementation if not using Oracle's implementation.
            // properties.load(new FileInputStream(ROWSET_PROPERTIES));
            // The rowset.properties needs to be in jdk/jre/lib when
            // integrated with jdk.
            // else it should be picked from -D option from command line.
            // -Drowset.properties will add to standard properties. Similar
            // keys will over-write
            /*
                 * Dependent on application
                 */
            String strRowsetProperties;
            try {
                strRowsetProperties = AccessController.doPrivileged(new PrivilegedAction<String>() {

                    public String run() {
                        return System.getProperty("rowset.properties");
                    }
                }, null, new PropertyPermission("rowset.properties", "read"));
            } catch (Exception ex) {
                System.out.println("errorget rowset.properties: " + ex);
                strRowsetProperties = null;
            }
            ;
            if (strRowsetProperties != null) {
                // Load user's implementation of SyncProvider
                // here. -Drowset.properties=/abc/def/pqr.txt
                ROWSET_PROPERTIES = strRowsetProperties;
                try (FileInputStream fis = new FileInputStream(ROWSET_PROPERTIES)) {
                    properties.load(fis);
                }
                parseProperties(properties);
            }
            /*
                 * Always available
                 */
            ROWSET_PROPERTIES = "javax" + strFileSep + "sql" + strFileSep + "rowset" + strFileSep + "rowset.properties";
            ClassLoader cl = Thread.currentThread().getContextClassLoader();
            try {
                AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
                    try (InputStream stream = (cl == null) ? ClassLoader.getSystemResourceAsStream(ROWSET_PROPERTIES) : cl.getResourceAsStream(ROWSET_PROPERTIES)) {
                        if (stream == null) {
                            throw new SyncFactoryException("Resource " + ROWSET_PROPERTIES + " not found");
                        }
                        properties.load(stream);
                    }
                    return null;
                });
            } catch (PrivilegedActionException ex) {
                Throwable e = ex.getException();
                if (e instanceof SyncFactoryException) {
                    throw (SyncFactoryException) e;
                } else {
                    SyncFactoryException sfe = new SyncFactoryException();
                    sfe.initCause(ex.getException());
                    throw sfe;
                }
            }
            parseProperties(properties);
        // removed else, has properties should sum together
        } catch (FileNotFoundException e) {
            throw new SyncFactoryException("Cannot locate properties file: " + e);
        } catch (IOException e) {
            throw new SyncFactoryException("IOException: " + e);
        }
        /*
             * Now deal with -Drowset.provider.classname
             * load additional properties from -D command line
             */
        properties.clear();
        String providerImpls;
        try {
            providerImpls = AccessController.doPrivileged(new PrivilegedAction<String>() {

                public String run() {
                    return System.getProperty(ROWSET_SYNC_PROVIDER);
                }
            }, null, new PropertyPermission(ROWSET_SYNC_PROVIDER, "read"));
        } catch (Exception ex) {
            providerImpls = null;
        }
        if (providerImpls != null) {
            int i = 0;
            if (providerImpls.indexOf(colon) > 0) {
                StringTokenizer tokenizer = new StringTokenizer(providerImpls, colon);
                while (tokenizer.hasMoreElements()) {
                    properties.put(ROWSET_SYNC_PROVIDER + "." + i, tokenizer.nextToken());
                    i++;
                }
            } else {
                properties.put(ROWSET_SYNC_PROVIDER, providerImpls);
            }
            parseProperties(properties);
        }
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream) PrivilegedAction(java.security.PrivilegedAction)

Example 37 with PrivilegedActionException

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

the class AppContextCreator method findClass.

/*
     * Finds the applet class with the specified name. First searches
     * loaded JAR files then the applet code base for the class.
     */
protected Class findClass(String name) throws ClassNotFoundException {
    int index = name.indexOf(";");
    String cookie = "";
    if (index != -1) {
        cookie = name.substring(index, name.length());
        name = name.substring(0, index);
    }
    // check loaded JAR files
    try {
        return super.findClass(name);
    } catch (ClassNotFoundException e) {
    }
    // during resource requests. [stanley.ho]
    if (codebaseLookup == false)
        throw new ClassNotFoundException(name);
    //      final String path = name.replace('.', '/').concat(".class").concat(cookie);
    String encodedName = ParseUtil.encodePath(name.replace('.', '/'), false);
    final String path = (new StringBuffer(encodedName)).append(".class").append(cookie).toString();
    try {
        byte[] b = (byte[]) AccessController.doPrivileged(new PrivilegedExceptionAction() {

            public Object run() throws IOException {
                try {
                    URL finalURL = new URL(base, path);
                    // Make sure the codebase won't be modified
                    if (base.getProtocol().equals(finalURL.getProtocol()) && base.getHost().equals(finalURL.getHost()) && base.getPort() == finalURL.getPort()) {
                        return getBytes(finalURL);
                    } else {
                        return null;
                    }
                } catch (Exception e) {
                    return null;
                }
            }
        }, acc);
        if (b != null) {
            return defineClass(name, b, 0, b.length, codesource);
        } else {
            throw new ClassNotFoundException(name);
        }
    } catch (PrivilegedActionException e) {
        throw new ClassNotFoundException(name, e.getException());
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) URL(java.net.URL) NullPointerException(java.lang.NullPointerException) NoSuchElementException(java.util.NoSuchElementException) PrivilegedActionException(java.security.PrivilegedActionException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 38 with PrivilegedActionException

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

the class FileFont method getPublicFileName.

protected String getPublicFileName() {
    SecurityManager sm = System.getSecurityManager();
    if (sm == null) {
        return platName;
    }
    boolean canReadProperty = true;
    try {
        sm.checkPropertyAccess("java.io.tmpdir");
    } catch (SecurityException e) {
        canReadProperty = false;
    }
    if (canReadProperty) {
        return platName;
    }
    final File f = new File(platName);
    Boolean isTmpFile = Boolean.FALSE;
    try {
        isTmpFile = AccessController.doPrivileged(new PrivilegedExceptionAction<Boolean>() {

            public Boolean run() {
                File tmp = new File(System.getProperty("java.io.tmpdir"));
                try {
                    String tpath = tmp.getCanonicalPath();
                    String fpath = f.getCanonicalPath();
                    return (fpath == null) || fpath.startsWith(tpath);
                } catch (IOException e) {
                    return Boolean.TRUE;
                }
            }
        });
    } catch (PrivilegedActionException e) {
        // unable to verify whether value of java.io.tempdir will be
        // exposed, so return only a name of the font file.
        isTmpFile = Boolean.TRUE;
    }
    return isTmpFile ? "temp file" : platName;
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) IOException(java.io.IOException) File(java.io.File)

Example 39 with PrivilegedActionException

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

the class ProviderFactory method getPrintStreamFromSpec.

private static PrintStream getPrintStreamFromSpec(final String spec) {
    try {
        // spec is in the form of <class>.<field>, where <class> is
        // a fully specified class name, and <field> is a static member
        // in that class.  The <field> must be a 'PrintStream' or subtype
        // in order to be used.
        final int fieldpos = spec.lastIndexOf('.');
        final Class<?> cls = Class.forName(spec.substring(0, fieldpos));
        Field f = AccessController.doPrivileged(new PrivilegedExceptionAction<Field>() {

            public Field run() throws NoSuchFieldException {
                return cls.getField(spec.substring(fieldpos + 1));
            }
        });
        return (PrintStream) f.get(null);
    } catch (ClassNotFoundException e) {
        throw new AssertionError(e);
    } catch (IllegalAccessException e) {
        throw new AssertionError(e);
    } catch (PrivilegedActionException e) {
        throw new AssertionError(e);
    }
}
Also used : Field(java.lang.reflect.Field) PrintStream(java.io.PrintStream) PrivilegedActionException(java.security.PrivilegedActionException)

Example 40 with PrivilegedActionException

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

the class ManagementFactoryHelper method addMBean.

/**
     * Registers a given MBean if not registered in the MBeanServer;
     * otherwise, just return.
     */
private static void addMBean(MBeanServer mbs, Object mbean, String mbeanName) {
    try {
        final ObjectName objName = Util.newObjectName(mbeanName);
        // inner class requires these fields to be final
        final MBeanServer mbs0 = mbs;
        final Object mbean0 = mbean;
        AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {

            public Void run() throws MBeanRegistrationException, NotCompliantMBeanException {
                try {
                    mbs0.registerMBean(mbean0, objName);
                    return null;
                } catch (InstanceAlreadyExistsException e) {
                // if an instance with the object name exists in
                // the MBeanServer ignore the exception
                }
                return null;
            }
        });
    } catch (PrivilegedActionException e) {
        throw Util.newException(e.getException());
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer)

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