Search in sources :

Example 1 with FSMsgException

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);
}
Also used : FSMsgException(com.sun.identity.federation.message.common.FSMsgException) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 2 with FSMsgException

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;
}
Also used : FSMsgException(com.sun.identity.federation.message.common.FSMsgException) SPProvidedNameIdentifier(com.sun.identity.federation.message.common.SPProvidedNameIdentifier) ParseException(java.text.ParseException) IDPProvidedNameIdentifier(com.sun.identity.federation.message.common.IDPProvidedNameIdentifier) OldProvidedNameIdentifier(com.sun.identity.federation.message.common.OldProvidedNameIdentifier)

Example 3 with FSMsgException

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);
    }
}
Also used : FSMsgException(com.sun.identity.federation.message.common.FSMsgException) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) SAMLException(com.sun.identity.saml.common.SAMLException)

Example 4 with FSMsgException

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);
}
Also used : FSMsgException(com.sun.identity.federation.message.common.FSMsgException) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 5 with FSMsgException

use of com.sun.identity.federation.message.common.FSMsgException in project OpenAM by OpenRock.

the class FSFederationTerminationNotification method toXMLString.

/**
     * Returns a String representation of the &lt;samlp:Response&gt; element.
     *
     * @param includeNS Determines whether or not the namespace qualifier
     *        is prepended to the Element when converted
     * @param declareNS Determines whether or not the namespace is declared
     *        within the Element.
     * @param includeHeader Determines whether the output include the xml
     *        declaration header.
     * @return a string containing the valid XML for this element
     * @throws FSMsgException if there is an error converting
     *         this object ot a string.
     */
