Search in sources :

Example 46 with PrivilegedActionException

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

the class Krb5AcceptCredential method getInstance.

static Krb5AcceptCredential getInstance(final GSSCaller caller, Krb5NameElement name) throws GSSException {
    final String serverPrinc = (name == null ? null : name.getKrb5PrincipalName().getName());
    final AccessControlContext acc = AccessController.getContext();
    ServiceCreds creds = null;
    try {
        creds = AccessController.doPrivileged(new PrivilegedExceptionAction<ServiceCreds>() {

            public ServiceCreds run() throws Exception {
                return Krb5Util.getServiceCreds(caller == GSSCaller.CALLER_UNKNOWN ? GSSCaller.CALLER_ACCEPT : caller, serverPrinc, acc);
            }
        });
    } catch (PrivilegedActionException e) {
        GSSException ge = new GSSException(GSSException.NO_CRED, -1, "Attempt to obtain new ACCEPT credentials failed!");
        ge.initCause(e.getException());
        throw ge;
    }
    if (creds == null)
        throw new GSSException(GSSException.NO_CRED, -1, "Failed to find any Kerberos credentails");
    if (name == null) {
        String fullName = creds.getName();
        if (fullName != null) {
            name = Krb5NameElement.getInstance(fullName, Krb5MechFactory.NT_GSS_KRB5_PRINCIPAL);
        }
    }
    return new Krb5AcceptCredential(name, creds);
}
Also used : AccessControlContext(java.security.AccessControlContext) PrivilegedActionException(java.security.PrivilegedActionException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction)

Example 47 with PrivilegedActionException

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

the class CertStoreHelper method getInstance.

public static CertStoreHelper getInstance(final String type) throws NoSuchAlgorithmException {
    CertStoreHelper helper = cache.get(type);
    if (helper != null) {
        return helper;
    }
    final String cl = classMap.get(type);
    if (cl == null) {
        throw new NoSuchAlgorithmException(type + " not available");
    }
    try {
        helper = AccessController.doPrivileged(new PrivilegedExceptionAction<CertStoreHelper>() {

            public CertStoreHelper run() throws ClassNotFoundException {
                try {
                    Class<?> c = Class.forName(cl, true, null);
                    CertStoreHelper csh = (CertStoreHelper) c.newInstance();
                    cache.put(type, csh);
                    return csh;
                } catch (InstantiationException | IllegalAccessException e) {
                    throw new AssertionError(e);
                }
            }
        });
        return helper;
    } catch (PrivilegedActionException e) {
        throw new NoSuchAlgorithmException(type + " not available", e.getException());
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction)

Example 48 with PrivilegedActionException

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

the class BreakDictionary method readDictionaryFile.

private void readDictionaryFile(final String dictionaryName) throws IOException, MissingResourceException {
    BufferedInputStream in;
    try {
        in = AccessController.doPrivileged(new PrivilegedExceptionAction<BufferedInputStream>() {

            @Override
            public BufferedInputStream run() throws Exception {
                return new BufferedInputStream(getClass().getResourceAsStream("/sun/text/resources/" + dictionaryName));
            }
        });
    } catch (PrivilegedActionException e) {
        throw new InternalError(e.toString(), e);
    }
    byte[] buf = new byte[8];
    if (in.read(buf) != 8) {
        throw new MissingResourceException("Wrong data length", dictionaryName, "");
    }
    // check version
    int version = RuleBasedBreakIterator.getInt(buf, 0);
    if (version != supportedVersion) {
        throw new MissingResourceException("Dictionary version(" + version + ") is unsupported", dictionaryName, "");
    }
    // get data size
    int len = RuleBasedBreakIterator.getInt(buf, 4);
    buf = new byte[len];
    if (in.read(buf) != len) {
        throw new MissingResourceException("Wrong data length", dictionaryName, "");
    }
    // close the stream
    in.close();
    int l;
    int offset = 0;
    // read in the column map for BMP characteres (this is serialized in
    // its internal form: an index array followed by a data array)
    l = RuleBasedBreakIterator.getInt(buf, offset);
    offset += 4;
    short[] temp = new short[l];
    for (int i = 0; i < l; i++, offset += 2) {
        temp[i] = RuleBasedBreakIterator.getShort(buf, offset);
    }
    l = RuleBasedBreakIterator.getInt(buf, offset);
    offset += 4;
    byte[] temp2 = new byte[l];
    for (int i = 0; i < l; i++, offset++) {
        temp2[i] = buf[offset];
    }
    columnMap = new CompactByteArray(temp, temp2);
    // read in numCols and numColGroups
    numCols = RuleBasedBreakIterator.getInt(buf, offset);
    offset += 4;
    numColGroups = RuleBasedBreakIterator.getInt(buf, offset);
    offset += 4;
    // read in the row-number index
    l = RuleBasedBreakIterator.getInt(buf, offset);
    offset += 4;
    rowIndex = new short[l];
    for (int i = 0; i < l; i++, offset += 2) {
        rowIndex[i] = RuleBasedBreakIterator.getShort(buf, offset);
    }
    // load in the populated-cells bitmap: index first, then bitmap list
    l = RuleBasedBreakIterator.getInt(buf, offset);
    offset += 4;
    rowIndexFlagsIndex = new short[l];
    for (int i = 0; i < l; i++, offset += 2) {
        rowIndexFlagsIndex[i] = RuleBasedBreakIterator.getShort(buf, offset);
    }
    l = RuleBasedBreakIterator.getInt(buf, offset);
    offset += 4;
    rowIndexFlags = new int[l];
    for (int i = 0; i < l; i++, offset += 4) {
        rowIndexFlags[i] = RuleBasedBreakIterator.getInt(buf, offset);
    }
    // load in the row-shift index
    l = RuleBasedBreakIterator.getInt(buf, offset);
    offset += 4;
    rowIndexShifts = new byte[l];
    for (int i = 0; i < l; i++, offset++) {
        rowIndexShifts[i] = buf[offset];
    }
    // load in the actual state table
    l = RuleBasedBreakIterator.getInt(buf, offset);
    offset += 4;
    table = new short[l];
    for (int i = 0; i < l; i++, offset += 2) {
        table[i] = RuleBasedBreakIterator.getShort(buf, offset);
    }
    // finally, prepare the column map for supplementary characters
    l = RuleBasedBreakIterator.getInt(buf, offset);
    offset += 4;
    int[] temp3 = new int[l];
    for (int i = 0; i < l; i++, offset += 4) {
        temp3[i] = RuleBasedBreakIterator.getInt(buf, offset);
    }
    supplementaryCharColumnMap = new SupplementaryCharacterData(temp3);
}
Also used : BufferedInputStream(java.io.BufferedInputStream) PrivilegedActionException(java.security.PrivilegedActionException) MissingResourceException(java.util.MissingResourceException) SupplementaryCharacterData(sun.text.SupplementaryCharacterData) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) CompactByteArray(sun.text.CompactByteArray)

