/* * The contents of this file are subject to the terms of the Common Development and * Distribution License (the License). You may not use this file except in compliance with the * License. * * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the * specific language governing permission and limitations under the License. * * When distributing Covered Software, include this CDDL Header Notice in each file and include * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL * Header, with the fields enclosed by brackets [] replaced by your own identifying * information: "Portions Copyright [year] [name of copyright owner]". * * Copyright 2016 ForgeRock AS. */ package org.forgerock.opendj.rest2ldap.authz; import static org.forgerock.opendj.rest2ldap.Rest2ldapMessages.*; import static java.util.concurrent.TimeUnit.SECONDS; import static org.forgerock.opendj.rest2ldap.authz.Utils.newAccessTokenException; import static org.forgerock.util.Reject.checkNotNull; import java.io.IOException; import java.net.URI; import java.util.Arrays; import java.util.HashSet; import java.util.Set; import org.forgerock.http.Handler; import org.forgerock.http.oauth2.AccessTokenException; import org.forgerock.http.oauth2.AccessTokenInfo; import org.forgerock.http.oauth2.AccessTokenResolver; import org.forgerock.http.protocol.Responses; import org.forgerock.http.protocol.Entity; import org.forgerock.http.protocol.Form; import org.forgerock.http.protocol.Headers; import org.forgerock.http.protocol.Request; import org.forgerock.http.protocol.Response; import org.forgerock.http.protocol.Status; import org.forgerock.json.JsonValue; import org.forgerock.json.JsonValueException; import org.forgerock.services.context.Context; import org.forgerock.util.Function; import org.forgerock.util.encode.Base64; import org.forgerock.util.promise.Promise; /** * An {@link AccessTokenResolver} which is RFC 7662 compliant. *
* @see RFC-7662
*/
final class Rfc7662AccessTokenResolver implements AccessTokenResolver {
/** RFC 7662 defined fields for token introspection request. */
private static final String RFC_7662_FORM_TOKEN_FIELD = "token";
private static final String RFC_7662_FORM_TOKEN_TYPE_HINT_FIELD = "token_type_hint";
private static final String RFC_7662_FORM_TOKEN_TYPE_HINT_ACCESS_TOKEN = "access_token";
/** RFC 7662 defined fields for token introspection response. */
private static final String RFC_7662_RESPONSE_SCOPE_FIELD = "scope";
private static final String RFC_7662_RESPONSE_EXPIRE_TIME_FIELD = "exp";
/** Rest2Ldap fields name for the RFC 7662 access token resolver. */
private static final String RFC_7662_RESPONSE_ACTIVE_FIELD = "active";
private final Handler httpClient;
private final URI introspectionEndPointURI;
private final String clientAppId;
private final String clientAppSecret;
Rfc7662AccessTokenResolver(final Handler httpClient,
final URI introspectionEndPointURI,
final String clientAppId,
final String clientAppSecret) {
this.httpClient = checkNotNull(httpClient);
this.introspectionEndPointURI = checkNotNull(introspectionEndPointURI);
this.clientAppId = checkNotNull(clientAppId);
this.clientAppSecret = checkNotNull(clientAppSecret);
}
@Override
public Promise