All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.cloudfoundry.identity.uaa.oauth.KeyInfoBuilder Maven / Gradle / Ivy

There is a newer version: 4.30.0
Show newest version
package org.cloudfoundry.identity.uaa.oauth;

import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

public class KeyInfoBuilder {
    public static KeyInfo build(String keyId, String signingKey, String uaaUrl) {
        if (StringUtils.isEmpty(signingKey)) {
            throw new IllegalArgumentException("Signing key cannot be empty");
        }

        Assert.hasText(signingKey, "[Assertion failed] - this String argument must have text; it must not be null, empty, or blank");
        signingKey = signingKey.trim();

        if (isAssymetricKey(signingKey)) {
            return new RsaKeyInfo(keyId, signingKey, uaaUrl);
        }
        return new HmacKeyInfo(keyId, signingKey, uaaUrl);
    }

    /**
     * @return true if the string represents an asymmetric (RSA) key
     */
    private static boolean isAssymetricKey(String key) {
        return key.startsWith("-----BEGIN");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy