use of com.sun.identity.federation.message.common.FSMsgException in project OpenAM by OpenRock.
the class CDCServlet method redirectWithAuthNResponse.
/**
* Constructs the Liberty AuthNResponse with Restricted SSOToken
* and redirects the user to the requested resouce
*/
private void redirectWithAuthNResponse(HttpServletRequest request, HttpServletResponse response, SSOToken token) throws ServletException, IOException {
String gotoURL = getRedirectURL(request, response);
if (debug.messageEnabled()) {
debug.message("CDCServlet.redirectWithAuthNResponse: gotoURL = " + gotoURL);
}
if (debug.messageEnabled()) {
debug.message("CDCServlet.redirectWithAuthNResponse: After encoding: gotoURL = " + gotoURL);
}
if (gotoURL != null) {
try {
String inResponseTo = request.getParameter(REQUEST_ID);
String spDescriptor = request.getParameter(PROVIDER_ID);
String resTokenID = null;
/**
* validateAndGetRestriction throws an exception if an agent
* profile with provider id and goto url is not present
*/
TokenRestriction tokenRes = spValidator.validateAndGetRestriction(FSAuthnRequest.parseURLEncodedRequest(request), gotoURL);
if (uniqueCookieEnabled) {
resTokenID = sessionService.getRestrictedTokenId(token.getTokenID().toString(), tokenRes);
} else {
resTokenID = token.getTokenID().toString();
}
FSAssertion assertion = createAssertion(spDescriptor, SELF_PROVIDER_ID, resTokenID, token.getAuthType(), token.getProperty("authInstant"), token.getPrincipal().getName(), inResponseTo);
String relayState = request.getParameter(RELAY_STATE);
Status status = new Status(new StatusCode(IFSConstants.STATUS_CODE_SUCCESS));
FSAuthnResponse authnResponse = createAuthnResponse(SELF_PROVIDER_ID, responseID, inResponseTo, status, assertion, relayState);
sendAuthnResponse(request, response, authnResponse, gotoURL);
} catch (SAMLException se) {
debug.error("CDCServlet.doGetPost", se);
showError(response);
} catch (FSMsgException fe) {
debug.error("CDCServlet.doGetPost", fe);
showError(response);
} catch (FSException fse) {
debug.error("CDCServlet.doGetPost", fse);
showError(response);
} catch (SessionException e) {
debug.error("CDCServlet.doGetPost", e);
} catch (SSOException ssoe) {
debug.error("CDCServlet.doGetPost", ssoe);
} catch (Exception e) {
debug.error("CDCServlet.doGetPost", e);
spValidator = new LdapSPValidator();
showError(response, FORBIDDEN_STR_MATCH);
}
}
}
use of com.sun.identity.federation.message.common.FSMsgException in project OpenAM by OpenRock.
the class FSNameRegistrationRequest method parseXML.
public static FSNameRegistrationRequest parseXML(String xml) throws FSMsgException {
Document doc = XMLUtils.toDOMDocument(xml, FSUtils.debug);
if (doc == null) {
FSUtils.debug.error("FSNameRegistrationRequest.parseXML:Error " + "while parsing input xml string");
throw new FSMsgException("parseError", null);
}
Element root = doc.getDocumentElement();
return new FSNameRegistrationRequest(root);
}
use of com.sun.identity.federation.message.common.FSMsgException in project OpenAM by OpenRock.
the class FSNameRegistrationRequest method parseURLEncodedRequest.
/**
* Returns <code>FSNameRegistrationRequest</code> object. The
* object is creating by parsing the <code>HttpServletRequest</code>
* object.
*
* @param request the <code>HttpServletRequest</code> object.
* @throws FSMsgException if there is an error
* creating this object.
* @throws SAMLException if there is an error.
*/
public static FSNameRegistrationRequest parseURLEncodedRequest(HttpServletRequest request) throws FSMsgException, SAMLException {
FSNameRegistrationRequest retNameRegistrationRequest = new FSNameRegistrationRequest();
try {
FSUtils.debug.message("checking minor version");
retNameRegistrationRequest.majorVersion = Integer.parseInt(request.getParameter("MajorVersion"));
retNameRegistrationRequest.minorVersion = Integer.parseInt(request.getParameter("MinorVersion"));
} catch (NumberFormatException ex) {
FSUtils.debug.error("FSNameRegistrationRequest.parseURLEncoded" + "Request: Invalid versions", ex);
throw new FSMsgException("invalidNumber", null);
}
FSUtils.debug.message("checking RequestID");
if (request.getParameter("RequestID") != null) {
retNameRegistrationRequest.requestID = request.getParameter("RequestID");
} else {
FSUtils.debug.error("FSNameRegistrationRequest.parseURLEncoded" + "Request: RequestID not found");
String[] args = { IFSConstants.REQUEST_ID };
throw new FSMsgException("missingAttribute", args);
}
FSUtils.debug.message("checking instantString");
String instantString = request.getParameter("IssueInstant");
FSUtils.debug.message("instantString : " + instantString);
if (instantString == null || instantString.length() == 0) {
FSUtils.debug.error("FSNameRegistrationRequest.parseURLEncoded" + "Request: IssueInstant not found");
String[] args = { IFSConstants.ISSUE_INSTANT };
throw new FSMsgException("missingAttribute", args);
}
try {
FSUtils.debug.message("calling : DateUtils.stringToDate.issueInstant");
retNameRegistrationRequest.issueInstant = DateUtils.stringToDate(instantString);
} catch (ParseException e) {
FSUtils.debug.error("FSNameRegistrationRequest.parseURLEncoded" + "Request: Can not parse IssueInstant", e);
throw new FSMsgException("parseError", null);
}
if (request.getParameter("ProviderID") != null) {
retNameRegistrationRequest.providerId = request.getParameter("ProviderID");
} else {
FSUtils.debug.error("FSNameRegistrationRequest.parseURLEncoded" + "Request: Can not find ProviderID");
throw new FSMsgException("missingElement", null);
}
FSUtils.debug.message("start identifier processing");
String spNameFormat = "";
String spNameQualifier = "";
String spName = "";
if (request.getParameter("SPNameFormat") != null) {
spNameFormat = request.getParameter("SPNameFormat");
}
if (request.getParameter("SPNameQualifier") != null) {
spNameQualifier = request.getParameter("SPNameQualifier");
}
if (request.getParameter("SPProvidedNameIdentifier") != null) {
spName = request.getParameter("SPProvidedNameIdentifier");
}
if (spName != null && !(spName.length() < 1)) {
retNameRegistrationRequest.setSPProvidedNameIdentifier(new SPProvidedNameIdentifier(spName, spNameQualifier, spNameFormat));
}
String idpNameFormat = null;
String idpNameQualifier = null;
String idpName = null;
if (request.getParameter("IDPNameFormat") != null) {
idpNameFormat = request.getParameter("IDPNameFormat");
}
if (request.getParameter("IDPNameQualifier") != null) {
idpNameQualifier = request.getParameter("IDPNameQualifier");
}
if (request.getParameter("IDPProvidedNameIdentifier") != null) {
idpName = request.getParameter("IDPProvidedNameIdentifier");
}
if (idpName != null && !(idpName.length() < 1)) {
retNameRegistrationRequest.idpProvidedNameIdentifier = new IDPProvidedNameIdentifier(idpName, idpNameQualifier, idpNameFormat);
}
String oldNameFormat = null;
String oldNameQualifier = null;
String oldName = null;
if (request.getParameter("OldNameFormat") != null) {
oldNameFormat = request.getParameter("OldNameFormat");
}
if (request.getParameter("OldNameQualifier") != null) {
oldNameQualifier = request.getParameter("OldNameQualifier");
}
if (request.getParameter("OldProvidedNameIdentifier") != null) {
oldName = request.getParameter("OldProvidedNameIdentifier");
}
if (oldName != null && !(oldName.length() < 1)) {
retNameRegistrationRequest.oldProvidedNameIdentifier = new OldProvidedNameIdentifier(oldName, oldNameQualifier, oldNameFormat);
}
if (request.getParameter("RelayState") != null) {
retNameRegistrationRequest.relayState = request.getParameter("RelayState");
}
return retNameRegistrationRequest;
}
use of com.sun.identity.federation.message.common.FSMsgException in project OpenAM by OpenRock.
the class FSNameRegistrationResponse method parseXML.
/**
* Returns the <code>FSNameRegistrationResponse</code> object.
*
* @param xml the XML string to be parsed.
* @return <code>FSNameRegistrationResponsee</code> object created from
* the XML string.
* @throws FSMsgException if there is error creating the object.
*/
public static FSNameRegistrationResponse parseXML(String xml) throws FSMsgException {
try {
Document doc = XMLUtils.toDOMDocument(xml, FSUtils.debug);
Element root = doc.getDocumentElement();
return new FSNameRegistrationResponse(root);
} catch (SAMLException ex) {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSNameRegistrationResponse.parseXML: " + "Error while parsing input xml string");
}
throw new FSMsgException("parseError", null, ex);
}
}
use of com.sun.identity.federation.message.common.FSMsgException in project OpenAM by OpenRock.
the class FSResponse method parseResponseXML.
public static FSResponse parseResponseXML(String xml) throws SAMLException, FSMsgException {
// parse the xml string
FSUtils.debug.message("FSResponse.parseResponseXML: Called");
Element root;
Document doc = XMLUtils.toDOMDocument(xml, FSUtils.debug);
if (doc == null) {
FSUtils.debug.error("FSResponse.parseXML:Error " + "while parsing input xml string");
throw new FSMsgException("parseError", null);
}
root = doc.getDocumentElement();
return new FSResponse(root);
}
Aggregations