Class AggregatePolicyProvider
- All Implemented Interfaces:
DynamicPolicy,SecurityContextSource
implies and
refresh operations are delegated to the currently active sub-policy. The
currently active sub-policy is determined as follows: if the current thread does not override the
getContextClassLoader method, then that method is called to
obtain the context class loader. If the context class loader is associated with a sub-policy
(via a previous call to setPolicy), then that sub-policy is the currently active
sub-policy. If no such association exists, then the same check is performed on each
non-null parent of the context class loader, proceeding up the chain of class loader
delegation, until a sub-policy association is found, in which case the associated sub-policy is
the currently active sub-policy. If no sub-policy association is found for the context class
loader or any of its parents, then a fallback sub-policy, the main policy, is the currently
active sub-policy. Also, if the current thread overrides the getContextClassLoader
method, then getContextClassLoader is not called and the main policy is the
currently active sub-policy.
- Since:
- 2.0
- Author:
- Sun Microsystems, Inc.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.security.Policy
Policy.Parameters -
Field Summary
Fields inherited from class java.security.Policy
UNSUPPORTED_EMPTY_COLLECTION -
Constructor Summary
ConstructorsConstructorDescriptionCreates a newAggregatePolicyProviderinstance, containing a main policy created as follows: if thecom.sun.jini.start.AggregatePolicyProvider.mainPolicyClasssecurity property is set, then its value is interpreted as the class name of the main policy provider; otherwise, a default class name of"net.jini.security.policy.DynamicPolicyProvider"is used.AggregatePolicyProvider(Policy mainPolicy) Creates a newAggregatePolicyProviderinstance with the given main policy, which must be non-null. -
Method Summary
Modifier and TypeMethodDescriptionReturns a snapshot of the current security context, which can be used to restore the context at a later time.If the currently active sub-policy supports dynamic permission grants, delegates to the correspondinggetGrantsmethod of the currently active sub-policy to return a new array containing the set of permissions dynamically granted to protection domains which are associated with the class loader of the given class and possess at least the given set of principals.getPermissions(CodeSource source) Delegates to the correspondinggetPermissionsmethod of the currently active sub-policy to return the set of permissions allowed for code from the specified code source, as a newly-created mutablePermissionCollectionwhich supports heterogeneous permission types.getPermissions(ProtectionDomain domain) If the given protection domain is the protection domain of this class, then a newly-createdPermissionCollectioncontainingAllPermissionis returned.voidgrant(Class cl, Principal[] principals, Permission[] permissions) If the currently active sub-policy supports dynamic permission grants, delegates to the correspondinggrantmethod of the currently active sub-policy to grant the specified permissions to all protection domains (including ones not yet created) which are associated with the class loader of the given class and possess at least the given set of principals.booleanReturnstrueif the currently active sub-policy supports dynamic grants; this is determined by delegating to thegrantSupportedmethod of the currently active sub-policy if it implements theDynamicPolicyinterface.booleanimplies(ProtectionDomain domain, Permission permission) If the given protection domain is the protection domain of this class, thentrueis returned.voidrefresh()Refreshes the currently active sub-policy by delegating to itsrefreshmethod.voidsetPolicy(ClassLoader loader, Policy subPolicy) Changes sub-policy association with given class loader.Methods inherited from class java.security.Policy
getInstance, getInstance, getInstance, getParameters, getPolicy, getProvider, getType, setPolicy
-
Constructor Details
-
AggregatePolicyProvider
Creates a newAggregatePolicyProviderinstance, containing a main policy created as follows: if thecom.sun.jini.start.AggregatePolicyProvider.mainPolicyClasssecurity property is set, then its value is interpreted as the class name of the main policy provider; otherwise, a default class name of"net.jini.security.policy.DynamicPolicyProvider"is used. The main policy is then instantiated using the no-arg public constructor of the named class. If the main policy class is not found, is not instantiable via a public no-arg constructor, or if invocation of its constructor fails, then aPolicyInitializationExceptionis thrown.Note that this constructor requires the appropriate
"getProperty"SecurityPermissionto read thecom.sun.jini.start.AggregatePolicyProvider.mainPolicyClasssecurity property, and may require"accessClassInPackage.*"RuntimePermissions, depending on the package of the main policy class.- Throws:
PolicyInitializationException- if unable to construct the main policySecurityException- if there is a security manager and the calling context does not haveSecurityPermissionfor reading thecom.sun.jini.start.AggregatePolicyProvider.mainPolicysecurity property, or if the calling context does not have adequate permissions to access the main policy class
-
AggregatePolicyProvider
Creates a newAggregatePolicyProviderinstance with the given main policy, which must be non-null.- Parameters:
mainPolicy- main policy- Throws:
NullPointerException- if main policy isnull
-
-
Method Details
-
getPermissions
Delegates to the correspondinggetPermissionsmethod of the currently active sub-policy to return the set of permissions allowed for code from the specified code source, as a newly-created mutablePermissionCollectionwhich supports heterogeneous permission types.- Overrides:
getPermissionsin classPolicy- Parameters:
source- code source for which to look up permissions- Returns:
- set of permissions allowed for the given code source
-
getPermissions
If the given protection domain is the protection domain of this class, then a newly-createdPermissionCollectioncontainingAllPermissionis returned. Otherwise, delegates to the correspondinggetPermissionsmethod of the currently active sub-policy to return the set of permissions allowed for code in the specified protection domain, as a newly-created mutablePermissionCollectionwhich supports heterogeneous permission types.- Overrides:
getPermissionsin classPolicy- Parameters:
domain- protection domain for which to look up permissions- Returns:
- set of permissions allowed for given protection domain
-
implies
If the given protection domain is the protection domain of this class, thentrueis returned. Otherwise, delegates to theimpliesmethod of the currently active sub-policy to determine if the given permission is implied by the permissions for the specified protection domain. -
refresh
public void refresh()Refreshes the currently active sub-policy by delegating to itsrefreshmethod. -
setPolicy
Changes sub-policy association with given class loader. IfsubPolicyis non-null, then it is used as a new sub-policy to associate with the given class loader, overriding any previous sub-policy associated with the loader. IfsubPolicyisnull, then any previous association between a sub-policy and the given class loader is removed. If loader isnull, thensubPolicyis used as the new main policy, and must be non-null. If there is a security manager, itscheckPermissionmethod is called with the"setPolicy"SecurityPermission.- Parameters:
loader- class loader with which to associate sub-policy, ornullif setting main policysubPolicy- sub-policy to associate with given class loader, ornullif removing sub-policy association- Throws:
NullPointerException- if bothloaderandsubPolicyarenullSecurityException- if there is a security manager and the calling context does not have the"setPolicy" SecurityPermission
-
grantSupported
public boolean grantSupported()Returnstrueif the currently active sub-policy supports dynamic grants; this is determined by delegating to thegrantSupportedmethod of the currently active sub-policy if it implements theDynamicPolicyinterface. If the currently active sub-policy does not implementDynamicPolicy, thenfalseis returned.- Specified by:
grantSupportedin interfaceDynamicPolicy- Returns:
trueif the currently active sub-policy supports dynamic grants, orfalseotherwise
-
grant
If the currently active sub-policy supports dynamic permission grants, delegates to the correspondinggrantmethod of the currently active sub-policy to grant the specified permissions to all protection domains (including ones not yet created) which are associated with the class loader of the given class and possess at least the given set of principals.- Specified by:
grantin interfaceDynamicPolicy- Parameters:
cl- class to grant permissions to the class loader of, ornullif granting across all class loadersprincipals- if non-null, minimum set of principals to which grants applypermissions- if non-null, permissions to grant- Throws:
UnsupportedOperationException- if policy does not support dynamic grants, or ifclis non-nulland belongs to a protection domain with anullclass loader other than the system domainSecurityException- if a security manager is installed and the calling context does not have sufficient permissions to grant the given permissionsNullPointerException- if any element of the principals or permissions arrays isnull
-
getGrants
If the currently active sub-policy supports dynamic permission grants, delegates to the correspondinggetGrantsmethod of the currently active sub-policy to return a new array containing the set of permissions dynamically granted to protection domains which are associated with the class loader of the given class and possess at least the given set of principals.- Specified by:
getGrantsin interfaceDynamicPolicy- Parameters:
cl- class to query the permissions dynamically granted to the class loader of, ornullif querying permissions granted across all class loadersprincipals- if non-null, principals to query dynamic grants for- Returns:
- new array containing the permissions dynamically granted to the indicated class loader (if any) and principals
- Throws:
UnsupportedOperationException- if policy does not support dynamic grants, or ifclis non-nulland belongs to a protection domain with anullclass loader other than the system domainNullPointerException- if any element of the principals array isnull
-
getContext
Returns a snapshot of the current security context, which can be used to restore the context at a later time.The security context returned by this method contains the security context of the currently active sub-policy (or an equivalent of the default security context described in the documentation for
Security.getContext, if the currently active sub-policy does not implementSecurityContextSource), as well as the current context class loader. The privileged action wrappers it creates restore the saved context class loader before delegating to the action wrappers of the underlying sub-policy security context. ThegetAccessControlContextmethod of the returned security context delegates to the corresponding method of the sub-policy security context.- Specified by:
getContextin interfaceSecurityContextSource- Returns:
- snapshot of the current security context
-