Skip to content

Instantly share code, notes, and snippets.

@codebrane
Created January 29, 2010 16:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codebrane/289879 to your computer and use it in GitHub Desktop.
Save codebrane/289879 to your computer and use it in GitHub Desktop.
Working with SAML in Guanxi
org.guanxi.xal.saml_2_0.protocol.ResponseDocument responseDoc;
responseDoc = ResponseDocument.Factory.parse(pod.getBag().getSamlResponse());
To access the attributes in a SAML2 Response, see:
org.guanxi.sp.guard.AttributeConsumer::processSAML2Response
// Start looking for a Guanx Guard cookie
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (int c=0; c<cookies.length; c++) {
// ...and look for a Guanxi Guard one.
if (cookies[c].getName().startsWith("GUANXI_GUARD_SERVICE_PROVIDER_")) {
/* If we have a Guanxi Guard cookie, it means authentication has taken
* place and the SAML attributes are in a Pod in the request.
* The cookie contains the session ID set up by the Guard, into which
* the Podder has dumped the Pod of attributes.
*/
Pod pod = (Pod)servletContext.getAttribute(cookies[c].getValue());
if (pod != null) {
Enumeration<String> e = pod.getBag().getAttributeNames();
String attributeName = null;
while (e.hasMoreElements()) {
attributeName = e.nextElement();
// Find a match for the access attribute
if (attributeName.equals(letMeInAttribute)) {
for (String letMeInAttributeValue : letMeInAttributeValues) {
if (pod.getBag().getAttributeValue(attributeName).equalsIgnoreCase(letMeInAttributeValue)) {
return true;
}
} // for (String letMeInAttributeValue : letMeInAttributeValues)
} // if (attributeName.equals(letMeInAttribute))
} // while (e.hasMoreElements())
} // if (pod != null)
} // if (cookies[c].getName().startsWith("GUANXI_GUARD_SERVICE_PROVIDER_"))
} // for (int c=0; c<cookies.length; c++)
} // if (cookies != null)
Enumeration headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
String name = (String)headerNames.nextElement();
String value = request.getHeader(name);
if (name.startsWith("HTTP_")) {
// CN
if (name.equals("HTTP_cn")) {
if (value.contains(";")) {
return value.split(";")[0];
}
else {
return value;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment