Search in sources :

Example 31 with SAMLException

use of com.sun.identity.saml.common.SAMLException in project OpenAM by OpenRock.

the class EncryptedNameIdentifier method getDecryptedNameIdentifier.

/**
     * Gets the decrypted NameIdentifier. 
     * @param encNI EncryptedNameIdentifier. 
     * @param decKey decryption key.
     * 
     * @return NameIdentifier Decrypted NameIdentifier.
     * @exception FSException for failures
     */
public static NameIdentifier getDecryptedNameIdentifier(NameIdentifier encNI, PrivateKey decKey) throws FSException {
    if (encNI.getFormat() == null || !encNI.getFormat().equals(IFSConstants.NI_ENCRYPTED_FORMAT_URI)) {
        throw new FSException("notValidFormat", null);
    }
    String name = encNI.getName();
    name = FSUtils.removeNewLineChars(name);
    String decodeStr = SAMLUtils.byteArrayToString(Base64.decode(name));
    Document encryptedDoc = XMLUtils.toDOMDocument(decodeStr, FSUtils.debug);
    try {
        XMLEncryptionManager manager = XMLEncryptionManager.getInstance();
        Document doc = manager.decryptAndReplace(encryptedDoc, decKey);
        Element element = (Element) doc.getElementsByTagNameNS(IFSConstants.FF_12_XML_NS, "EncryptableNameIdentifier").item(0);
        EncryptableNameIdentifier eni = new EncryptableNameIdentifier(element);
        return new NameIdentifier(eni.getName(), eni.getNameQualifier(), eni.getFormat());
    } catch (EncryptionException ee) {
        FSUtils.debug.error("EncryptedNameIdentifier.getDecryptedName" + "Identifier: Decryption exception", ee);
        throw new FSException(ee);
    } catch (SAMLException se) {
        throw new FSException(se);
    }
}
Also used : NameIdentifier(com.sun.identity.saml.assertion.NameIdentifier) Element(org.w3c.dom.Element) FSException(com.sun.identity.federation.common.FSException) EncryptionException(com.sun.identity.xmlenc.EncryptionException) XMLEncryptionManager(com.sun.identity.xmlenc.XMLEncryptionManager) Document(org.w3c.dom.Document) SAMLException(com.sun.identity.saml.common.SAMLException)

Example 32 with SAMLException

use of com.sun.identity.saml.common.SAMLException in project OpenAM by OpenRock.

the class FSFederationTerminationNotification method signXML.

/**
     * Signs the <code>FSFederationTerminationNotification</code>.
     * object
     *
     * @param certAlias the Certificate Alias
     * @throws SAMLException if
     *         <code>FSFederationTerminationNotification</code>
     *         cannot be signed.
     */
public void signXML(String certAlias) throws SAMLException {
    FSUtils.debug.message("FSFederationTerminationNotification.signXML: Called");
    if (signed) {
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSFederationTerminationNotification.signXML: " + "the assertion is already signed.");
        }
        throw new SAMLResponderException(FSUtils.BUNDLE_NAME, "alreadySigned", null);
    }
    if (certAlias == null || certAlias.length() == 0) {
        throw new SAMLResponderException(FSUtils.BUNDLE_NAME, "cannotFindCertAlias", null);
    }
    try {
        XMLSignatureManager manager = XMLSignatureManager.getInstance();
        if (minorVersion == IFSConstants.FF_11_PROTOCOL_MINOR_VERSION) {
            signatureString = manager.signXML(this.toXMLString(true, true), certAlias, (String) null, IFSConstants.ID, this.id, false);
        } else if (minorVersion == IFSConstants.FF_12_PROTOCOL_MINOR_VERSION) {
            signatureString = manager.signXML(this.toXMLString(true, true), certAlias, (String) null, IFSConstants.REQUEST_ID, this.getRequestID(), false);
        } else {
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("invalid minor version.");
            }
        }
        signature = XMLUtils.toDOMDocument(signatureString, FSUtils.debug).getDocumentElement();
        signed = true;
        xmlString = this.toXMLString(true, true);
    } catch (Exception e) {
        throw new SAMLResponderException(FSUtils.BUNDLE_NAME, "signFailed", null);
    }
}
Also used : XMLSignatureManager(com.sun.identity.saml.xmlsig.XMLSignatureManager) SAMLResponderException(com.sun.identity.saml.common.SAMLResponderException) SAMLException(com.sun.identity.saml.common.SAMLException) ParseException(java.text.ParseException) FSMsgException(com.sun.identity.federation.message.common.FSMsgException) SAMLResponderException(com.sun.identity.saml.common.SAMLResponderException)

Example 33 with SAMLException

use of com.sun.identity.saml.common.SAMLException in project OpenAM by OpenRock.

the class EncryptedNameIdentifier method getEncryptedNameIdentifier.

/**
     * Gets then Encrypted NameIdentifier for a given name identifier 
     * and the provider ID.
     * @param ni NameIdentifier.
     * @param providerID Remote Provider ID.
     * @param enckey Key Encryption Key
     * @param dataEncAlgorithm Data encryption algorithm
     * @param dataEncStrength Data encryption key size
     *
     * @return NameIdentifier EncryptedNameIdentifier. 
     * @exception FSException for failure.
     */
