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

Key Manager Visibility in Developer Portal #12163

Merged
merged 38 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d1cfc17
Added the DAO layer for Managing KeyManagerPermissions
Kirishikesan Aug 31, 2023
ca79bbc
Adds KeyManagerPermissionDTO
Kirishikesan Sep 5, 2023
7ed5efd
Changes in DB layer for KeyManagerPermissions
Kirishikesan Sep 5, 2023
8ba9eee
Merge branch 'master' of https://github.com/Kirishikesan/carbon-apimgt
Kirishikesan Sep 5, 2023
9e11194
Merge branch 'master' of https://github.com/Kirishikesan/carbon-apimgt
Kirishikesan Sep 18, 2023
9a74cdb
Adding the dao calls for key manager permissions
Kirishikesan Sep 26, 2023
65dfb48
Adds consumer layer implementation with dao
Kirishikesan Sep 26, 2023
876c4a2
Adds DTO in admin and publiser portals
Kirishikesan Sep 26, 2023
8b03d08
Adds database layer
Kirishikesan Sep 26, 2023
f6c5ea3
Adds api service layer
Kirishikesan Sep 26, 2023
12c3ac1
Adds api schema changes
Kirishikesan Sep 26, 2023
3504c89
Merge branch 'master' of https://github.com/Kirishikesan/carbon-apimgt
Kirishikesan Sep 26, 2023
92ae809
Removes import all
Kirishikesan Sep 26, 2023
d697fd0
Remove publisher portal role restriction warning
Kirishikesan Oct 2, 2023
ffb742c
Remove generated KeyManagerInfoDTO changes
Kirishikesan Oct 2, 2023
7bca24f
Changes KeyManagerPermissionConfigurationDTO schema by reducing redun…
Kirishikesan Oct 2, 2023
a46dd0a
Changes KeyManagerPermissionConfigurationDTO by removing permissionTy…
Kirishikesan Oct 2, 2023
fbe9f34
Changes KeyManagerPermissions CRUD logic to DAO level
Kirishikesan Oct 3, 2023
702e01b
Refactor isKeyManagerAllowedForUser method to be reused
Kirishikesan Oct 3, 2023
7ee04c3
Add role validation in rest api level
Kirishikesan Oct 4, 2023
dc288f9
Removes unused DAO methods
Kirishikesan Oct 4, 2023
31c2620
Changes to adhere to wso2 checkstyle
Kirishikesan Oct 4, 2023
1ab19fc
Adding error code for restricted key manager access
Kirishikesan Oct 5, 2023
ed65537
Changes in DB scripts
Kirishikesan Oct 5, 2023
561d53f
Fix retrieving multiple permissions
Kirishikesan Oct 16, 2023
9fa329b
Add keymanager permission checks for updating oauth keys and keytype
Kirishikesan Oct 20, 2023
879bd66
Add keymanagerpermissions when fetched by organization
Kirishikesan Oct 20, 2023
f8d34ac
KeyManager Restriction in KeyType call
Kirishikesan Oct 20, 2023
f75015b
Remove key manager restrictions in applicationsApplicationIdKeysKeyTy…
Kirishikesan Oct 20, 2023
dfa2ad9
Remove unused imports
Kirishikesan Oct 20, 2023
5904e8d
Merge branch 'wso2:master' into master
Kirishikesan Dec 19, 2023
cfc8569
Optimise has Intersection method
Kirishikesan Dec 19, 2023
f3c1bd0
Adds a constant for Public permission
Kirishikesan Dec 19, 2023
b1f1bce
Fixes an indentation
Kirishikesan Dec 19, 2023
cbd1b21
Adds comments in APIConsumerImpl
Kirishikesan Dec 22, 2023
094e532
Adds license header and formatting
Kirishikesan Jan 5, 2024
1d58204
Formatting Issues
Kirishikesan Jan 8, 2024
91ce624
Changes License header
Kirishikesan Jan 8, 2024
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 @@ -18,6 +18,7 @@
package org.wso2.carbon.apimgt.api;

