Class PolicyParser
The Java runtime creates one global Policy object, which is used to represent the static policy configuration file. It is consulted by a ProtectionDomain when the protection domain initializes its set of permissions.
The Policy init method parses the policy
configuration file, and then
populates the Policy object. The Policy object is agnostic in that
it is not involved in making policy decisions. It is merely the
Java runtime representation of the persistent policy configuration
file.
When a protection domain needs to initialize its set of permissions, it executes code such as the following to ask the global Policy object to populate a Permissions object with the appropriate permissions:
policy = Policy.getPolicy(); Permissions perms = policy.getPermissions(protectiondomain)
The protection domain contains a CodeSource object, which encapsulates its codebase (URL) and public key attributes. It also contains the principals associated with the domain. The Policy object evaluates the global policy in light of whom the principal is and what the code source is and returns an appropriate Permissions object.
- Since:
- 1.2 Copy of OpenJDK 21 sun.security.provider.PolicyParser (removed in JDK 24), openjdk/jdk21u bb6b279495ceff8442dbd0225756b92d466d5309, minus property expansion and debug output.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classEach domain entry in the keystore domain configuration file is represented by a DomainEntry object.static classEach grant entry in the policy configuration file is represented by a GrantEntry object.(package private) static classEach keystore entry in the keystore domain configuration file is represented by a KeyStoreEntry object.private static final classstatic classstatic classEach permission entry in the policy configuration file is represented by a PermissionEntry object.static classPrincipal info (class and name) in a grant entryprivate static final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Map<String, PolicyParser.DomainEntry> private final Vector<PolicyParser.GrantEntry> private Stringprivate Stringprivate Stringprivate intprivate StreamTokenizerprivate String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidprivate Stringprivate StringReturns the (possibly expanded) keystore location, or null if the expansion fails.Enumerate all the entries in the global policy object.private Stringprivate PolicyParser.DomainEntryparse a domain entryprivate PolicyParser.GrantEntryparse a Grant entryprivate voidparses a keystore entryprivate PolicyParser.PermissionEntryparse a Permission entryparseProperties(String terminator) private voidprivate booleanprivate booleanpeekAndMatch(String expect) voidReads a policy configuration into the Policy object using a Reader object.booleanvoidreplace(PolicyParser.GrantEntry origGe, PolicyParser.GrantEntry newGe) voidsetKeyStoreProvider(String provider) voidsetKeyStoreType(String type) voidsetKeyStoreUrl(String url) voidsetStorePassURL(String storePassURL) private voidskip all tokens for this entry leaving the delimiter ";" in the stream.voidwrite out the policyprivate voidwrites the (unexpanded) keystore entryprivate void
-
Field Details
-
grantEntries
-
domainEntries
-
st
-
lookahead
private int lookahead -
keyStoreUrlString
-
keyStoreType
-
keyStoreProvider
-
storePassURL
-
-
Constructor Details
-
PolicyParser
public PolicyParser()Creates a PolicyParser object.
-
-
Method Details
-
expand
-
expand
private String expand(String value, boolean encodeURL) throws PolicyParser.PropertyExpander.ExpandException -
read
Reads a policy configuration into the Policy object using a Reader object.- Parameters:
policy- the policy Reader object.- Throws:
PolicyParser.ParsingException- if the policy configuration contains a syntax error.IOException- if an error occurs while reading the policy configuration.
-
add
-
replace
-
remove
-
getKeyStoreUrl
Returns the (possibly expanded) keystore location, or null if the expansion fails. -
setKeyStoreUrl
-
getKeyStoreType
-
setKeyStoreType
-
getKeyStoreProvider
-
setKeyStoreProvider
-
getStorePassURL
-
setStorePassURL
-
grantElements
Enumerate all the entries in the global policy object. This method is used by policy admin tools. The tools should use the Enumeration methods on the returned object to fetch the elements sequentially. -
getDomainEntries
-
write
write out the policy -
parseKeyStoreEntry
parses a keystore entry -
parseStorePassURL
-
writeKeyStoreEntry
writes the (unexpanded) keystore entry -
writeStorePassURL
-
parseGrantEntry
parse a Grant entry -
parsePermissionEntry
private PolicyParser.PermissionEntry parsePermissionEntry() throws PolicyParser.ParsingException, IOException, PolicyParser.PropertyExpander.ExpandExceptionparse a Permission entry -
parseDomainEntry
private PolicyParser.DomainEntry parseDomainEntry() throws PolicyParser.ParsingException, IOExceptionparse a domain entry -
parseProperties
private Map<String,String> parseProperties(String terminator) throws PolicyParser.ParsingException, IOException -
peekAndMatch
-
peek
-
match
-
skipEntry
skip all tokens for this entry leaving the delimiter ";" in the stream.
-