AccessTokenProviderImpl.java 23.3 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
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  aQute.bnd.annotation.component.Deactivate
 *  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.JwtValidator
 *  javax.jcr.RepositoryException
 *  javax.jcr.Session
 *  javax.jcr.Value
 *  javax.jcr.ValueFactory
 *  org.apache.commons.io.IOUtils
 *  org.apache.felix.scr.annotations.Activate
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.ConfigurationPolicy
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.PropertyUnbounded
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.http.Consts
 *  org.apache.http.HttpEntity
 *  org.apache.http.HttpException
 *  org.apache.http.HttpHost
 *  org.apache.http.HttpRequest
 *  org.apache.http.StatusLine
 *  org.apache.http.client.HttpClient
 *  org.apache.http.client.config.RequestConfig
 *  org.apache.http.client.config.RequestConfig$Builder
 *  org.apache.http.client.entity.UrlEncodedFormEntity
 *  org.apache.http.client.methods.CloseableHttpResponse
 *  org.apache.http.client.methods.HttpPost
 *  org.apache.http.client.methods.HttpUriRequest
 *  org.apache.http.client.utils.HttpClientUtils
 *  org.apache.http.config.Registry
 *  org.apache.http.config.RegistryBuilder
 *  org.apache.http.conn.HttpClientConnectionManager
 *  org.apache.http.conn.SchemePortResolver
 *  org.apache.http.conn.routing.HttpRoute
 *  org.apache.http.conn.routing.HttpRoutePlanner
 *  org.apache.http.conn.socket.LayeredConnectionSocketFactory
 *  org.apache.http.conn.ssl.SSLConnectionSocketFactory
 *  org.apache.http.conn.ssl.SSLContextBuilder
 *  org.apache.http.conn.ssl.TrustSelfSignedStrategy
 *  org.apache.http.conn.ssl.TrustStrategy
 *  org.apache.http.conn.ssl.X509HostnameVerifier
 *  org.apache.http.impl.client.CloseableHttpClient
 *  org.apache.http.impl.client.HttpClientBuilder
 *  org.apache.http.impl.client.HttpClients
 *  org.apache.http.impl.conn.DefaultRoutePlanner
 *  org.apache.http.impl.conn.DefaultSchemePortResolver
 *  org.apache.http.impl.conn.PoolingHttpClientConnectionManager
 *  org.apache.http.message.BasicNameValuePair
 *  org.apache.http.protocol.HttpContext
 *  org.apache.jackrabbit.api.security.user.Authorizable
 *  org.apache.jackrabbit.api.security.user.User
 *  org.apache.jackrabbit.api.security.user.UserManager
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.apache.sling.commons.json.JSONException
 *  org.apache.sling.commons.json.JSONObject
 *  org.apache.sling.commons.osgi.PropertiesUtil
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.granite.auth.oauth.impl;

import aQute.bnd.annotation.component.Deactivate;
import com.adobe.granite.auth.oauth.AccessTokenProvider;
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.JwtValidator;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.nio.charset.Charset;
import java.security.Key;
import java.security.KeyPair;
import java.security.KeyStore;
import java.security.PrivateKey;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Value;
import javax.jcr.ValueFactory;
import javax.net.ssl.SSLContext;
import org.apache.commons.io.IOUtils;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.ConfigurationPolicy;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.PropertyUnbounded;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.http.Consts;
import org.apache.http.HttpEntity;
import org.apache.http.HttpException;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.StatusLine;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.utils.HttpClientUtils;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.HttpClientConnectionManager;
import org.apache.http.conn.SchemePortResolver;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.conn.routing.HttpRoutePlanner;
import org.apache.http.conn.socket.LayeredConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLContextBuilder;
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.conn.ssl.X509HostnameVerifier;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.DefaultRoutePlanner;
import org.apache.http.impl.conn.DefaultSchemePortResolver;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HttpContext;
import org.apache.jackrabbit.api.security.user.Authorizable;
import org.apache.jackrabbit.api.security.user.User;
import org.apache.jackrabbit.api.security.user.UserManager;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/*
 * This class specifies class file version 49.0 but uses Java 6 signatures.  Assumed Java 6.
 */