import org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO;
import org.wso2.carbon.apimgt.api.dto.KeyManagerPermissionConfigurationDTO;
import org.wso2.carbon.apimgt.api.model.APICategory;
import org.wso2.carbon.apimgt.api.model.Application;
import org.wso2.carbon.apimgt.api.model.ApplicationInfo;
Expand Down Expand Up @@ -332,6 +333,14 @@ KeyManagerConfigurationDTO addKeyManagerConfiguration(KeyManagerConfigurationDTO
KeyManagerConfigurationDTO updateKeyManagerConfiguration(KeyManagerConfigurationDTO keyManagerConfigurationDTO)
throws APIManagementException;

/**
* This method used to get key manager permissions with key manager id and role
* @param id uuid of key manager
* @return key manager permissions
* @throws APIManagementException
*/
KeyManagerPermissionConfigurationDTO getKeyManagerPermissions(String id) throws APIManagementException;

/**
* hTis method used to delete IDP mapped with key manager
* @param organization organization requested
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO;
import org.wso2.carbon.apimgt.api.model.API;
import org.wso2.carbon.apimgt.api.model.APIIdentifier;
import org.wso2.carbon.apimgt.api.model.APIKey;
Expand Down Expand Up @@ -797,4 +798,35 @@ Set<SubscribedAPI> getPaginatedSubscribedAPIsByApplication(Application applicati
* @throws APIManagementException if failed to retrieve policy.
*/
Tier getThrottlePolicyByName(String name, int policyType, String organization) throws APIManagementException;

/**
* This method used to retrieve key manager configurations for tenant
* @param organization organization of the key manager
* @param username username of the logged in user
* @return KeyManagerConfigurationDTO list
* @throws APIManagementException if error occurred
*/
List<KeyManagerConfigurationDTO> getKeyManagerConfigurationsByOrganization(String organization, String username)
throws APIManagementException;

/**
* This method used to check if key manager configuration is allowed for user
* @param keyManagerId uuid of the key manager
* @param username username of the logged in user
* @return boolean
* @throws APIManagementException if error occurred
*/
boolean isKeyManagerAllowedForUser(String keyManagerId, String username) throws APIManagementException;

/**
* This method used to check if key manager configuration by name is allowed for user
* @param keyManagerName name of the key manager
* @param organization organization of the logged in user
* @param username username of the logged in user
* @return boolean
* @throws APIManagementException if error occurred
*/
boolean isKeyManagerByNameAllowedForUser(String keyManagerName, String organization, String username)
throws APIManagementException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@
"Revision deployment request conflicted with the current deployment state of the revision %s. Please try again later", false),
INVALID_API_ID(902006, "Invalid API ID", 404, "The provided API ID is not found %s", false),
INVALID_ENDPOINT_CONFIG(902012, "Endpoint config value(s) is(are) not valid", 400, "Endpoint config value(s) is(are) not valid"),
KEY_MANAGER_RESTRICTED_FOR_USER(902013, "Unauthorized Access to Key Manager", 403, "Key Manager is Restricted for this user"),

Check warning on line 544 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/ExceptionCodes.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/ExceptionCodes.java#L544

Added line #L544 was not covered by tests
ARTIFACT_SYNC_HTTP_REQUEST_FAILED(903009, "Error while retrieving from remote endpoint", 500, "Error while executing HTTP request to retrieve from remote endpoint");

private final long errorCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
private String tokenType;
private String externalReferenceId = null;
private String alias = null;
private KeyManagerPermissionConfigurationDTO permissions = new KeyManagerPermissionConfigurationDTO();

Check warning on line 45 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/KeyManagerConfigurationDTO.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/KeyManagerConfigurationDTO.java#L45

Added line #L45 was not covered by tests

public KeyManagerConfigurationDTO() {

}

public KeyManagerConfigurationDTO(KeyManagerConfigurationDTO keyManagerConfigurationDTO) {
Expand All @@ -60,6 +60,7 @@
this.tokenType = keyManagerConfigurationDTO.getTokenType();
this.externalReferenceId = keyManagerConfigurationDTO.getExternalReferenceId();
this.endpoints = keyManagerConfigurationDTO.getEndpoints();
this.setPermissions(keyManagerConfigurationDTO.getPermissions());

Check warning on line 63 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/KeyManagerConfigurationDTO.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/KeyManagerConfigurationDTO.java#L63

Added line #L63 was not covered by tests
}
public String getName() {

Expand Down Expand Up @@ -184,4 +185,15 @@

this.endpoints = endpoints;
}

