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

Check for multi groups #12191

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
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 @@ -631,7 +631,8 @@ public Response applicationsApplicationIdApiKeysKeyTypeRevokePost(String applica
new String(Base64.getUrlDecoder().decode(splitToken[1])));
org.json.JSONObject appInfo = decodedBody.getJSONObject(APIConstants.JwtTokenConstants.APPLICATION);
if (appInfo != null && application != null) {
if (RestAPIStoreUtils.isUserOwnerOfApplication(application)) {
if (RestAPIStoreUtils.isUserOwnerOfApplication(application)
|| RestAPIStoreUtils.isApplicationSharedtoUser(application)) {
String appUuid = appInfo.getString(APIConstants.JwtTokenConstants.APPLICATION_UUID);
if (applicationId.equals(appUuid)) {
long expiryTime = Long.MAX_VALUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,29 @@
return false;
}

/**
* check whether an application is shared with the current logged-in user
*
* @param application Application object
* @return true if the application is shared with the current logged-in user
*/
public static boolean isApplicationSharedtoUser(Application application) {
boolean multiGroupAppSharingEnabled = APIUtil.isMultiGroupAppSharingEnabled();

Check warning on line 121 in components/apimgt/org.wso2.carbon.apimgt.rest.api.util/src/main/java/org/wso2/carbon/apimgt/rest/api/util/utils/RestAPIStoreUtils.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.rest.api.util/src/main/java/org/wso2/carbon/apimgt/rest/api/util/utils/RestAPIStoreUtils.java#L121

Added line #L121 was not covered by tests
if (multiGroupAppSharingEnabled) {
String groupId = application.getGroupId();
String userGroupId = RestApiUtil.getLoggedInUserGroupId();

Check warning on line 124 in components/apimgt/org.wso2.carbon.apimgt.rest.api.util/src/main/java/org/wso2/carbon/apimgt/rest/api/util/utils/RestAPIStoreUtils.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.rest.api.util/src/main/java/org/wso2/carbon/apimgt/rest/api/util/utils/RestAPIStoreUtils.java#L123-L124

Added lines #L123 - L124 were not covered by tests
if (groupId != null && userGroupId != null) {
String[] grpIdArray = groupId.split(",");

Check warning on line 126 in components/apimgt/org.wso2.carbon.apimgt.rest.api.util/src/main/java/org/wso2/carbon/apimgt/rest/api/util/utils/RestAPIStoreUtils.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.rest.api.util/src/main/java/org/wso2/carbon/apimgt/rest/api/util/utils/RestAPIStoreUtils.java#L126

Added line #L126 was not covered by tests
for (String id : grpIdArray) {
if (id.equals(userGroupId)) {
return true;

Check warning on line 129 in components/apimgt/org.wso2.carbon.apimgt.rest.api.util/src/main/java/org/wso2/carbon/apimgt/rest/api/util/utils/RestAPIStoreUtils.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.rest.api.util/src/main/java/org/wso2/carbon/apimgt/rest/api/util/utils/RestAPIStoreUtils.java#L129

Added line #L129 was not covered by tests
}
}
}
}
return false;

Check warning on line 134 in components/apimgt/org.wso2.carbon.apimgt.rest.api.util/src/main/java/org/wso2/carbon/apimgt/rest/api/util/utils/RestAPIStoreUtils.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.rest.api.util/src/main/java/org/wso2/carbon/apimgt/rest/api/util/utils/RestAPIStoreUtils.java#L134

Added line #L134 was not covered by tests
}

/**
* Check whether the specified API exists and the current logged in user has access to it.
* <p>
Expand Down
Loading