Search in sources :

Example 6 with PreEnvironment

use of net.openid.conformance.condition.PreEnvironment in project conformance-suite by openid-certification.

the class CreateLoginRequiredErrorResponse method evaluate.

@Override
@PreEnvironment(required = CreateAuthorizationEndpointResponseParams.ENV_KEY)
@PostEnvironment(required = ERROR_RESPONSE_PARAMS, strings = ERROR_RESPONSE_URL)
public Environment evaluate(Environment env) {
    JsonObject originalResponseParams = env.getObject(CreateAuthorizationEndpointResponseParams.ENV_KEY);
    JsonObject errorResponseParams = new JsonObject();
    if (originalResponseParams.has("state")) {
        errorResponseParams.add("state", originalResponseParams.get("state"));
    }
    errorResponseParams.addProperty("error", "login_required");
    errorResponseParams.addProperty("error_description", "This is a login_required error response");
    env.putObject(ERROR_RESPONSE_PARAMS, errorResponseParams);
    String responseUrl = OIDFJSON.getString(originalResponseParams.remove("redirect_uri"));
    env.putString(ERROR_RESPONSE_URL, responseUrl);
    log("Created login_required error", args(ERROR_RESPONSE_PARAMS, errorResponseParams, ERROR_RESPONSE_URL, responseUrl));
    return env;
}
Also used : JsonObject(com.google.gson.JsonObject) PostEnvironment(net.openid.conformance.condition.PostEnvironment) PreEnvironment(net.openid.conformance.condition.PreEnvironment)

Example 7 with PreEnvironment

use of net.openid.conformance.condition.PreEnvironment in project conformance-suite by openid-certification.

the class CreateTokenEndpointResponse method evaluate.

@Override
// note the others are optional
@PreEnvironment(strings = { "access_token", "token_type" })
@PostEnvironment(required = "token_endpoint_response")
public Environment evaluate(Environment env) {
    String accessToken = env.getString("access_token");
    String tokenType = env.getString("token_type");
    String idToken = env.getString("id_token");
    String refreshToken = env.getString("refresh_token");
    String scope = env.getString("scope");
    String accessTokenExpiration = env.getString("access_token_expiration");
    if (Strings.isNullOrEmpty(accessToken) || Strings.isNullOrEmpty(tokenType)) {
        throw error("Missing required access_token or token_type");
    }
    JsonObject tokenEndpointResponse = new JsonObject();
    tokenEndpointResponse.addProperty("access_token", accessToken);
    tokenEndpointResponse.addProperty("token_type", tokenType);
    if (!Strings.isNullOrEmpty(idToken)) {
        tokenEndpointResponse.addProperty("id_token", idToken);
    }
    if (!Strings.isNullOrEmpty(refreshToken)) {
        tokenEndpointResponse.addProperty("refresh_token", refreshToken);
    }
    if (!Strings.isNullOrEmpty(scope)) {
        tokenEndpointResponse.addProperty("scope", scope);
    }
    if (!Strings.isNullOrEmpty(accessTokenExpiration)) {
        tokenEndpointResponse.addProperty("expires_in", Integer.parseInt(accessTokenExpiration));
    }
    env.putObject("token_endpoint_response", tokenEndpointResponse);
    logSuccess("Created token endpoint response", tokenEndpointResponse);
    return env;
}
Also used : JsonObject(com.google.gson.JsonObject) PostEnvironment(net.openid.conformance.condition.PostEnvironment) PreEnvironment(net.openid.conformance.condition.PreEnvironment)

Example 8 with PreEnvironment

use of net.openid.conformance.condition.PreEnvironment in project conformance-suite by openid-certification.

the class CreateWebfingerResponse method evaluate.

@Override
@PreEnvironment(required = { "incoming_webfinger_request" }, strings = { "incoming_webfinger_resource" })
@PostEnvironment(required = "webfinger_response")
public Environment evaluate(Environment env) {
    JsonObject response = new JsonObject();
    response.addProperty("subject", env.getString("incoming_webfinger_resource"));
    JsonArray linksArray = new JsonArray();
    JsonObject linkEntry = new JsonObject();
    linkEntry.addProperty("rel", "http://openid.net/specs/connect/1.0/issuer");
    linkEntry.addProperty("href", env.getString("issuer"));
    linksArray.add(linkEntry);
    response.add("links", linksArray);
    env.putObject("webfinger_response", response);
    log("Created webfinger response", args("webfinger_response", response));
    return env;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) PostEnvironment(net.openid.conformance.condition.PostEnvironment) PreEnvironment(net.openid.conformance.condition.PreEnvironment)

