Search in sources :

Example 1 with Key

use of com.microsoft.azure.oidc.configuration.key.Key in project azure-tools-for-java by Microsoft.

the class SimpleConfigurationLoader method load.

public Configuration load() {
    try {
        final JsonNode wellKnownNode = futureHelper.getResult(wellKnownLoader.loadAsync());
        if (wellKnownNode == null) {
            LOGGER.error("Error loading metadata");
            return null;
        }
        final List<Algorithm> algorithms = wellKnownParser.getAlgorithms(wellKnownNode);
        final EndPoint authenticationEndPoint = wellKnownParser.getAuthenticationEndPoint(wellKnownNode);
        final EndPoint keyStoreEndPoint = wellKnownParser.getKeyStoreEndPoint(wellKnownNode);
        final EndPoint logoutEndPoint = wellKnownParser.getLogoutEndPoint(wellKnownNode);
        final Issuer issuer = wellKnownParser.getIssuer(wellKnownNode);
        final JsonNode keyStoreNode = futureHelper.getResult(keyStoreLoader.loadAsync(keyStoreEndPoint));
        if (keyStoreNode == null) {
            LOGGER.error("Error loading keystore");
            return null;
        }
        final Map<Name, Key> keys = keyStoreParser.getKeys(keyStoreNode);
        return configurationFactory.createConfiguration(algorithms, keys, issuer, authenticationEndPoint, logoutEndPoint);
    } catch (RuntimeException e) {
        LOGGER.error(e.getMessage(), e);
        return null;
    }
}
Also used : Issuer(com.microsoft.azure.oidc.common.issuer.Issuer) JsonNode(com.fasterxml.jackson.databind.JsonNode) EndPoint(com.microsoft.azure.oidc.configuration.endpoint.EndPoint) Algorithm(com.microsoft.azure.oidc.common.algorithm.Algorithm) Key(com.microsoft.azure.oidc.configuration.key.Key) Name(com.microsoft.azure.oidc.common.name.Name)

Example 2 with Key

use of com.microsoft.azure.oidc.configuration.key.Key in project azure-tools-for-java by Microsoft.

the class SimpleKeyStoreParser method getKeys.

@Override
public Map<Name, Key> getKeys(final JsonNode node) {
    if (node == null) {
        throw new PreconditionException("Required parameter is null");
    }
    final Map<Name, Key> keys = new HashMap<Name, Key>();
    for (final JsonNode n : node.get("keys")) {
        final TimeStamp notBefore = timeStampFactory.createTimeStamp(n.has("nbf") ? n.get("nbf").asLong() : 0L);
        final Name keyName = nameFactory.createKeyName(n.get("kid").asText());
        final Modulus modulus = modulusFactory.createKeyValue(n.get("n").asText());
        final Exponent exponent = exponentFactory.createKeyExponent(n.get("e").asText());
        final Key key = keyFactory.createKey(notBefore, modulus, exponent);
        keys.put(keyName, key);
    }
    return keys;
}
Also used : Exponent(com.microsoft.azure.oidc.configuration.key.exponent.Exponent) HashMap(java.util.HashMap) Modulus(com.microsoft.azure.oidc.configuration.key.modulus.Modulus) JsonNode(com.fasterxml.jackson.databind.JsonNode) Key(com.microsoft.azure.oidc.configuration.key.Key) TimeStamp(com.microsoft.azure.oidc.common.timestamp.TimeStamp) PreconditionException(com.microsoft.azure.oidc.exception.PreconditionException) Name(com.microsoft.azure.oidc.common.name.Name)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)2 Name (com.microsoft.azure.oidc.common.name.Name)2 Key (com.microsoft.azure.oidc.configuration.key.Key)2 Algorithm (com.microsoft.azure.oidc.common.algorithm.Algorithm)1 Issuer (com.microsoft.azure.oidc.common.issuer.Issuer)1 TimeStamp (com.microsoft.azure.oidc.common.timestamp.TimeStamp)1 EndPoint (com.microsoft.azure.oidc.configuration.endpoint.EndPoint)1 Exponent (com.microsoft.azure.oidc.configuration.key.exponent.Exponent)1 Modulus (com.microsoft.azure.oidc.configuration.key.modulus.Modulus)1 PreconditionException (com.microsoft.azure.oidc.exception.PreconditionException)1 HashMap (java.util.HashMap)1