use of org.apereo.cas.util.crypto.PublicKeyFactoryBean in project cas by apereo.
the class RegisteredServicePublicKeyImpl method initializePublicKeyFactoryBean.
@JsonIgnore
private PublicKeyFactoryBean initializePublicKeyFactoryBean() throws Exception {
val resolved = SpringExpressionLanguageValueResolver.getInstance().resolve(this.location);
val resource = ResourceUtils.getResourceFrom(resolved);
val factory = new PublicKeyFactoryBean(resource, this.algorithm);
factory.setSingleton(false);
return factory;
}
use of org.apereo.cas.util.crypto.PublicKeyFactoryBean in project cas by apereo.
the class EncodingUtilsTests method getPublicKey.
@SneakyThrows
private static PublicKey getPublicKey() {
val factory = new PublicKeyFactoryBean(new ClassPathResource("keys/RSA2048Public.key"), RsaKeyUtil.RSA);
factory.setSingleton(false);
assertEquals(PublicKey.class, factory.getObjectType());
return factory.getObject();
}
use of org.apereo.cas.util.crypto.PublicKeyFactoryBean in project cas by apereo.
the class RegisteredServicePublicKeyImpl method createInstance.
@SneakyThrows
@Override
public PublicKey createInstance() {
final PublicKeyFactoryBean factory = this.publicKeyFactoryBeanClass.getDeclaredConstructor().newInstance();
if (this.location.startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) {
factory.setResource(new ClassPathResource(StringUtils.removeStart(this.location, ResourceUtils.CLASSPATH_URL_PREFIX)));
} else {
factory.setResource(new FileSystemResource(this.location));
}
factory.setAlgorithm(this.algorithm);
factory.setSingleton(false);
return factory.getObject();
}
use of org.apereo.cas.util.crypto.PublicKeyFactoryBean in project cas by apereo.
the class AbstractCipherExecutor method extractPublicKeyFromResource.
/**
* Extract public key from resource public key.
*
* @param secretKeyToUse the secret key to use
* @return the public key
*/
@SneakyThrows
public static PublicKey extractPublicKeyFromResource(final String secretKeyToUse) {
LOGGER.debug("Attempting to extract public key from [{}]...", secretKeyToUse);
val resource = ResourceUtils.getResourceFrom(secretKeyToUse);
val factory = new PublicKeyFactoryBean(resource, RsaKeyUtil.RSA);
factory.setSingleton(false);
return factory.getObject();
}
use of org.apereo.cas.util.crypto.PublicKeyFactoryBean in project cas by apereo.
the class GoogleAccountsServiceResponseBuilder method createGoogleAppsPublicKey.
/**
* Create the public key.
*
* @throws Exception if key creation ran into an error
*/
protected void createGoogleAppsPublicKey() throws Exception {
if (!isValidConfiguration()) {
LOGGER.debug("Google Apps public key bean will not be created, because it's not configured");
return;
}
var resource = (Resource) null;
if (this.publicKeyLocation.startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) {
resource = new ClassPathResource(StringUtils.removeStart(this.publicKeyLocation, ResourceUtils.CLASSPATH_URL_PREFIX));
} else if (this.publicKeyLocation.startsWith(ResourceUtils.FILE_URL_PREFIX)) {
resource = new FileSystemResource(StringUtils.removeStart(this.publicKeyLocation, ResourceUtils.FILE_URL_PREFIX));
} else {
resource = new FileSystemResource(this.publicKeyLocation);
}
val bean = new PublicKeyFactoryBean(resource, this.keyAlgorithm);
LOGGER.debug("Loading Google Apps public key from [{}] with key algorithm [{}]", bean.getResource(), bean.getAlgorithm());
bean.afterPropertiesSet();
LOGGER.debug("Creating Google Apps public key instance via [{}]", this.publicKeyLocation);
this.publicKey = bean.getObject();
}
Aggregations