Skip to content

Commit

Permalink
Add support for org-wide application update
Browse files Browse the repository at this point in the history
  • Loading branch information
YasasRangika committed Jan 2, 2025
1 parent adb0bd5 commit 18fab8e
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3257,4 +3257,7 @@ public static class TransactionCounter {
public static final String TRANSACTIONCOUNTER = "TransactionCounter";
public static final String COUNTER_ENABLED = "Enabled";
}

//Property for enabling application update capabilities for users in the same organization.
public static final String ORGANIZATION_WIDE_APPLICATION_UPDATE_ENABLED = "orgWideAppUpdateEnabled";
}
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ public class APIConsumerImpl extends AbstractAPIManager implements APIConsumer {
private final Object tagCacheMutex = new Object();
protected String userNameWithoutChange;

boolean orgWideAppUpdateEnabled = Boolean.getBoolean(APIConstants.ORGANIZATION_WIDE_APPLICATION_UPDATE_ENABLED);

public APIConsumerImpl() throws APIManagementException {

super();
Expand Down Expand Up @@ -1790,7 +1792,7 @@ public void updateApplication(Application application) throws APIManagementExcep
isUserAppOwner = application.getSubscriber().getName().equals(existingApp.getSubscriber().getName());
}

if (!isUserAppOwner) {
if (!orgWideAppUpdateEnabled && !isUserAppOwner) {
throw new APIManagementException("user: " + application.getSubscriber().getName() + ", " +
"attempted to update application owned by: " + existingApp.getSubscriber().getName());
}
Expand Down Expand Up @@ -1982,7 +1984,7 @@ public void removeApplication(Application application, String username) throws A
isUserAppOwner = application.getSubscriber().getName().equals(username);
}

if (!isUserAppOwner) {
if (!orgWideAppUpdateEnabled && !isUserAppOwner) {
throw new APIManagementException("user: " + username + ", " + "attempted to remove application owned by: "
+ application.getSubscriber().getName());
}
Expand Down Expand Up @@ -2356,7 +2358,7 @@ public Map<String, Object> requestApprovalForApplicationRegistration(String user
isUserAppOwner = application.getSubscriber().getName().equals(userId);
}

if (!isUserAppOwner) {
if (!orgWideAppUpdateEnabled && !isUserAppOwner) {
throw new APIManagementException("user: " + application.getSubscriber().getName() + ", " +
"attempted to generate tokens for application owned by: " + userId);
}
Expand Down Expand Up @@ -2856,7 +2858,7 @@ public OAuthApplicationInfo updateAuthClient(String userId, Application applicat
isUserAppOwner = subscriberName.equals(userId);
}

if (!isUserAppOwner) {
if (!orgWideAppUpdateEnabled && !isUserAppOwner) {
throw new APIManagementException("user: " + userId + ", attempted to update OAuth application " +
"owned by: " + subscriberName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10972,4 +10972,20 @@ public static boolean getTransactionCounterEnable() {
return ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService()
.getAPIManagerConfiguration().getTransactionCounterProperties();
}

/**
* Checks if organization-wide application updates are enabled.
* <p>
* This method retrieves the value of the system property defined by
* ORGANIZATION_WIDE_APPLICATION_UPDATE_ENABLED.
* If the property is not set, it returns false by default.
*
* @return {true} if organization-wide application updates are enabled;
* {false} otherwise.
*/
public static Boolean isOrgWideAppUpdateEnabled() {

return Boolean.getBoolean(
APIConstants.ORGANIZATION_WIDE_APPLICATION_UPDATE_ENABLED);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5625,6 +5625,9 @@ components:
type: boolean
description: Specifies whether Marketplace Assistant feature is enabled.
default: true
orgWideAppUpdateEnabled:
type: boolean
default: false
ApplicationAttribute:
title: Application attributes
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class SettingsDTO {
private Boolean apiChatEnabled = true;
private Boolean aiAuthTokenProvided = false;
private Boolean marketplaceAssistantEnabled = true;
private Boolean orgWideAppUpdateEnabled = false;

/**
**/
Expand Down Expand Up @@ -374,6 +375,23 @@ public void setMarketplaceAssistantEnabled(Boolean marketplaceAssistantEnabled)
this.marketplaceAssistantEnabled = marketplaceAssistantEnabled;
}

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


@ApiModelProperty(value = "")
@JsonProperty("orgWideAppUpdateEnabled")
public Boolean isOrgWideAppUpdateEnabled() {
return orgWideAppUpdateEnabled;
}
public void setOrgWideAppUpdateEnabled(Boolean orgWideAppUpdateEnabled) {
this.orgWideAppUpdateEnabled = orgWideAppUpdateEnabled;
}


@Override
public boolean equals(java.lang.Object o) {
Expand Down Expand Up @@ -402,12 +420,13 @@ public boolean equals(java.lang.Object o) {
Objects.equals(passwordPolicyMaxLength, settings.passwordPolicyMaxLength) &&
Objects.equals(apiChatEnabled, settings.apiChatEnabled) &&
Objects.equals(aiAuthTokenProvided, settings.aiAuthTokenProvided) &&
Objects.equals(marketplaceAssistantEnabled, settings.marketplaceAssistantEnabled);
Objects.equals(marketplaceAssistantEnabled, settings.marketplaceAssistantEnabled) &&
Objects.equals(orgWideAppUpdateEnabled, settings.orgWideAppUpdateEnabled);
}

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

@Override
Expand All @@ -434,6 +453,7 @@ public String toString() {
sb.append(" apiChatEnabled: ").append(toIndentedString(apiChatEnabled)).append("\n");
sb.append(" aiAuthTokenProvided: ").append(toIndentedString(aiAuthTokenProvided)).append("\n");
sb.append(" marketplaceAssistantEnabled: ").append(toIndentedString(marketplaceAssistantEnabled)).append("\n");
sb.append(" orgWideAppUpdateEnabled: ").append(toIndentedString(orgWideAppUpdateEnabled)).append("\n");
sb.append("}");
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
public class ApplicationsApiServiceImpl implements ApplicationsApiService {
private static final Log log = LogFactory.getLog(ApplicationsApiServiceImpl.class);

boolean orgWideAppUpdateEnabled = Boolean.getBoolean(APIConstants.ORGANIZATION_WIDE_APPLICATION_UPDATE_ENABLED);

/**
* Retrieves all the applications that the user has access to
Expand Down Expand Up @@ -458,7 +459,7 @@ public Response applicationsApplicationIdPut(String applicationId, ApplicationDT
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_APPLICATION, applicationId, log);
}

if (!RestAPIStoreUtils.isUserOwnerOfApplication(oldApplication)) {
if (!orgWideAppUpdateEnabled && !RestAPIStoreUtils.isUserOwnerOfApplication(oldApplication)) {
RestApiUtil.handleAuthorizationFailure(RestApiConstants.RESOURCE_APPLICATION, applicationId, log);
}
if (body.getName() != null && !body.getName().equalsIgnoreCase(oldApplication.getName())) {
Expand Down Expand Up @@ -666,7 +667,7 @@ public Response applicationsApplicationIdApiKeysKeyTypeRevokePost(String applica
org.json.JSONObject decodedBody = new org.json.JSONObject(
new String(Base64.getUrlDecoder().decode(splitToken[1])));
if (application != null) {
if (RestAPIStoreUtils.isUserOwnerOfApplication(application)
if (orgWideAppUpdateEnabled || RestAPIStoreUtils.isUserOwnerOfApplication(application)
|| RestAPIStoreUtils.isApplicationSharedtoUser(application)) {
if (decodedBody.getJSONObject(APIConstants.JwtTokenConstants.APPLICATION) != null) {
org.json.JSONObject appInfo =
Expand Down Expand Up @@ -749,7 +750,7 @@ public Response applicationsApplicationIdDelete(String applicationId, String ifM
APIConsumer apiConsumer = APIManagerFactory.getInstance().getAPIConsumer(username);
Application application = apiConsumer.getLightweightApplicationByUUID(applicationId);
if (application != null) {
if (RestAPIStoreUtils.isUserOwnerOfApplication(application)) {
if (orgWideAppUpdateEnabled || RestAPIStoreUtils.isUserOwnerOfApplication(application)) {
apiConsumer.removeApplication(application, username);
if (APIConstants.ApplicationStatus.DELETE_PENDING.equals(application.getStatus())) {
if (application.getId() == -1) {
Expand Down Expand Up @@ -790,7 +791,7 @@ public Response applicationsApplicationIdGenerateKeysPost(String applicationId,
}
Application application = apiConsumer.getApplicationByUUID(applicationId);
if (application != null) {
if (RestAPIStoreUtils.isUserOwnerOfApplication(application)) {
if (orgWideAppUpdateEnabled || RestAPIStoreUtils.isUserOwnerOfApplication(application)) {
String[] accessAllowDomainsArray = {"ALL"};
JSONObject jsonParamObj = new JSONObject();
jsonParamObj.put(ApplicationConstants.OAUTH_CLIENT_USERNAME, username);
Expand Down Expand Up @@ -1071,7 +1072,7 @@ public Response applicationsApplicationIdKeysKeyTypePut(String applicationId, St
APIConsumer apiConsumer = APIManagerFactory.getInstance().getAPIConsumer(username);
Application application = apiConsumer.getApplicationByUUID(applicationId);
if (application != null) {
if (RestAPIStoreUtils.isUserOwnerOfApplication(application)) {
if (orgWideAppUpdateEnabled || RestAPIStoreUtils.isUserOwnerOfApplication(application)) {
String grantTypes = StringUtils.join(body.getSupportedGrantTypes(), ',');
JsonObject jsonParams = new JsonObject();
jsonParams.addProperty(APIConstants.JSON_GRANT_TYPES, grantTypes);
Expand Down Expand Up @@ -1176,7 +1177,7 @@ public Response applicationsApplicationIdMapKeysPost(String applicationId, Appli
keyManagerName = body.getKeyManager();
}
if (application != null) {
if (RestAPIStoreUtils.isUserOwnerOfApplication(application)) {
if (orgWideAppUpdateEnabled || RestAPIStoreUtils.isUserOwnerOfApplication(application)) {
String clientId = body.getConsumerKey();
String keyType = body.getKeyType().toString();
String tokenType = APIConstants.DEFAULT_TOKEN_TYPE;
Expand Down Expand Up @@ -1353,7 +1354,8 @@ public Response applicationsApplicationIdOauthKeysKeyMappingIdPut(String applica
}
if (application != null) {
ApplicationKeyDTO appKey = getApplicationKeyByAppIDAndKeyMapping(applicationId, keyMappingId);
if (RestAPIStoreUtils.isUserOwnerOfApplication(application) && appKey != null) {
if ((orgWideAppUpdateEnabled || RestAPIStoreUtils.isUserOwnerOfApplication(application))
&& appKey != null) {
String grantTypes = StringUtils.join(body.getSupportedGrantTypes(), ',');
JsonObject jsonParams = new JsonObject();
jsonParams.addProperty(APIConstants.JSON_GRANT_TYPES, grantTypes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public SettingsDTO fromSettingstoDTO(Boolean isUserAvailable, Boolean moneatizat
settingsDTO.setRecommendationEnabled(recommendationEnabled);
settingsDTO.setMapExistingAuthApps(APIUtil.isMapExistingAuthAppsEnabled());
settingsDTO.setMonetizationEnabled(moneatizationEnabled);
settingsDTO.setOrgWideAppUpdateEnabled(APIUtil.isOrgWideAppUpdateEnabled());
SettingsIdentityProviderDTO identityProviderDTO = new SettingsIdentityProviderDTO();
identityProviderDTO.setExternal(APIUtil.getIdentityProviderConfig() != null);
settingsDTO.setIdentityProvider(identityProviderDTO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5625,6 +5625,9 @@ components:
type: boolean
description: Specifies whether Marketplace Assistant feature is enabled.
default: true
orgWideAppUpdateEnabled:
type: boolean
default: false
ApplicationAttribute:
title: Application attributes
type: object
Expand Down

0 comments on commit 18fab8e

Please sign in to comment.