< prev index next >
src/share/classes/sun/security/action/GetPropertyAction.java
Print this page
rev 12543 : 8181048: Refactor existing providers to refer to the same constants for default values for key length
Reviewed-by: mullan, ahgross
*** 1,7 ****
/*
! * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 23,32 ****
--- 23,35 ----
* questions.
*/
package sun.security.action;
+ import java.security.AccessController;
+ import java.security.PrivilegedAction;
+
/**
* A convenience class for retrieving the string value of a system
* property as a privileged action.
*
* <p>An instance of this class can be used as the argument of
*** 44,55 ****
* @see java.security.PrivilegedAction
* @see java.security.AccessController
* @since 1.2
*/
! public class GetPropertyAction
! implements java.security.PrivilegedAction<String> {
private String theProp;
private String defaultVal;
/**
* Constructor that takes the name of the system property whose
--- 47,57 ----
* @see java.security.PrivilegedAction
* @see java.security.AccessController
* @since 1.2
*/
! public class GetPropertyAction implements PrivilegedAction<String> {
private String theProp;
private String defaultVal;
/**
* Constructor that takes the name of the system property whose
*** 82,87 ****
--- 84,111 ----
*/
public String run() {
String value = System.getProperty(theProp);
return (value == null) ? defaultVal : value;
}
+
+ /**
+ * Convenience method to get a property without going through doPrivileged
+ * if no security manager is present. This is unsafe for inclusion in a
+ * public API but allowable here since this class is by default restricted
+ * by the package.access security property.
+ *
+ * Note that this method performs a privileged action using caller-provided
+ * inputs. The caller of this method should take care to ensure that the
+ * inputs are not tainted and the returned property is not made accessible
+ * to untrusted code if it contains sensitive information.
+ *
+ * @param theProp the name of the system property.
+ */
+ public static String privilegedGetProperty(String theProp) {
+ if (System.getSecurityManager() == null) {
+ return System.getProperty(theProp);
+ } else {
+ return AccessController.doPrivileged(
+ new GetPropertyAction(theProp));
+ }
+ }
}
< prev index next >