Skip to content

Commit

Permalink
Add createTokenValidator method in OidcOpMetadataResolver in orde…
Browse files Browse the repository at this point in the history
…r to reduce copy-pasted code (#2885)

* Add `createTokenValidator()` method in `OidcOpMetadataResolver` in order to reduce copy-paste

* remove unused import

---------

Co-authored-by: dpodaruev <dpodaruev@naumen.ru>
  • Loading branch information
ddqof and dpodaruev committed May 13, 2024
1 parent 92b5ac9 commit be321de
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.extern.slf4j.Slf4j;
import org.pac4j.oidc.config.OidcConfiguration;
import org.pac4j.oidc.profile.azuread.AzureAdTokenValidator;
import org.pac4j.oidc.profile.creator.TokenValidator;

/**
* The metadata resolver for AzureAd.
Expand All @@ -22,13 +23,8 @@ public AzureAdOpMetadataResolver(final OidcConfiguration configuration) {
super(configuration);
}

/** {@inheritDoc} */
@Override
protected void internalLoad() {
this.loaded = retrieveMetadata();

this.clientAuthentication = computeClientAuthentication();

this.tokenValidator = new AzureAdTokenValidator(configuration, this.loaded);
protected TokenValidator createTokenValidator() {
return new AzureAdTokenValidator(configuration, this.loaded);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected void internalLoad() {

this.clientAuthentication = computeClientAuthentication();

this.tokenValidator = new TokenValidator(configuration, this.loaded);
this.tokenValidator = createTokenValidator();
}

/**
Expand Down Expand Up @@ -175,8 +175,8 @@ private static ClientAuthenticationMethod getPreferredAuthenticationMethod(OidcC
}

private static ClientAuthenticationMethod firstSupportedMethod(
final Collection<ClientAuthenticationMethod> serverSupportedAuthMethods,
Collection<ClientAuthenticationMethod> clientSupportedAuthMethods) {
final Collection<ClientAuthenticationMethod> serverSupportedAuthMethods,
Collection<ClientAuthenticationMethod> clientSupportedAuthMethods) {
Collection<ClientAuthenticationMethod> supportedMethods =
clientSupportedAuthMethods != null ? clientSupportedAuthMethods : SUPPORTED_METHODS;
var firstSupported =
Expand All @@ -188,4 +188,13 @@ private static ClientAuthenticationMethod firstSupportedMethod(
+ "supported: " + serverSupportedAuthMethods);
}
}

/**
* <p>createTokenValidator.</p>
*
* @return a {@link TokenValidator} object
*/
protected TokenValidator createTokenValidator() {
return new TokenValidator(configuration, this.loaded);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.nimbusds.openid.connect.sdk.op.OIDCProviderMetadata;
import org.pac4j.oidc.config.OidcConfiguration;
import org.pac4j.oidc.profile.creator.TokenValidator;

/**
* An OP metadata resolver with static metadata.
Expand Down Expand Up @@ -32,6 +31,6 @@ protected void internalLoad() {

this.clientAuthentication = computeClientAuthentication();

this.tokenValidator = new TokenValidator(configuration, this.loaded);
this.tokenValidator = createTokenValidator();
}
}

0 comments on commit be321de

Please sign in to comment.