Methods Summary |
---|
static java.security.Policy | getAccessiblePolicy()Shortcut accessor for friendly classes, to skip security checks.
If active policy was set to null , loads default provider,
so this method never returns null .
This method is synchronized with setPolicy()
Policy current = activePolicy;
if (current == null) {
synchronized (Policy.class) {
// double check in case value has been reassigned
// while we've been awaiting monitor
if (activePolicy == null) {
activePolicy = getDefaultProvider();
}
return activePolicy;
}
}
return current;
|
private static java.security.Policy | getDefaultProvider()
final String defaultClass = (String) AccessController
.doPrivileged(new PolicyUtils.SecurityPropertyAccessor(
POLICY_PROVIDER));
if (defaultClass == null) {
//TODO log warning
//System.err.println("No policy provider specified. Loading the "
// + DefaultPolicy.class.getName());
return new DefaultPolicy();
}
// TODO accurate classloading
return AccessController.doPrivileged(new PrivilegedAction<Policy>() {
public Policy run() {
try {
return (Policy) Class.forName(defaultClass, true,
ClassLoader.getSystemClassLoader()).newInstance();
}
catch (Exception e) {
//TODO log error
//System.err.println("Error loading policy provider <"
// + defaultClass + "> : " + e
// + "\nSwitching to the default "
// + DefaultPolicy.class.getName());
return new DefaultPolicy();
}
}
});
|
public abstract java.security.PermissionCollection | getPermissions(java.security.CodeSource cs)Returns a {@code PermissionCollection} describing what permissions are
allowed for the specified {@code CodeSource} based on the current
security policy.
Note that this method is not called for classes which are in the system
domain (i.e. system classes). System classes are always given
full permissions (i.e. AllPermission). This can not be changed by
installing a new policy.
|
public java.security.PermissionCollection | getPermissions(java.security.ProtectionDomain domain)Returns a {@code PermissionCollection} describing what permissions are
allowed for the specified {@code ProtectionDomain} (more specifically,
its {@code CodeSource}) based on the current security policy.
Note that this method is not< called for classes which are in the
system domain (i.e. system classes). System classes are always
given full permissions (i.e. AllPermission). This can not be changed by
installing a new policy.
if (domain != null) {
return getPermissions(domain.getCodeSource());
}
return new Permissions();
|
public static java.security.Policy | getPolicy()Returns the current system security policy. If no policy has been
instantiated then this is done using the security property {@code
"policy.provider"}.
If a {@code SecurityManager} is installed, code calling this method needs
the {@code SecurityPermission} {@code getPolicy} to be granted, otherwise
a {@code SecurityException} will be thrown.
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(GET_POLICY);
}
return getAccessiblePolicy();
|
public boolean | implies(java.security.ProtectionDomain domain, java.security.Permission permission)Indicates whether the specified {@code Permission} is implied by the
{@code PermissionCollection} of the specified {@code ProtectionDomain}.
if (domain != null) {
PermissionCollection total = getPermissions(domain);
PermissionCollection inherent = domain.getPermissions();
if (total == null) {
total = inherent;
} else if (inherent != null) {
for (Enumeration en = inherent.elements(); en.hasMoreElements();) {
total.add((Permission)en.nextElement());
}
}
if (total != null && total.implies(permission)) {
return true;
}
}
return false;
|
static boolean | isSet()Returns {@code true} if system policy provider is instantiated.
return activePolicy != null;
|
public abstract void | refresh()Reloads the policy configuration for this {@code Policy} instance.
|
public static void | setPolicy(java.security.Policy policy)Sets the system wide policy.
If a {@code SecurityManager} is installed, code calling this method needs
the {@code SecurityPermission} {@code setPolicy} to be granted, otherwise
a {@code SecurityException} will be thrown.
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(SET_POLICY);
}
synchronized (Policy.class) {
activePolicy = policy;
}
|