Search in sources :

Example 1 with Algorithm

use of com.microsoft.azure.oidc.common.algorithm.Algorithm in project azure-tools-for-java by Microsoft.

the class SimpleWellKnownParser method getAlgorithms.

@Override
public List<Algorithm> getAlgorithms(JsonNode node) {
    if (node == null) {
        throw new PreconditionException("Required parameter is null");
    }
    final List<Algorithm> algorithms = new ArrayList<Algorithm>();
    for (final JsonNode n : node.get("id_token_signing_alg_values_supported")) {
        final Algorithm algorithm = algorithmFactory.createAlgorithm(n.asText());
        algorithms.add(algorithm);
    }
    return algorithms;
}
Also used : ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) Algorithm(com.microsoft.azure.oidc.common.algorithm.Algorithm) PreconditionException(com.microsoft.azure.oidc.exception.PreconditionException)

Example 2 with Algorithm

use of com.microsoft.azure.oidc.common.algorithm.Algorithm in project azure-tools-for-java by Microsoft.

the class SimpeTokenParser method getToken.

@Override
public Token getToken(String value) {
    final String[] parts = value.split("\\.");
    if (parts.length != 3) {
        throw new IllegalStateException(String.format("Incorrect number of parts: Expected 3 got %s", parts.length));
    }
    final JsonNode header = parsePart(decodePart(parts[0]));
    final JsonNode body = parsePart(decodePart(parts[1]));
    final Name keyName = getKeyName(header);
    final Algorithm algorithm = getAlgorithm(header);
    final TimeStamp issuedAt = getIssuedAt(body);
    final TimeStamp notBefore = getNotBefore(body);
    final TimeStamp expiration = getExpiration(body);
    final Issuer issuer = getIssuer(body);
    final ID audience = getAudience(body);
    final ID userID = getUserID(body);
    final List<Email> userEmails = getEmails(body);
    final Payload payload = getPayload(parts[0], parts[1]);
    final Signature signature = getSignature(parts[2]);
    return tokenFactory.createToken(keyName, algorithm, issuedAt, notBefore, expiration, userID, userEmails, issuer, audience, payload, signature);
}
Also used : Email(com.microsoft.azure.oidc.token.email.Email) Issuer(com.microsoft.azure.oidc.common.issuer.Issuer) JsonNode(com.fasterxml.jackson.databind.JsonNode) Algorithm(com.microsoft.azure.oidc.common.algorithm.Algorithm) TimeStamp(com.microsoft.azure.oidc.common.timestamp.TimeStamp) Name(com.microsoft.azure.oidc.common.name.Name) Signature(com.microsoft.azure.oidc.token.signature.Signature) Payload(com.microsoft.azure.oidc.token.payload.Payload) ID(com.microsoft.azure.oidc.common.id.ID)

Example 3 with Algorithm

use of com.microsoft.azure.oidc.common.algorithm.Algorithm 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)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)3 Algorithm (com.microsoft.azure.oidc.common.algorithm.Algorithm)3 Issuer (com.microsoft.azure.oidc.common.issuer.Issuer)2 Name (com.microsoft.azure.oidc.common.name.Name)2 ID (com.microsoft.azure.oidc.common.id.ID)1 TimeStamp (com.microsoft.azure.oidc.common.timestamp.TimeStamp)1 EndPoint (com.microsoft.azure.oidc.configuration.endpoint.EndPoint)1 Key (com.microsoft.azure.oidc.configuration.key.Key)1 PreconditionException (com.microsoft.azure.oidc.exception.PreconditionException)1 Email (com.microsoft.azure.oidc.token.email.Email)1 Payload (com.microsoft.azure.oidc.token.payload.Payload)1 Signature (com.microsoft.azure.oidc.token.signature.Signature)1 ArrayList (java.util.ArrayList)1