OAuth2TokenEndpointServlet.java 24.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.granite.crypto.CryptoException
 *  com.adobe.granite.crypto.CryptoSupport
 *  com.adobe.granite.keystore.KeyStoreService
 *  com.adobe.granite.oauth.jwt.JwsBuilder
 *  com.adobe.granite.oauth.jwt.JwsBuilderFactory
 *  com.adobe.granite.oauth.jwt.JwsValidator
 *  javax.jcr.RepositoryException
 *  javax.jcr.Session
 *  javax.servlet.Servlet
 *  javax.servlet.ServletException
 *  javax.servlet.http.HttpServlet
 *  javax.servlet.http.HttpServletRequest
 *  javax.servlet.http.HttpServletResponse
 *  org.apache.felix.scr.annotations.Activate
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Modified
 *  org.apache.felix.scr.annotations.Properties
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.jackrabbit.api.security.user.Authorizable
 *  org.apache.jackrabbit.api.security.user.Group
 *  org.apache.jackrabbit.api.security.user.User
 *  org.apache.jackrabbit.oak.spi.security.ConfigurationParameters
 *  org.apache.jackrabbit.oak.spi.security.authorization.AuthorizationConfiguration
 *  org.apache.oltu.oauth2.as.request.OAuthTokenRequest
 *  org.apache.oltu.oauth2.as.response.OAuthASResponse
 *  org.apache.oltu.oauth2.as.response.OAuthASResponse$OAuthTokenResponseBuilder
 *  org.apache.oltu.oauth2.common.exception.OAuthProblemException
 *  org.apache.oltu.oauth2.common.exception.OAuthSystemException
 *  org.apache.oltu.oauth2.common.message.OAuthResponse
 *  org.apache.oltu.oauth2.common.message.OAuthResponse$OAuthErrorResponseBuilder
 *  org.apache.oltu.oauth2.common.message.types.GrantType
 *  org.apache.oltu.oauth2.common.utils.OAuthUtils
 *  org.apache.oltu.oauth2.jwt.ClaimsSet
 *  org.apache.oltu.oauth2.jwt.Header
 *  org.apache.oltu.oauth2.jwt.JWT
 *  org.apache.oltu.oauth2.jwt.io.JWTReader
 *  org.apache.oltu.oauth2.jwt.request.JWTOAuthRequest
 *  org.apache.sling.api.resource.LoginException
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.apache.sling.api.resource.ResourceResolverFactory
 *  org.apache.sling.commons.osgi.OsgiUtil
 *  org.apache.sling.jcr.api.SlingRepository
 *  org.osgi.framework.BundleContext
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.granite.oauth.server.impl;

import com.adobe.granite.crypto.CryptoException;
import com.adobe.granite.crypto.CryptoSupport;
import com.adobe.granite.keystore.KeyStoreService;
import com.adobe.granite.oauth.jwt.JwsBuilder;
import com.adobe.granite.oauth.jwt.JwsBuilderFactory;
import com.adobe.granite.oauth.jwt.JwsValidator;
import com.adobe.granite.oauth.server.OAuth2ResourceServer;
import com.adobe.granite.oauth.server.impl.OAuth2GraniteIssuer;
import com.adobe.granite.oauth.server.impl.helper.OAuth2Helper;
import java.io.IOException;
import java.io.PrintWriter;
import java.security.Key;
import java.security.KeyPair;
import java.security.Principal;
import java.security.PublicKey;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Modified;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.jackrabbit.api.security.user.Authorizable;
import org.apache.jackrabbit.api.security.user.Group;
import org.apache.jackrabbit.api.security.user.User;
import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
import org.apache.jackrabbit.oak.spi.security.authorization.AuthorizationConfiguration;
import org.apache.oltu.oauth2.as.request.OAuthTokenRequest;
import org.apache.oltu.oauth2.as.response.OAuthASResponse;
import org.apache.oltu.oauth2.common.exception.OAuthProblemException;
import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
import org.apache.oltu.oauth2.common.message.OAuthResponse;
import org.apache.oltu.oauth2.common.message.types.GrantType;
import org.apache.oltu.oauth2.common.utils.OAuthUtils;
import org.apache.oltu.oauth2.jwt.ClaimsSet;
import org.apache.oltu.oauth2.jwt.Header;
import org.apache.oltu.oauth2.jwt.JWT;
import org.apache.oltu.oauth2.jwt.io.JWTReader;
import org.apache.oltu.oauth2.jwt.request.JWTOAuthRequest;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.commons.osgi.OsgiUtil;
import org.apache.sling.jcr.api.SlingRepository;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/*
 * This class specifies class file version 49.0 but uses Java 6 signatures.  Assumed Java 6.
 */
