Search in sources :

Example 1 with PublicKeyFactoryBean

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;
}
Also used : lombok.val(lombok.val) PublicKeyFactoryBean(org.apereo.cas.util.crypto.PublicKeyFactoryBean) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore)

Example 2 with PublicKeyFactoryBean

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();
}
Also used : lombok.val(lombok.val) PublicKeyFactoryBean(org.apereo.cas.util.crypto.PublicKeyFactoryBean) ClassPathResource(org.springframework.core.io.ClassPathResource) SneakyThrows(lombok.SneakyThrows)

Example 3 with PublicKeyFactoryBean

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();
}
Also used : PublicKeyFactoryBean(org.apereo.cas.util.crypto.PublicKeyFactoryBean) FileSystemResource(org.springframework.core.io.FileSystemResource) ClassPathResource(org.springframework.core.io.ClassPathResource) SneakyThrows(lombok.SneakyThrows)

Example 4 with PublicKeyFactoryBean

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();
}
Also used : lombok.val(lombok.val) PublicKeyFactoryBean(org.apereo.cas.util.crypto.PublicKeyFactoryBean) SneakyThrows(lombok.SneakyThrows)

Example 5 with PublicKeyFactoryBean

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();
}
Also used : lombok.val(lombok.val) PublicKeyFactoryBean(org.apereo.cas.util.crypto.PublicKeyFactoryBean) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) FileSystemResource(org.springframework.core.io.FileSystemResource) ClassPathResource(org.springframework.core.io.ClassPathResource)

Aggregations

PublicKeyFactoryBean (org.apereo.cas.util.crypto.PublicKeyFactoryBean)5 lombok.val (lombok.val)4 SneakyThrows (lombok.SneakyThrows)3 ClassPathResource (org.springframework.core.io.ClassPathResource)3 FileSystemResource (org.springframework.core.io.FileSystemResource)2 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 Resource (org.springframework.core.io.Resource)1