use of com.sun.identity.federation.message.common.FSMsgException in project OpenAM by OpenRock.
the class FSAuthnRequest method parseURLEncodedRequest.
/**
* Returns <code>FSAuthnRequest</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 <code>FSAuthnRequest</code> object.
*/
public static FSAuthnRequest parseURLEncodedRequest(HttpServletRequest request) throws FSMsgException {
FSAuthnRequest retAuthnRequest = new FSAuthnRequest();
String authReqID = request.getParameter(IFSConstants.AUTH_REQUEST_ID);
if (authReqID == null || authReqID.length() == 0) {
throw new FSMsgException("nullAuthnRequestID", null);
}
retAuthnRequest.requestID = authReqID;
String instantString = request.getParameter(IFSConstants.ISSUE_INSTANT);
if (instantString == null || instantString.length() == 0) {
String[] args = { IFSConstants.ISSUE_INSTANT };
throw new FSMsgException("missingAttribute", args);
}
try {
retAuthnRequest.issueInstant = DateUtils.stringToDate(instantString);
} catch (ParseException e) {
throw new FSMsgException("parseError", null);
}
retAuthnRequest.majorVersion = checkMajorVersion(request.getParameter(IFSConstants.MAJOR_VERSION));
retAuthnRequest.minorVersion = checkMinorVersion(request.getParameter(IFSConstants.MINOR_VERSION));
String providerId = request.getParameter(IFSConstants.PROVIDER_ID);
if (providerId == null || providerId.length() == 0) {
throw new FSMsgException("nullProviderIdInRequest", null);
} else {
FSUtils.debug.message("ProviderID of the sender: " + providerId);
retAuthnRequest.providerId = providerId;
}
retAuthnRequest.affiliationID = request.getParameter(IFSConstants.AFFILIATIONID);
String forceAuthn = request.getParameter(IFSConstants.FORCE_AUTHN_ELEM);
if (forceAuthn != null && forceAuthn.length() != 0 && (forceAuthn.equals(IFSConstants.TRUE) || forceAuthn.equals(IFSConstants.ONE))) {
retAuthnRequest.forceAuthn = true;
} else {
retAuthnRequest.forceAuthn = false;
}
String isPassive = request.getParameter(IFSConstants.IS_PASSIVE_ELEM);
if (isPassive != null && isPassive.length() != 0 && (isPassive.equals(IFSConstants.TRUE) || isPassive.equals(IFSConstants.ONE))) {
retAuthnRequest.isPassive = true;
} else {
retAuthnRequest.isPassive = false;
}
if (retAuthnRequest.minorVersion == IFSConstants.FF_12_PROTOCOL_MINOR_VERSION) {
String nameIDPolicy = request.getParameter(IFSConstants.NAMEID_POLICY_ELEMENT);
if (nameIDPolicy != null && (nameIDPolicy.equals(IFSConstants.NAME_ID_POLICY_FEDERATED) || nameIDPolicy.equals(IFSConstants.NAME_ID_POLICY_ONETIME))) {
retAuthnRequest.federate = true;
}
retAuthnRequest.nameIDPolicy = nameIDPolicy;
} else {
String federate = request.getParameter(IFSConstants.FEDERATE);
if (federate != null && federate.length() != 0 && (federate.equals(IFSConstants.TRUE) || federate.equals(IFSConstants.ONE))) {
retAuthnRequest.federate = true;
} else {
retAuthnRequest.federate = false;
}
}
String protocolProfile = request.getParameter(IFSConstants.PROTOCOL_PROFILE);
if (protocolProfile != null && protocolProfile.length() != 0) {
retAuthnRequest.protocolProfile = protocolProfile;
}
String relayState = request.getParameter(IFSConstants.RELAY_STATE);
if (relayState != null && relayState.length() != 0) {
retAuthnRequest.setRelayState(relayState);
}
String authnContextComparison = request.getParameter(IFSConstants.AUTHN_CONTEXT_COMPARISON);
if (authnContextComparison != null && authnContextComparison.length() != 0) {
retAuthnRequest.setAuthContextCompType(authnContextComparison);
String authType = retAuthnRequest.getAuthContextCompType();
if (!(authType.equals(IFSConstants.MINIMUM) || authType.equals(IFSConstants.EXACT) || authType.equals(IFSConstants.MAXIMUM) || authType.equals(IFSConstants.BETTER))) {
throw new FSMsgException("wrongInput", null);
}
}
retAuthnRequest.authnContext = RequestAuthnContext.parseURLEncodedRequest(request, retAuthnRequest.getMinorVersion());
retAuthnRequest.scoping = FSScoping.parseURLEncodedRequest(request);
Extension extension = Extension.parseURLEncodedRequest(request, QUERY_STRING_EXTENSION_PREFIX, retAuthnRequest.getMinorVersion());
if (extension != null) {
retAuthnRequest.extensions = new ArrayList();
retAuthnRequest.extensions.add(extension);
}
return retAuthnRequest;
}
use of com.sun.identity.federation.message.common.FSMsgException in project OpenAM by OpenRock.
the class FSAuthnRequestEnvelope method parseXML.
/**
* Returns the <code>FSAuthnRequestEnvelope</code> object.
*
* @param xml the XML string to create this object from
* @return <code>FSAuthnRequestEnvelope</code> object.
* @throws FSMsgException if there is
* error creating the object.
*/
public static FSAuthnRequestEnvelope parseXML(String xml) throws FSMsgException {
Document doc = XMLUtils.toDOMDocument(xml, FSUtils.debug);
if (doc == null) {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSAuthnRequestEnvelope.parseXML:Error " + "while parsing input xml string");
}
throw new FSMsgException("parseError", null);
}
Element root = doc.getDocumentElement();
return new FSAuthnRequestEnvelope(root);
}
use of com.sun.identity.federation.message.common.FSMsgException in project OpenAM by OpenRock.
the class FSLogoutResponse method parseXML.
/**
* Returns the <code>FSLogoutResponse</code> object.
*
* @param xml the XML string to be parsed.
* @return <code>FSLogoutResponse</code> object created from the XML string.
* @throws FSMsgException if there is
* error creating the object.
*/
public static FSLogoutResponse parseXML(String xml) throws FSMsgException {
FSLogoutResponse logoutResponse = null;
try {
Document doc = XMLUtils.toDOMDocument(xml, FSUtils.debug);
Element root = doc.getDocumentElement();
logoutResponse = new FSLogoutResponse(root);
} catch (SAMLException ex) {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSLogoutResponse.parseXML: " + "Error while parsing input xml string");
}
throw new FSMsgException("parseError", null, ex);
}
return logoutResponse;
}
use of com.sun.identity.federation.message.common.FSMsgException in project OpenAM by OpenRock.
the class FSNameIdentifierMappingRequest method parseXML.
/**
* Returns <code>FSNameIdentifierMappingRequest</code> object. This
* object is created by parsing the <code>XML</code> string.
*
* @param xml <code>XML</code> String
* @return the <code>FSNameIdentifierMappingRequest</code> object.
* @throws FSMsgException if there is an error creating this object.
*/
public static FSNameIdentifierMappingRequest parseXML(String xml) throws FSMsgException {
Document doc = XMLUtils.toDOMDocument(xml, FSUtils.debug);
if (doc == null) {
FSUtils.debug.error("FSNameIdentifierMappingRequest.parseXML: " + "error while parsing input xml string");
throw new FSMsgException("parseError", null);
}
Element root = doc.getDocumentElement();
return new FSNameIdentifierMappingRequest(root);
}
use of com.sun.identity.federation.message.common.FSMsgException in project OpenAM by OpenRock.
the class FSAuthnRequest method toURLEncodedQueryString.
/**
* Returns an URL Encoded Query String.
*
* @return a url encoded query string.
* @throws FSMsgException if there is an error.
*/
public String toURLEncodedQueryString() throws FSMsgException {
if ((providerId == null) || (providerId.length() == 0)) {
FSUtils.debug.error("FSAuthnRequest.toURLEncodedQueryString: " + "providerId is null in the request with requestId:" + requestID);
String[] args = { requestID };
throw new FSMsgException("nullProviderIdWRequestId", args);
}
if ((requestID == null) || (requestID.length() == 0)) {
requestID = SAMLUtils.generateID();
if (requestID == null) {
FSUtils.debug.error("FSAuthnRequest.toURLEncodedQueryString: " + "couldn't generate RequestID.");
throw new FSMsgException("errorGenerateID", null);
}
}
StringBuffer urlEncodedAuthnReq = new StringBuffer(300);
urlEncodedAuthnReq.append(IFSConstants.AUTH_REQUEST_ID).append(IFSConstants.EQUAL_TO).append(URLEncDec.encode(requestID)).append(IFSConstants.AMPERSAND).append(IFSConstants.MAJOR_VERSION).append(IFSConstants.EQUAL_TO).append(majorVersion).append(IFSConstants.AMPERSAND).append(IFSConstants.MINOR_VERSION).append(IFSConstants.EQUAL_TO).append(minorVersion).append(IFSConstants.AMPERSAND);
if ((extensions != null) && (!extensions.isEmpty())) {
Extension extension = (Extension) extensions.get(0);
urlEncodedAuthnReq.append(extension.toURLEncodedQueryString(QUERY_STRING_EXTENSION_PREFIX)).append(IFSConstants.AMPERSAND);
if (extensions.size() > 1) {
if (FSUtils.debug.warningEnabled()) {
FSUtils.debug.warning("FSAuthnRequest.toURLEncodedQueryString: " + "only one Extension element is allowed and extras " + " will be removed");
}
}
}
urlEncodedAuthnReq.append(IFSConstants.PROVIDER_ID).append(IFSConstants.EQUAL_TO).append(URLEncDec.encode(providerId)).append(IFSConstants.AMPERSAND);
if (consentURI != null) {
urlEncodedAuthnReq.append(IFSConstants.CONSENT).append(IFSConstants.EQUAL_TO).append(URLEncDec.encode(consentURI)).append(IFSConstants.AMPERSAND);
}
if (affiliationID != null) {
urlEncodedAuthnReq.append(IFSConstants.AFFILIATIONID).append(IFSConstants.EQUAL_TO).append(URLEncDec.encode(affiliationID)).append(IFSConstants.AMPERSAND);
}
if (issueInstant != null) {
urlEncodedAuthnReq.append(IFSConstants.ISSUE_INSTANT).append(IFSConstants.EQUAL_TO).append(URLEncDec.encode(DateUtils.toUTCDateFormat(issueInstant))).append(IFSConstants.AMPERSAND);
} else {
FSUtils.debug.error("FSAuthnRequest.toURLEncodedQueryString: " + "issueInstant missing");
String[] args = { IFSConstants.ISSUE_INSTANT };
throw new FSMsgException("missingAttribute", args);
}
String strForceAuthn = IFSConstants.FALSE;
if (forceAuthn) {
strForceAuthn = IFSConstants.TRUE;
}
urlEncodedAuthnReq.append(IFSConstants.FORCE_AUTHN_ELEM).append(IFSConstants.EQUAL_TO).append(strForceAuthn).append(IFSConstants.AMPERSAND);
String strIsPassive = IFSConstants.FALSE;
if (isPassive) {
strIsPassive = IFSConstants.TRUE;
}
urlEncodedAuthnReq.append(IFSConstants.IS_PASSIVE_ELEM).append(IFSConstants.EQUAL_TO).append(strIsPassive).append(IFSConstants.AMPERSAND);
if (minorVersion == IFSConstants.FF_12_PROTOCOL_MINOR_VERSION) {
String strFederate = IFSConstants.NAME_ID_POLICY_NONE;
if (federate) {
strFederate = IFSConstants.NAME_ID_POLICY_FEDERATED;
if (nameIDPolicy != null && nameIDPolicy.length() > 0) {
strFederate = nameIDPolicy;
}
}
urlEncodedAuthnReq.append(IFSConstants.NAMEID_POLICY_ELEMENT).append(IFSConstants.EQUAL_TO).append(strFederate).append(IFSConstants.AMPERSAND);
} else {
String strFederate = IFSConstants.FALSE;
if (federate) {
strFederate = IFSConstants.TRUE;
}
urlEncodedAuthnReq.append(IFSConstants.FEDERATE).append(IFSConstants.EQUAL_TO).append(strFederate).append(IFSConstants.AMPERSAND);
}
if (protocolProfile != null && protocolProfile.length() != 0) {
urlEncodedAuthnReq.append(IFSConstants.PROTOCOL_PROFILE).append(IFSConstants.EQUAL_TO).append(URLEncDec.encode(protocolProfile)).append(IFSConstants.AMPERSAND);
}
if (authnContext != null) {
authnContext.setMinorVersion(minorVersion);
urlEncodedAuthnReq.append(authnContext.toURLEncodedQueryString());
}
if (relayState != null && relayState.length() != 0) {
urlEncodedAuthnReq.append(IFSConstants.RELAY_STATE).append(IFSConstants.EQUAL_TO).append(URLEncDec.encode(relayState)).append(IFSConstants.AMPERSAND);
}
if (scoping != null) {
urlEncodedAuthnReq.append(scoping.toURLEncodedQueryString());
}
if (minorVersion == IFSConstants.FF_11_PROTOCOL_MINOR_VERSION) {
if (authContextCompType != null && authContextCompType.length() != 0) {
urlEncodedAuthnReq.append(IFSConstants.AUTHN_CONTEXT_COMPARISON).append(IFSConstants.EQUAL_TO).append(URLEncDec.encode(authContextCompType)).append(IFSConstants.AMPERSAND);
}
}
int len = urlEncodedAuthnReq.length() - 1;
if (urlEncodedAuthnReq.charAt(len) == '&') {
urlEncodedAuthnReq = urlEncodedAuthnReq.deleteCharAt(len);
}
return urlEncodedAuthnReq.toString();
}
Aggregations