public class JsonPolicyWriter
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
(package private) static class |
JsonPolicyWriter.ConditionsByKey
Inner class to hold condition values for each key under a condition type.
|
Modifier and Type | Field and Description |
---|---|
private com.fasterxml.jackson.core.JsonGenerator |
generator
The JSON Generator to generator a JSON string.
|
private static org.apache.commons.logging.Log |
log
Logger used to log exceptions that occurs while writing the Json policy.
|
private java.io.Writer |
writer
The output writer to which the JSON String is written.
|
Constructor and Description |
---|
JsonPolicyWriter()
Constructs a new instance of JSONPolicyWriter.
|
Modifier and Type | Method and Description |
---|---|
private java.util.Map<java.lang.String,JsonPolicyWriter.ConditionsByKey> |
groupConditionsByTypeAndKey(java.util.List<Condition> conditions)
Groups the list of
Condition s by the condition type and
condition key. |
private java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
groupPrincipalByScheme(java.util.List<Principal> principals)
Groups the list of
Principal s by the Scheme. |
private boolean |
isNotNull(java.lang.Object object)
Checks if the given object is not null.
|
private java.lang.String |
jsonStringOf(Policy policy)
Converts the given
Policy into a JSON String. |
private void |
writeActions(java.util.List<Action> actions)
Writes the list of
Action s to the JSONGenerator. |
private void |
writeConditions(java.util.List<Condition> conditions)
Writes the list of conditions to the JSONGenerator.
|
private void |
writeJsonArray(java.lang.String arrayName,
java.util.List<java.lang.String> values)
Writes an array along with its values to the JSONGenerator.
|
private void |
writeJsonArrayEnd()
Writes the End of Array String to the JSONGenerator.
|
private void |
writeJsonArrayStart(java.lang.String fieldName)
Writes the Start of Array String to the JSONGenerator along with Array
Name.
|
private void |
writeJsonKeyValue(java.lang.String fieldName,
java.lang.String value)
Writes the given field and the value to the JsonGenerator
|
private void |
writeJsonObjectEnd()
Writes the End of Object String to the JSONGenerator.
|
private void |
writeJsonObjectStart(java.lang.String fieldName)
Writes the Start of Object String to the JSONGenerator along with Object
Name.
|
java.lang.String |
writePolicyToString(Policy policy)
Converts the specified AWS policy object to a JSON string, suitable for
passing to an AWS service.
|
private void |
writePrincipals(java.util.List<Principal> principals)
Writes the list of
Principal s to the JSONGenerator. |
private void |
writeResources(java.util.List<Resource> resources)
Writes the list of
Resource s to the JSONGenerator. |
private com.fasterxml.jackson.core.JsonGenerator generator
private java.io.Writer writer
private static final org.apache.commons.logging.Log log
public JsonPolicyWriter()
public java.lang.String writePolicyToString(Policy policy)
policy
- The AWS policy object to convert to a JSON string.java.lang.IllegalArgumentException
- If the specified policy is null or invalid and cannot be
serialized to a JSON string.private java.lang.String jsonStringOf(Policy policy) throws com.fasterxml.jackson.core.JsonGenerationException, java.io.IOException
Policy
into a JSON String.policy
- the policy to be converted.com.fasterxml.jackson.core.JsonGenerationException
java.io.IOException
private void writeConditions(java.util.List<Condition> conditions) throws com.fasterxml.jackson.core.JsonGenerationException, java.io.IOException
conditions
- the conditions to be written.com.fasterxml.jackson.core.JsonGenerationException
java.io.IOException
private void writeResources(java.util.List<Resource> resources) throws com.fasterxml.jackson.core.JsonGenerationException, java.io.IOException
Resource
s to the JSONGenerator.resources
- the list of resources to be written.com.fasterxml.jackson.core.JsonGenerationException
java.io.IOException
private void writeActions(java.util.List<Action> actions) throws com.fasterxml.jackson.core.JsonGenerationException, java.io.IOException
Action
s to the JSONGenerator.actions
- the list of the actions to be written.com.fasterxml.jackson.core.JsonGenerationException
java.io.IOException
private void writePrincipals(java.util.List<Principal> principals) throws com.fasterxml.jackson.core.JsonGenerationException, java.io.IOException
Principal
s to the JSONGenerator.principals
- the list of principals to be written.com.fasterxml.jackson.core.JsonGenerationException
java.io.IOException
private java.util.Map<java.lang.String,java.util.List<java.lang.String>> groupPrincipalByScheme(java.util.List<Principal> principals)
Principal
s by the Scheme.principals
- the list of Principal
sprivate java.util.Map<java.lang.String,JsonPolicyWriter.ConditionsByKey> groupConditionsByTypeAndKey(java.util.List<Condition> conditions)
Condition
s by the condition type and
condition key.conditions
- the list of conditions to be groupedprivate void writeJsonArray(java.lang.String arrayName, java.util.List<java.lang.String> values) throws com.fasterxml.jackson.core.JsonGenerationException, java.io.IOException
arrayName
- name of the JSON array.values
- values of the JSON array.com.fasterxml.jackson.core.JsonGenerationException
java.io.IOException
private void writeJsonObjectStart(java.lang.String fieldName) throws com.fasterxml.jackson.core.JsonGenerationException, java.io.IOException
fieldName
- name of the JSON Object.com.fasterxml.jackson.core.JsonGenerationException
java.io.IOException
private void writeJsonObjectEnd() throws com.fasterxml.jackson.core.JsonGenerationException, java.io.IOException
com.fasterxml.jackson.core.JsonGenerationException
java.io.IOException
private void writeJsonArrayStart(java.lang.String fieldName) throws com.fasterxml.jackson.core.JsonGenerationException, java.io.IOException
fieldName
- name of the JSON arraycom.fasterxml.jackson.core.JsonGenerationException
java.io.IOException
private void writeJsonArrayEnd() throws com.fasterxml.jackson.core.JsonGenerationException, java.io.IOException
com.fasterxml.jackson.core.JsonGenerationException
java.io.IOException
private void writeJsonKeyValue(java.lang.String fieldName, java.lang.String value) throws com.fasterxml.jackson.core.JsonGenerationException, java.io.IOException
fieldName
- the JSON field namevalue
- value for the fieldcom.fasterxml.jackson.core.JsonGenerationException
java.io.IOException
private boolean isNotNull(java.lang.Object object)
object
- the object compared to null.