public static NameIdentifier getEncryptedNameIdentifier(NameIdentifier ni, String providerID, Key enckey, String dataEncAlgorithm, int dataEncStrength) throws FSException {
    if (ni == null || providerID == null) {
        FSUtils.debug.error("EncryptedNameIdentifier.construct: " + "nullInputParameter");
        throw new FSException("nullInputParameter", null);
    }
    EncryptableNameIdentifier eni = new EncryptableNameIdentifier(ni);
    Document encryptableDoc = getEncryptableDocument(eni);
    Document encryptedDoc = null;
    try {
        Element encryptElement = (Element) encryptableDoc.getElementsByTagNameNS(IFSConstants.FF_12_XML_NS, "EncryptableNameIdentifier").item(0);
        XMLEncryptionManager manager = XMLEncryptionManager.getInstance();
        encryptedDoc = manager.encryptAndReplace(encryptableDoc, encryptElement, dataEncAlgorithm, dataEncStrength, enckey, // TODO: should we pick it up from extended meta?
        0, providerID);
    } catch (EncryptionException ee) {
        FSUtils.debug.error("EncryptedNameIdentifier.construct: Unable" + "to encrypt the xml doc", ee);
        throw new FSException(ee);
    }
    if (encryptedDoc == null) {
        throw new FSException("EncryptionFailed", null);
    }
    String encodedStr = Base64.encode(SAMLUtils.stringToByteArray(XMLUtils.print((Node) (encryptedDoc))));
    try {
        return new NameIdentifier(encodedStr, ni.getNameQualifier(), IFSConstants.NI_ENCRYPTED_FORMAT_URI);
    } catch (SAMLException se) {
        throw new FSException(se);
    }
}
Also used : NameIdentifier(com.sun.identity.saml.assertion.NameIdentifier) Element(org.w3c.dom.Element) FSException(com.sun.identity.federation.common.FSException) EncryptionException(com.sun.identity.xmlenc.EncryptionException) XMLEncryptionManager(com.sun.identity.xmlenc.XMLEncryptionManager) Document(org.w3c.dom.Document) SAMLException(com.sun.identity.saml.common.SAMLException)

Example 34 with SAMLException

use of com.sun.identity.saml.common.SAMLException in project OpenAM by OpenRock.

the class FSLogoutResponse method signXML.

/**
     * Signs the <code>LogoutResponse</code>.
     *
     * @param certAlias the Certificate Alias.
     * @throws XMLSignatureException if this object cannot be signed.
     */
public void signXML(String certAlias) throws SAMLException {
    FSUtils.debug.message("FSLogoutResponse.signXML: Called");
    if (signed) {
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSLogoutResponse.signXML: " + "the assertion is already signed.");
        }
        throw new SAMLResponderException(FSUtils.BUNDLE_NAME, "alreadySigned", null);
    }
    if (certAlias == null || certAlias.length() == 0) {
        throw new SAMLResponderException(FSUtils.BUNDLE_NAME, "cannotFindCertAlias", null);
    }
    try {
        XMLSignatureManager manager = XMLSignatureManager.getInstance();
        if (minorVersion == IFSConstants.FF_11_PROTOCOL_MINOR_VERSION) {
            signatureString = manager.signXML(this.toXMLString(true, true), certAlias, IFSConstants.DEF_SIG_ALGO, IFSConstants.ID, this.id, false);
        } else if (minorVersion == IFSConstants.FF_12_PROTOCOL_MINOR_VERSION) {
            signatureString = manager.signXML(this.toXMLString(true, true), certAlias, IFSConstants.DEF_SIG_ALGO, IFSConstants.RESPONSE_ID, this.getResponseID(), false);
        } else {
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("invalid minor version.");
            }
        }
        signature = XMLUtils.toDOMDocument(signatureString, FSUtils.debug).getDocumentElement();
        signed = true;
        xmlString = this.toXMLString(true, true);
    } catch (Exception e) {
        throw new SAMLResponderException(FSUtils.BUNDLE_NAME, "signFailed", null);
    }
}
Also used : XMLSignatureManager(com.sun.identity.saml.xmlsig.XMLSignatureManager) SAMLResponderException(com.sun.identity.saml.common.SAMLResponderException) IOException(java.io.IOException) SAMLVersionMismatchException(com.sun.identity.saml.common.SAMLVersionMismatchException) SAMLException(com.sun.identity.saml.common.SAMLException) FSMsgException(com.sun.identity.federation.message.common.FSMsgException) ParseException(java.text.ParseException) SAMLResponderException(com.sun.identity.saml.common.SAMLResponderException)

Example 35 with SAMLException

use of com.sun.identity.saml.common.SAMLException 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;
}
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)

Aggregations

SAMLException (com.sun.identity.saml.common.SAMLException)86 SessionException (com.sun.identity.plugin.session.SessionException)30 FSMsgException (com.sun.identity.federation.message.common.FSMsgException)26 List (java.util.List)23 SAMLResponderException (com.sun.identity.saml.common.SAMLResponderException)19 ArrayList (java.util.ArrayList)19 FSException (com.sun.identity.federation.common.FSException)17 IDFFMetaException (com.sun.identity.federation.meta.IDFFMetaException)17 Iterator (java.util.Iterator)17 XMLSignatureManager (com.sun.identity.saml.xmlsig.XMLSignatureManager)16 SessionProvider (com.sun.identity.plugin.session.SessionProvider)15 Assertion (com.sun.identity.saml.assertion.Assertion)15 Set (java.util.Set)15 Attribute (com.sun.identity.saml.assertion.Attribute)13 Element (org.w3c.dom.Element)13 ParseException (java.text.ParseException)12 Map (java.util.Map)12 Status (com.sun.identity.saml.protocol.Status)11 Document (org.w3c.dom.Document)11 BaseConfigType (com.sun.identity.federation.jaxb.entityconfig.BaseConfigType)10