@Service
@Component(metatype=1, name="com.adobe.granite.auth.oauth.accesstoken.provider", configurationFactory=1, immediate=1, policy=ConfigurationPolicy.REQUIRE, label="%auth.token.provider.name", description="%auth.token.provider.description")
public class AccessTokenProviderImpl
implements AccessTokenProvider {
    public static final String FACTORY_PID = "com.adobe.granite.auth.oauth.accesstoken.provider";
    private static final Logger log = LoggerFactory.getLogger(AccessTokenProvider.class);
    private static final String CLAIM_SEPARATOR = ":";
    private static final String HTTPS = "https";
    private static final String[] DEFAULT_CLAIMS = new String[0];
    @Property(unbounded=PropertyUnbounded.ARRAY, value={})
    protected static final String CLAIMS = "auth.token.provider.default.claims";
    private static final String DEFAULT_END_POINT = "gateway-api.omniture.com";
    @Property(value={"gateway-api.omniture.com"})
    protected static final String END_POINT = "auth.token.provider.endpoint";
    private static final String DEFAULT_AUTHORIZATION_GRANTS_TYPE = "urn:ietf:params:oauth:grant-type:jwt-bearer";
    @Property(propertyPrivate=1, value={"urn:ietf:params:oauth:grant-type:jwt-bearer"})
    protected static final String AUTHORIZATION_GRANTS_TYPE = "auth.token.provider.authorization.grants";
    private static final String DEFAULT_ACCESS_TOKEN_REQ_FORMAT = "https://%s/token";
    @Property(value={"https://%s/token"})
    protected static final String ACCESS_TOKEN_REQ_FORMAT = "auth.access.token.request";
    private static final String DEFAULT_KEYPAIR_ALIAS = "access-token-key-pair";
    @Property(value={"access-token-key-pair"})
    protected static final String KEYPAIR_ALIAS = "auth.token.provider.keypair.alias";
    private static final String DEFAULT_ALGORITHM = "RS256";
    @Property(propertyPrivate=1, value={"RS256"})
    protected static final String ALGORITHM = "auth.token.provider.algorithm";
    private static final String DEFAULT_ACCESS_TOKEN_PATH_FORMAT = "oauth/oauthid-%s";
    private static final int DEFAULT_CONNECTION_TIMEOUT = 30000;
    @Property(intValue={30000})
    protected static final String CONNECTION_TIMEOUT = "auth.token.provider.conn.timeout";
    private static final int DEFAULT_SO_TIMEOUT = 30000;
    @Property(intValue={30000})
    protected static final String SO_TIMEOUT = "auth.token.provider.so.timeout";
    private static final String DEFAULT_CLIENT_ID = "TestClient";
    @Property(value={"TestClient"})
    protected static final String CLIENT_ID = "auth.token.provider.client.id";
    private static final String DEFAULT_SCOPE = "";
    @Property(value={""})
    protected static final String SCOPE = "auth.token.provider.scope";
    private static final int DEFAULT_LEEWAY = 180000;
    @Property(propertyPrivate=1, intValue={180000})
    protected static final String LEEWAY = "auth.token.provider.leeway";
    private static final boolean DEFAULT_REUSE_ACCESS_TOKENS = true;
    @Property(boolValue={1})
    protected static final String REUSE_ACCESS_TOKENS = "auth.token.provider.reuse.access.token";
    private static final boolean DEFAULT_RELAXED_SSL = false;
    @Property(boolValue={0})
    protected static final String RELAXED_SSL = "auth.token.provider.relaxed.ssl";
    private static final int CLAIM_MAX_VALIDITY_TIME = 600;
    @Reference
    private JwtValidator jwtValidator;
    @Reference
    private CryptoSupport cryptoSupport;
    @Reference
    private KeyStoreService keyStoreService;
    @Reference
    private JwsBuilderFactory jwsBuilderFactory;
    private CloseableHttpClient httpClient;
    private PoolingHttpClientConnectionManager connectionManager;
    private Map<String, String> defaultClaims = new LinkedHashMap<String, String>();
    private String authorizationGrantType;
    private String keyPairAlias;
    private String algorithm;
    private String clientId;
    private String scope;
    private int leeway;
    private String accessRequestFormat;
    private String endPoint;
    private int connectionTimeout;
    private int soTimeout;
    private boolean reuseAccessTokens;
    private boolean relaxedSsl;
    private String relativeUri;

    @Activate
    protected void activate(Map<String, Object> props) throws Exception {
        HttpClientBuilder builder;
        String[] claims;
        this.defaultClaims.clear();
        for (String claim : claims = PropertiesUtil.toStringArray((Object)props.get("auth.token.provider.default.claims"), (String[])DEFAULT_CLAIMS)) {
            String[] tokens = claim.split(":");
            if (tokens.length == 2) {
                this.defaultClaims.put(tokens[0], tokens[1]);
                continue;
            }
            if (tokens.length <= 2) continue;
            this.defaultClaims.put(tokens[0], claim.substring(claim.indexOf(":") + 1));
        }
        this.authorizationGrantType = PropertiesUtil.toString((Object)props.get("auth.token.provider.authorization.grants"), (String)"urn:ietf:params:oauth:grant-type:jwt-bearer");
        this.keyPairAlias = PropertiesUtil.toString((Object)props.get("auth.token.provider.keypair.alias"), (String)"access-token-key-pair");
        this.algorithm = PropertiesUtil.toString((Object)props.get("auth.token.provider.algorithm"), (String)"RS256");
        this.clientId = PropertiesUtil.toString((Object)props.get("auth.token.provider.client.id"), (String)"TestClient");
        this.scope = PropertiesUtil.toString((Object)props.get("auth.token.provider.scope"), (String)"").trim();
        this.leeway = Math.abs(PropertiesUtil.toInteger((Object)props.get("auth.token.provider.leeway"), (int)180000));
        this.endPoint = PropertiesUtil.toString((Object)props.get("auth.token.provider.endpoint"), (String)"gateway-api.omniture.com");
        this.reuseAccessTokens = PropertiesUtil.toBoolean((Object)props.get("auth.token.provider.reuse.access.token"), (boolean)true);
        this.accessRequestFormat = PropertiesUtil.toString((Object)props.get("auth.access.token.request"), (String)"https://%s/token");
        this.connectionTimeout = Math.abs(PropertiesUtil.toInteger((Object)props.get("auth.token.provider.conn.timeout"), (int)30000));
        this.soTimeout = Math.abs(PropertiesUtil.toInteger((Object)props.get("auth.token.provider.so.timeout"), (int)30000));
        this.relaxedSsl = PropertiesUtil.toBoolean((Object)props.get("auth.token.provider.relaxed.ssl"), (boolean)false);
        final URI uri = new URI(String.format(this.accessRequestFormat, this.endPoint));
        if ("https".equals(uri.getScheme())) {
            this.relativeUri = uri.toString();
            builder = HttpClients.custom();
            DefaultRoutePlanner routePlanner = new DefaultRoutePlanner((SchemePortResolver)DefaultSchemePortResolver.INSTANCE){

                public HttpRoute determineRoute(HttpHost target, HttpRequest request, HttpContext context) throws HttpException {
                    return super.determineRoute(target != null ? target : new HttpHost(uri.getHost(), uri.getPort(), "https"), request, context);
                }
            };
            builder.setRoutePlanner((HttpRoutePlanner)routePlanner);
            if (this.relaxedSsl) {
                log.info("Enable relaxed SSL");
                log.warn("Do not use relaxed SSL in production");
                SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
                sslContextBuilder.loadTrustMaterial(null, (TrustStrategy)new TrustSelfSignedStrategy());
                SSLContext sslContext = sslContextBuilder.build();
                SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
                Registry socketFactoryRegistry = RegistryBuilder.create().register("https", (Object)sslConnectionSocketFactory).build();
                this.connectionManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
                builder.setSSLSocketFactory((LayeredConnectionSocketFactory)sslConnectionSocketFactory);
            } else {
                this.connectionManager = new PoolingHttpClientConnectionManager();
            }
        } else {
            String msg = "Communication with authorization server requires HTTPS";
            log.error(msg);
            throw new IllegalArgumentException(msg);
        }
        builder.setConnectionManager((HttpClientConnectionManager)this.connectionManager);
        RequestConfig.Builder configBuilder = RequestConfig.custom();
        configBuilder.setConnectTimeout(this.connectionTimeout);
        configBuilder.setSocketTimeout(this.soTimeout);
        builder.setDefaultRequestConfig(configBuilder.build());
        this.httpClient = builder.build();
        log.info("activating provider");
    }

    @Deactivate
    protected void deactivate() throws Exception {
        HttpClientUtils.closeQuietly((HttpClient)this.httpClient);
        log.info("deactivating provider");
        if (this.connectionManager != null) {
            try {
                this.connectionManager.close();
            }
            catch (Exception e) {
                // empty catch block
            }
            this.connectionManager = null;
        }
    }

    @Override
    public String getAccessToken(ResourceResolver resolver, String userId, Map<String, String> claims) throws CryptoException, IOException, NullPointerException {
        long validationTime;
        String storedAccessToken;
        if (this.reuseAccessTokens && (storedAccessToken = this.internalGetAccessToken(resolver, userId)) != null && this.jwtValidator.validate(storedAccessToken, validationTime = System.currentTimeMillis() + (long)this.leeway)) {
            return storedAccessToken;
        }
        log.info("requires a new access token");
        String jwt = this.buildJwt(resolver, userId, claims);
        String accessToken = this.tradeAccessToken(this.relativeUri, jwt);
        if (this.reuseAccessTokens) {
            this.internalStoreAccessToken(resolver, userId, accessToken);
        }
        return accessToken;
    }

    private String buildJwt(ResourceResolver resolver, String userId, Map<String, String> claims) throws CryptoException {
        KeyPair keyPair = this.keyStoreService.getKeyStoreKeyPair(resolver, userId, this.keyPairAlias);
        PrivateKey privateKey = keyPair.getPrivate();
        JwsBuilder builder = this.jwsBuilderFactory.getInstance(this.algorithm, (Key)privateKey).setExpiresIn(600);
        for (Map.Entry<String, String> claim2 : this.defaultClaims.entrySet()) {
            builder.setCustomClaimsSetField(claim2.getKey(), (Object)claim2.getValue());
        }
        if (claims != null) {
            for (Map.Entry<String, String> claim2 : claims.entrySet()) {
                builder.setCustomClaimsSetField(claim2.getKey(), (Object)claim2.getValue());
            }
        }
        return builder.build();
    }

    private String internalGetAccessToken(ResourceResolver resolver, String userId) {
        UserManager userManager = (UserManager)resolver.adaptTo(UserManager.class);
        try {
            Value[] value;
            String accessTokenPath;
            User user = this.getUser(userManager, userId);
            if (user != null && user.hasProperty(accessTokenPath = this.getAccessTokenPath(this.clientId)) && (value = user.getProperty(accessTokenPath)) != null && value[0] != null) {
                String protectedAccessToken = value[0].getString();
                return this.unprotect(protectedAccessToken);
            }
        }
        catch (RepositoryException e) {
            log.error("error while looking for access token for the user: {}", (Object)userId, (Object)e);
        }
        return null;
    }

    private void internalStoreAccessToken(ResourceResolver resolver, String userId, String accessToken) {
        UserManager userManager = (UserManager)resolver.adaptTo(UserManager.class);
        try {
            User user = this.getUser(userManager, userId);
            if (user != null) {
                Session session = (Session)resolver.adaptTo(Session.class);
                ValueFactory valueFactory = session.getValueFactory();
                String protectedAccessToken = this.protect(accessToken);
                String accessTokenPath = this.getAccessTokenPath(this.clientId);
                user.setProperty(accessTokenPath, valueFactory.createValue(protectedAccessToken));
                if (!userManager.isAutoSave()) {
                    session.save();
                }
            }
        }
        catch (RepositoryException e) {
            log.error("error while storing an access token for the user: {}", (Object)userId, (Object)e);
        }
    }

    private User getUser(UserManager userManager, String userId) throws RepositoryException {
        Authorizable auth = userManager.getAuthorizable(userId);
        if (auth instanceof User) {
            return (User)auth;
        }
        log.warn("authorizable {} does not exist or is not a User", (Object)userId);
        return null;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    private String tradeAccessToken(String uri, String jwt) throws IOException {
        String response;
        block5 : {
            response = null;
            HttpPost postMethod = null;
            CloseableHttpResponse responseObj = null;
            try {
                postMethod = new HttpPost(uri);
                ArrayList<BasicNameValuePair> body = new ArrayList<BasicNameValuePair>();
                body.add(new BasicNameValuePair("grant_type", this.authorizationGrantType));
                body.add(new BasicNameValuePair("client_id", this.clientId));
                body.add(new BasicNameValuePair("scope", this.scope));
                body.add(new BasicNameValuePair("assertion", jwt));
                UrlEncodedFormEntity entity = new UrlEncodedFormEntity(body, Consts.UTF_8);
                postMethod.setEntity((HttpEntity)entity);
                responseObj = this.httpClient.execute((HttpUriRequest)postMethod);
                InputStream is = responseObj.getEntity().getContent();
                response = IOUtils.toString((InputStream)is);
                int status = responseObj.getStatusLine().getStatusCode();
                if (status == 200) {
                    response = this.parseAccessToken(response);
                    break block5;
                }
                String msg = String.format("failed to get access token from authorization server status: %s response: %s", String.valueOf(status), response);
                log.error(msg);
                throw new IOException(msg);
            }
            finally {
                HttpClientUtils.closeQuietly((CloseableHttpResponse)responseObj);
                if (postMethod != null) {
                    postMethod.releaseConnection();
                }
            }
        }
        return response;
    }

    private String parseAccessToken(String response) throws IOException {
        try {
            JSONObject json = new JSONObject(response);
            return json.getString("access_token");
        }
        catch (JSONException e) {
            String msg = String.format("failed to parse access token: %s", e.getMessage());
            log.error(msg);
            throw new IOException(msg);
        }
    }

    protected Map<String, String> getDefaultClaims() {
        return this.defaultClaims;
    }

    private String getAccessTokenPath(String clientId) {
        return String.format("oauth/oauthid-%s", clientId);
    }

    private String protect(String accessToken) {
        try {
            return this.cryptoSupport.protect(accessToken);
        }
        catch (Exception e) {
            log.error("failed to protect access token", (Throwable)e);
            return null;
        }
    }

    private String unprotect(String protectedAccessToken) {
        try {
            return this.cryptoSupport.unprotect(protectedAccessToken);
        }
        catch (Exception e) {
            log.error("failed to unprotect access token", (Throwable)e);
            return null;
        }
    }

    protected void bindJwtValidator(JwtValidator jwtValidator) {
        this.jwtValidator = jwtValidator;
    }

    protected void unbindJwtValidator(JwtValidator jwtValidator) {
        if (this.jwtValidator == jwtValidator) {
            this.jwtValidator = null;
        }
    }

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

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

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

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

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

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

}