public KeyManagerPermissionConfigurationDTO getPermissions () {
return permissions;

Check warning on line 190 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/KeyManagerConfigurationDTO.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/KeyManagerConfigurationDTO.java#L190

Added line #L190 was not covered by tests
}

public void setPermissions (KeyManagerPermissionConfigurationDTO permissions) {
if (permissions == null) {
permissions = new KeyManagerPermissionConfigurationDTO();

Check warning on line 195 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/KeyManagerConfigurationDTO.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/KeyManagerConfigurationDTO.java#L195

Added line #L195 was not covered by tests
}
this.permissions = permissions;
}

Check warning on line 198 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/KeyManagerConfigurationDTO.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/KeyManagerConfigurationDTO.java#L197-L198

Added lines #L197 - L198 were not covered by tests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.apimgt.api.dto;
Kirishikesan marked this conversation as resolved.
Show resolved Hide resolved


import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
*KeyManagerPermissionConfiguration model
*/
public class KeyManagerPermissionConfigurationDTO implements Serializable {

private String permissionType = null;
private List<String> roles = new ArrayList<String>();

Check warning on line 32 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/KeyManagerPermissionConfigurationDTO.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/KeyManagerPermissionConfigurationDTO.java#L31-L32

Added lines #L31 - L32 were not covered by tests

public KeyManagerPermissionConfigurationDTO () {
this.setPermissionType("PUBLIC");
}

Check warning on line 36 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/KeyManagerPermissionConfigurationDTO.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/KeyManagerPermissionConfigurationDTO.java#L34-L36

Added lines #L34 - L36 were not covered by tests

public KeyManagerPermissionConfigurationDTO(String permissionType, List<String> roles) {
this.permissionType = permissionType;
this.roles = roles;
}

Check warning on line 41 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/KeyManagerPermissionConfigurationDTO.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/KeyManagerPermissionConfigurationDTO.java#L38-L41

Added lines #L38 - L41 were not covered by tests

public String getPermissionType () {
return permissionType;

Check warning on line 44 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/KeyManagerPermissionConfigurationDTO.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/KeyManagerPermissionConfigurationDTO.java#L44

Added line #L44 was not covered by tests
}

public void setPermissionType (String permissionType) {
this.permissionType = permissionType;
}

Check warning on line 49 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/KeyManagerPermissionConfigurationDTO.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/KeyManagerPermissionConfigurationDTO.java#L48-L49

Added lines #L48 - L49 were not covered by tests

public List<String> getRoles() {
return roles;

Check warning on line 52 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/KeyManagerPermissionConfigurationDTO.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/KeyManagerPermissionConfigurationDTO.java#L52

Added line #L52 was not covered by tests
}

public void setRoles(List<String> roles) {
if (roles == null) {
return;

Check warning on line 57 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/KeyManagerPermissionConfigurationDTO.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/KeyManagerPermissionConfigurationDTO.java#L57

Added line #L57 was not covered by tests
}
this.roles = roles;
}

Check warning on line 60 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/KeyManagerPermissionConfigurationDTO.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/KeyManagerPermissionConfigurationDTO.java#L59-L60

Added lines #L59 - L60 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException;
import org.wso2.carbon.apimgt.api.ExceptionCodes;
import org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO;
import org.wso2.carbon.apimgt.api.dto.KeyManagerPermissionConfigurationDTO;
import org.wso2.carbon.apimgt.api.model.APICategory;
import org.wso2.carbon.apimgt.api.model.Application;
import org.wso2.carbon.apimgt.api.model.ApplicationInfo;
Expand Down Expand Up @@ -745,6 +746,17 @@
.notify(decryptedKeyManagerConfiguration, APIConstants.KeyManager.KeyManagerEvent.ACTION_UPDATE);
return keyManagerConfigurationDTO;
}
@Override

Check warning on line 749 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIAdminImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIAdminImpl.java#L749