Example 49 with PrivilegedActionException

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

the class RuleBasedBreakIterator method readFile.

protected byte[] readFile(final String datafile) throws IOException, MissingResourceException {
    BufferedInputStream is;
    try {
        is = AccessController.doPrivileged(new PrivilegedExceptionAction<BufferedInputStream>() {

            @Override
            public BufferedInputStream run() throws Exception {
                return new BufferedInputStream(getClass().getResourceAsStream("/sun/text/resources/" + datafile));
            }
        });
    } catch (PrivilegedActionException e) {
        throw new InternalError(e.toString(), e);
    }
    int offset = 0;
    /* First, read magic, version, and header_info. */
    int len = LABEL_LENGTH + 5;
    byte[] buf = new byte[len];
    if (is.read(buf) != len) {
        throw new MissingResourceException("Wrong header length", datafile, "");
    }
    /* Validate the magic number. */
    for (int i = 0; i < LABEL_LENGTH; i++, offset++) {
        if (buf[offset] != LABEL[offset]) {
            throw new MissingResourceException("Wrong magic number", datafile, "");
        }
    }
    /* Validate the version number. */
    if (buf[offset] != supportedVersion) {
        throw new MissingResourceException("Unsupported version(" + buf[offset] + ")", datafile, "");
    }
    /* Read data: totalDataSize + 8(for checksum) */
    len = getInt(buf, ++offset);
    buf = new byte[len];
    if (is.read(buf) != len) {
        throw new MissingResourceException("Wrong data length", datafile, "");
    }
    is.close();
    return buf;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) PrivilegedActionException(java.security.PrivilegedActionException) MissingResourceException(java.util.MissingResourceException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction)

Example 50 with PrivilegedActionException

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

the class UnixPrintServiceLookup method execCmd.

static String[] execCmd(final String command) {
    ArrayList results = null;
    try {
        final String[] cmd = new String[3];
        if (isSysV() || isAIX()) {
            cmd[0] = "/usr/bin/sh";
            cmd[1] = "-c";
            cmd[2] = "env LC_ALL=C " + command;
        } else {
            cmd[0] = "/bin/sh";
            cmd[1] = "-c";
            cmd[2] = "LC_ALL=C " + command;
        }
        results = (ArrayList) AccessController.doPrivileged(new PrivilegedExceptionAction() {

            public Object run() throws IOException {
                Process proc;
                BufferedReader bufferedReader = null;
                File f = Files.createTempFile("prn", "xc").toFile();
                cmd[2] = cmd[2] + ">" + f.getAbsolutePath();
                proc = Runtime.getRuntime().exec(cmd);
                try {
                    // in case of interrupt.
                    boolean done = false;
                    while (!done) {
                        try {
                            proc.waitFor();
                            done = true;
                        } catch (InterruptedException e) {
                        }
                    }
                    if (proc.exitValue() == 0) {
                        FileReader reader = new FileReader(f);
                        bufferedReader = new BufferedReader(reader);
                        String line;
                        ArrayList results = new ArrayList();
                        while ((line = bufferedReader.readLine()) != null) {
                            results.add(line);
                        }
                        return results;
                    }
                } finally {
                    f.delete();
                    // promptly close all streams.
                    if (bufferedReader != null) {
                        bufferedReader.close();
                    }
                    proc.getInputStream().close();
                    proc.getErrorStream().close();
                    proc.getOutputStream().close();
                }
                return null;
            }
        });
    } catch (PrivilegedActionException e) {
    }
    if (results == null) {
        return new String[0];
    } else {
        return (String[]) results.toArray(new String[results.size()]);
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) IOException(java.io.IOException) File(java.io.File)

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