Search in sources :

Example 6 with NameIDMappingResponse

use of com.sun.identity.saml2.protocol.NameIDMappingResponse in project OpenAM by OpenRock.

the class NameIDMappingServiceSOAP method doPost.

public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    try {
        // handle DOS attack
        SAMLUtils.checkHTTPContentLength(req);
        // Get IDP entity ID
        String idpMetaAlias = SAML2MetaUtils.getMetaAliasByUri(req.getRequestURI());
        String idpEntityID = SAML2Utils.getSAML2MetaManager().getEntityByMetaAlias(idpMetaAlias);
        String realm = SAML2MetaUtils.getRealmByMetaAlias(idpMetaAlias);
        if (!SAML2Utils.isIDPProfileBindingSupported(realm, idpEntityID, SAML2Constants.NAMEID_MAPPING_SERVICE, SAML2Constants.SOAP)) {
            throw new SAML2Exception(SAML2Utils.bundle.getString("unsuppoprtedBinding"));
        }
        if (SAML2Utils.debug.messageEnabled()) {
            SAML2Utils.debug.message("NameIDMappingServiceSOAP.doPost : " + "uri = " + req.getRequestURI() + ", idpMetaAlias = " + idpMetaAlias + ", idpEntityID = " + idpEntityID);
        }
        SOAPMessage msg = SOAPCommunicator.getInstance().getSOAPMessage(req);
        Element reqElem = SOAPCommunicator.getInstance().getSamlpElement(msg, SAML2Constants.NAME_ID_MAPPING_REQUEST);
        NameIDMappingRequest nimRequest = ProtocolFactory.getInstance().createNameIDMappingRequest(reqElem);
        NameIDMappingResponse nimResponse = NameIDMapping.processNameIDMappingRequest(nimRequest, realm, idpEntityID);
        SOAPMessage reply = SOAPCommunicator.getInstance().createSOAPMessage(nimResponse.toXMLString(true, true), false);
        if (reply != null) {
            if (reply.saveRequired()) {
                reply.saveChanges();
            }
            resp.setStatus(HttpServletResponse.SC_OK);
            SAML2Utils.putHeaders(reply.getMimeHeaders(), resp);
            OutputStream os = resp.getOutputStream();
            reply.writeTo(os);
            os.flush();
        }
    } catch (SAML2Exception ex) {
        SAML2Utils.debug.error("NameIDMappingServiceSOAP", ex);
        SAMLUtils.sendError(req, resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "nameIDMappingFailed", ex.getMessage());
        return;
    } catch (SOAPException soap) {
        SAML2Utils.debug.error("NameIDMappingServiceSOAP", soap);
        SAMLUtils.sendError(req, resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "nameIDMappingFailed", soap.getMessage());
        return;
    }
}
Also used : SAML2Exception(com.sun.identity.saml2.common.SAML2Exception) NameIDMappingResponse(com.sun.identity.saml2.protocol.NameIDMappingResponse) Element(org.w3c.dom.Element) OutputStream(java.io.OutputStream) SOAPException(javax.xml.soap.SOAPException) SOAPMessage(javax.xml.soap.SOAPMessage) NameIDMappingRequest(com.sun.identity.saml2.protocol.NameIDMappingRequest)

Aggregations

SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)6 NameIDMappingResponse (com.sun.identity.saml2.protocol.NameIDMappingResponse)3 IDPSSODescriptorElement (com.sun.identity.saml2.jaxb.metadata.IDPSSODescriptorElement)2 NameIDMappingServiceElement (com.sun.identity.saml2.jaxb.metadata.NameIDMappingServiceElement)2 NameIDMappingRequest (com.sun.identity.saml2.protocol.NameIDMappingRequest)2 X509Certificate (java.security.cert.X509Certificate)2 SOAPException (javax.xml.soap.SOAPException)2 SOAPMessage (javax.xml.soap.SOAPMessage)2 Element (org.w3c.dom.Element)2 SessionException (com.sun.identity.plugin.session.SessionException)1 Issuer (com.sun.identity.saml2.assertion.Issuer)1 NameID (com.sun.identity.saml2.assertion.NameID)1 NameIDInfo (com.sun.identity.saml2.common.NameIDInfo)1 BaseConfigType (com.sun.identity.saml2.jaxb.entityconfig.BaseConfigType)1 IDPSSOConfigElement (com.sun.identity.saml2.jaxb.entityconfig.IDPSSOConfigElement)1 SPSSODescriptorElement (com.sun.identity.saml2.jaxb.metadata.SPSSODescriptorElement)1 SAML2MetaException (com.sun.identity.saml2.meta.SAML2MetaException)1 IDPAccountMapper (com.sun.identity.saml2.plugins.IDPAccountMapper)1 NameIDPolicy (com.sun.identity.saml2.protocol.NameIDPolicy)1 Status (com.sun.identity.saml2.protocol.Status)1