Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code refactoring to improve readability #2491

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ public class JWTTokenIssuer extends OauthTokenIssuerImpl {
private static final String MAY_ACT = "may_act";
private static final String SUB = "sub";

private static final boolean renewWithoutRevokingExistingEnabled = Boolean.parseBoolean(IdentityUtil.
getProperty(RENEW_TOKEN_WITHOUT_REVOKING_EXISTING_ENABLE_CONFIG));

public JWTTokenIssuer() throws IdentityOAuth2Exception {

if (log.isDebugEnabled()) {
Expand Down Expand Up @@ -628,8 +631,14 @@ protected JWTClaimsSet createJWTClaimSet(OAuthAuthzReqMessageContext authAuthzRe
}
}
}

// When renew JWT without revoking existing token is enabled, setting the binding type to request.
if (renewWithoutRevokingExistingEnabled) {
setRequestBindingType(tokenReqMessageContext);
}

// Include token binding.
jwtClaimsSet = handleTokenBinding(jwtClaimsSetBuilder, tokenReqMessageContext);
jwtClaimsSet = getJwtClaimSetWithBinding(jwtClaimsSetBuilder, tokenReqMessageContext);

if (tokenReqMessageContext != null && tokenReqMessageContext.getProperty(CNF) != null) {
jwtClaimsSet = handleCnf(jwtClaimsSetBuilder, tokenReqMessageContext);
Expand Down Expand Up @@ -883,8 +892,7 @@ private boolean isUserAccessTokenType(String grantType, OAuthTokenReqMessageCont
return grantHandler.isOfTypeApplicationUser(tokReqMsgCtx);
}

private JWTClaimsSet handleTokenBinding(JWTClaimsSet.Builder jwtClaimsSetBuilder,
OAuthTokenReqMessageContext tokReqMsgCtx) {
private void setRequestBindingType(OAuthTokenReqMessageContext tokReqMsgCtx) {

/**
* If OAuth.JWT.RenewTokenWithoutRevokingExisting is enabled from configurations, and current token
Expand All @@ -906,10 +914,7 @@ private JWTClaimsSet handleTokenBinding(JWTClaimsSet.Builder jwtClaimsSetBuilder
* enable = true
* allowed_grant_types = ["client_credentials","password", ...]
*/
boolean renewWithoutRevokingExistingEnabled = Boolean.parseBoolean(IdentityUtil.
getProperty(RENEW_TOKEN_WITHOUT_REVOKING_EXISTING_ENABLE_CONFIG));

if (renewWithoutRevokingExistingEnabled && tokReqMsgCtx != null && tokReqMsgCtx.getTokenBinding() == null) {
if (tokReqMsgCtx != null && tokReqMsgCtx.getTokenBinding() == null) {
if (OAuth2ServiceComponentHolder.getJwtRenewWithoutRevokeAllowedGrantTypes()
.contains(tokReqMsgCtx.getOauth2AccessTokenReqDTO().getGrantType())) {
String tokenBindingValue = UUID.randomUUID().toString();
Expand All @@ -918,6 +923,10 @@ private JWTClaimsSet handleTokenBinding(JWTClaimsSet.Builder jwtClaimsSetBuilder
tokenBindingValue));
}
}
}

private JWTClaimsSet getJwtClaimSetWithBinding(JWTClaimsSet.Builder jwtClaimsSetBuilder,
OAuthTokenReqMessageContext tokReqMsgCtx) {

if (tokReqMsgCtx != null && tokReqMsgCtx.getTokenBinding() != null) {
// Include token binding into the jwt token.
Expand Down
Loading