本文整理汇总了Java中org.opensaml.saml2.core.EncryptedAssertion类的典型用法代码示例。如果您正苦于以下问题:Java EncryptedAssertion类的具体用法?Java EncryptedAssertion怎么用?Java EncryptedAssertion使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EncryptedAssertion类属于org.opensaml.saml2.core包,在下文中一共展示了EncryptedAssertion类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decryptAssertion
import org.opensaml.saml2.core.EncryptedAssertion; //导入依赖的package包/类
protected Assertion decryptAssertion(EncryptedAssertion encryptedAssertion, KeyStore.PrivateKeyEntry keystoreEntry) {
BasicX509Credential decryptionCredential = new BasicX509Credential();
decryptionCredential.setPrivateKey(keystoreEntry.getPrivateKey());
StaticKeyInfoCredentialResolver resolver = new StaticKeyInfoCredentialResolver(decryptionCredential);
ChainingEncryptedKeyResolver keyResolver = new ChainingEncryptedKeyResolver();
keyResolver.getResolverChain().add(new InlineEncryptedKeyResolver());
keyResolver.getResolverChain().add(new EncryptedElementTypeEncryptedKeyResolver());
keyResolver.getResolverChain().add(new SimpleRetrievalMethodEncryptedKeyResolver());
Decrypter decrypter = new Decrypter(null, resolver, keyResolver);
decrypter.setRootInNewDocument(true);
Assertion assertion = null;
try {
assertion = decrypter.decrypt(encryptedAssertion);
} catch (DecryptionException e) {
raiseSamlValidationError("Unable to decrypt SAML assertion", null);
}
return assertion;
}
示例2: processChildElement
import org.opensaml.saml2.core.EncryptedAssertion; //导入依赖的package包/类
/** {@inheritDoc} */
protected void processChildElement(XMLObject parentObject, XMLObject childObject) throws UnmarshallingException {
Evidence evidence = (Evidence) parentObject;
if (childObject instanceof AssertionIDRef) {
evidence.getAssertionIDReferences().add((AssertionIDRef) childObject);
} else if (childObject instanceof AssertionURIRef) {
evidence.getAssertionURIReferences().add((AssertionURIRef) childObject);
} else if (childObject instanceof Assertion) {
evidence.getAssertions().add((Assertion) childObject);
} else if (childObject instanceof EncryptedAssertion) {
evidence.getEncryptedAssertions().add((EncryptedAssertion) childObject);
} else {
super.processChildElement(parentObject, childObject);
}
}
示例3: processChildElement
import org.opensaml.saml2.core.EncryptedAssertion; //导入依赖的package包/类
@Override
protected void processChildElement(XMLObject parentXMLObject, XMLObject childXMLObject) throws UnmarshallingException
{
Token token = (Token) parentXMLObject;
if(childXMLObject instanceof Assertion)
{
token.setAssertion((Assertion)childXMLObject);
}
else if(childXMLObject instanceof EncryptedAssertion)
{
token.setEncryptedAssertion((EncryptedAssertion)childXMLObject);
}
else
{
token.getUnknownXMLObjects().add(childXMLObject);
}
}
示例4: encryptAssertion
import org.opensaml.saml2.core.EncryptedAssertion; //导入依赖的package包/类
private EncryptedAssertion encryptAssertion(boolean inline) throws NoSuchAlgorithmException, NoSuchProviderException, EncryptionException {
Credential symmetricCredential = SecurityTestHelper.generateKeyAndCredential(EncryptionConstants.ALGO_ID_BLOCKCIPHER_AES128);
assertNotNull(symmetricCredential.getSecretKey());
EncryptionParameters encParams = new EncryptionParameters();
encParams.setAlgorithm(EncryptionConstants.ALGO_ID_BLOCKCIPHER_AES128);
encParams.setEncryptionCredential(symmetricCredential);
KeyEncryptionParameters kek = new KeyEncryptionParameters();
kek.setAlgorithm(EncryptionConstants.ALGO_ID_KEYTRANSPORT_RSA15);
kek.setEncryptionCredential(this.credential);
Encrypter encrypter = new Encrypter(encParams, kek);
if (inline) {
encrypter.setKeyPlacement(KeyPlacement.INLINE);
} else {
encrypter.setKeyPlacement(KeyPlacement.PEER);
}
EncryptedAssertion encrypted = encrypter.encrypt(response.getAssertion().getAssertion());
return encrypted;
}
示例5: doEncryptedAssertion
import org.opensaml.saml2.core.EncryptedAssertion; //导入依赖的package包/类
@Override
public EncryptedAssertion doEncryptedAssertion(Assertion assertion, X509Credential cred, String alias, String encryptionAlgorithm) throws IdentityException {
try {
Credential symmetricCredential = SecurityHelper.getSimpleCredential(
SecurityHelper.generateSymmetricKey(EncryptionConstants.ALGO_ID_BLOCKCIPHER_AES256));
EncryptionParameters encParams = new EncryptionParameters();
encParams.setAlgorithm(EncryptionConstants.ALGO_ID_BLOCKCIPHER_AES256);
encParams.setEncryptionCredential(symmetricCredential);
KeyEncryptionParameters keyEncryptionParameters = new KeyEncryptionParameters();
keyEncryptionParameters.setAlgorithm(EncryptionConstants.ALGO_ID_KEYTRANSPORT_RSA15);
keyEncryptionParameters.setEncryptionCredential(cred);
Encrypter encrypter = new Encrypter(encParams, keyEncryptionParameters);
encrypter.setKeyPlacement(Encrypter.KeyPlacement.INLINE);
EncryptedAssertion encrypted = encrypter.encrypt(assertion);
return encrypted;
} catch (Exception e) {
throw IdentityException.error("Error while Encrypting Assertion", e);
}
}
示例6: testEncryptedAssertion
import org.opensaml.saml2.core.EncryptedAssertion; //导入依赖的package包/类
/**
* Test decryption of an EncryptedAssertion.
*
* @throws XMLParserException thrown if there is an error parsing the control XML file
* @throws EncryptionException thrown if there is an error encrypting the control XML
*/
public void testEncryptedAssertion() throws XMLParserException, EncryptionException {
String filename = "/data/org/opensaml/saml2/encryption/Assertion.xml";
Document targetDOM = getDOM(filename);
Assertion target = (Assertion) unmarshallElement(filename);
EncryptedAssertion encryptedTarget = encrypter.encrypt(target);
Decrypter decrypter = new Decrypter(keyResolver, null, null);
SAMLObject decryptedTarget = null;
try {
decryptedTarget = decrypter.decrypt(encryptedTarget);
} catch (DecryptionException e) {
fail("Error on decryption of encrypted SAML 2 type to element: " + e);
}
assertNotNull("Decrypted target was null", decryptedTarget);
assertTrue("Decrypted target was not the expected type", decryptedTarget instanceof Assertion);
assertEquals(targetDOM, decryptedTarget);
}
示例7: testErrorInvalidDataDecryptionKey
import org.opensaml.saml2.core.EncryptedAssertion; //导入依赖的package包/类
/**
* Test error condition of invalid data decryption key.
* @throws EncryptionException
*
* @throws XMLParserException thrown if there is an error parsing the control XML file
* @throws EncryptionException thrown if there is an error encrypting the control XML
* @throws NoSuchProviderException security provider was invalid
* @throws NoSuchAlgorithmException security/key algorithm was invalid
*/
public void testErrorInvalidDataDecryptionKey()
throws XMLParserException, EncryptionException, NoSuchAlgorithmException, NoSuchProviderException {
Key badKey = SecurityTestHelper.generateKeyFromURI(encURI);
BasicCredential encCred = new BasicCredential();
encCred.setSecretKey((SecretKey) badKey);
KeyInfoCredentialResolver badEncResolver = new StaticKeyInfoCredentialResolver(encCred);
String filename = "/data/org/opensaml/saml2/encryption/Assertion.xml";
Assertion target = (Assertion) unmarshallElement(filename);
EncryptedAssertion encryptedTarget = encrypter.encrypt(target);
Decrypter decrypter = new Decrypter(badEncResolver, null, null);
SAMLObject decryptedTarget = null;
try {
decryptedTarget = decrypter.decrypt(encryptedTarget);
fail("Decryption should have failed due to bad decryption key");
} catch (DecryptionException e) {
// do nothing, should faile
}
}
示例8: testAutoKeyGen
import org.opensaml.saml2.core.EncryptedAssertion; //导入依赖的package包/类
/** Test that a data encryption key is auto-generated if it is not supplied. */
public void testAutoKeyGen() {
Assertion target = (Assertion) unmarshallElement("/data/org/opensaml/saml2/encryption/Assertion.xml");
encParams.setEncryptionCredential(null);
kekParamsList.add(kekParamsRSA);
encrypter = new Encrypter(encParams, kekParamsList);
XMLObject encObject = null;
try {
encObject = encrypter.encrypt(target);
} catch (EncryptionException e) {
fail("Object encryption failed: " + e);
}
assertNotNull("Encrypted object was null", encObject);
assertTrue("Encrypted object was not an instance of the expected type",
encObject instanceof EncryptedAssertion);
}
示例9: testSingleEKNoRecipients
import org.opensaml.saml2.core.EncryptedAssertion; //导入依赖的package包/类
/** No recipients specified to resolver, one EncryptedKey in instance. */
public void testSingleEKNoRecipients() {
String filename =
"/data/org/opensaml/saml2/encryption/EncryptedElementTypeEncryptedKeyResolverSingleNoRecipient.xml";
EncryptedAssertion encAssertion = (EncryptedAssertion) unmarshallElement(filename);
assertNotNull(encAssertion.getEncryptedData());
EncryptedData encData = encAssertion.getEncryptedData();
List<EncryptedKey> allKeys = encAssertion.getEncryptedKeys();
assertFalse(allKeys.isEmpty());
resolver.getRecipients().clear();
List<EncryptedKey> resolved = generateList(encData, resolver);
assertEquals("Incorrect number of resolved EncryptedKeys found", 1, resolved.size());
assertTrue("Unexpected EncryptedKey instance found", resolved.get(0) == allKeys.get(0));
}
示例10: testSingleEKMultiRecipientWithImplicitMatch
import org.opensaml.saml2.core.EncryptedAssertion; //导入依赖的package包/类
/** Multiple recipients specified to resolver, one EncryptedKey in instance with no recipient. */
public void testSingleEKMultiRecipientWithImplicitMatch() {
String filename =
"/data/org/opensaml/saml2/encryption/EncryptedElementTypeEncryptedKeyResolverSingleNoRecipient.xml";
EncryptedAssertion encAssertion = (EncryptedAssertion) unmarshallElement(filename);
assertNotNull(encAssertion.getEncryptedData());
EncryptedData encData = encAssertion.getEncryptedData();
List<EncryptedKey> allKeys = encAssertion.getEncryptedKeys();
assertFalse(allKeys.isEmpty());
resolver.getRecipients().add("foo");
resolver.getRecipients().add("bar");
resolver.getRecipients().add("baz");
List<EncryptedKey> resolved = generateList(encData, resolver);
assertEquals("Incorrect number of resolved EncryptedKeys found", 1, resolved.size());
assertTrue("Unexpected EncryptedKey instance found", resolved.get(0) == allKeys.get(0));
}
示例11: testSingleEKOneRecipientWithMatch
import org.opensaml.saml2.core.EncryptedAssertion; //导入依赖的package包/类
/** One recipient specified to resolver, one matching EncryptedKey in instance. */
public void testSingleEKOneRecipientWithMatch() {
String filename =
"/data/org/opensaml/saml2/encryption/EncryptedElementTypeEncryptedKeyResolverSingleWithRecipient.xml";
EncryptedAssertion encAssertion = (EncryptedAssertion) unmarshallElement(filename);
assertNotNull(encAssertion.getEncryptedData());
EncryptedData encData = encAssertion.getEncryptedData();
List<EncryptedKey> allKeys = encAssertion.getEncryptedKeys();
assertFalse(allKeys.isEmpty());
resolver.getRecipients().add("foo");
List<EncryptedKey> resolved = generateList(encData, resolver);
assertEquals("Incorrect number of resolved EncryptedKeys found", 1, resolved.size());
assertTrue("Unexpected EncryptedKey instance found", resolved.get(0) == allKeys.get(0));
}
示例12: testSingleEKOneRecipientNoMatch
import org.opensaml.saml2.core.EncryptedAssertion; //导入依赖的package包/类
/** One recipient specified to resolver, zero matching EncryptedKey in instance. */
public void testSingleEKOneRecipientNoMatch() {
String filename =
"/data/org/opensaml/saml2/encryption/EncryptedElementTypeEncryptedKeyResolverSingleWithRecipient.xml";
EncryptedAssertion encAssertion = (EncryptedAssertion) unmarshallElement(filename);
assertNotNull(encAssertion.getEncryptedData());
EncryptedData encData = encAssertion.getEncryptedData();
List<EncryptedKey> allKeys = encAssertion.getEncryptedKeys();
assertFalse(allKeys.isEmpty());
resolver.getRecipients().add("bar");
List<EncryptedKey> resolved = generateList(encData, resolver);
assertEquals("Incorrect number of resolved EncryptedKeys found", 0, resolved.size());
}
示例13: testMultiEKNoRecipients
import org.opensaml.saml2.core.EncryptedAssertion; //导入依赖的package包/类
/** No recipients specified to resolver. */
public void testMultiEKNoRecipients() {
String filename = "/data/org/opensaml/saml2/encryption/EncryptedElementTypeEncryptedKeyResolverMultiple.xml";
EncryptedAssertion encAssertion = (EncryptedAssertion) unmarshallElement(filename);
assertNotNull(encAssertion.getEncryptedData());
EncryptedData encData = encAssertion.getEncryptedData();
List<EncryptedKey> allKeys = encAssertion.getEncryptedKeys();
assertFalse(allKeys.isEmpty());
resolver.getRecipients().clear();
List<EncryptedKey> resolved = generateList(encData, resolver);
assertEquals("Incorrect number of resolved EncryptedKeys found", 4, resolved.size());
assertTrue("Unexpected EncryptedKey instance found", resolved.get(0) == allKeys.get(0));
assertTrue("Unexpected EncryptedKey instance found", resolved.get(1) == allKeys.get(1));
assertTrue("Unexpected EncryptedKey instance found", resolved.get(2) == allKeys.get(2));
assertTrue("Unexpected EncryptedKey instance found", resolved.get(3) == allKeys.get(3));
}
示例14: testMultiEKOneRecipientWithMatch
import org.opensaml.saml2.core.EncryptedAssertion; //导入依赖的package包/类
/** One recipient specified to resolver, one matching & and one recipient-less
* EncryptedKey in instance. */
public void testMultiEKOneRecipientWithMatch() {
String filename = "/data/org/opensaml/saml2/encryption/EncryptedElementTypeEncryptedKeyResolverMultiple.xml";
EncryptedAssertion encAssertion = (EncryptedAssertion) unmarshallElement(filename);
assertNotNull(encAssertion.getEncryptedData());
EncryptedData encData = encAssertion.getEncryptedData();
List<EncryptedKey> allKeys = encAssertion.getEncryptedKeys();
assertFalse(allKeys.isEmpty());
resolver.getRecipients().clear();
resolver.getRecipients().add("foo");
List<EncryptedKey> resolved = generateList(encData, resolver);
assertEquals("Incorrect number of resolved EncryptedKeys found", 2, resolved.size());
assertTrue("Unexpected EncryptedKey instance found", resolved.get(0) == allKeys.get(0));
assertTrue("Unexpected EncryptedKey instance found", resolved.get(1) == allKeys.get(2));
}
示例15: testMultiEKOneRecipientWithMatches
import org.opensaml.saml2.core.EncryptedAssertion; //导入依赖的package包/类
/** Multi recipient specified to resolver, several matching EncryptedKey in instance. */
public void testMultiEKOneRecipientWithMatches() {
String filename = "/data/org/opensaml/saml2/encryption/EncryptedElementTypeEncryptedKeyResolverMultiple.xml";
EncryptedAssertion encAssertion = (EncryptedAssertion) unmarshallElement(filename);
assertNotNull(encAssertion.getEncryptedData());
EncryptedData encData = encAssertion.getEncryptedData();
List<EncryptedKey> allKeys = encAssertion.getEncryptedKeys();
assertFalse(allKeys.isEmpty());
resolver.getRecipients().add("foo");
resolver.getRecipients().add("baz");
List<EncryptedKey> resolved = generateList(encData, resolver);
assertEquals("Incorrect number of resolved EncryptedKeys found", 3, resolved.size());
assertTrue("Unexpected EncryptedKey instance found", resolved.get(0) == allKeys.get(0));
assertTrue("Unexpected EncryptedKey instance found", resolved.get(1) == allKeys.get(2));
assertTrue("Unexpected EncryptedKey instance found", resolved.get(2) == allKeys.get(3));
}