use of org.opensaml.security.credential.BasicCredential in project cas by apereo.
the class SamlIdPObjectSigner method getResolvedSigningCredential.
private AbstractCredential getResolvedSigningCredential(final Credential c, final PrivateKey privateKey, final SamlRegisteredService service) {
final SamlIdPProperties samlIdp = casProperties.getAuthn().getSamlIdp();
try {
final SamlIdPResponseProperties.SignatureCredentialTypes credType = SamlIdPResponseProperties.SignatureCredentialTypes.valueOf(StringUtils.defaultIfBlank(service.getSigningCredentialType(), samlIdp.getResponse().getCredentialType().name()).toUpperCase());
LOGGER.debug("Requested credential type [{}] is found for service [{}]", credType, service);
switch(credType) {
case BASIC:
LOGGER.debug("Building basic credential signing key [{}] based on requested credential type", credType);
return new BasicCredential(c.getPublicKey(), privateKey);
case X509:
default:
if (c instanceof BasicX509Credential) {
final X509Certificate certificate = BasicX509Credential.class.cast(c).getEntityCertificate();
LOGGER.debug("Locating signature signing certificate from credential [{}]", CertUtils.toString(certificate));
return new BasicX509Credential(certificate, privateKey);
}
final Resource signingCert = samlIdPMetadataLocator.getSigningCertificate();
LOGGER.debug("Locating signature signing certificate file from [{}]", signingCert);
final X509Certificate certificate = SamlUtils.readCertificate(signingCert);
return new BasicX509Credential(certificate, privateKey);
}
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return null;
}
use of org.opensaml.security.credential.BasicCredential 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.security.credential.BasicCredential in project spring-security by spring-projects.
the class TestOpenSamlObjects method getSigningCredential.
static Credential getSigningCredential(Saml2X509Credential credential, String entityId) {
BasicCredential cred = getBasicCredential(credential);
cred.setEntityId(entityId);
cred.setUsageType(UsageType.SIGNING);
return cred;
}
use of org.opensaml.security.credential.BasicCredential in project spring-security by spring-projects.
the class OpenSamlSigningUtils method resolveSigningCredentials.
private static List<Credential> resolveSigningCredentials(RelyingPartyRegistration relyingPartyRegistration) {
List<Credential> credentials = new ArrayList<>();
for (Saml2X509Credential x509Credential : relyingPartyRegistration.getSigningX509Credentials()) {
X509Certificate certificate = x509Credential.getCertificate();
PrivateKey privateKey = x509Credential.getPrivateKey();
BasicCredential credential = CredentialSupport.getSimpleCredential(certificate, privateKey);
credential.setEntityId(relyingPartyRegistration.getEntityId());
credential.setUsageType(UsageType.SIGNING);
credentials.add(credential);
}
return credentials;
}
use of org.opensaml.security.credential.BasicCredential in project spring-security by spring-projects.
the class OpenSamlSigningUtils method resolveSigningCredentials.
private static List<Credential> resolveSigningCredentials(RelyingPartyRegistration relyingPartyRegistration) {
List<Credential> credentials = new ArrayList<>();
for (Saml2X509Credential x509Credential : relyingPartyRegistration.getSigningX509Credentials()) {
X509Certificate certificate = x509Credential.getCertificate();
PrivateKey privateKey = x509Credential.getPrivateKey();
BasicCredential credential = CredentialSupport.getSimpleCredential(certificate, privateKey);
credential.setEntityId(relyingPartyRegistration.getEntityId());
credential.setUsageType(UsageType.SIGNING);
credentials.add(credential);
}
return credentials;
}
Aggregations