@Component(immediate=1, metatype=1, label="%oauth.token.endpoint.name", description="%oauth.token.endpoint.description")
@Service(value={Servlet.class})
@Properties(value={@Property(name="service.description", value={"OAuth2 Token Endpoint Servlet"}), @Property(name="oauth.issuer", value={"Adobe Granite"}), @Property(name="oauth.access.token.expires.in", value={"3600"}), @Property(name="alias", value={"/oauth/token"})})
public class OAuth2TokenEndpointServlet
extends HttpServlet {
    private static final long serialVersionUID = -5800923073209065538L;
    private final Logger logger;
    private static final String REFRESH_TOKEN_EXPIRES_IN = "31536000";
    protected static final String DEFAULT_SERVLET_PATH = "/oauth/token";
    protected static final String OAUTH_SERVLET_PATH = "alias";
    protected static final String OAUTH_ISSUER_NAME = "oauth.issuer";
    protected static final String OAUTH_TOKEN_EXPIRES_IN = "oauth.access.token.expires.in";
    protected static final String OAUTH_ISSUER_NAME_DEFAULT = "Adobe Granite";
    @Reference
    private SlingRepository repository;
    @Reference
    private CryptoSupport cryptoSupport;
    @Reference
    private JwsBuilderFactory jwsBuilderFactory;
    @Reference
    JwsValidator jwsValidator;
    @Reference
    KeyStoreService keyStoreService;
    @Reference
    ResourceResolverFactory resourceResolverFactory;
    @Reference
    private OAuth2ResourceServer oAuth2ResourceServer;
    @Reference
    private AuthorizationConfiguration authorizationConfiguration;
    private String oauthIssuerName;
    private String tokenExpiresIn;
    private String oauthServletPath;

    public OAuth2TokenEndpointServlet() {
        this.logger = LoggerFactory.getLogger(this.getClass());
    }

    @Activate
    @Modified
    private void activate(BundleContext context, Map<String, Object> config) {
        this.oauthIssuerName = OsgiUtil.toString((Object)config.get("oauth.issuer"), (String)"Adobe Granite");
        this.tokenExpiresIn = OsgiUtil.toString((Object)config.get("oauth.access.token.expires.in"), (String)"3600");
        this.oauthServletPath = OsgiUtil.toString((Object)config.get("alias"), (String)"/oauth/token");
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        block8 : {
            try {
                String grantType = request.getParameter("grant_type");
                if (GrantType.AUTHORIZATION_CODE.toString().equals(grantType)) {
                    this.handleAuthorizationCodeGrantType(request, response);
                    break block8;
                }
                if (GrantType.REFRESH_TOKEN.toString().equals(grantType)) {
                    this.handleRefreshTokenGrantType(request, response);
                    break block8;
                }
                if (GrantType.JWT_BEARER.toString().equals(grantType)) {
                    this.handleJwtBearerGrantType(request, response);
                    break block8;
                }
                throw OAuthUtils.handleOAuthProblemException((String)"Invalid grant_type parameter value");
            }
            catch (OAuthSystemException e) {
                OAuth2Helper.handleOAuthSystemException(e, response);
            }
            catch (OAuthProblemException e) {
                OAuthResponse r = null;
                try {
                    r = OAuthResponse.errorResponse((int)400).error(e).buildJSONMessage();
                    response.setStatus(r.getResponseStatus());
                    PrintWriter pw = response.getWriter();
                    pw.print(r.getBody());
                    pw.flush();
                    response.sendError(400);
                }
                catch (OAuthSystemException e1) {
                    OAuth2Helper.handleOAuthSystemException(e1, response);
                }
            }
        }
    }

    private void handleAuthorizationCodeGrantType(HttpServletRequest request, HttpServletResponse response) throws OAuthSystemException, OAuthProblemException, IOException {
        String refreshToken;
        String accessToken;
        OAuthTokenRequest oauthRequest = new OAuthTokenRequest(request);
        String authzCode = oauthRequest.getCode();
        if (this.validAuthorizationCode(authzCode)) {
            this.validateClient(oauthRequest, authzCode);
            String subject = this.getSubject(authzCode);
            String scopes = (String)((JWT)new JWTReader().read(authzCode)).getClaimsSet().getCustomField("scope", String.class);
            accessToken = this.generateAccessToken(oauthRequest.getClientId(), subject, scopes);
            Set<String> scopesSet = OAuth2Helper.getScopesSet(scopes);
            refreshToken = null;
            if (scopesSet.contains("offline_access")) {
                this.logger.debug("generating refresh token");
                refreshToken = this.generateRefreshToken(oauthRequest.getClientId(), subject, scopes);
            }
        } else {
            OAuthProblemException oAuthProblemException = OAuthProblemException.error((String)"invalid_grant", (String)"Invalid code");
            throw oAuthProblemException;
        }
        this.validResponse(response, accessToken, refreshToken);
    }

    private void handleRefreshTokenGrantType(HttpServletRequest request, HttpServletResponse response) throws OAuthSystemException, OAuthProblemException, IOException {
        OAuthTokenRequest oauthRequest = new OAuthTokenRequest(request);
        String refreshToken = oauthRequest.getRefreshToken();
        if (!this.validRefreshToken(refreshToken)) {
            OAuthProblemException oAuthProblemException = OAuthProblemException.error((String)"invalid_grant", (String)"Invalid refresh token");
            throw oAuthProblemException;
        }
        this.validateClient(oauthRequest, refreshToken);
        String subject = this.getSubject(refreshToken);
        String scopes = (String)((JWT)new JWTReader().read(refreshToken)).getClaimsSet().getCustomField("scope", String.class);
        String accessToken = this.generateAccessToken(oauthRequest.getClientId(), subject, scopes);
        this.validResponse(response, accessToken, null);
    }

    private void handleJwtBearerGrantType(HttpServletRequest request, HttpServletResponse response) throws OAuthSystemException, OAuthProblemException, IOException {
        String clientId;
        String scopes;
        JWTOAuthRequest jwtoAuthRequest = new JWTOAuthRequest(request);
        String assertion = jwtoAuthRequest.getAssertion();
        JWT token = (JWT)new JWTReader().read(assertion);
        String userId = this.validateAssertion(request, token, clientId = token.getClaimsSet().getIssuer(), scopes = (String)token.getClaimsSet().getCustomField("scope", String.class));
        if (userId == null) {
            OAuthProblemException oAuthProblemException = OAuthProblemException.error((String)"invalid_grant", (String)"Invalid assertion");
            throw oAuthProblemException;
        }
        String accessToken = this.generateAccessToken(clientId, userId, scopes);
        this.validResponse(response, accessToken, null);
    }

    private void validateClient(OAuthTokenRequest oauthRequest, String code) throws OAuthProblemException, OAuthSystemException {
        String aud;
        String clientId = oauthRequest.getClientId();
        if (!clientId.equals(aud = ((JWT)new JWTReader().read(code)).getClaimsSet().getAudience())) {
            this.logger.debug("the clientId from request parameter {} did not match the token aud {}", (Object)clientId, (Object)aud);
            OAuthProblemException oAuthProblemException = OAuthProblemException.error((String)"invalid_client", (String)"Invalid client");
            throw oAuthProblemException;
        }
        Session oauthServiceSession = null;
        try {
            String clientSecret;
            String redirectUri;
            oauthServiceSession = this.repository.loginService(null, null);
            Authorizable user = OAuth2Helper.getOAuthClientAuthorizable(oauthServiceSession, clientId);
            if (user == null) {
                this.logger.debug("validateClient: Invalid value {} for parameter client_id", (Object)clientId);
                OAuthProblemException oAuthProblemException = OAuthProblemException.error((String)"invalid_client", (String)"Invalid client");
                throw oAuthProblemException;
            }
            String clientSecretStored = this.cryptoSupport.unprotect(OAuth2Helper.getOAuthClientPropertyValue(user, clientId, "oauth:clientSecret"));
            if (!clientSecretStored.equals(clientSecret = oauthRequest.getClientSecret())) {
                this.logger.debug("validateClient: client secret did not match");
                OAuthProblemException oAuthProblemException = OAuthProblemException.error((String)"invalid_client", (String)"Invalid client");
                throw oAuthProblemException;
            }
            String redirectUriStored = OAuth2Helper.getOAuthClientPropertyValue(user, clientId, "oauth:redirectURI");
            if (!redirectUriStored.equalsIgnoreCase(redirectUri = oauthRequest.getRedirectURI())) {
                this.logger.debug("validateClient: The redirect URI in the request {} did not match a registered redirect URI {}", (Object)redirectUri, (Object)redirectUriStored);
                OAuthProblemException oAuthProblemException = OAuthProblemException.error((String)"redirect_uri_mismatch", (String)"");
                throw oAuthProblemException;
            }
        }
        catch (RepositoryException e) {
            this.logger.error("validateClient: failed while accessing repository", (Throwable)e);
            throw new OAuthSystemException("failed while accessing repository");
        }
        catch (CryptoException e) {
            this.logger.error("validateClient: failed while using crypto support", (Throwable)e);
            throw new OAuthSystemException(" failed while using crypto support");
        }
        finally {
            if (oauthServiceSession != null) {
                oauthServiceSession.logout();
            }
        }
    }

    private boolean validAuthorizationCode(String authorizationCode) {
        String contentType;
        boolean validAuthorizationCode = this.jwsValidator.validate(authorizationCode);
        if (validAuthorizationCode && !"code".equals(contentType = OAuth2Helper.getContentType(authorizationCode))) {
            validAuthorizationCode = false;
        }
        return validAuthorizationCode;
    }

    private boolean validRefreshToken(String refreshToken) {
        String contentType;
        boolean validRefreshToken = this.jwsValidator.validate(refreshToken);
        if (validRefreshToken && !"rt".equals(contentType = OAuth2Helper.getContentType(refreshToken))) {
            validRefreshToken = false;
        }
        return validRefreshToken;
    }

    private String getSubject(String authorizationCode) throws OAuthSystemException {
        if (authorizationCode != null) {
            return ((JWT)new JWTReader().read(authorizationCode)).getClaimsSet().getSubject();
        }
        this.logger.info("the provided authorization code is not valid");
        return null;
    }

    private String validateAssertion(HttpServletRequest request, JWT token, String clientId, String scopes) throws OAuthSystemException, OAuthProblemException {
        boolean validAssertion;
        String userId;
        userId = null;
        validAssertion = false;
        String algorithm = token.getHeader().getAlgorithm();
        if (clientId != null && "RS256".equals(algorithm)) {
            String audience = token.getClaimsSet().getAudience();
            if (this.getAudienceDomain(request).equals(audience)) {
                ResourceResolver resourceResolver = null;
                String scope = (String)token.getClaimsSet().getCustomField("scope", String.class);
                OAuth2Helper.validateScopes(this.oAuth2ResourceServer, OAuth2Helper.getScopesSet(scope), true);
                try {
                    resourceResolver = this.resourceResolverFactory.getServiceResourceResolver(null);
                    Session oauthServiceSession = (Session)resourceResolver.adaptTo(Session.class);
                    User authorizable = OAuth2Helper.getUser(oauthServiceSession, clientId);
                    if (authorizable != null) {
                        KeyPair keyPair = this.keyStoreService.getKeyStoreKeyPair(resourceResolver, authorizable.getID(), clientId);
                        Authorizable user = OAuth2Helper.getOAuthClientAuthorizable(oauthServiceSession, clientId);
                        if (this.isAllowedScope(user, scopes)) {
                            validAssertion = this.jwsValidator.validate(token.getRawString(), (Key)keyPair.getPublic());
                            if (user != null && validAssertion) {
                                userId = user.getID();
                            }
                        }
                    }
                }
                catch (LoginException e) {
                    this.logger.error("validateAssertion: failed to login", (Throwable)e);
                    throw new OAuthSystemException("failed to login");
                }
                catch (RepositoryException e) {
                    this.logger.error("validateAssertion: failed while accessing repository", (Throwable)e);
                    throw new OAuthSystemException("failed while accessing repository");
                }
                finally {
                    if (resourceResolver != null) {
                        resourceResolver.close();
                    }
                }
            }
        }
        if (validAssertion) {
            return userId;
        }
        return null;
    }

    private String generateAccessToken(String clientId, String subject, String scope) throws OAuthSystemException {
        OAuth2GraniteIssuer oauthIssuer = new OAuth2GraniteIssuer(this.jwsBuilderFactory.getInstance("HS256")).setSubject(subject).setAudience(clientId).setIssuer(this.oauthIssuerName).setExpiresIn(this.tokenExpiresIn);
        if (scope != null) {
            oauthIssuer.setScope(scope);
        }
        oauthIssuer.setCustomClaimsSetField("cty", "at");
        return oauthIssuer.accessToken();
    }

    private String generateRefreshToken(String clientId, String subject, String scope) throws OAuthSystemException {
        OAuth2GraniteIssuer oauthIssuer = new OAuth2GraniteIssuer(this.jwsBuilderFactory.getInstance("HS256")).setSubject(subject).setAudience(clientId).setIssuer(this.oauthIssuerName).setExpiresIn("31536000");
        if (scope != null) {
            oauthIssuer.setScope(scope);
        }
        oauthIssuer.setCustomClaimsSetField("cty", "rt");
        return oauthIssuer.refreshToken();
    }

    private void validResponse(HttpServletResponse response, String accessToken, String refreshToken) throws OAuthSystemException, IOException {
        OAuthASResponse.OAuthTokenResponseBuilder rt = OAuthASResponse.tokenResponse((int)200).setAccessToken(accessToken).setExpiresIn(this.tokenExpiresIn);
        if (refreshToken != null) {
            rt.setRefreshToken(refreshToken);
        }
        OAuthResponse r = rt.buildJSONMessage();
        response.setStatus(r.getResponseStatus());
        PrintWriter pw = response.getWriter();
        pw.print(r.getBody());
        pw.flush();
    }

    private String getAudienceDomain(HttpServletRequest request) {
        String scheme = request.getScheme();
        String serverName = request.getServerName();
        int serverPort = request.getServerPort();
        StringBuilder url = new StringBuilder();
        url.append(scheme).append("://").append(serverName);
        if (!("https".equals(scheme) && serverPort == 443 || "http".equals(scheme) && serverPort == 80)) {
            url.append(":").append(serverPort);
        }
        url.append(this.oauthServletPath);
        return url.toString();
    }

    private boolean isAllowedScope(Authorizable user, String scopes) throws RepositoryException {
        Set<String> scopesSet = OAuth2Helper.getScopesSet(scopes);
        if (scopesSet.contains("replicate")) {
            User u = (User)user;
            if (u.isAdmin()) {
                return true;
            }
            ConfigurationParameters configurationParameters = this.authorizationConfiguration.getParameters();
            Set administrativePrincipals = (Set)configurationParameters.getConfigValue("administrativePrincipals", (Object)Collections.EMPTY_SET);
            Iterator it = user.memberOf();
            while (it.hasNext()) {
                Group g = (Group)it.next();
                if (!administrativePrincipals.contains(g.getPrincipal().getName())) continue;
                return true;
            }
            return false;
        }
        return true;
    }

    protected void bindRepository(SlingRepository slingRepository) {
        this.repository = slingRepository;
    }

    protected void unbindRepository(SlingRepository slingRepository) {
        if (this.repository == slingRepository) {
            this.repository = null;
        }
    }

    protected void bindCryptoSupport(CryptoSupport cryptoSupport) {
        this.cryptoSupport = cryptoSupport;
    }

    protected void unbindCryptoSupport(CryptoSupport cryptoSupport) {
        if (this.cryptoSupport == cryptoSupport) {
            this.cryptoSupport = null;
        }
    }

    protected void bindJwsBuilderFactory(JwsBuilderFactory jwsBuilderFactory) {
        this.jwsBuilderFactory = jwsBuilderFactory;
    }

    protected void unbindJwsBuilderFactory(JwsBuilderFactory jwsBuilderFactory) {
        if (this.jwsBuilderFactory == jwsBuilderFactory) {
            this.jwsBuilderFactory = null;
        }
    }

    protected void bindJwsValidator(JwsValidator jwsValidator) {
        this.jwsValidator = jwsValidator;
    }

    protected void unbindJwsValidator(JwsValidator jwsValidator) {
        if (this.jwsValidator == jwsValidator) {
            this.jwsValidator = null;
        }
    }

    protected void bindKeyStoreService(KeyStoreService keyStoreService) {
        this.keyStoreService = keyStoreService;
    }

    protected void unbindKeyStoreService(KeyStoreService keyStoreService) {
        if (this.keyStoreService == keyStoreService) {
            this.keyStoreService = null;
        }
    }

    protected void bindResourceResolverFactory(ResourceResolverFactory resourceResolverFactory) {
        this.resourceResolverFactory = resourceResolverFactory;
    }

    protected void unbindResourceResolverFactory(ResourceResolverFactory resourceResolverFactory) {
        if (this.resourceResolverFactory == resourceResolverFactory) {
            this.resourceResolverFactory = null;
        }
    }

    protected void bindOAuth2ResourceServer(OAuth2ResourceServer oAuth2ResourceServer) {
        this.oAuth2ResourceServer = oAuth2ResourceServer;
    }

    protected void unbindOAuth2ResourceServer(OAuth2ResourceServer oAuth2ResourceServer) {
        if (this.oAuth2ResourceServer == oAuth2ResourceServer) {
            this.oAuth2ResourceServer = null;
        }
    }

    protected void bindAuthorizationConfiguration(AuthorizationConfiguration authorizationConfiguration) {
        this.authorizationConfiguration = authorizationConfiguration;
    }

    protected void unbindAuthorizationConfiguration(AuthorizationConfiguration authorizationConfiguration) {
        if (this.authorizationConfiguration == authorizationConfiguration) {
            this.authorizationConfiguration = null;
        }
    }
}