Example 9 with PreEnvironment

use of net.openid.conformance.condition.PreEnvironment in project conformance-suite by openid-certification.

the class EncryptIdToken method evaluate.

@Override
@PreEnvironment(strings = "id_token", required = "client")
@PostEnvironment(strings = "id_token")
public Environment evaluate(Environment env) {
    String idToken = env.getString("id_token");
    String alg = env.getString("client", "id_token_encrypted_response_alg");
    String enc = env.getString("client", "id_token_encrypted_response_enc");
    String clientSecret = env.getString("client", "client_secret");
    // client jwks may be null
    JsonElement clientJwksElement = env.getElementFromObject("client", "jwks");
    JsonObject clientJwks = null;
    if (clientJwksElement != null) {
        clientJwks = clientJwksElement.getAsJsonObject();
    }
    String encryptedIdToken = encrypt("client", idToken, clientSecret, clientJwks, alg, enc, "id_token_encrypted_response_alg", "id_token_encrypted_response_enc");
    log("Encrypted the id token", args("id_token", encryptedIdToken, "id_token_encrypted_response_alg", alg, "id_token_encrypted_response_enc", enc));
    env.putString("id_token", encryptedIdToken);
    return env;
}
Also used : JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) PostEnvironment(net.openid.conformance.condition.PostEnvironment) PreEnvironment(net.openid.conformance.condition.PreEnvironment)

Example 10 with PreEnvironment

use of net.openid.conformance.condition.PreEnvironment in project conformance-suite by openid-certification.

the class EncryptJARMResponse method evaluate.

@Override
@PreEnvironment(strings = "jarm_response", required = "client")
@PostEnvironment(strings = "jarm_response")
public Environment evaluate(Environment env) {
    String response = env.getString("jarm_response");
    String alg = env.getString("client", "authorization_encrypted_response_alg");
    String enc = env.getString("client", "authorization_encrypted_response_enc");
    String clientSecret = env.getString("client", "client_secret");
    // client jwks may be null
    JsonElement clientJwksElement = env.getElementFromObject("client", "jwks");
    JsonObject clientJwks = null;
    if (clientJwksElement != null) {
        clientJwks = clientJwksElement.getAsJsonObject();
    }
    String encryptedResponse = encrypt("client", response, clientSecret, clientJwks, alg, enc, "authorization_encrypted_response_alg", "authorization_encrypted_response_enc");
    log("Encrypted the JARM response", args("response", encryptedResponse, "authorization_encrypted_response_alg", alg, "authorization_encrypted_response_enc", enc));
    env.putString("jarm_response", encryptedResponse);
    return env;
}
Also used : JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) PostEnvironment(net.openid.conformance.condition.PostEnvironment) PreEnvironment(net.openid.conformance.condition.PreEnvironment)

Aggregations

PreEnvironment (net.openid.conformance.condition.PreEnvironment)591 JsonObject (com.google.gson.JsonObject)469 PostEnvironment (net.openid.conformance.condition.PostEnvironment)379 JsonElement (com.google.gson.JsonElement)143 JsonArray (com.google.gson.JsonArray)74 Instant (java.time.Instant)40 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)29 IOException (java.io.IOException)25 CertificateException (java.security.cert.CertificateException)24 ParseException (java.text.ParseException)24 KeyManagementException (java.security.KeyManagementException)20 KeyStoreException (java.security.KeyStoreException)20 UnrecoverableKeyException (java.security.UnrecoverableKeyException)20 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)20 RestClientException (org.springframework.web.client.RestClientException)20 RestTemplate (org.springframework.web.client.RestTemplate)20 JsonPrimitive (com.google.gson.JsonPrimitive)18 Date (java.util.Date)17 JWK (com.nimbusds.jose.jwk.JWK)13 JOSEException (com.nimbusds.jose.JOSEException)11