Skip to content

Commit

Permalink
Resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
RushanNanayakkara committed Feb 12, 2024
2 parents fb117f2 + 10df894 commit e1c9a68
Show file tree
Hide file tree
Showing 292 changed files with 2,380 additions and 3,796 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>api-resource-mgt</artifactId>
<version>7.0.33-SNAPSHOT</version>
<version>7.0.54-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>api-resource-mgt</artifactId>
<version>7.0.33-SNAPSHOT</version>
<version>7.0.54-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>org.wso2.carbon.identity.api.resource.mgt</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class SQLConstants {
public static final String SCOPE_QUALIFIED_NAME_COLUMN_NAME = "SCOPE_QUALIFIED_NAME";
public static final String SCOPE_DISPLAY_NAME_COLUMN_NAME = "SCOPE_DISPLAY_NAME";
public static final String SCOPE_DESCRIPTION_COLUMN_NAME = "SCOPE_DESCRIPTION";
public static final String SCOPE_API_ID_COLUMN_NAME = "API_ID";
public static final String API_RESOURCE_PROPERTY_ID_COLUMN_NAME = "PROPERTY_ID";
public static final String API_RESOURCE_PROPERTY_NAME_COLUMN_NAME = "PROPERTY_NAME";
public static final String API_RESOURCE_PROPERTY_VALUE_COLUMN_NAME = "PROPERTY_VALUE";
Expand Down Expand Up @@ -138,7 +139,7 @@ public class SQLConstants {
"OR TENANT_ID IS NULL)";
public static final String DELETE_SCOPES_BY_API = "DELETE FROM SCOPE WHERE API_ID = ? AND ( TENANT_ID = ? " +
"OR TENANT_ID IS NULL)";
public static final String UPDATE_API_RESOURCE = "UPDATE API_RESOURCE SET NAME = ?, DESCRIPTION = ?" +
public static final String UPDATE_API_RESOURCE = "UPDATE API_RESOURCE SET NAME = ?, DESCRIPTION = ?, TYPE = ?" +
" WHERE ID = ?";
public static final String IS_SCOPE_EXIST_BY_ID = "SELECT ID FROM SCOPE WHERE ID = ? AND TENANT_ID = ?";
public static final String GET_SCOPE_BY_NAME = "SELECT ID, NAME, DISPLAY_NAME, DESCRIPTION, API_ID, TENANT_ID "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ public void updateAPIResource(APIResource apiResource, List<Scope> addedScopes,
try {
preparedStatement.setString(1, apiResource.getName());
preparedStatement.setString(2, apiResource.getDescription());
preparedStatement.setString(3, apiResource.getId());
preparedStatement.setString(3, apiResource.getType());
preparedStatement.setString(4, apiResource.getId());
preparedStatement.executeUpdate();

if (CollectionUtils.isNotEmpty(addedScopes)) {
Expand Down Expand Up @@ -433,7 +434,9 @@ public List<Scope> getScopesByTenantId(Integer tenantId, List<ExpressionNode> ex
resultSet.getString(SQLConstants.ID_COLUMN_NAME),
resultSet.getString(SQLConstants.NAME_COLUMN_NAME),
resultSet.getString(SQLConstants.DISPLAY_NAME_COLUMN_NAME),
resultSet.getString(SQLConstants.DESCRIPTION_COLUMN_NAME)
resultSet.getString(SQLConstants.DESCRIPTION_COLUMN_NAME),
resultSet.getString(SQLConstants.SCOPE_API_ID_COLUMN_NAME),
resultSet.getString(SQLConstants.TENANT_ID_COLUMN_NAME)
));
}
return scopesList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@
import javax.xml.stream.XMLStreamReader;

/**
* Config builder class for organization management related configs in organization-mgt.xml file.
* Config builder class for system API resource configs in system-api-resource.xml file.
*/
public class APIResourceManagementConfigBuilder {

private static final Log LOG = LogFactory.getLog(APIResourceManagementConfigBuilder.class);
private static final Map<String, APIResource> apiResourceMgtConfigurations = new HashMap<>();
private static final Map<String, APIResource> duplicateAPIResourceConfigs = new HashMap<>();
private static final APIResourceManagementConfigBuilder apiResourceManagementConfigBuilder =
new APIResourceManagementConfigBuilder();

Expand All @@ -67,15 +68,25 @@ private APIResourceManagementConfigBuilder() {
}

/**
* Get organization management related configs.
* Get system API resource configs.
*
* @return Map of org mgt configs.
* @return Map of API resource configs.
*/
public Map<String, APIResource> getAPIResourceMgtConfigurations() {

return apiResourceMgtConfigurations;
}

/**
* Get duplicate system API resource configs.
*
* @return Map of duplicate API resource configs.
*/
public Map<String, APIResource> getDuplicateAPIResourceConfigs() {

return duplicateAPIResourceConfigs;
}

/**
* Read the system-api-resource.xml file and build the configuration map.
*/
Expand Down Expand Up @@ -140,6 +151,17 @@ private void buildAPIResourceConfig() {
apiResourceObj.setScopes(scopeList);
}
}
/* If an API resource with the same identifier already exists in the config map, add the second one
to the duplicate list. During API resource registration, diff will be applied as a patch to the existing
API resource. API resource in the duplicate config map will be considered as the original API resource.
*/
if (apiResourceMgtConfigurations.containsKey(apiResourceObj.getIdentifier())) {
if (LOG.isDebugEnabled()) {
LOG.debug("API resource with duplicate identifier: " + apiResourceObj.getIdentifier() + " found.");
}
duplicateAPIResourceConfigs.put(apiResourceObj.getIdentifier(), apiResourceObj);
continue;
}
apiResourceMgtConfigurations.put(apiResourceObj.getIdentifier(), apiResourceObj);
}
}
Expand All @@ -148,13 +170,6 @@ private APIResource buildAPIResource(OMElement element) {

String apiResourceIdentifier = element.getAttributeValue(
new QName(APIResourceConfigBuilderConstants.IDENTIFIER));
if (apiResourceMgtConfigurations.containsKey(apiResourceIdentifier)) {
if (LOG.isDebugEnabled()) {
LOG.debug("API resource with identifier: " + apiResourceIdentifier + " already exists.");
}
return null;
}

String type = APIResourceConfigBuilderConstants.TENANT_ADMIN_TYPE;
if (element.getAttributeValue(new QName(APIResourceConfigBuilderConstants.TYPE)) != null) {
type = element.getAttributeValue(new QName(APIResourceConfigBuilderConstants.TYPE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@
import org.wso2.carbon.identity.api.resource.mgt.APIResourceMgtServerException;
import org.wso2.carbon.identity.api.resource.mgt.constant.APIResourceManagementConstants;
import org.wso2.carbon.identity.application.common.model.APIResource;
import org.wso2.carbon.identity.application.common.model.Scope;
import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* Utility class for API Resource Management.
Expand Down Expand Up @@ -87,22 +90,63 @@ public static void addSystemAPIs() {
String tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
Map<String, APIResource> configs = APIResourceManagementConfigBuilder.getInstance()
.getAPIResourceMgtConfigurations();
Map<String, APIResource> duplicateConfigs = APIResourceManagementConfigBuilder.getInstance()
.getDuplicateAPIResourceConfigs();
if (!isSystemAPIExist(tenantDomain)) {
LOG.debug("Registering system API resources in the server.");
registerAPIResources(new ArrayList<>(configs.values()), tenantDomain);
} else {
LOG.debug("System APIs are already registered in the server. Applying the latest configurations.");
// Remove the existing system APIs from the configs.
// Existing system APIs will be evaluated using the identifier.
HashMap<String, APIResource> tempConfigs = new HashMap<>(configs);
List<APIResource> systemAPIs = getSystemAPIs(tenantDomain);
for (APIResource systemAPI : systemAPIs) {
if (configs.containsKey(systemAPI.getIdentifier())) {
configs.remove(systemAPI.getIdentifier());
if (tempConfigs.containsKey(systemAPI.getIdentifier())) {
tempConfigs.remove(systemAPI.getIdentifier());
} else {
String apiId = APIResourceManagerImpl.getInstance().getAPIResourceByIdentifier(
systemAPI.getIdentifier(), tenantDomain).getId();
APIResourceManagerImpl.getInstance().deleteAPIResourceById(apiId, tenantDomain);
}
}
registerAPIResources(new ArrayList<>(configs.values()), tenantDomain);
// Register the new system APIs.
registerAPIResources(new ArrayList<>(tempConfigs.values()), tenantDomain);

// Handle duplicate system APIs.
for (APIResource oldAPIResource : duplicateConfigs.values()) {
// Get the existing API resource from the DB.
APIResource apiResourceFromDB = APIResourceManagerImpl.getInstance().getAPIResourceByIdentifier(
oldAPIResource.getIdentifier(), tenantDomain);
// Get the updated API resource from the configs.
APIResource updatedAPIResource = configs.get(oldAPIResource.getIdentifier());
// Get the scopes which are not in the existing API resource.
List<Scope> addedScopes = updatedAPIResource.getScopes().stream()
.filter(scope1 -> apiResourceFromDB.getScopes().stream()
.noneMatch(scope2 -> scope2.getName().equals(scope1.getName())))
.collect(Collectors.toList());
if (addedScopes.isEmpty()) {
continue;
}

APIResource updatedAPIResourceFromDB = new APIResource.APIResourceBuilder()
.id(apiResourceFromDB.getId())
.name(apiResourceFromDB.getName())
.description(apiResourceFromDB.getDescription())
.identifier(apiResourceFromDB.getIdentifier())
// Set the type as the updated API resource type.
.type(updatedAPIResource.getType())
.tenantId(apiResourceFromDB.getTenantId())
.requiresAuthorization(apiResourceFromDB.isAuthorizationRequired())
.scopes(updatedAPIResource.getScopes())
.subscribedApplications(apiResourceFromDB.getSubscribedApplications())
.properties(apiResourceFromDB.getProperties())
.build();

// If there are scopes which are not in the existing API resource, update the API resource.
APIResourceManagerImpl.getInstance().updateAPIResource(updatedAPIResourceFromDB, addedScopes,
new ArrayList<>(), tenantDomain);
}
}

LOG.debug("System APIs successfully registered in tenant domain: " + tenantDomain);
Expand Down
2 changes: 1 addition & 1 deletion components/api-resource-mgt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>identity-framework</artifactId>
<version>7.0.33-SNAPSHOT</version>
<version>7.0.54-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<parent>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>application-mgt</artifactId>
<version>7.0.33-SNAPSHOT</version>
<version>7.0.54-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,21 @@ public String getAppId() {
return appId;
}

public void setAppId(String appId) {

this.appId = appId;
}

public String getAPIId() {

return apiId;
}

public void setAPIId(String apiId) {

this.apiId = apiId;
}

public String getAPIIdentifier() {

return apiIdentifier;
Expand All @@ -81,6 +91,11 @@ public String getPolicyId() {
return policyId;
}

public void setPolicyId(String policyId) {

this.policyId = policyId;
}

public List<Scope> getScopes() {

return scopes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>application-mgt</artifactId>
<version>7.0.33-SNAPSHOT</version>
<version>7.0.54-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>application-mgt</artifactId>
<version>7.0.33-SNAPSHOT</version>
<version>7.0.54-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>org.wso2.carbon.identity.application.mgt</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ private ApplicationConstants() {
public static final String MY_ACCOUNT_APPLICATION_NAME = "My Account";
public static final String CONSOLE_ACCESS_URL_FROM_SERVER_CONFIGS = "Console.AccessURL";
public static final String MY_ACCOUNT_ACCESS_URL_FROM_SERVER_CONFIGS = "MyAccount.AccessURL";
public static final String CONSOLE_APPLICATION_CLIENT_ID = "CONSOLE";
public static final String CONSOLE_APPLICATION_INBOUND_TYPE = "oauth2";
public static final String TENANT_DOMAIN_PLACEHOLDER = "{TENANT_DOMAIN}";

/**
Expand Down
Loading

0 comments on commit e1c9a68

Please sign in to comment.