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);
}
}
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);
}
}
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);
}
}
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);
}
}
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;
}
Aggregations