Class PolicyParser
- java.lang.Object
-
- net.adoptopenjdk.icedteaweb.client.policyeditor.PolicyParser
-
public class PolicyParser extends java.lang.ObjectThe policy for a Java runtime (specifying which permissions are available for code from various principals) is represented as a separate persistent configuration. The configuration may be stored as a flat ASCII file, as a serialized binary file of the Policy class, or as a database.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
initmethod 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 Classes Modifier and Type Class Description (package private) static classPolicyParser.DomainEntryEach domain entry in the keystore domain configuration file is represented by a DomainEntry object.static classPolicyParser.GrantEntryEach grant entry in the policy configuration file is represented by a GrantEntry object.(package private) static classPolicyParser.KeyStoreEntryEach keystore entry in the keystore domain configuration file is represented by a KeyStoreEntry object.private static classPolicyParser.LocalizedMessagestatic classPolicyParser.ParsingExceptionstatic classPolicyParser.PermissionEntryEach permission entry in the policy configuration file is represented by a PermissionEntry object.static classPolicyParser.PrincipalEntryPrincipal info (class and name) in a grant entryprivate static classPolicyParser.PropertyExpander
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,PolicyParser.DomainEntry>domainEntriesprivate java.util.Vector<PolicyParser.GrantEntry>grantEntriesprivate java.lang.StringkeyStoreProviderprivate java.lang.StringkeyStoreTypeprivate java.lang.StringkeyStoreUrlStringprivate intlookaheadprivate java.io.StreamTokenizerstprivate java.lang.StringstorePassURL
-
Constructor Summary
Constructors Constructor Description PolicyParser()Creates a PolicyParser object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(PolicyParser.GrantEntry ge)private java.lang.Stringexpand(java.lang.String value)private java.lang.Stringexpand(java.lang.String value, boolean encodeURL)java.util.Collection<PolicyParser.DomainEntry>getDomainEntries()java.lang.StringgetKeyStoreProvider()java.lang.StringgetKeyStoreType()java.lang.StringgetKeyStoreUrl()Returns the (possibly expanded) keystore location, or null if the expansion fails.java.lang.StringgetStorePassURL()java.util.Enumeration<PolicyParser.GrantEntry>grantElements()Enumerate all the entries in the global policy object.private java.lang.Stringmatch(java.lang.String expect)private PolicyParser.DomainEntryparseDomainEntry()parse a domain entryprivate PolicyParser.GrantEntryparseGrantEntry()parse a Grant entryprivate voidparseKeyStoreEntry()parses a keystore entryprivate PolicyParser.PermissionEntryparsePermissionEntry()parse a Permission entryprivate java.util.Map<java.lang.String,java.lang.String>parseProperties(java.lang.String terminator)private voidparseStorePassURL()private booleanpeek(java.lang.String expect)private booleanpeekAndMatch(java.lang.String expect)voidread(java.io.Reader policy)Reads a policy configuration into the Policy object using a Reader object.booleanremove(PolicyParser.GrantEntry ge)voidreplace(PolicyParser.GrantEntry origGe, PolicyParser.GrantEntry newGe)voidsetKeyStoreProvider(java.lang.String provider)voidsetKeyStoreType(java.lang.String type)voidsetKeyStoreUrl(java.lang.String url)voidsetStorePassURL(java.lang.String storePassURL)private voidskipEntry()skip all tokens for this entry leaving the delimiter ";" in the stream.voidwrite(java.io.Writer policy)write out the policyprivate voidwriteKeyStoreEntry(java.io.PrintWriter out)writes the (unexpanded) keystore entryprivate voidwriteStorePassURL(java.io.PrintWriter out)
-
-
-
Field Detail
-
grantEntries
private final java.util.Vector<PolicyParser.GrantEntry> grantEntries
-
domainEntries
private java.util.Map<java.lang.String,PolicyParser.DomainEntry> domainEntries
-
st
private java.io.StreamTokenizer st
-
lookahead
private int lookahead
-
keyStoreUrlString
private java.lang.String keyStoreUrlString
-
keyStoreType
private java.lang.String keyStoreType
-
keyStoreProvider
private java.lang.String keyStoreProvider
-
storePassURL
private java.lang.String storePassURL
-
-
Method Detail
-
expand
private java.lang.String expand(java.lang.String value) throws PolicyParser.PropertyExpander.ExpandException
-
expand
private java.lang.String expand(java.lang.String value, boolean encodeURL) throws PolicyParser.PropertyExpander.ExpandException
-
read
public void read(java.io.Reader policy) throws PolicyParser.ParsingException, java.io.IOExceptionReads 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.java.io.IOException- if an error occurs while reading the policy configuration.
-
add
public void add(PolicyParser.GrantEntry ge)
-
replace
public void replace(PolicyParser.GrantEntry origGe, PolicyParser.GrantEntry newGe)
-
remove
public boolean remove(PolicyParser.GrantEntry ge)
-
getKeyStoreUrl
public java.lang.String getKeyStoreUrl()
Returns the (possibly expanded) keystore location, or null if the expansion fails.
-
setKeyStoreUrl
public void setKeyStoreUrl(java.lang.String url)
-
getKeyStoreType
public java.lang.String getKeyStoreType()
-
setKeyStoreType
public void setKeyStoreType(java.lang.String type)
-
getKeyStoreProvider
public java.lang.String getKeyStoreProvider()
-
setKeyStoreProvider
public void setKeyStoreProvider(java.lang.String provider)
-
getStorePassURL
public java.lang.String getStorePassURL()
-
setStorePassURL
public void setStorePassURL(java.lang.String storePassURL)
-
grantElements
public java.util.Enumeration<PolicyParser.GrantEntry> 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
public java.util.Collection<PolicyParser.DomainEntry> getDomainEntries()
-
write
public void write(java.io.Writer policy)
write out the policy
-
parseKeyStoreEntry
private void parseKeyStoreEntry() throws PolicyParser.ParsingException, java.io.IOExceptionparses a keystore entry- Throws:
PolicyParser.ParsingExceptionjava.io.IOException
-
parseStorePassURL
private void parseStorePassURL() throws PolicyParser.ParsingException, java.io.IOException- Throws:
PolicyParser.ParsingExceptionjava.io.IOException
-
writeKeyStoreEntry
private void writeKeyStoreEntry(java.io.PrintWriter out)
writes the (unexpanded) keystore entry
-
writeStorePassURL
private void writeStorePassURL(java.io.PrintWriter out)
-
parseGrantEntry
private PolicyParser.GrantEntry parseGrantEntry() throws PolicyParser.ParsingException, java.io.IOException
parse a Grant entry- Throws:
PolicyParser.ParsingExceptionjava.io.IOException
-
parsePermissionEntry
private PolicyParser.PermissionEntry parsePermissionEntry() throws PolicyParser.ParsingException, java.io.IOException, PolicyParser.PropertyExpander.ExpandException
parse a Permission entry- Throws:
PolicyParser.ParsingExceptionjava.io.IOExceptionPolicyParser.PropertyExpander.ExpandException
-
parseDomainEntry
private PolicyParser.DomainEntry parseDomainEntry() throws PolicyParser.ParsingException, java.io.IOException
parse a domain entry- Throws:
PolicyParser.ParsingExceptionjava.io.IOException
-
parseProperties
private java.util.Map<java.lang.String,java.lang.String> parseProperties(java.lang.String terminator) throws PolicyParser.ParsingException, java.io.IOException- Throws:
PolicyParser.ParsingExceptionjava.io.IOException
-
peekAndMatch
private boolean peekAndMatch(java.lang.String expect) throws PolicyParser.ParsingException, java.io.IOException- Throws:
PolicyParser.ParsingExceptionjava.io.IOException
-
peek
private boolean peek(java.lang.String expect)
-
match
private java.lang.String match(java.lang.String expect) throws PolicyParser.ParsingException, java.io.IOException- Throws:
PolicyParser.ParsingExceptionjava.io.IOException
-
skipEntry
private void skipEntry() throws PolicyParser.ParsingException, java.io.IOExceptionskip all tokens for this entry leaving the delimiter ";" in the stream.- Throws:
PolicyParser.ParsingExceptionjava.io.IOException
-
-