Added line #L749 was not covered by tests
public KeyManagerPermissionConfigurationDTO getKeyManagerPermissions(String id) throws APIManagementException {

KeyManagerPermissionConfigurationDTO keyManagerPermissionConfigurationDTO;

Check warning on line 752 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIAdminImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIAdminImpl.java#L752

Added line #L752 was not covered by tests
try {
keyManagerPermissionConfigurationDTO = apiMgtDAO.getKeyManagerPermissions(id);

Check warning on line 754 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIAdminImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIAdminImpl.java#L754

Added line #L754 was not covered by tests
} catch (APIManagementException e) {
throw new APIManagementException("Key Manager Permissions retrieval failed for Key Manager id " + id, e);

Check warning on line 756 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIAdminImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIAdminImpl.java#L756

Added line #L756 was not covered by tests
}
return keyManagerPermissionConfigurationDTO;
}

private IdentityProvider updatedIDP(IdentityProvider retrievedIDP,
KeyManagerConfigurationDTO keyManagerConfigurationDTO) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2596,6 +2596,9 @@ public static class KeyManager {
public static final String PKCE_MANDATORY = "pkceMandatory";
public static final String PKCE_SUPPORT_PLAIN = "pkceSupportPlain";
public static final String BYPASS_CLIENT_CREDENTIALS = "bypassClientCredentials";
public static final String PERMISSIONS = "permissions";
public static final String ROLES = "roles";
public static final String PERMISSION_TYPE = "permissionType";

public static class KeyManagerEvent {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
import org.json.simple.parser.ParseException;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.apimgt.api.APIConsumer;
import org.wso2.carbon.apimgt.api.APIAdmin;
import org.wso2.carbon.apimgt.api.APIDefinition;
import org.wso2.carbon.apimgt.api.APIManagementException;
import org.wso2.carbon.apimgt.api.APIMgtAuthorizationFailedException;
import org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException;
import org.wso2.carbon.apimgt.api.ExceptionCodes;
import org.wso2.carbon.apimgt.api.WorkflowResponse;
import org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO;
import org.wso2.carbon.apimgt.api.dto.KeyManagerPermissionConfigurationDTO;
import org.wso2.carbon.apimgt.api.model.API;
import org.wso2.carbon.apimgt.api.model.APIIdentifier;
import org.wso2.carbon.apimgt.api.model.APIKey;
Expand Down Expand Up @@ -188,6 +190,9 @@
public static final String API_NAME = "apiName";
public static final String API_VERSION = "apiVersion";
public static final String API_PROVIDER = "apiProvider";
private static final String PERMISSION_ALLOW = "ALLOW";
private static final String PERMISSION_DENY = "DENY";
private static final String PERMISSION_NOT_RESTRICTED = "PUBLIC";
private static final String PRESERVED_CASE_SENSITIVE_VARIABLE = "preservedCaseSensitive";

private static final String GET_SUB_WORKFLOW_REF_FAILED = "Failed to get external workflow reference for subscription ";
Expand Down Expand Up @@ -4234,4 +4239,106 @@
apiTypeWrapper.getTier(), username));
}
}

/**
* This method is used to retrieve key manager configurations for tenant
* @param organization organization of the key manager
Kirishikesan marked this conversation as resolved.
Show resolved Hide resolved
* @param username username of the logged-in user
* @return KeyManagerConfigurationDTO list
* @throws APIManagementException if error occurred
*/
@Override
public List<KeyManagerConfigurationDTO> getKeyManagerConfigurationsByOrganization(
String organization, String username) throws APIManagementException {

APIAdmin apiAdmin = new APIAdminImpl();
List<KeyManagerConfigurationDTO> keyManagerConfigurations =
apiAdmin.getKeyManagerConfigurationsByOrganization(organization);
List<KeyManagerConfigurationDTO> permittedKeyManagerConfigurations = new ArrayList<>();
if (keyManagerConfigurations.size() > 0) {

Check warning on line 4258 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java#L4255-L4258

Added lines #L4255 - L4258 were not covered by tests
for (KeyManagerConfigurationDTO keyManagerConfiguration : keyManagerConfigurations) {
if (isKeyManagerAllowedForUser(keyManagerConfiguration.getUuid(), username)) {
permittedKeyManagerConfigurations.add(keyManagerConfiguration);
}

Check warning on line 4262 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java#L4262

Added line #L4262 was not covered by tests
}
}

Check warning on line 4264 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java#L4264

Added line #L4264 was not covered by tests
return permittedKeyManagerConfigurations;
}

