use of org.opensaml.xmlsec.encryption.support.DataEncryptionParameters in project cas by apereo.
the class SamlObjectEncrypter method getDataEncryptionParameters.
/**
* Gets data encryption parameters.
*
* @param samlObject the saml object
* @param service the service
* @param adaptor the adaptor
* @return the data encryption parameters
*/
protected DataEncryptionParameters getDataEncryptionParameters(final Assertion samlObject, final SamlRegisteredService service, final SamlRegisteredServiceServiceProviderMetadataFacade adaptor) {
final DataEncryptionParameters dataEncParams = new DataEncryptionParameters();
dataEncParams.setAlgorithm(EncryptionConstants.ALGO_ID_BLOCKCIPHER_AES128);
return dataEncParams;
}
use of org.opensaml.xmlsec.encryption.support.DataEncryptionParameters in project spring-security by spring-projects.
the class TestOpenSamlObjects method getEncrypter.
private static Encrypter getEncrypter(X509Certificate certificate) {
String dataAlgorithm = XMLCipherParameters.AES_256;
String keyAlgorithm = XMLCipherParameters.RSA_1_5;
BasicCredential dataCredential = new BasicCredential(SECRET_KEY);
DataEncryptionParameters dataEncryptionParameters = new DataEncryptionParameters();
dataEncryptionParameters.setEncryptionCredential(dataCredential);
dataEncryptionParameters.setAlgorithm(dataAlgorithm);
Credential credential = CredentialSupport.getSimpleCredential(certificate, null);
KeyEncryptionParameters keyEncryptionParameters = new KeyEncryptionParameters();
keyEncryptionParameters.setEncryptionCredential(credential);
keyEncryptionParameters.setAlgorithm(keyAlgorithm);
Encrypter encrypter = new Encrypter(dataEncryptionParameters, keyEncryptionParameters);
Encrypter.KeyPlacement keyPlacement = Encrypter.KeyPlacement.valueOf("PEER");
encrypter.setKeyPlacement(keyPlacement);
return encrypter;
}
use of org.opensaml.xmlsec.encryption.support.DataEncryptionParameters in project cas by apereo.
the class SamlObjectEncrypter method encode.
/**
* Encode a given saml object by invoking a number of outbound security handlers on the context.
*
* @param samlObject the saml object
* @param service the service
* @param adaptor the adaptor
* @param response the response
* @param request the request
* @return the t
* @throws SamlException the saml exception
*/
@SneakyThrows
public EncryptedAssertion encode(final Assertion samlObject, final SamlRegisteredService service, final SamlRegisteredServiceServiceProviderMetadataFacade adaptor, final HttpServletResponse response, final HttpServletRequest request) throws SamlException {
final String className = samlObject.getClass().getName();
final String entityId = adaptor.getEntityId();
LOGGER.debug("Attempting to encrypt [{}] for [{}]", className, entityId);
final Credential credential = getKeyEncryptionCredential(entityId, adaptor, service);
LOGGER.info("Found encryption public key: [{}]", EncodingUtils.encodeBase64(credential.getPublicKey().getEncoded()));
final KeyEncryptionParameters keyEncParams = getKeyEncryptionParameters(samlObject, service, adaptor, credential);
LOGGER.debug("Key encryption algorithm for [{}] is [{}]", keyEncParams.getRecipient(), keyEncParams.getAlgorithm());
final DataEncryptionParameters dataEncParams = getDataEncryptionParameters(samlObject, service, adaptor);
LOGGER.debug("Data encryption algorithm for [{}] is [{}]", entityId, dataEncParams.getAlgorithm());
final Encrypter encrypter = getEncrypter(samlObject, service, adaptor, keyEncParams, dataEncParams);
LOGGER.debug("Attempting to encrypt [{}] for [{}] with key placement of [{}]", className, entityId, encrypter.getKeyPlacement());
return encrypter.encrypt(samlObject);
}
use of org.opensaml.xmlsec.encryption.support.DataEncryptionParameters in project cas by apereo.
the class SamlIdPObjectEncrypter method getDataEncryptionParameters.
/**
* Gets data encryption parameters.
*
* @param samlObject the saml object
* @param service the service
* @param adaptor the adaptor
* @param encryptionConfiguration the encryption configuration
* @return the data encryption parameters
*/
protected DataEncryptionParameters getDataEncryptionParameters(final Object samlObject, final SamlRegisteredService service, final SamlRegisteredServiceServiceProviderMetadataFacade adaptor, final BasicEncryptionConfiguration encryptionConfiguration) {
try {
val params = resolveEncryptionParameters(service, encryptionConfiguration);
if (params != null) {
return new DataEncryptionParameters(params);
}
LOGGER.debug("No data encryption parameters could be determined");
return null;
} catch (final Exception e) {
throw new SamlException(e.getMessage(), e);
}
}
Aggregations