Search in sources :

Example 1 with Encrypter

use of org.opensaml.saml.saml2.encryption.Encrypter 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
     */
public EncryptedAssertion encode(final Assertion samlObject, final SamlRegisteredService service, final SamlRegisteredServiceServiceProviderMetadataFacade adaptor, final HttpServletResponse response, final HttpServletRequest request) throws SamlException {
    try {
        LOGGER.debug("Attempting to encrypt [{}] for [{}]", samlObject.getClass().getName(), adaptor.getEntityId());
        final Credential credential = getKeyEncryptionCredential(adaptor.getEntityId(), 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 [{}]", adaptor.getEntityId(), dataEncParams.getAlgorithm());
        final Encrypter encrypter = getEncrypter(samlObject, service, adaptor, keyEncParams, dataEncParams);
        LOGGER.debug("Attempting to encrypt [{}] for [{}] with key placement of [{}]", samlObject.getClass().getName(), adaptor.getEntityId(), encrypter.getKeyPlacement());
        return encrypter.encrypt(samlObject);
    } catch (final Exception e) {
        throw new SamlException(e.getMessage(), e);
    }
}
Also used : Encrypter(org.opensaml.saml.saml2.encryption.Encrypter) KeyEncryptionParameters(org.opensaml.xmlsec.encryption.support.KeyEncryptionParameters) Credential(org.opensaml.security.credential.Credential) SamlException(org.apereo.cas.support.saml.SamlException) DataEncryptionParameters(org.opensaml.xmlsec.encryption.support.DataEncryptionParameters) SamlException(org.apereo.cas.support.saml.SamlException)

Example 2 with Encrypter

use of org.opensaml.saml.saml2.encryption.Encrypter in project cas by apereo.

the class SamlObjectEncrypter method getEncrypter.

/**
     * Gets encrypter.
     *
     * @param samlObject    the saml object
     * @param service       the service
     * @param adaptor       the adaptor
     * @param keyEncParams  the key enc params
     * @param dataEncParams the data enc params
     * @return the encrypter
     */
protected Encrypter getEncrypter(final Assertion samlObject, final SamlRegisteredService service, final SamlRegisteredServiceServiceProviderMetadataFacade adaptor, final KeyEncryptionParameters keyEncParams, final DataEncryptionParameters dataEncParams) {
    final Encrypter encrypter = new Encrypter(dataEncParams, keyEncParams);
    encrypter.setKeyPlacement(Encrypter.KeyPlacement.PEER);
    return encrypter;
}
Also used : Encrypter(org.opensaml.saml.saml2.encryption.Encrypter)

Aggregations

Encrypter (org.opensaml.saml.saml2.encryption.Encrypter)2 SamlException (org.apereo.cas.support.saml.SamlException)1 Credential (org.opensaml.security.credential.Credential)1 DataEncryptionParameters (org.opensaml.xmlsec.encryption.support.DataEncryptionParameters)1 KeyEncryptionParameters (org.opensaml.xmlsec.encryption.support.KeyEncryptionParameters)1