Java Code Examples for sun.security.action.GetPropertyAction#privilegedGetProperty()

The following examples show how to use sun.security.action.GetPropertyAction#privilegedGetProperty() . 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: LocalGregorianCalendar.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
static LocalGregorianCalendar getLocalGregorianCalendar(String name) {
    // Only the Japanese calendar is supported.
    if (!"japanese".equals(name)) {
        return null;
    }

    // Append an era to the predefined eras if it's given by the property.
    String prop = GetPropertyAction
            .privilegedGetProperty("jdk.calendar.japanese.supplemental.era");
    if (prop != null) {
        Era era = parseEraEntry(prop);
        if (era != null) {
            if (isValidEra(era, JAPANESE_ERAS)) {
                int length = JAPANESE_ERAS.length;
                Era[] eras = new Era[length + 1];
                System.arraycopy(JAPANESE_ERAS, 0, eras, 0, length);
                eras[length] = era;
                return new LocalGregorianCalendar(name, eras);
            }
        }
    }
    return new LocalGregorianCalendar(name, JAPANESE_ERAS);
}
 
Example 2
Source File: Util.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the max size allowed for a cached temp buffers, in
 * bytes. It defaults to Long.MAX_VALUE. It can be set with the
 * jdk.nio.maxCachedBufferSize property. Even though
 * ByteBuffer.capacity() returns an int, we're using a long here
 * for potential future-proofing.
 */
private static long getMaxCachedBufferSize() {
    String s = GetPropertyAction
            .privilegedGetProperty("jdk.nio.maxCachedBufferSize");
    if (s != null) {
        try {
            long m = Long.parseLong(s);
            if (m >= 0) {
                return m;
            } else {
                // if it's negative, ignore the system property
            }
        } catch (NumberFormatException e) {
            // if the string is not well formed, ignore the system property
        }
    }
    return Long.MAX_VALUE;
}
 
Example 3
Source File: LocalGregorianCalendar.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
static LocalGregorianCalendar getLocalGregorianCalendar(String name) {
    // Only the Japanese calendar is supported.
    if (!"japanese".equals(name)) {
        return null;
    }

    // Append an era to the predefined eras if it's given by the property.
    String prop = GetPropertyAction
            .privilegedGetProperty("jdk.calendar.japanese.supplemental.era");
    if (prop != null) {
        Era era = parseEraEntry(prop);
        if (era != null) {
            if (isValidEra(era, JAPANESE_ERAS)) {
                int length = JAPANESE_ERAS.length;
                Era[] eras = new Era[length + 1];
                System.arraycopy(JAPANESE_ERAS, 0, eras, 0, length);
                eras[length] = era;
                return new LocalGregorianCalendar(name, eras);
            }
        }
    }
    return new LocalGregorianCalendar(name, JAPANESE_ERAS);
}
 
Example 4
Source File: LinuxFileSystemProvider.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
FileTypeDetector getFileTypeDetector() {
    String userHome = GetPropertyAction.privilegedGetProperty("user.home");
    Path userMimeTypes = Paths.get(userHome, ".mime.types");
    Path etcMimeTypes = Paths.get("/etc/mime.types");

    return chain(new MimeTypesFileTypeDetector(userMimeTypes),
                 new MimeTypesFileTypeDetector(etcMimeTypes));
}
 
Example 5
Source File: FileDispatcherImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static boolean isFastFileTransferRequested() {
    String fileTransferProp = GetPropertyAction
            .privilegedGetProperty("jdk.nio.enableFastFileTransfer");
    boolean enable;
    if ("".equals(fileTransferProp)) {
        enable = true;
    } else {
        enable = Boolean.parseBoolean(fileTransferProp);
    }
    return enable;
}
 
Example 6
Source File: ProcessImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static Platform get() {
    String osName = GetPropertyAction.privilegedGetProperty("os.name");

    if (osName.equals("Linux")) { return LINUX; }
    if (osName.contains("OS X")) { return BSD; }
    if (osName.equals("SunOS")) { return SOLARIS; }
    if (osName.equals("AIX")) { return AIX; }

    throw new Error(osName + " is not a supported OS platform.");
}
 
Example 7
Source File: FileChannelImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static boolean isSharedFileLockTable() {
    if (!propertyChecked) {
        synchronized (FileChannelImpl.class) {
            if (!propertyChecked) {
                String value = GetPropertyAction.privilegedGetProperty(
                        "sun.nio.ch.disableSystemWideOverlappingFileLockCheck");
                isSharedFileLockTable = ((value == null) || value.equals("false"));
                propertyChecked = true;
            }
        }
    }
    return isSharedFileLockTable;
}
 
