Search in sources :

Example 6 with NameIDMappingRequest

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

the class NameIDMapping method getNameID.

private static NameID getNameID(NameIDMappingRequest nimRequest, String realm, String idpEntityID) {
    NameID nameID = nimRequest.getNameID();
    if (nameID == null) {
        EncryptedID encryptedID = nimRequest.getEncryptedID();
        try {
            final IDPSSOConfigElement idpSsoConfig = metaManager.getIDPSSOConfig(realm, idpEntityID);
            nameID = encryptedID.decrypt(KeyUtil.getDecryptionKeys(idpSsoConfig));
        } catch (SAML2Exception ex) {
            if (SAML2Utils.debug.messageEnabled()) {
                SAML2Utils.debug.message("NameIDMapping.getNameID:", ex);
            }
            return null;
        }
    }
    if (!SAML2Utils.isPersistentNameID(nameID)) {
        return null;
    }
    return nameID;
}
Also used : SAML2Exception(com.sun.identity.saml2.common.SAML2Exception) NameID(com.sun.identity.saml2.assertion.NameID) IDPSSOConfigElement(com.sun.identity.saml2.jaxb.entityconfig.IDPSSOConfigElement) EncryptedID(com.sun.identity.saml2.assertion.EncryptedID)

Example 7 with NameIDMappingRequest

use of com.sun.identity.saml2.protocol.NameIDMappingRequest 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)5 NameID (com.sun.identity.saml2.assertion.NameID)3 NameIDMappingRequest (com.sun.identity.saml2.protocol.NameIDMappingRequest)3 EncryptedID (com.sun.identity.saml2.assertion.EncryptedID)2 NameIDInfo (com.sun.identity.saml2.common.NameIDInfo)2 NameIDMappingResponse (com.sun.identity.saml2.protocol.NameIDMappingResponse)2 NameIDPolicy (com.sun.identity.saml2.protocol.NameIDPolicy)2 Date (java.util.Date)2 SessionException (com.sun.identity.plugin.session.SessionException)1 BaseConfigType (com.sun.identity.saml2.jaxb.entityconfig.BaseConfigType)1 IDPSSOConfigElement (com.sun.identity.saml2.jaxb.entityconfig.IDPSSOConfigElement)1 NameIDMappingServiceElement (com.sun.identity.saml2.jaxb.metadata.NameIDMappingServiceElement)1 SAML2MetaException (com.sun.identity.saml2.meta.SAML2MetaException)1 IDPAccountMapper (com.sun.identity.saml2.plugins.IDPAccountMapper)1 Status (com.sun.identity.saml2.protocol.Status)1 OutputStream (java.io.OutputStream)1 PrivateKey (java.security.PrivateKey)1 X509Certificate (java.security.cert.X509Certificate)1 SOAPException (javax.xml.soap.SOAPException)1 SOAPMessage (javax.xml.soap.SOAPMessage)1