Skip to content

Commit

Permalink
Merge pull request #12297 from chamilaadhi/jwt-login
Browse files Browse the repository at this point in the history
Add JWT as default token for portals
  • Loading branch information
chamilaadhi authored Mar 12, 2024
2 parents 37627c9 + ec75e45 commit cd5a45f
Show file tree
Hide file tree
Showing 19 changed files with 144 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1487,6 +1487,7 @@ private OAuthConstants() {
public static final String API_STORE_GROUP_EXTRACTOR_IMPLEMENTATION = API_STORE + "GroupingExtractor";
public static final String API_STORE_REST_API_GROUP_EXTRACTOR_IMPLEMENTATION =
API_STORE + "RESTApiGroupingExtractor";
public static final String IS_ENABLE_JWT_FOR_PORTALS = OAUTH_CONFIGS + "EnableJWTForPortals";
public static final String API_CUSTOM_SEQUENCES_FOLDER_LOCATION =
"repository" + File.separator + "resources" + File.separator + "customsequences";
public static final String WORKFLOW_EXTENSION_LOCATION =
Expand Down Expand Up @@ -2151,6 +2152,8 @@ public static class JwtTokenConstants {
public static final String TOKEN_TYPE = "token_type";
public static final String API_KEY_TOKEN_TYPE = "apiKey";
public static final String DECODING_ALGORITHM_BASE64URL = "base64url";
public static final String APP_DOMAIN = "app_td";
public static final String USER_DOMAIN = "user_td";
}

public static final String SIGNATURE_ALGORITHM_RS256 = "RS256";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7052,6 +7052,24 @@ public static boolean isMultiGroupAppSharingEnabled() {
return Boolean.valueOf(multiGrpAppSharing);
}

/**
* Enable jwt for portal logins
*
* @return boolean value of the config
*/
public static boolean isJWTEnabledForPortals() {

APIManagerConfiguration config = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService()
.getAPIManagerConfiguration();

String isEnabledJwtForPortals = config.getFirstProperty(APIConstants.IS_ENABLE_JWT_FOR_PORTALS);
if (isEnabledJwtForPortals != null) {
return Boolean.valueOf(isEnabledJwtForPortals);
}

return false;

}
/**
* Used to check whether Provisioning Out-of-Band OAuth Clients feature is enabled
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class SettingsDTO {

private List<String> scopes = new ArrayList<String>();
private List<String> gatewayTypes = new ArrayList<String>();
private Boolean isJWTEnabledForLoginTokens = false;
private List<SettingsKeyManagerConfigurationDTO> keyManagerConfiguration = new ArrayList<SettingsKeyManagerConfigurationDTO>();
private Boolean analyticsEnabled = null;

Expand Down Expand Up @@ -62,6 +63,23 @@ public void setGatewayTypes(List<String> gatewayTypes) {
this.gatewayTypes = gatewayTypes;
}

/**
**/
public SettingsDTO isJWTEnabledForLoginTokens(Boolean isJWTEnabledForLoginTokens) {
this.isJWTEnabledForLoginTokens = isJWTEnabledForLoginTokens;
return this;
}


@ApiModelProperty(value = "")
@JsonProperty("IsJWTEnabledForLoginTokens")
public Boolean isIsJWTEnabledForLoginTokens() {
return isJWTEnabledForLoginTokens;
}
public void setIsJWTEnabledForLoginTokens(Boolean isJWTEnabledForLoginTokens) {
this.isJWTEnabledForLoginTokens = isJWTEnabledForLoginTokens;
}

/**
**/
public SettingsDTO keyManagerConfiguration(List<SettingsKeyManagerConfigurationDTO> keyManagerConfiguration) {
Expand Down Expand Up @@ -110,13 +128,14 @@ public boolean equals(java.lang.Object o) {
SettingsDTO settings = (SettingsDTO) o;
return Objects.equals(scopes, settings.scopes) &&
Objects.equals(gatewayTypes, settings.gatewayTypes) &&
Objects.equals(isJWTEnabledForLoginTokens, settings.isJWTEnabledForLoginTokens) &&
Objects.equals(keyManagerConfiguration, settings.keyManagerConfiguration) &&
Objects.equals(analyticsEnabled, settings.analyticsEnabled);
}

@Override
public int hashCode() {
return Objects.hash(scopes, gatewayTypes, keyManagerConfiguration, analyticsEnabled);
return Objects.hash(scopes, gatewayTypes, isJWTEnabledForLoginTokens, keyManagerConfiguration, analyticsEnabled);
}

@Override
Expand All @@ -126,6 +145,7 @@ public String toString() {

sb.append(" scopes: ").append(toIndentedString(scopes)).append("\n");
sb.append(" gatewayTypes: ").append(toIndentedString(gatewayTypes)).append("\n");
sb.append(" isJWTEnabledForLoginTokens: ").append(toIndentedString(isJWTEnabledForLoginTokens)).append("\n");
sb.append(" keyManagerConfiguration: ").append(toIndentedString(keyManagerConfiguration)).append("\n");
sb.append(" analyticsEnabled: ").append(toIndentedString(analyticsEnabled)).append("\n");
sb.append("}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public SettingsDTO fromSettingsToDTO(Boolean isUserAvailable) throws APIManageme
}
settingsDTO.setScopes(getScopeList());
settingsDTO.setGatewayTypes(APIUtil.getGatewayTypes());
settingsDTO.setIsJWTEnabledForLoginTokens(APIUtil.isJWTEnabledForPortals());
return settingsDTO;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4594,6 +4594,9 @@ components:
type: array
items:
type: string
IsJWTEnabledForLoginTokens:
type: boolean
default: false
keyManagerConfiguration:
type: array
items:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4594,6 +4594,9 @@ components:
type: array
items:
type: string
IsJWTEnabledForLoginTokens:
type: boolean
default: false
keyManagerConfiguration:
type: array
items:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5290,6 +5290,9 @@ components:
IsPasswordChangeEnabled:
type: boolean
default: true
IsJWTEnabledForLoginTokens:
type: boolean
default: false
userStorePasswordPattern:
type: string
description: The 'PasswordJavaRegEx' cofigured in the UserStoreManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11915,6 +11915,9 @@ components:
type: string
description: Authorization Header
example: authorization
IsJWTEnabledForLoginTokens:
type: boolean
default: false
customProperties:
type: array
items:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class RegistrationProfile {
private boolean saasApp;
private String audience;
private String tokenType;
private boolean userstoreDomainInSubject;

public String getRecepientValidationURL() {
return recepientValidationURL;
Expand Down Expand Up @@ -215,4 +216,12 @@ public void setTokenType(String tokenType) {
this.tokenType = tokenType;
}

public boolean isUserStoreDomainInSubject() {
return userstoreDomainInSubject;
}

public void setUserStoreDomainInSubject(boolean setUserStoreDomainInSubject) {
this.userstoreDomainInSubject = setUserStoreDomainInSubject;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ public Response register(RegistrationProfile profile) {
returnedAPP = this.getExistingApp(applicationName, appServiceProvider.isSaasApp());
} else {
//create a new application if the application doesn't exists.
returnedAPP = this.createApplication(applicationName, appRequest, grantTypes);
returnedAPP = this.createApplication(applicationName, appRequest, grantTypes,
profile.isUserStoreDomainInSubject());
}
//ReturnedAPP is null
if (returnedAPP == null) {
Expand Down Expand Up @@ -278,8 +279,8 @@ private OAuthApplicationInfo getExistingApp(String applicationName, boolean saas
* @return created Application
* @throws APIManagementException if failed to create the new application
*/
private OAuthApplicationInfo createApplication(String applicationName, OAuthAppRequest appRequest,
String grantType) throws APIManagementException {
private OAuthApplicationInfo createApplication(String applicationName, OAuthAppRequest appRequest, String grantType,
boolean setUserStoreDomainInSubject) throws APIManagementException {
String userName;
OAuthApplicationInfo applicationInfo = appRequest.getOAuthApplicationInfo();
String appName = applicationInfo.getClientName();
Expand Down Expand Up @@ -325,15 +326,15 @@ private OAuthApplicationInfo createApplication(String applicationName, OAuthAppR
logoutConsentProperty.setName(APIConstants.APP_SKIP_LOGOUT_CONSENT_NAME);
logoutConsentProperty.setValue(APIConstants.APP_SKIP_LOGOUT_CONSENT_VALUE);
serviceProviderProperties.add(logoutConsentProperty);

if (APIConstants.JWT.equals(applicationInfo.getTokenType())) {
LocalAndOutboundAuthenticationConfig localAndOutboundConfig =
new LocalAndOutboundAuthenticationConfig();
localAndOutboundConfig.setSkipConsent(true);
localAndOutboundConfig.setSkipLogoutConsent(true);
localAndOutboundConfig.setUseTenantDomainInLocalSubjectIdentifier(true);

if (setUserStoreDomainInSubject) {
LocalAndOutboundAuthenticationConfig localAndOutboundConfig = new LocalAndOutboundAuthenticationConfig();
localAndOutboundConfig.setSkipConsent(true); // to prevent overriding
localAndOutboundConfig.setSkipLogoutConsent(true); // to prevent overriding
localAndOutboundConfig.setUseUserstoreDomainInLocalSubjectIdentifier(true);
serviceProvider.setLocalAndOutBoundAuthenticationConfig(localAndOutboundConfig);
}

String orgId = null;
try {
orgId = RestApiUtil.getValidatedOrganization(securityContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ components:
type: string
readOnly: true
example: JWT
userstoreDomainInSubject:
type: string
readOnly: true
example: true
DCRResult:
title: DCRResult
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class SettingsDTO {
private String defaultAdvancePolicy = null;
private String defaultSubscriptionPolicy = null;
private String authorizationHeader = null;
private Boolean isJWTEnabledForLoginTokens = false;
private List<SettingsCustomPropertiesDTO> customProperties = new ArrayList<SettingsCustomPropertiesDTO>();

/**
Expand Down Expand Up @@ -273,6 +274,23 @@ public void setAuthorizationHeader(String authorizationHeader) {
this.authorizationHeader = authorizationHeader;
}

/**
**/
public SettingsDTO isJWTEnabledForLoginTokens(Boolean isJWTEnabledForLoginTokens) {
this.isJWTEnabledForLoginTokens = isJWTEnabledForLoginTokens;
return this;
}


@ApiModelProperty(value = "")
@JsonProperty("IsJWTEnabledForLoginTokens")
public Boolean isIsJWTEnabledForLoginTokens() {
return isJWTEnabledForLoginTokens;
}
public void setIsJWTEnabledForLoginTokens(Boolean isJWTEnabledForLoginTokens) {
this.isJWTEnabledForLoginTokens = isJWTEnabledForLoginTokens;
}

/**
**/
public SettingsDTO customProperties(List<SettingsCustomPropertiesDTO> customProperties) {
Expand Down Expand Up @@ -314,12 +332,13 @@ public boolean equals(java.lang.Object o) {
Objects.equals(defaultAdvancePolicy, settings.defaultAdvancePolicy) &&
Objects.equals(defaultSubscriptionPolicy, settings.defaultSubscriptionPolicy) &&
Objects.equals(authorizationHeader, settings.authorizationHeader) &&
Objects.equals(isJWTEnabledForLoginTokens, settings.isJWTEnabledForLoginTokens) &&
Objects.equals(customProperties, settings.customProperties);
}

@Override
public int hashCode() {
return Objects.hash(devportalUrl, environment, gatewayTypes, scopes, monetizationAttributes, subscriberContactAttributes, securityAuditProperties, externalStoresEnabled, docVisibilityEnabled, crossTenantSubscriptionEnabled, defaultAdvancePolicy, defaultSubscriptionPolicy, authorizationHeader, customProperties);
return Objects.hash(devportalUrl, environment, gatewayTypes, scopes, monetizationAttributes, subscriberContactAttributes, securityAuditProperties, externalStoresEnabled, docVisibilityEnabled, crossTenantSubscriptionEnabled, defaultAdvancePolicy, defaultSubscriptionPolicy, authorizationHeader, isJWTEnabledForLoginTokens, customProperties);
}

@Override
Expand All @@ -340,6 +359,7 @@ public String toString() {
sb.append(" defaultAdvancePolicy: ").append(toIndentedString(defaultAdvancePolicy)).append("\n");
sb.append(" defaultSubscriptionPolicy: ").append(toIndentedString(defaultSubscriptionPolicy)).append("\n");
sb.append(" authorizationHeader: ").append(toIndentedString(authorizationHeader)).append("\n");
sb.append(" isJWTEnabledForLoginTokens: ").append(toIndentedString(isJWTEnabledForLoginTokens)).append("\n");
sb.append(" customProperties: ").append(toIndentedString(customProperties)).append("\n");
sb.append("}");
return sb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public SettingsDTO fromSettingstoDTO(Boolean isUserAvailable, String organizatio
APIUtil.isExternalStoresEnabled(RestApiCommonUtil.getLoggedInUserTenantDomain()));
settingsDTO.setDocVisibilityEnabled(APIUtil.isDocVisibilityLevelsEnabled());
settingsDTO.setCrossTenantSubscriptionEnabled(APIUtil.isCrossTenantSubscriptionsEnabled());
settingsDTO.setIsJWTEnabledForLoginTokens(APIUtil.isJWTEnabledForPortals());
Map<String, Environment> gatewayEnvironments = APIUtil.getReadOnlyGatewayEnvironments();
String authorizationHeader = APIUtil.getOAuthConfiguration(loggedInUserTenantDomain,
APIConstants.AUTHORIZATION_HEADER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11915,6 +11915,9 @@ components:
type: string
description: Authorization Header
example: authorization
IsJWTEnabledForLoginTokens:
type: boolean
default: false
customProperties:
type: array
items:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class SettingsDTO {
private SettingsIdentityProviderDTO identityProvider = null;
private Boolean isAnonymousModeEnabled = true;
private Boolean isPasswordChangeEnabled = true;
private Boolean isJWTEnabledForLoginTokens = false;
private String userStorePasswordPattern = null;
private String passwordPolicyPattern = null;
private Integer passwordPolicyMinLength = null;
Expand Down Expand Up @@ -227,6 +228,23 @@ public void setIsPasswordChangeEnabled(Boolean isPasswordChangeEnabled) {
this.isPasswordChangeEnabled = isPasswordChangeEnabled;
}

/**
**/
public SettingsDTO isJWTEnabledForLoginTokens(Boolean isJWTEnabledForLoginTokens) {
this.isJWTEnabledForLoginTokens = isJWTEnabledForLoginTokens;
return this;
}


@ApiModelProperty(value = "")
@JsonProperty("IsJWTEnabledForLoginTokens")
public Boolean isIsJWTEnabledForLoginTokens() {
return isJWTEnabledForLoginTokens;
}
public void setIsJWTEnabledForLoginTokens(Boolean isJWTEnabledForLoginTokens) {
this.isJWTEnabledForLoginTokens = isJWTEnabledForLoginTokens;
}

/**
* The &#39;PasswordJavaRegEx&#39; cofigured in the UserStoreManager
**/
Expand Down Expand Up @@ -320,6 +338,7 @@ public boolean equals(java.lang.Object o) {
Objects.equals(identityProvider, settings.identityProvider) &&
Objects.equals(isAnonymousModeEnabled, settings.isAnonymousModeEnabled) &&
Objects.equals(isPasswordChangeEnabled, settings.isPasswordChangeEnabled) &&
Objects.equals(isJWTEnabledForLoginTokens, settings.isJWTEnabledForLoginTokens) &&
Objects.equals(userStorePasswordPattern, settings.userStorePasswordPattern) &&
Objects.equals(passwordPolicyPattern, settings.passwordPolicyPattern) &&
Objects.equals(passwordPolicyMinLength, settings.passwordPolicyMinLength) &&
Expand All @@ -328,7 +347,7 @@ public boolean equals(java.lang.Object o) {

@Override
public int hashCode() {
return Objects.hash(grantTypes, scopes, applicationSharingEnabled, mapExistingAuthApps, apiGatewayEndpoint, monetizationEnabled, recommendationEnabled, isUnlimitedTierPaid, identityProvider, isAnonymousModeEnabled, isPasswordChangeEnabled, userStorePasswordPattern, passwordPolicyPattern, passwordPolicyMinLength, passwordPolicyMaxLength);
return Objects.hash(grantTypes, scopes, applicationSharingEnabled, mapExistingAuthApps, apiGatewayEndpoint, monetizationEnabled, recommendationEnabled, isUnlimitedTierPaid, identityProvider, isAnonymousModeEnabled, isPasswordChangeEnabled, isJWTEnabledForLoginTokens, userStorePasswordPattern, passwordPolicyPattern, passwordPolicyMinLength, passwordPolicyMaxLength);
}

@Override
Expand All @@ -347,6 +366,7 @@ public String toString() {
sb.append(" identityProvider: ").append(toIndentedString(identityProvider)).append("\n");
sb.append(" isAnonymousModeEnabled: ").append(toIndentedString(isAnonymousModeEnabled)).append("\n");
sb.append(" isPasswordChangeEnabled: ").append(toIndentedString(isPasswordChangeEnabled)).append("\n");
sb.append(" isJWTEnabledForLoginTokens: ").append(toIndentedString(isJWTEnabledForLoginTokens)).append("\n");
sb.append(" userStorePasswordPattern: ").append(toIndentedString(userStorePasswordPattern)).append("\n");
sb.append(" passwordPolicyPattern: ").append(toIndentedString(passwordPolicyPattern)).append("\n");
sb.append(" passwordPolicyMinLength: ").append(toIndentedString(passwordPolicyMinLength)).append("\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public SettingsDTO fromSettingstoDTO(Boolean isUserAvailable, Boolean moneatizat
SettingsDTO settingsDTO = new SettingsDTO();
settingsDTO.setScopes(GetScopeList());
settingsDTO.setApplicationSharingEnabled(APIUtil.isMultiGroupAppSharingEnabled());
settingsDTO.setIsJWTEnabledForLoginTokens(APIUtil.isJWTEnabledForPortals());
settingsDTO.setRecommendationEnabled(recommendationEnabled);
settingsDTO.setMapExistingAuthApps(APIUtil.isMapExistingAuthAppsEnabled());
settingsDTO.setMonetizationEnabled(moneatizationEnabled);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5290,6 +5290,9 @@ components:
IsPasswordChangeEnabled:
type: boolean
default: true
IsJWTEnabledForLoginTokens:
type: boolean
default: false
userStorePasswordPattern:
type: string
description: The 'PasswordJavaRegEx' cofigured in the UserStoreManager
Expand Down
Loading

0 comments on commit cd5a45f

Please sign in to comment.