Example 8
Source File: SimpleConsoleLogger.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
static String getSimpleFormat(String key, Function<String, String> defaultPropertyGetter) {
    // Double check that 'key' is one of the expected property names:
    // - DEFAULT_FORMAT_PROP_KEY is used to control the
    //   SimpleConsoleLogger format when java.logging is
    //   not present.
    // - JUL_FORMAT_PROP_KEY is used when this method is called
    //   from the SurrogateLogger subclass. It is used to control the
    //   SurrogateLogger format and java.util.logging.SimpleFormatter
    //   format when java.logging is present.
    // This method should not be called with any other key.
    if (!DEFAULT_FORMAT_PROP_KEY.equals(key)
            && !JUL_FORMAT_PROP_KEY.equals(key)) {
        throw new IllegalArgumentException("Invalid property name: " + key);
    }

    // Do not use any lambda in this method. Using a lambda here causes
    //    jdk/test/java/lang/invoke/lambda/LogGeneratedClassesTest.java
    // to fail - because that test has a testcase which somehow references
    // PlatformLogger and counts the number of generated lambda classes.
    String format = GetPropertyAction.privilegedGetProperty(key);

    if (format == null && defaultPropertyGetter != null) {
        format = defaultPropertyGetter.apply(key);
    }
    if (format != null) {
        try {
            // validate the user-defined format string
            String.format(format, ZonedDateTime.now(), "", "", "", "", "");
        } catch (IllegalArgumentException e) {
            // illegal syntax; fall back to the default format
            format = DEFAULT_FORMAT;
        }
    } else {
        format = DEFAULT_FORMAT;
    }
    return format;
}
 
Example 9
Source File: SimpleConsoleLogger.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static String getSimpleFormat(String key, Function<String, String> defaultPropertyGetter) {
    // Double check that 'key' is one of the expected property names:
    // - DEFAULT_FORMAT_PROP_KEY is used to control the
    //   SimpleConsoleLogger format when java.logging is
    //   not present.
    // - JUL_FORMAT_PROP_KEY is used when this method is called
    //   from the SurrogateLogger subclass. It is used to control the
    //   SurrogateLogger format and java.util.logging.SimpleFormatter
    //   format when java.logging is present.
    // This method should not be called with any other key.
    if (!DEFAULT_FORMAT_PROP_KEY.equals(key)
            && !JUL_FORMAT_PROP_KEY.equals(key)) {
        throw new IllegalArgumentException("Invalid property name: " + key);
    }

    // Do not use any lambda in this method. Using a lambda here causes
    //    jdk/test/java/lang/invoke/lambda/LogGeneratedClassesTest.java
    // to fail - because that test has a testcase which somehow references
    // PlatformLogger and counts the number of generated lambda classes.
    String format = GetPropertyAction.privilegedGetProperty(key);

    if (format == null && defaultPropertyGetter != null) {
        format = defaultPropertyGetter.apply(key);
    }
    if (format != null) {
        try {
            // validate the user-defined format string
            String.format(format, ZonedDateTime.now(), "", "", "", "", "");
        } catch (IllegalArgumentException e) {
            // illegal syntax; fall back to the default format
            format = DEFAULT_FORMAT;
        }
    } else {
        format = DEFAULT_FORMAT;
    }
    return format;
}
 
Example 10
Source File: SimpleConsoleLogger.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static Level getDefaultLevel() {
    String levelName = GetPropertyAction
            .privilegedGetProperty("jdk.system.logger.level", "INFO");
    try {
        return Level.valueOf(levelName);
    } catch (IllegalArgumentException iae) {
        return Level.INFO;
    }
}
 
Example 11
Source File: GSSUtil.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determines if the application doesn't mind if the mechanism obtains
 * the required credentials from outside of the current Subject. Our
 * Kerberos v5 mechanism would do a JAAS login on behalf of the
 * application if this were the case.
 *
 * The application indicates this by explicitly setting the system
 * property javax.security.auth.useSubjectCredsOnly to false.
 */
public static boolean useSubjectCredsOnly(GSSCaller caller) {

    String propValue = GetPropertyAction.privilegedGetProperty(
            "javax.security.auth.useSubjectCredsOnly");

    // Invalid values should be ignored and the default assumed.
    if (caller instanceof HttpCaller) {
        // Default for HTTP/SPNEGO is false.
        return "true".equalsIgnoreCase(propValue);
    } else {
        // Default for JGSS is true.
        return !("false".equalsIgnoreCase(propValue));
    }
}
 
Example 12
Source File: GSSUtil.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determines if the application doesn't mind if the mechanism obtains
 * the required credentials from outside of the current Subject. Our
 * Kerberos v5 mechanism would do a JAAS login on behalf of the
 * application if this were the case.
 *
 * The application indicates this by explicitly setting the system
 * property javax.security.auth.useSubjectCredsOnly to false.
 */
