use of com.sun.identity.federation.message.common.FSMsgException in project OpenAM by OpenRock.
the class FSFederationTerminationNotification method parseXML.
/**
* Returns the <code>FSAuthnRequest</code> object.
*
* @param xml the XML string to be parsed.
* @return <code>FSAuthnRequest</code> object created from the XML string.
* @throws FSMsgException if there is
* error creating the object.
*/
public static FSFederationTerminationNotification parseXML(String xml) throws FSMsgException {
Document doc = XMLUtils.toDOMDocument(xml, FSUtils.debug);
if (doc == null) {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSFederationTerminationNotification.parseXML:Error " + "while parsing input xml string");
}
throw new FSMsgException("parseError", null);
}
Element root = doc.getDocumentElement();
return new FSFederationTerminationNotification(root);
}
use of com.sun.identity.federation.message.common.FSMsgException in project OpenAM by OpenRock.
the class FSLogoutNotification method toURLEncodedQueryString.
/**
* Returns an URL Encoded 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("FSLogoutNotification.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("FSLogoutNotification.toURLEncodedQueryString: " + "couldn't generate RequestID.");
throw new FSMsgException("errorGenerateID", null);
}
}
StringBuffer urlEncodedAuthnReq = new StringBuffer(300);
urlEncodedAuthnReq.append(IFSConstants.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 (issueInstant != null) {
urlEncodedAuthnReq.append(IFSConstants.ISSUE_INSTANT).append(IFSConstants.EQUAL_TO).append(URLEncDec.encode(DateUtils.toUTCDateFormat(issueInstant))).append(IFSConstants.AMPERSAND);
if (minorVersion == IFSConstants.FF_12_PROTOCOL_MINOR_VERSION) {
notOnOrAfter = new Date(issueInstant.getTime() + IFSConstants.ASSERTION_TIMEOUT_ALLOWED_DIFFERENCE);
urlEncodedAuthnReq.append(IFSConstants.NOT_ON_OR_AFTER).append(IFSConstants.EQUAL_TO).append(URLEncDec.encode(DateUtils.toUTCDateFormat(notOnOrAfter))).append(IFSConstants.AMPERSAND);
}
} else {
FSUtils.debug.error("FSLogoutNotification." + "toURLEncodedQueryString: issueInstant missing");
String[] args = { IFSConstants.ISSUE_INSTANT };
throw new FSMsgException("missingAttribute", args);
}
if (providerId != null && providerId.length() != 0) {
urlEncodedAuthnReq.append(IFSConstants.PROVIDER_ID).append(IFSConstants.EQUAL_TO).append(URLEncDec.encode(providerId)).append(IFSConstants.AMPERSAND);
}
if (sessionIndex != null && sessionIndex.length() != 0) {
urlEncodedAuthnReq.append(IFSConstants.SESSION_INDEX).append(IFSConstants.EQUAL_TO).append(URLEncDec.encode(sessionIndex)).append(IFSConstants.AMPERSAND);
}
if (relayState != null && relayState.length() != 0) {
urlEncodedAuthnReq.append(IFSConstants.RELAY_STATE).append(IFSConstants.EQUAL_TO).append(URLEncDec.encode(relayState)).append(IFSConstants.AMPERSAND);
}
if (nameIdentifier != null) {
if (nameIdentifier.getName() != null && nameIdentifier.getName().length() != 0) {
urlEncodedAuthnReq.append(IFSConstants.NAME).append(IFSConstants.EQUAL_TO).append(URLEncDec.encode(nameIdentifier.getName())).append(IFSConstants.AMPERSAND).append(IFSConstants.NAME_IDENTIFIER).append(IFSConstants.EQUAL_TO).append(URLEncDec.encode(nameIdentifier.getName())).append(IFSConstants.AMPERSAND);
}
if (nameIdentifier.getNameQualifier() != null && nameIdentifier.getNameQualifier().length() != 0) {
urlEncodedAuthnReq.append(IFSConstants.NAME_QUALIFIER).append(IFSConstants.EQUAL_TO).append(URLEncDec.encode(nameIdentifier.getNameQualifier())).append(IFSConstants.AMPERSAND);
}
if (nameIdentifier.getFormat() != null && nameIdentifier.getFormat().length() != 0) {
urlEncodedAuthnReq.append(IFSConstants.NAME_FORMAT).append(IFSConstants.EQUAL_TO).append(URLEncDec.encode(nameIdentifier.getFormat())).append(IFSConstants.AMPERSAND);
}
}
return urlEncodedAuthnReq.toString();
}
use of com.sun.identity.federation.message.common.FSMsgException in project OpenAM by OpenRock.
the class FSLogoutNotification method parseURLEncodedRequest.
/**
* Returns <code>FSLogoutNotification</code> object. The
* object is created by parsing the <code>HttpServletRequest</code>
* object.
*
* @param request the <code>HttpServletRequest</code> object.
* @return <code>FSLogoutNotification</code> object.
* @throws FSMsgException if there is an error
* creating <code>FSAuthnRequest</code> object.
*/
public static FSLogoutNotification parseURLEncodedRequest(HttpServletRequest request) throws FSMsgException {
try {
FSLogoutNotification retLogoutNotification = new FSLogoutNotification();
String requestID = request.getParameter("RequestID");
if (requestID != null) {
retLogoutNotification.requestID = requestID;
} else {
String[] args = { IFSConstants.REQUEST_ID };
throw new FSMsgException("missingAttribute", args);
}
try {
retLogoutNotification.majorVersion = Integer.parseInt(request.getParameter(IFSConstants.MAJOR_VERSION));
FSUtils.debug.message("Majorversion : " + retLogoutNotification.majorVersion);
retLogoutNotification.minorVersion = Integer.parseInt(request.getParameter(IFSConstants.MINOR_VERSION));
FSUtils.debug.message("Minorversion : " + retLogoutNotification.minorVersion);
} catch (NumberFormatException ex) {
FSUtils.debug.message("FSLogoutNotification. " + "parseURLEncodedRequest:Major/Minor version problem");
throw new FSMsgException("invalidNumber", null);
}
String instantString = request.getParameter(IFSConstants.ISSUE_INSTANT);
if (instantString == null || instantString.length() == 0) {
String[] args = { IFSConstants.ISSUE_INSTANT };
throw new FSMsgException("missingAttribute", args);
}
try {
retLogoutNotification.issueInstant = DateUtils.stringToDate(instantString);
} catch (ParseException e) {
throw new FSMsgException("parseError", null);
}
String notAfter = request.getParameter(IFSConstants.NOT_ON_OR_AFTER);
if (notAfter != null && notAfter.length() != 0) {
try {
retLogoutNotification.notOnOrAfter = DateUtils.stringToDate(notAfter);
} catch (ParseException pe) {
FSUtils.debug.message("FSLogoutNotification.parseURLEncoded" + "Request: parsing exception", pe);
}
}
String providerId = request.getParameter(IFSConstants.PROVIDER_ID);
if (providerId != null) {
retLogoutNotification.providerId = providerId;
} else {
throw new FSMsgException("missingElement", null);
}
String sessionIndex = request.getParameter(IFSConstants.SESSION_INDEX);
if (sessionIndex != null) {
retLogoutNotification.sessionIndex = sessionIndex;
}
String relayState = request.getParameter(IFSConstants.RELAY_STATE);
if (relayState != null) {
retLogoutNotification.relayState = relayState;
}
String nameFormat = request.getParameter(IFSConstants.NAME_FORMAT);
String nameQualifier = request.getParameter(IFSConstants.NAME_QUALIFIER);
String name = request.getParameter(IFSConstants.NAME);
if (name == null) {
name = request.getParameter(IFSConstants.NAME_IDENTIFIER);
}
if (name == null) {
throw new FSMsgException("missingElement", null);
}
retLogoutNotification.nameIdentifier = new NameIdentifier(name, nameQualifier, nameFormat);
FSUtils.debug.message("Returning Logout Object");
return retLogoutNotification;
} catch (Exception e) {
throw new FSMsgException("parseError", null);
}
}
use of com.sun.identity.federation.message.common.FSMsgException in project OpenAM by OpenRock.
the class FSAuthnRequest method parseXML.
/**
* Returns the <code>FSAuthnRequest</code> object.
*
* @param xml the XML string.
* @return <code>FSAuthnRequest</code> object.
* @throws FSMsgException if there is
* error creating the object.
*/
public static FSAuthnRequest parseXML(String xml) throws FSMsgException {
Document doc = XMLUtils.toDOMDocument(xml, FSUtils.debug);
if (doc == null) {
FSUtils.debug.error("FSAuthnRequest.parseXML:Error " + "while parsing input xml string");
throw new FSMsgException("parseError", null);
}
Element root = doc.getDocumentElement();
return new FSAuthnRequest(root);
}
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;
}
Aggregations