public class SAMLUtils extends SAMLUtilsCommon
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_CONTENT_LENGTH
Default maximum content length in string format.
|
static int |
defaultMaxLength
Default maximum content length is set to 16k.
|
static String |
HTTP_MAX_CONTENT_LENGTH
Attribute that specifies maximum content length for SAML request in
AMConfig.properties file. |
bundle, debug, random, SAMLID_PREFIX, sc
Modifier and Type | Method and Description |
---|---|
static void |
addEnvParamsFromAssertion(Map envParameters,
Assertion assertion,
Subject subject)
Returns attributes included in
AttributeStatement of the
assertion. |
static void |
checkHTTPContentLength(javax.servlet.http.HttpServletRequest request)
Checks content length of a http request to avoid dos attack.
|
static boolean |
checkQuery(Element element,
String queryname)
Verifies if an element is a type of a specific query.
|
static boolean |
checkSignatureValid(String xmlString,
String idAttribute,
String issuer)
Return whether the signature on the object is valid or not.
|
static String |
displayXML(String input)
Displays an XML string.
|
static Subject |
examAssertions(List assertions)
Determines if there is a valid SSO Assertion
inside of SAML Response.
|
static String |
generateAssertionHandle()
Generates assertion handle.
|
static String |
generateAssertionID()
Generates an ID String with length of SAMLConstants.ID_LENGTH.
|
static Object |
generateSession(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
Map attrMap)
Creates Session
|
static String |
generateSourceID(String siteURL)
Generates sourceID of a site.
|
static Map |
getAttributeMap(SAMLServiceManager.SOAPEntry partnerdest,
List assertions,
Subject subject,
String target)
Gets Attribute Map to be set in the Session.
|
static Element |
getCanonicalElement(Node node)
Gets input Node Canonicalized
|
static String |
getFullServiceURL(String shortUrl)
Returns full service url.
|
static List |
getListOfAssertions(List assertions)
Gets the list of
Assertion objects from a list of
'String' assertions. |
static String |
getLoginRedirectURL(javax.servlet.http.HttpServletRequest req)
Returns the authenticaion login url with goto parameter
in the given
HttpServletRequest object. |
static int |
getMaxContentLength()
Returns maximum content length of a SAML request.
|
static MimeHeaders |
getMimeHeaders(javax.servlet.http.HttpServletRequest req)
Returns a
MimeHeaders object that contains the headers
in the given HttpServletRequest object. |
static Response |
getResponse(byte[] bytes)
Returns
Response object from byte array. |
static byte[] |
getResponseBytes(Response samlResponse)
Returns byte array from a SAML
Response . |
static String |
getServerID(String idTypeString)
Returns server ID.
|
static String |
getServerURL(String str)
Returns server url of a site.
|
static SAMLServiceManager.SOAPEntry |
getSourceSite(String issuer)
Gets sourceSite corresponding to an issuer from the partner URL list.
|
static List |
getStrAssertions(List assertions)
Gets List of assertions in String format from a list of
Assertion objects. |
static String |
hexStringToBase64(String hexString)
Converts HEX encoded string to Base64 encoded string.
|
static byte[] |
hexStringToByteArray(String hexString)
Converts a HEX encoded string to a byte array.
|
static String |
HTMLEncode(String srcStr,
char ch)
Replaces every occurence of ch with
"<ascii code of ch>;"
|
static boolean |
isAuthNAssertion(Assertion assertion)
Returns true if the assertion is valid both time wise and
signature wise, and contains at least one AuthenticationStatement.
|
static boolean |
isCorrectConfirmationMethod(SubjectConfirmation sc)
Checks if a
SubjectConfirmation is correct. |
static void |
main(String[] args)
Returns site ID based on the host name.
|
static void |
postToTarget(javax.servlet.http.HttpServletResponse response,
PrintWriter out,
List assertion,
String targeturl,
Map attrMap)
Post assertions and attributes to the target url.
|
static boolean |
postYN(String targetIn)
Returns true of false based on whether the target passed as parameter
accepts form POST.
|
static Map |
processArtifact(String[] artifact,
String target)
Processes SAML Artifact
|
static Map |
processResponse(Response samlResponse,
String target)
Processes SAML Response
|
static void |
sendError(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
int httpStatusCode,
String errorCode,
String errorMsg)
Sends to error page URL for SAML protocols.
|
static void |
setMimeHeaders(MimeHeaders headers,
javax.servlet.http.HttpServletResponse response)
Sets the given
HttpServletResponse object with the
headers in the given MimeHeaders object. |
static byte[] |
stringToByteArray(String input)
Converts a string to a byte array.
|
static Map |
verifyAssertionAndGetSSMap(Response response)
Checks response and get back a Map of relevant data including,
Subject, SOAPEntry for the partner and the List of Assertions.
|
static boolean |
verifyResponse(Response response,
String requestUrl,
javax.servlet.http.HttpServletRequest request)
Verifies a
Response . |
static boolean |
verifySignature(Response samlResponse)
Verifies Signature for Post response.
|
byteArrayToHexString, byteArrayToString, checkStatement, decodePassword, generateID, getDecodedSourceIDString, makeEndElementTagXML, makeStartElementTagXML, removeNewLineChars, setDebugInstance, setResourceBundle
public static final String HTTP_MAX_CONTENT_LENGTH
AMConfig.properties
file.public static final int defaultMaxLength
public static final String DEFAULT_CONTENT_LENGTH
public static String generateAssertionID()
public static boolean checkQuery(Element element, String queryname)
element
- a DOM Element which needs to be verified.queryname
- A specific name of a query, for example,
AuthenticationQuery, AuthorizationDecisionQuery, or
AttributeQuery.public static String generateSourceID(String siteURL)
siteURL
- a String that uniquely identifies a site.Base64
encoded SHA digest of siteURL.public static String generateAssertionHandle()
public static byte[] hexStringToByteArray(String hexString)
hexString
- HEX encoded stringpublic static String hexStringToBase64(String hexString)
hexString
- HEX encoded string.public static SAMLServiceManager.SOAPEntry getSourceSite(String issuer)
issuer
- The issuer string.public static void main(String[] args)
args
- host namepublic static boolean isCorrectConfirmationMethod(SubjectConfirmation sc)
SubjectConfirmation
is correct.sc
- SubjectConfirmation
instance to be checked.SubjectConfirmation
instance passed in
has only one ConfirmationMethod
, and this
ConfirmationMethod
is set to
SAMLConstants.CONFIRMATION_METHOD_IS
.public static boolean isAuthNAssertion(Assertion assertion)
assertion
- Assertion
instance to be checked.true
if the assertion is valid both time wise and
signature wise, and contains at least one AuthenticationStatement.public static byte[] stringToByteArray(String input)
input
- a String to be converted.public static String getServerID(String idTypeString)
idTypeString
- An ID stringpublic static String getServerURL(String str)
str
- Server ID.public static String getFullServiceURL(String shortUrl)
shortUrl
- short URL of the service.public static void addEnvParamsFromAssertion(Map envParameters, Assertion assertion, Subject subject)
AttributeStatement
of the
assertion.envParameters
- return map which includes name value pairs of
attributes included in AttributeStatement
of the assertionassertion
- an Assertion
object which contains
AttributeStatement
subject
- the Subject
instance from
AuthenticationStatement
. The Subject
included in AttributeStatement
must match this
Subject
instance.public static int getMaxContentLength()
public static void checkHTTPContentLength(javax.servlet.http.HttpServletRequest request) throws javax.servlet.ServletException
request
- HttpServletRequest
instance to be checked.javax.servlet.ServletException
- if context length of the request exceeds
maximum content length allowed.public static void postToTarget(javax.servlet.http.HttpServletResponse response, PrintWriter out, List assertion, String targeturl, Map attrMap) throws IOException
Assertion
in the passed Set.response
- HttpServletResponse
objectout
- The print writer which for content is to be written too.assertion
- List of Assertion
s to be posted.targeturl
- target urlattrMap
- Map of attributes to be posted to the targetIOException
public static boolean postYN(String targetIn)
targetIn
- url to be checkedpublic static String HTMLEncode(String srcStr, char ch)
srcStr
- orginal string to to be encoded.ch
- the charactor needs to be encoded.public static String displayXML(String input)
input
- original stringpublic static List getListOfAssertions(List assertions)
Assertion
objects from a list of
'String' assertions.assertions
- List of assertions in string formatAssertion
objectspublic static byte[] getResponseBytes(Response samlResponse) throws SAMLException
Response
.samlResponse
- Response
objectSAMLException
- if error occurrs during the process.public static Response getResponse(byte[] bytes)
Response
object from byte array.bytes
- byte arrayResponse
objectpublic static boolean verifyResponse(Response response, String requestUrl, javax.servlet.http.HttpServletRequest request)
Response
.response
- SAML Response
objectrequestUrl
- this server's POST profile URLrequest
- HttpServletRequest
objectpublic static List getStrAssertions(List assertions)
Assertion
objects.assertions
- List of Assertion
objects.public static boolean verifySignature(Response samlResponse)
samlResponse
- Response
object from post profile.public static Map getAttributeMap(SAMLServiceManager.SOAPEntry partnerdest, List assertions, Subject subject, String target) throws Exception
partnerdest
- SOAPEntry
objectassertions
- List of Assertion
ssubject
- Subject
objecttarget
- target of final SSOException
- if an error occurrs.public static Map verifyAssertionAndGetSSMap(Response response)
response
- Response
objectpublic static Subject examAssertions(List assertions) throws IOException
assertions
- a List of Assertion
objectsIOException
- IOExceptionpublic static boolean checkSignatureValid(String xmlString, String idAttribute, String issuer)
xmlString
- input XML StringidAttribute
- ASSERTION_ID_ATTRIBUTE or RESPONSE_ID_ATTRIBUTEissuer
- the issuer of the Assertionpublic static void setMimeHeaders(MimeHeaders headers, javax.servlet.http.HttpServletResponse response)
HttpServletResponse
object with the
headers in the given MimeHeaders
object.headers
- the MimeHeaders
objectresponse
- the HttpServletResponse
object to which the
headers are to be written.public static MimeHeaders getMimeHeaders(javax.servlet.http.HttpServletRequest req)
MimeHeaders
object that contains the headers
in the given HttpServletRequest
object.req
- the HttpServletRequest
object.MimeHeaders
object containing the headers.public static String getLoginRedirectURL(javax.servlet.http.HttpServletRequest req)
HttpServletRequest
object.req
- the HttpServletRequest
object.public static Map processArtifact(String[] artifact, String target) throws SAMLException
artifact
- SAML Artifacttarget
- Target URLSAMLException
- if failed to get the Assertions or
Attribute Map.public static Object generateSession(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Map attrMap) throws SAMLException
request
- HttpServletRequestresponse
- HttpServletResponseattrMap
- Attribute Mapif
- failed to create SessionSAMLException
public static Map processResponse(Response samlResponse, String target) throws SAMLException
samlResponse
- SAML Response objecttarget
- Target URLSAMLException
- if failed to get Attribute Map.public static Element getCanonicalElement(Node node)
node
- Nodepublic static void sendError(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, int httpStatusCode, String errorCode, String errorMsg)
request
- HttpServletRequest objectresponse
- HttpServletResponse objecthttpStatusCode
- Http Status codeerrorCode
- Error codeerrorMsg
- Detailed error messageCopyright © 2010–2025 Open Identity Platform Community. All rights reserved.