public static boolean useSubjectCredsOnly(GSSCaller caller) {

    String propValue = GetPropertyAction.privilegedGetProperty(
            "javax.security.auth.useSubjectCredsOnly");

    // Invalid values should be ignored and the default assumed.
    if (caller instanceof HttpCaller) {
        // Default for HTTP/SPNEGO is false.
        return "true".equalsIgnoreCase(propValue);
    } else {
        // Default for JGSS is true.
        return !("false".equalsIgnoreCase(propValue));
    }
}
 
Example 13
Source File: PKIXValidator.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static boolean allowNonCaAnchor() {
    String prop = GetPropertyAction
        .privilegedGetProperty("jdk.security.allowNonCaAnchor");
    return prop != null && (prop.isEmpty() || prop.equalsIgnoreCase("true"));
}
 
Example 14
Source File: MimeLauncher.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private boolean findExecutablePath(String str) {
    if (str == null || str.length() == 0) {
        return false;
    }

    String command;
    int index = str.indexOf(' ');
    if (index != -1) {
        command = str.substring(0, index);
    }
    else {
        command = str;
    }

    File f = new File(command);
    if (f.isFile()) {
        // Already executable as it is
        execPath = str;
        return true;
    }

    String execPathList;
    execPathList = GetPropertyAction.privilegedGetProperty("exec.path");
    if (execPathList == null) {
        // exec.path property not set
        return false;
    }

    StringTokenizer iter = new StringTokenizer(execPathList, "|");
    while (iter.hasMoreElements()) {
        String prefix = (String)iter.nextElement();
        String fullCmd = prefix + File.separator + command;
        f = new File(fullCmd);
        if (f.isFile()) {
            execPath = prefix + File.separator + str;
            return true;
        }
    }

    return false; // application not found in exec.path
}
 
Example 15
Source File: SSLContextImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static Collection<CipherSuite> getCustomizedCipherSuites(
        String propertyName) {

    String property = GetPropertyAction.privilegedGetProperty(propertyName);
    if (debug != null && Debug.isOn("sslctx")) {
        System.out.println(
                "System property " + propertyName + " is set to '" +
                property + "'");
    }
    if (property != null && property.length() != 0) {
        // remove double quote marks from beginning/end of the property
        if (property.length() > 1 && property.charAt(0) == '"' &&
                property.charAt(property.length() - 1) == '"') {
            property = property.substring(1, property.length() - 1);
        }
    }

    if (property != null && property.length() != 0) {
        String[] cipherSuiteNames = property.split(",");
        Collection<CipherSuite> cipherSuites =
                    new ArrayList<>(cipherSuiteNames.length);
        for (int i = 0; i < cipherSuiteNames.length; i++) {
            cipherSuiteNames[i] = cipherSuiteNames[i].trim();
            if (cipherSuiteNames[i].isEmpty()) {
                continue;
            }

            CipherSuite suite;
            try {
                suite = CipherSuite.valueOf(cipherSuiteNames[i]);
            } catch (IllegalArgumentException iae) {
                if (debug != null && Debug.isOn("sslctx")) {
                    System.out.println(
                            "Unknown or unsupported cipher suite name: " +
                            cipherSuiteNames[i]);
                }

                continue;
            }

            if (suite.isAvailable()) {
                cipherSuites.add(suite);
            } else {
                if (debug != null && Debug.isOn("sslctx")) {
                    System.out.println(
                            "The current installed providers do not " +
                            "support cipher suite: " + cipherSuiteNames[i]);
                }
            }
        }

        return cipherSuites;
    }

    return Collections.emptyList();
}
 
Example 16
Source File: PKIXValidator.java    From openjsse with GNU General Public License v2.0 4 votes vote down vote up
private static boolean allowNonCaAnchor() {
    String prop = GetPropertyAction
        .privilegedGetProperty("jdk.security.allowNonCaAnchor");
    return prop != null && (prop.isEmpty() || prop.equalsIgnoreCase("true"));
}
 
Example 17
Source File: MimeLauncher.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
private boolean findExecutablePath(String str) {
    if (str == null || str.isEmpty()) {
        return false;
    }

    String command;
    int index = str.indexOf(' ');
    if (index != -1) {
        command = str.substring(0, index);
    }
    else {
        command = str;
    }

    File f = new File(command);
    if (f.isFile()) {
        // Already executable as it is
        execPath = str;
        return true;
    }

    String execPathList;
    execPathList = GetPropertyAction.privilegedGetProperty("exec.path");
    if (execPathList == null) {
        // exec.path property not set
        return false;
    }

    StringTokenizer iter = new StringTokenizer(execPathList, "|");
    while (iter.hasMoreElements()) {
        String prefix = (String)iter.nextElement();
        String fullCmd = prefix + File.separator + command;
        f = new File(fullCmd);
        if (f.isFile()) {
            execPath = prefix + File.separator + str;
            return true;
        }
    }

    return false; // application not found in exec.path
}
 