public String toXMLString(boolean includeNS, boolean declareNS, boolean includeHeader) throws FSMsgException {
    if ((providerId == null) || (providerId.length() == 0)) {
        FSUtils.debug.error("FSFederationTerminationNotification.toXMLString" + ": 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("FSFederationTerminationNotification." + "toXMLString: couldn't generate RequestID.");
            throw new FSMsgException("errorGenerateID", null);
        }
    }
    StringBuffer xml = new StringBuffer(300);
    if (includeHeader) {
        xml.append(IFSConstants.XML_PREFIX).append(IFSConstants.QUOTE).append(IFSConstants.SPACE).append(IFSConstants.QUESTION_MARK).append(IFSConstants.RIGHT_ANGLE);
    }
    String prefix = "";
    String uriSAML = "";
    String uri = "";
    if (includeNS) {
        prefix = IFSConstants.LIB_PREFIX;
    }
    if (declareNS) {
        uri = IFSConstants.LIB_NAMESPACE_STRING;
        if (minorVersion == IFSConstants.FF_12_PROTOCOL_MINOR_VERSION) {
            uri = IFSConstants.LIB_12_NAMESPACE_STRING;
        }
        uriSAML = IFSConstants.assertionDeclareStr;
    }
    String instantString = DateUtils.toUTCDateFormat(issueInstant);
    if (requestID != null) {
        xml.append(IFSConstants.LEFT_ANGLE).append(prefix).append(IFSConstants.FEDERATION_TERMINATION_NOTICFICATION).append(uri).append(uriSAML).append(IFSConstants.SPACE);
        if (minorVersion == IFSConstants.FF_11_PROTOCOL_MINOR_VERSION && id != null && !(id.length() == 0)) {
            xml.append(IFSConstants.SPACE).append("id").append(IFSConstants.EQUAL_TO).append(IFSConstants.QUOTE).append(id).append(IFSConstants.QUOTE).append(IFSConstants.SPACE);
        }
        xml.append(IFSConstants.REQUEST_ID).append(IFSConstants.EQUAL_TO).append(IFSConstants.QUOTE).append(requestID).append(IFSConstants.QUOTE).append(IFSConstants.SPACE).append(IFSConstants.MAJOR_VERSION).append(IFSConstants.EQUAL_TO).append(IFSConstants.QUOTE).append(majorVersion).append(IFSConstants.QUOTE).append(IFSConstants.SPACE).append(IFSConstants.MINOR_VERSION).append(IFSConstants.EQUAL_TO).append(IFSConstants.QUOTE).append(minorVersion).append(IFSConstants.QUOTE).append(IFSConstants.SPACE).append(IFSConstants.ISSUE_INSTANT).append(IFSConstants.EQUAL_TO).append(IFSConstants.QUOTE).append(instantString).append(IFSConstants.QUOTE).append(IFSConstants.RIGHT_ANGLE);
        if ((respondWiths != null) && (respondWiths != Collections.EMPTY_LIST)) {
            Iterator i = respondWiths.iterator();
            while (i.hasNext()) {
                xml.append(IFSConstants.LEFT_ANGLE).append(prefix).append(IFSConstants.RESPONDWITH).append(IFSConstants.RIGHT_ANGLE).append((String) i.next()).append(IFSConstants.START_END_ELEMENT).append(prefix).append(IFSConstants.RESPONDWITH).append(IFSConstants.LEFT_ANGLE);
            }
        }
        if (signed) {
            if (signatureString != null) {
                xml.append(signatureString);
            } else if (signature != null) {
                signatureString = XMLUtils.print(signature);
                xml.append(signatureString);
            }
        }
        xml.append(IFSConstants.LEFT_ANGLE).append(prefix).append(IFSConstants.PROVIDER_ID).append(uri).append(IFSConstants.RIGHT_ANGLE).append(providerId).append(IFSConstants.START_END_ELEMENT).append(prefix).append(IFSConstants.PROVIDER_ID).append(IFSConstants.RIGHT_ANGLE);
        if (nameIdentifier != null) {
            xml.append(nameIdentifier.toString());
        }
        if (relayState != null) {
            xml.append(IFSConstants.LEFT_ANGLE).append(prefix).append(IFSConstants.RELAY_STATE).append(uri).append(IFSConstants.RIGHT_ANGLE).append(providerId).append(IFSConstants.START_END_ELEMENT).append(prefix).append(IFSConstants.RELAY_STATE).append(IFSConstants.RIGHT_ANGLE);
        }
        xml.append(IFSConstants.START_END_ELEMENT).append(prefix).append(IFSConstants.FEDERATION_TERMINATION_NOTICFICATION).append(IFSConstants.RIGHT_ANGLE);
    } else {
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSFederationTerminationNotification." + "toString: requestID is null ");
        }
        throw new FSMsgException("nullRequestID", null);
    }
    return xml.toString();
}
Also used : FSMsgException(com.sun.identity.federation.message.common.FSMsgException) Iterator(java.util.Iterator)

Aggregations

FSMsgException (com.sun.identity.federation.message.common.FSMsgException)46 SAMLException (com.sun.identity.saml.common.SAMLException)17 Document (org.w3c.dom.Document)15 Element (org.w3c.dom.Element)15 BaseConfigType (com.sun.identity.federation.jaxb.entityconfig.BaseConfigType)10 IDFFMetaException (com.sun.identity.federation.meta.IDFFMetaException)10 ProviderDescriptorType (com.sun.identity.liberty.ws.meta.jaxb.ProviderDescriptorType)8 Status (com.sun.identity.saml.protocol.Status)8 IOException (java.io.IOException)8 Iterator (java.util.Iterator)8 FSException (com.sun.identity.federation.common.FSException)7 ParseException (java.text.ParseException)7 SessionException (com.sun.identity.plugin.session.SessionException)6 FSNameRegistrationResponse (com.sun.identity.federation.message.FSNameRegistrationResponse)5 StatusCode (com.sun.identity.saml.protocol.StatusCode)5 FSLogoutNotification (com.sun.identity.federation.message.FSLogoutNotification)4 NameIdentifier (com.sun.identity.saml.assertion.NameIdentifier)4 List (java.util.List)4 SOAPMessage (javax.xml.soap.SOAPMessage)4 FSAccountMgmtException (com.sun.identity.federation.accountmgmt.FSAccountMgmtException)3