Check warning on line 4266 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java#L4266

Added line #L4266 was not covered by tests

/**
* This method is used to check if key manager configuration is allowed for user
* @param keyManagerId uuid of the key manager
* @param username username of the logged in user
* @return boolean returns if the key manager is allowed for the logged in user
* @throws APIManagementException if error occurred
*/
@Override
public boolean isKeyManagerAllowedForUser(String keyManagerId, String username) throws APIManagementException {

APIAdmin apiAdmin = new APIAdminImpl();
KeyManagerPermissionConfigurationDTO permissions = apiAdmin.getKeyManagerPermissions(keyManagerId);
String permissionType = permissions.getPermissionType();
if (permissions != null && !permissionType.equals(PERMISSION_NOT_RESTRICTED)) {

Check warning on line 4281 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java#L4279-L4281

Added lines #L4279 - L4281 were not covered by tests
String[] permissionRoles = permissions.getRoles()
.stream()
.toArray(String[]::new);
String[] userRoles = APIUtil.getListOfRoles(username);
Kirishikesan marked this conversation as resolved.
Show resolved Hide resolved
boolean roleIsRestricted = hasIntersection(userRoles, permissionRoles);
if ((PERMISSION_ALLOW.equals(permissionType) && !roleIsRestricted)

Check warning on line 4287 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java#L4283-L4287

Added lines #L4283 - L4287 were not covered by tests
|| (PERMISSION_DENY.equals(permissionType) && roleIsRestricted)) {
return false;
}

Check warning on line 4290 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java#L4290

Added line #L4290 was not covered by tests
}
return true;
}

Check warning on line 4293 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java#L4293

Added line #L4293 was not covered by tests


/**
* This method is used to check if key manager configuration is allowed for user
* @param keyManagerName name of the key manager
* @param organization organization of the logged in user
* @param username username of the logged in user
* @return boolean returns if the key manager is allowed for the logged in user
* @throws APIManagementException if error occurred
*/
@Override
public boolean isKeyManagerByNameAllowedForUser(String keyManagerName, String organization, String username)
throws APIManagementException {
APIAdmin apiAdmin = new APIAdminImpl();
KeyManagerConfigurationDTO keyManagerConfiguration = apiAdmin
.getKeyManagerConfigurationByName(organization, keyManagerName);
KeyManagerPermissionConfigurationDTO permissions = keyManagerConfiguration.getPermissions();
String permissionType = permissions.getPermissionType();
//Checks if the keymanager is permission restricted and if the user is in the restricted list

Check warning on line 4312 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java#L4308-L4312

Added lines #L4308 - L4312 were not covered by tests
if (permissions != null && !permissionType.equals(PERMISSION_NOT_RESTRICTED)) {
String[] permissionRoles = permissions.getRoles()
.stream()
.toArray(String[]::new);
String[] userRoles = APIUtil.getListOfRoles(username);
//list of common roles the user has and the restricted list

Check warning on line 4318 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java#L4315-L4318

Added lines #L4315 - L4318 were not covered by tests
boolean roleIsRestricted = hasIntersection(userRoles, permissionRoles);
//Checks if the user is allowed to access the key manager

Check warning on line 4320 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java#L4320

Added line #L4320 was not covered by tests
if ((PERMISSION_ALLOW.equals(permissionType) && !roleIsRestricted)
|| (PERMISSION_DENY.equals(permissionType) && roleIsRestricted)) {
return false;
}

Check warning on line 4324 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java#L4324

Added line #L4324 was not covered by tests
}
return true;
}

Check warning on line 4327 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java#L4327

Added line #L4327 was not covered by tests

public static boolean hasIntersection(String[] arr1, String[] arr2) {
Set<String> set = new HashSet<>();

Check warning on line 4331 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java#L4331

Added line #L4331 was not covered by tests
for (String element : arr1) {
set.add(element);
}

Check warning on line 4334 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java#L4334

Added line #L4334 was not covered by tests

for (String element : arr2) {
if (set.contains(element)) {
return true;
}

Check warning on line 4339 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java#L4339

Added line #L4339 was not covered by tests
}

return false;
}

Check warning on line 4343 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java#L4343

Added line #L4343 was not covered by tests
}
Loading
Loading