Package com.sun.identity.policy
Class PolicyUtils
- java.lang.Object
-
- com.sun.identity.policy.PolicyUtils
-
public class PolicyUtils extends Object
The classPolicyUtils
provides utility(static) methods that would be used by policy pacakge
-
-
Field Summary
Fields Modifier and Type Field Description static String
ADVICES_END_TAG
static String
ADVICES_START_TAG
static String
ADVICES_TAG_NAME
static String
EMPTY_STRING
static boolean
logStatus
static String
NEW_LINE
static String
NULL_STRING
-
Constructor Summary
Constructors Constructor Description PolicyUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
advicesToXMLString(Map advices)
Returns XML string representation of aMap
of policy advicesstatic Map
appendElementToMap(String key, Set values, Map toMap)
Appends a key/value pair to a mapstatic Map
appendMapToMap(Map mapToAdd, Map toMap)
Appends a map to another mapstatic String
attributeValuePairToXMLString(String name, Set values)
Converts an attribute value pair into its XML string representation.static Map
cloneMap(Map map)
Returns deep copy of aMap The passed in
Map
should haveString
object as keys andSet
ofString
objects as valuesstatic String
constructUserFilter(SSOToken token, String userRDNAttrName, String userName, boolean aliasEnabled)
Constructs a search filter used in subject evaluation.static void
createOrReplacePolicies(PolicyManager pm, InputStream xmlPolicies, boolean replace)
Creates or replaces policy objects given an input stream of policy XML which confines tocom/sun/identity/policy/policyAdmin.dtd
.static void
createPolicies(PolicyManager pm, InputStream xmlPolicies)
Creates policy objects given an input stream of policy XML which confines tocom/sun/identity/policy/policyAdmin.dtd
.static String
decrypt(String encryptedText)
static Set
delimStringToSet(String str, String delimiter)
Parses a string into a set using the specified delimiterstatic String
encrypt(String plainText)
static String
envParametersToXMLString(Map envMap)
Converts a map which stores a set of environment parameters into its XML string representation.static String
getAttributeName(Node pNode)
Parses an XML node which represents an AttributeValuePair and returns the attribute name.static Set
getAttributeValues(Node pNode)
Parses an XML node which represents an AttributeValuePair and returns the attribute values.static String
getDisplayName(String dn)
Returns the display name for a given dn This implementation assumes the display name to be the value of the naming attribute of the entry.static String
getDNDisplayString(String strDN)
Returns a display string for an LDAP distinguished name.static String
getISDSHostName()
Returns the LDAP server host used by Access Manager SDK stored inserverconfig.xml
file.static boolean
isLocalDS(String hostName)
Checks if thehostName
is the same as the one used by the OpenAM SDK.static void
logAccessMessage(String msgIdName, String[] data, SSOToken token)
Logs an access messagestatic void
logAccessMessage(String msgIdName, String[] data, SSOToken token, String serviceType)
static void
logErrorMessage(String msgIdName, String[] data, SSOToken token)
Logs an error messagestatic String
mapToXMLString(Map envMap)
Converts a map to its XML string representation.static Map
parseAdvicesXML(String advicesXML)
Parses an XML string representation of policy advices and returns a Map of advices.static Map
parseAttributeValuePairs(Node pNode)
Parses an XML node which represents Attribute-Value pairs and returns a map of such values.static Map
parseEnvParameters(Node pNode)
Parses an XML node which represents a collection of the environment parameters and returns a map which contains these parameters.static Set
parseResponseAttributes(Node pNode)
Parses an XML node which represents a collection of user response attributes and returns a set which contains the names of these attributesstatic boolean
principalNameEqualsUuid(SSOToken token)
Checks if principal name and uuid are same in the sessionstatic String
quote(int i)
Return a quoted string, quoting anint
.static String
quote(long l)
Return a quoted string, quoting along
.static String
quote(String s)
Return a quoted string Surrounds a string on either side with double quote and returns the quoted stringstatic void
removePolicyRules(SSOToken token, String serviceName)
Removes policy rules defined for a service.static String
responseAttributesToXMLString(Set attrs)
Converts a set which stores a set of response attribute names into its XML string representation.
-
-
-
Field Detail
-
logStatus
public static boolean logStatus
-
EMPTY_STRING
public static final String EMPTY_STRING
- See Also:
- Constant Field Values
-
NULL_STRING
public static final String NULL_STRING
- See Also:
- Constant Field Values
-
NEW_LINE
public static final String NEW_LINE
- See Also:
- Constant Field Values
-
ADVICES_TAG_NAME
public static final String ADVICES_TAG_NAME
- See Also:
- Constant Field Values
-
ADVICES_START_TAG
public static final String ADVICES_START_TAG
- See Also:
- Constant Field Values
-
ADVICES_END_TAG
public static final String ADVICES_END_TAG
- See Also:
- Constant Field Values
-
-
Method Detail
-
appendMapToMap
public static Map appendMapToMap(Map mapToAdd, Map toMap)
Appends a map to another map- Parameters:
mapToAdd
- map that needs to be added Each key should be a String Each value would be a Set of String valuestoMap
- map the map to which the mapToAdd would be added Each key should be a String Each value would be a Set of String values- Returns:
- the combined map which is also the toMap The combined map is formed by adding the values for each key found in the addToMap to the toMap. If a key was found both in addToMap and toMap, the new value for the key is the combined set of values for the key from the addToMap and original toMap
-
appendElementToMap
public static Map appendElementToMap(String key, Set values, Map toMap)
Appends a key/value pair to a map- Parameters:
key
- a String valued keyvalues
- a set of String valuestoMap
- the map to which to append the key/value pair Each key of the map should be a String Each value of the map should be a Set of String values- Returns:
- the combined map which is also the toMap The combined map is formed by adding the values for argument key to the toMap with the argument values. If the key is already present in addToMap, the new value for the key is the combined set of values for the key from argument values and original toMap
-
getDisplayName
public static String getDisplayName(String dn)
Returns the display name for a given dn This implementation assumes the display name to be the value of the naming attribute of the entry. So, the value of the naming attribute is the return value.- Parameters:
dn
- dn of the entry for which to get the display name- Returns:
- disaplay name for the entry, this is same as the value of the naming attribute of the entry
-
parseEnvParameters
public static Map parseEnvParameters(Node pNode) throws PolicyException
Parses an XML node which represents a collection of the environment parameters and returns a map which contains these parameters.- Parameters:
pNode
- the XML DOM node for the environment parameters.- Returns:
- a map which contains the environment parameters
- Throws:
PolicyException
- if the node can not be parsed into a map
-
parseResponseAttributes
public static Set parseResponseAttributes(Node pNode) throws PolicyException
Parses an XML node which represents a collection of user response attributes and returns a set which contains the names of these attributes- Parameters:
pNode
- the XML DOM node for the response attributes- Returns:
- a set which contains the names of these attributes
- Throws:
PolicyException
- if the node can not be parsed into a set
-
parseAttributeValuePairs
public static Map parseAttributeValuePairs(Node pNode)
Parses an XML node which represents Attribute-Value pairs and returns a map of such values.- Parameters:
pNode
- the XML DOM node containing Attribute-Value pairs as child nodes.- Returns:
- a map which contains Attribute-Value pairs
-
getAttributeName
public static String getAttributeName(Node pNode)
Parses an XML node which represents an AttributeValuePair and returns the attribute name.- Parameters:
pNode
- the XML DOM node for an AttributeValuePair- Returns:
- the attribute name of the AttributeValuePair
-
getAttributeValues
public static Set getAttributeValues(Node pNode)
Parses an XML node which represents an AttributeValuePair and returns the attribute values.- Parameters:
pNode
- the XML DOM node for an AttributeValuePair- Returns:
- the set of attribute values of the AttributeValuePair
-
envParametersToXMLString
public static String envParametersToXMLString(Map envMap)
Converts a map which stores a set of environment parameters into its XML string representation.- Parameters:
envMap
- a map respresents a collection of the parameters- Returns:
- its XML string representation
-
responseAttributesToXMLString
public static String responseAttributesToXMLString(Set attrs)
Converts a set which stores a set of response attribute names into its XML string representation.- Parameters:
attrs
- a set of response attribute names- Returns:
- XML string representation of set of attributes
-
mapToXMLString
public static String mapToXMLString(Map envMap)
Converts a map to its XML string representation.- Parameters:
envMap
- a map that has String valued keys. Value corresponding to each key should be a set of String(s).- Returns:
- its XML string representation of env map
-
attributeValuePairToXMLString
public static String attributeValuePairToXMLString(String name, Set values)
Converts an attribute value pair into its XML string representation.- Parameters:
name
- the attribute name of the attribute value pairvalues
- the attribute values of the attribute value pair- Returns:
- XML string representation of attribue value pair
-
quote
public static String quote(String s)
Return a quoted string Surrounds a string on either side with double quote and returns the quoted string- Parameters:
s
- string to be quoted- Returns:
- quoted string
-
quote
public static String quote(int i)
Return a quoted string, quoting anint
. Converts anint
to string and quotes it on either side with double quote and returns the quoted string- Parameters:
i
-int
to be quoted- Returns:
- quoted string
-
quote
public static String quote(long l)
Return a quoted string, quoting along
. Converts along
to string and quotes it on either side with double quote and returns the quoted string- Parameters:
l
-long
to be quoted- Returns:
- quoted string
-
logAccessMessage
public static void logAccessMessage(String msgIdName, String[] data, SSOToken token) throws SSOException
Logs an access message- Parameters:
msgIdName
- name of message iddata
- array of data to be loggedtoken
- session token of the user who did the operation that triggered this logging- Throws:
SSOException
-
logAccessMessage
public static void logAccessMessage(String msgIdName, String[] data, SSOToken token, String serviceType) throws SSOException
- Throws:
SSOException
-
logErrorMessage
public static void logErrorMessage(String msgIdName, String[] data, SSOToken token) throws SSOException
Logs an error message- Parameters:
msgIdName
- name of message iddata
- array of data to be loggedtoken
- session token of the user who did the operation that triggered this logging- Throws:
SSOException
-
getISDSHostName
public static String getISDSHostName()
Returns the LDAP server host used by Access Manager SDK stored inserverconfig.xml
file. For multiple hosts, the returned value is a space-delimited list of hosts.- Returns:
- the LDAP server host used by Access Manager SDK. Returns null if unable to get the host.
-
isLocalDS
public static boolean isLocalDS(String hostName) throws PolicyException
Checks if thehostName
is the same as the one used by the OpenAM SDK.- Parameters:
hostName
- host name to compare against OpenAM SDK config store host- Returns:
- true if
hostName
is the same as the one used by the OpenAM SDK, false otherwise - Throws:
PolicyException
- if host names comparison does not succeed
-
constructUserFilter
public static String constructUserFilter(SSOToken token, String userRDNAttrName, String userName, boolean aliasEnabled) throws SSOException
Constructs a search filter used in subject evaluation. If aliasEnabled is true, the user aliases will also be used to construct the search filter.- Parameters:
token
- SSO tokenuserRDNAttrName
- naming attributeuserName
- the value of the user namealiasEnabled
- if true, user alias list will be used to construct the search filter- Returns:
- search filter
- Throws:
SSOException
- if there is error when trying to retrieve token properties
-
removePolicyRules
public static void removePolicyRules(SSOToken token, String serviceName) throws SSOException, AMException
Removes policy rules defined for a service. All the policy rules defined for a service in the system are removed.- Parameters:
token
- session token of the user doing the operationserviceName
- name of the service- Throws:
SSOException
AMException
-
delimStringToSet
public static Set delimStringToSet(String str, String delimiter)
Parses a string into a set using the specified delimiter- Parameters:
str
- string to be parseddelimiter
- delimiter used in the string- Returns:
- the parsed set
-
getDNDisplayString
public static String getDNDisplayString(String strDN)
Returns a display string for an LDAP distinguished name.- Parameters:
strDN
- distinguished name.- Returns:
- display string for the LDAP distinguished name.
-
parseAdvicesXML
public static Map parseAdvicesXML(String advicesXML) throws PolicyException
Parses an XML string representation of policy advices and returns a Map of advices. The keys of returned map would be advice name keys. Each key is a String object. The values against each key is a Set of String(s) of advice values- Parameters:
advicesXML
- XML string representation of policy advices conforming to the following DTD. The input string may not be validated against the dtd for performance reasons.- Returns:
- the map of policy advices parsed from the passed in advicesXML If the passed in advicesXML is null, null would be returned
- Throws:
PolicyException
- if there is any error parsing the passed in advicesXML
-
advicesToXMLString
public static String advicesToXMLString(Map advices) throws PolicyException
Returns XML string representation of aMap
of policy advices- Parameters:
advices
-Map
of policy advices- Returns:
- XML string representation of policy advices
- Throws:
PolicyException
- if there is any error while converting
-
principalNameEqualsUuid
public static boolean principalNameEqualsUuid(SSOToken token) throws SSOException
Checks if principal name and uuid are same in the session- Parameters:
token
- session token- Returns:
true
if the principal name and uuid are same in the session. Otherwise,false
- Throws:
SSOException
- if the session token is not valid
-
createPolicies
public static void createPolicies(PolicyManager pm, InputStream xmlPolicies) throws PolicyException, SSOException
Creates policy objects given an input stream of policy XML which confines tocom/sun/identity/policy/policyAdmin.dtd
.- Parameters:
pm
- Policy manager.xmlPolicies
- Policy XML input stream.- Throws:
PolicyException
- if policies cannot be created.SSOException
- if Single Sign On token used to create policy manager is no longer valid.
-
createOrReplacePolicies
public static void createOrReplacePolicies(PolicyManager pm, InputStream xmlPolicies, boolean replace) throws PolicyException, SSOException
Creates or replaces policy objects given an input stream of policy XML which confines tocom/sun/identity/policy/policyAdmin.dtd
.- Parameters:
pm
- Policy manager.xmlPolicies
- Policy XML input stream.replace
- True if the policies should be replaced, otherwise create.- Throws:
PolicyException
- if policies cannot be updated.SSOException
- if Single Sign On token used to update policy manager is no longer valid.
-
cloneMap
public static Map cloneMap(Map map)
Returns deep copy of aMap The passed in
Map
should haveString
object as keys andSet
ofString
objects as values- Parameters:
map
-Map
that needs to be copied- Returns:
- a deep copy of passed in
Map
-
-