use of com.sun.identity.saml2.plugins.AssertionIDRequestMapper in project OpenAM by OpenRock.
the class AssertionIDRequestUtil method getAssertionIDRequestMapper.
private static AssertionIDRequestMapper getAssertionIDRequestMapper(String realm, String samlAuthorityEntityID, String role) throws SAML2Exception {
String aidReqMapperName = null;
AssertionIDRequestMapper aidReqMapper = null;
try {
aidReqMapperName = SAML2Utils.getAttributeValueFromSSOConfig(realm, samlAuthorityEntityID, role, SAML2Constants.ASSERTION_ID_REQUEST_MAPPER);
if (aidReqMapperName == null) {
aidReqMapperName = SAML2Constants.DEFAULT_ASSERTION_ID_REQUEST_MAPPER_CLASS;
if (SAML2Utils.debug.messageEnabled()) {
SAML2Utils.debug.message("AssertionIDRequestUtil.getAssertionIDRequestMapper:" + " use " + aidReqMapperName);
}
}
aidReqMapper = (AssertionIDRequestMapper) assertionIDRequestMapperCache.get(aidReqMapperName);
if (aidReqMapper == null) {
aidReqMapper = (AssertionIDRequestMapper) Class.forName(aidReqMapperName).newInstance();
assertionIDRequestMapperCache.put(aidReqMapperName, aidReqMapper);
} else {
if (SAML2Utils.debug.messageEnabled()) {
SAML2Utils.debug.message("AssertionIDRequestUtil.getAssertionIDRequestMapper:" + " got the AssertionIDRequestMapper from cache");
}
}
} catch (Exception ex) {
SAML2Utils.debug.error("AssertionIDRequestUtil.getAssertionIDRequestMapper:", ex);
throw new SAML2Exception(ex);
}
return aidReqMapper;
}
use of com.sun.identity.saml2.plugins.AssertionIDRequestMapper in project OpenAM by OpenRock.
the class AssertionIDRequestUtil method processAssertionIDRequestURI.
/**
* Gets assertion ID from URI and returns assertion if found.
*
* @param request the <code>HttpServletRequest</code> object
* @param response the <code>HttpServletResponse</code> object
* @param samlAuthorityEntityID entity ID of SAML authority
* @param role SAML authority role
* @param realm the realm of hosted entity
*
* @exception IOException if response can't be sent
*/
public static void processAssertionIDRequestURI(HttpServletRequest request, HttpServletResponse response, String samlAuthorityEntityID, String role, String realm) throws IOException {
String assertionID = request.getParameter("ID");
if (assertionID == null) {
SAMLUtils.sendError(request, response, HttpServletResponse.SC_BAD_REQUEST, "nullAssertionID", SAML2Utils.bundle.getString("nullAssertionID"));
return;
}
AssertionIDRequestMapper aidReqMapper = null;
try {
aidReqMapper = getAssertionIDRequestMapper(realm, samlAuthorityEntityID, role);
} catch (SAML2Exception ex) {
SAMLUtils.sendError(request, response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "failedToGetAssertionIDRequestMapper", ex.getMessage());
return;
}
try {
aidReqMapper.authenticateRequesterURI(request, response, samlAuthorityEntityID, role, realm);
} catch (SAML2Exception ex) {
SAMLUtils.sendError(request, response, HttpServletResponse.SC_FORBIDDEN, "failedToAuthenticateRequesterURI", ex.getMessage());
return;
}
Assertion assertion = (Assertion) IDPCache.assertionByIDCache.get(assertionID);
if ((assertion == null) || (!assertion.isTimeValid())) {
SAMLUtils.sendError(request, response, HttpServletResponse.SC_NOT_FOUND, "invalidAssertionID", SAML2Utils.bundle.getString("invalidAssertionID"));
return;
}
response.setContentType(MIME_TYPE_ASSERTION);
response.addHeader("Cache-Control", "no-cache, no-store");
response.addHeader("Pragma", "no-cache");
String content = null;
try {
content = assertion.toXMLString(true, true);
} catch (SAML2Exception ex) {
if (SAML2Utils.debug.messageEnabled()) {
SAML2Utils.debug.message("AssertionIDRequestUtil." + "processAssertionIDRequestURI:", ex);
}
SAMLUtils.sendError(request, response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "invalidAssertion", ex.getMessage());
return;
}
byte[] bytes = null;
try {
bytes = content.getBytes("UTF-8");
} catch (UnsupportedEncodingException ueex) {
if (SAML2Utils.debug.messageEnabled()) {
SAML2Utils.debug.message("AssertionIDRequestUtil." + "processAssertionIDRequestURI:", ueex);
}
SAMLUtils.sendError(request, response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "unsupportedEncoding", ueex.getMessage());
return;
}
response.setContentLength(bytes.length);
BufferedOutputStream bos = null;
try {
bos = new BufferedOutputStream(response.getOutputStream());
bos.write(bytes, 0, bytes.length);
} catch (IOException ioex) {
SAML2Utils.debug.error("AssertionIDRequestUtil." + "processAssertionIDRequestURI:", ioex);
} finally {
if (bos != null) {
try {
bos.close();
} catch (IOException ioex) {
SAML2Utils.debug.error("AssertionIDRequestUtil." + "processAssertionIDRequestURI:", ioex);
}
}
}
}
Aggregations