Example 18
Source File: PKIXValidator.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private static boolean allowNonCaAnchor() {
    String prop = GetPropertyAction
        .privilegedGetProperty("jdk.security.allowNonCaAnchor");
    return prop != null && (prop.isEmpty() || prop.equalsIgnoreCase("true"));
}
 
Example 19
Source File: SSLContextImpl.java    From openjsse with GNU General Public License v2.0 4 votes vote down vote up
private static Collection<CipherSuite> getCustomizedCipherSuites(
        String propertyName) {

    String property = GetPropertyAction.privilegedGetProperty(propertyName);
    if (SSLLogger.isOn && SSLLogger.isOn("ssl,sslctx")) {
        SSLLogger.fine(
                "System property " + propertyName + " is set to '" +
                property + "'");
    }
    if (property != null && property.length() != 0) {
        // remove double quote marks from beginning/end of the property
        if (property.length() > 1 && property.charAt(0) == '"' &&
                property.charAt(property.length() - 1) == '"') {
            property = property.substring(1, property.length() - 1);
        }
    }

    if (property != null && property.length() != 0) {
        String[] cipherSuiteNames = property.split(",");
        Collection<CipherSuite> cipherSuites =
                    new ArrayList<>(cipherSuiteNames.length);
        for (int i = 0; i < cipherSuiteNames.length; i++) {
            cipherSuiteNames[i] = cipherSuiteNames[i].trim();
            if (cipherSuiteNames[i].isEmpty()) {
                continue;
            }

            CipherSuite suite;
            try {
                suite = CipherSuite.nameOf(cipherSuiteNames[i]);
            } catch (IllegalArgumentException iae) {
                if (SSLLogger.isOn && SSLLogger.isOn("ssl,sslctx")) {
                    SSLLogger.fine(
                            "Unknown or unsupported cipher suite name: " +
                            cipherSuiteNames[i]);
                }

                continue;
            }

            if (suite != null && suite.isAvailable()) {
                cipherSuites.add(suite);
            } else {
                if (SSLLogger.isOn && SSLLogger.isOn("ssl,sslctx")) {
                    SSLLogger.fine(
                            "The current installed providers do not " +
                            "support cipher suite: " + cipherSuiteNames[i]);
                }
            }
        }

        return cipherSuites;
    }

    return Collections.emptyList();
}
 
Example 20
Source File: StatusResponseManager.java    From openjsse with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a StatusResponseManager with default parameters.
 */
StatusResponseManager() {
    int cap = AccessController.doPrivileged(
            new GetIntegerAction("jdk.tls.stapling.cacheSize",
                DEFAULT_CACHE_SIZE));
    cacheCapacity = cap > 0 ? cap : 0;

    int life = AccessController.doPrivileged(
            new GetIntegerAction("jdk.tls.stapling.cacheLifetime",
                DEFAULT_CACHE_LIFETIME));
    cacheLifetime = life > 0 ? life : 0;

    String uriStr = GetPropertyAction
            .privilegedGetProperty("jdk.tls.stapling.responderURI");
    URI tmpURI;
    try {
        tmpURI = ((uriStr != null && !uriStr.isEmpty()) ?
                new URI(uriStr) : null);
    } catch (URISyntaxException urise) {
        tmpURI = null;
    }
    defaultResponder = tmpURI;

    respOverride = AccessController.doPrivileged(
            new GetBooleanAction("jdk.tls.stapling.responderOverride"));
    ignoreExtensions = AccessController.doPrivileged(
            new GetBooleanAction("jdk.tls.stapling.ignoreExtensions"));

    threadMgr = new ScheduledThreadPoolExecutor(DEFAULT_CORE_THREADS,
            new ThreadFactory() {
        @Override
        public Thread newThread(Runnable r) {
            Thread t = Executors.defaultThreadFactory().newThread(r);
            t.setDaemon(true);
            return t;
        }
    }, new ThreadPoolExecutor.DiscardPolicy());
    threadMgr.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
    threadMgr.setContinueExistingPeriodicTasksAfterShutdownPolicy(
            false);
    threadMgr.setKeepAliveTime(5000, TimeUnit.MILLISECONDS);
    threadMgr.allowCoreThreadTimeOut(true);
    responseCache = Cache.newSoftMemoryCache(
            cacheCapacity, cacheLifetime);
}