From 2b9d51e640231eef5a62c7c232331e9ab029c535 Mon Sep 17 00:00:00 2001 From: Thamindu Aluthwala Date: Wed, 27 Sep 2023 10:39:08 +0530 Subject: [PATCH] Minor fixes --- .../ApplicationManagementConstants.java | 3 +- .../management/v1/ApplicationsApi.java | 4 +- .../management/v1/ApplicationsApiService.java | 34 ++++++++- .../v1/AuthorizedAPICreationModel.java | 4 +- .../v1/AuthorizedAPIPatchModel.java | 4 +- .../management/v1/AuthorizedAPIResponse.java | 4 +- .../management/v1/AuthorizedScope.java | 4 +- .../ServerApplicationManagementService.java | 74 ++++++++++++------- .../cxf/applications-server-v1-cxf.xml | 1 + 9 files changed, 90 insertions(+), 42 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.common/src/main/java/org/wso2/carbon/identity/api/server/application/management/common/ApplicationManagementConstants.java b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.common/src/main/java/org/wso2/carbon/identity/api/server/application/management/common/ApplicationManagementConstants.java index 88236d7c85..fe06dcdf6a 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.common/src/main/java/org/wso2/carbon/identity/api/server/application/management/common/ApplicationManagementConstants.java +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.common/src/main/java/org/wso2/carbon/identity/api/server/application/management/common/ApplicationManagementConstants.java @@ -53,6 +53,7 @@ private ApplicationManagementConstants() { public static final String ISSUER = "issuer"; public static final String RBAC = "RBAC"; public static final String NO_POLICY = "No Policy"; + public static final String NON_EXISTING_USER_CODE = "30007 - "; /** @@ -116,7 +117,7 @@ public enum ErrorMessage { "API resource with id: %s is not authorized for the application with id: %s."), INVALID_POLICY_VALUE("60511", "Invalid policy id value provided.", "Invalid policy id value. It should be 'RBAC' or 'No Policy'."), - INVALID_POLICY_TYPE_FOR_API_RESOURCE("60511", "Invalid policy type provided for the API " + + INVALID_POLICY_TYPE_FOR_API_RESOURCE("60512", "Invalid policy type provided for the API " + "resource.", "API resource with id: %s doesn't allow the provided policy type: %s."), // Server Errors. diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/ApplicationsApi.java b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/ApplicationsApi.java index 32c5102599..23f6658fce 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/ApplicationsApi.java +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/ApplicationsApi.java @@ -1,7 +1,7 @@ /* - * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.com). + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). * - * WSO2 Inc. licenses this file to you under the Apache License, + * 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 diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/ApplicationsApiService.java b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/ApplicationsApiService.java index bfba868988..a98f9c8576 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/ApplicationsApiService.java +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/ApplicationsApiService.java @@ -1,7 +1,7 @@ /* - * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.com). + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). * - * WSO2 Inc. licenses this file to you under the Apache License, + * 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 @@ -19,10 +19,38 @@ package org.wso2.carbon.identity.api.server.application.management.v1; import org.apache.cxf.jaxrs.ext.search.SearchContext; +import org.wso2.carbon.identity.api.server.application.management.v1.*; +import org.wso2.carbon.identity.api.server.application.management.v1.*; import org.apache.cxf.jaxrs.ext.multipart.Attachment; +import org.apache.cxf.jaxrs.ext.multipart.Multipart; import java.io.InputStream; - +import java.util.List; +import org.wso2.carbon.identity.api.server.application.management.v1.AdaptiveAuthTemplates; +import org.wso2.carbon.identity.api.server.application.management.v1.ApplicationListResponse; +import org.wso2.carbon.identity.api.server.application.management.v1.ApplicationModel; +import org.wso2.carbon.identity.api.server.application.management.v1.ApplicationOwner; +import org.wso2.carbon.identity.api.server.application.management.v1.ApplicationPatchModel; +import org.wso2.carbon.identity.api.server.application.management.v1.ApplicationResponseModel; +import org.wso2.carbon.identity.api.server.application.management.v1.ApplicationTemplateModel; +import org.wso2.carbon.identity.api.server.application.management.v1.ApplicationTemplatesList; +import org.wso2.carbon.identity.api.server.application.management.v1.AuthProtocolMetadata; +import org.wso2.carbon.identity.api.server.application.management.v1.ConfiguredAuthenticatorsModal; +import org.wso2.carbon.identity.api.server.application.management.v1.CustomInboundProtocolConfiguration; +import org.wso2.carbon.identity.api.server.application.management.v1.CustomInboundProtocolMetaData; +import org.wso2.carbon.identity.api.server.application.management.v1.Error; +import java.io.File; +import org.wso2.carbon.identity.api.server.application.management.v1.InboundProtocolListItem; +import org.wso2.carbon.identity.api.server.application.management.v1.OIDCMetaData; +import org.wso2.carbon.identity.api.server.application.management.v1.OpenIDConnectConfiguration; +import org.wso2.carbon.identity.api.server.application.management.v1.PassiveStsConfiguration; +import org.wso2.carbon.identity.api.server.application.management.v1.ProvisioningConfiguration; +import org.wso2.carbon.identity.api.server.application.management.v1.ResidentApplication; +import org.wso2.carbon.identity.api.server.application.management.v1.SAML2Configuration; +import org.wso2.carbon.identity.api.server.application.management.v1.SAML2ServiceProvider; +import org.wso2.carbon.identity.api.server.application.management.v1.SAMLMetaData; +import org.wso2.carbon.identity.api.server.application.management.v1.WSTrustConfiguration; +import org.wso2.carbon.identity.api.server.application.management.v1.WSTrustMetaData; import javax.ws.rs.core.Response; diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/AuthorizedAPICreationModel.java b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/AuthorizedAPICreationModel.java index 4d0814fd7d..f536b29b7a 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/AuthorizedAPICreationModel.java +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/AuthorizedAPICreationModel.java @@ -1,7 +1,7 @@ /* - * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.com). + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). * - * WSO2 Inc. licenses this file to you under the Apache License, + * 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 diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/AuthorizedAPIPatchModel.java b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/AuthorizedAPIPatchModel.java index 3904534c23..5833456fb2 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/AuthorizedAPIPatchModel.java +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/AuthorizedAPIPatchModel.java @@ -1,7 +1,7 @@ /* - * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.com). + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). * - * WSO2 Inc. licenses this file to you under the Apache License, + * 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 diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/AuthorizedAPIResponse.java b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/AuthorizedAPIResponse.java index 35709edbab..5d9d1ad3d7 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/AuthorizedAPIResponse.java +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/AuthorizedAPIResponse.java @@ -1,7 +1,7 @@ /* - * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.com). + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). * - * WSO2 Inc. licenses this file to you under the Apache License, + * 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 diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/AuthorizedScope.java b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/AuthorizedScope.java index d66422c81a..67a8b50e27 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/AuthorizedScope.java +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/AuthorizedScope.java @@ -1,7 +1,7 @@ /* - * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.com). + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). * - * WSO2 Inc. licenses this file to you under the Apache License, + * 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 diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/ServerApplicationManagementService.java b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/ServerApplicationManagementService.java index d84daaed48..ebf05ccfe4 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/ServerApplicationManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/ServerApplicationManagementService.java @@ -216,8 +216,8 @@ public class ServerApplicationManagementService { private static final String[] VALID_MEDIA_TYPES_XML = {"application/xml", "text/xml"}; private static final String[] VALID_MEDIA_TYPES_YAML = {"application/yaml", "text/yaml", "application/x-yaml"}; private static final String[] VALID_MEDIA_TYPES_JSON = {"application/json", "text/json"}; - private static final Class[] INBOUND_CONFIG_PROTOCOLS = new Class[]{ServiceProvider.class, - SAMLSSOServiceProviderDTO.class, OAuthAppDO.class}; + private static final Class[] INBOUND_CONFIG_PROTOCOLS = new Class[] {ServiceProvider.class, + SAMLSSOServiceProviderDTO.class, OAuthAppDO.class}; static { SUPPORTED_FILTER_ATTRIBUTES.add(NAME); @@ -791,7 +791,7 @@ public String createApplication(ApplicationModel applicationModel, String templa // Update owner for B2B Self Service applications. if (application.isB2BSelfServiceApp()) { String systemUserID = org.wso2.carbon.identity.organization.management.service.util.Utils - .getB2BSelfServiceSystemUser(tenantDomain); + .getB2BSelfServiceSystemUser(tenantDomain); if (StringUtils.isNotEmpty(systemUserID)) { ApplicationOwner systemOwner = new ApplicationOwner(); systemOwner.id(systemUserID); @@ -1308,6 +1308,12 @@ public void changeApplicationOwner(String applicationId, ApplicationOwner applic updateServiceProvider(applicationId, appToUpdate); } + /** + * Authorize an API resource to the application. + * + * @param applicationId Application ID. + * @param authorizedAPICreationModel API Authorization creation model. + */ public void addAuthorizedAPI(String applicationId, AuthorizedAPICreationModel authorizedAPICreationModel) { try { @@ -1355,31 +1361,12 @@ public void addAuthorizedAPI(String applicationId, AuthorizedAPICreationModel au } } - public String validatePolicy(String policyId) { - - if (policyId == null || policyId.isEmpty()) { - // No input provided, use the default policy identifier. - return ApplicationManagementConstants.RBAC; - } else if (policyId.equalsIgnoreCase(ApplicationManagementConstants.RBAC) - || policyId.equalsIgnoreCase(ApplicationManagementConstants.NO_POLICY)) { - return policyId.toUpperCase(Locale.ENGLISH); - } else { - throw buildClientError(ErrorMessage.INVALID_POLICY_VALUE); - } - } - - private void validateAPIResourceScopes(APIResource apiResource, List scopes) - throws APIResourceMgtException { - - List apiResourceScopes = apiResource.getScopes(); - for (String scopeName : scopes) { - if (apiResourceScopes.stream().noneMatch(scope -> scope.getName().equals(scopeName))) { - throw buildClientError(ErrorMessage.SCOPES_NOT_FOUND, apiResource.getId(), - CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); - } - } - } - + /** + * Delete an API authorization from the application. + * + * @param applicationId Application ID. + * @param apiId API resource ID. + */ public void deleteAuthorizedAPI(String applicationId, String apiId) { try { @@ -1392,6 +1379,12 @@ public void deleteAuthorizedAPI(String applicationId, String apiId) { } } + /** + * Update the API authorization of the application for an API resource. + * @param applicationId Application ID. + * @param apiId API resource ID. + * @param authorizedAPIPatchModel + */ public void updateAuthorizedAPI(String applicationId, String apiId, AuthorizedAPIPatchModel authorizedAPIPatchModel) { @@ -1454,6 +1447,31 @@ public List getAuthorizedAPIs(String applicationId) { } } + private String validatePolicy(String policyId) { + + if (policyId == null || policyId.isEmpty()) { + // No input provided, use the default policy identifier. + return ApplicationManagementConstants.RBAC; + } else if (policyId.equalsIgnoreCase(ApplicationManagementConstants.RBAC) + || policyId.equalsIgnoreCase(ApplicationManagementConstants.NO_POLICY)) { + return policyId.toUpperCase(Locale.ENGLISH); + } else { + throw buildClientError(ErrorMessage.INVALID_POLICY_VALUE); + } + } + + private void validateAPIResourceScopes(APIResource apiResource, List scopes) + throws APIResourceMgtException { + + List apiResourceScopes = apiResource.getScopes(); + for (String scopeName : scopes) { + if (apiResourceScopes.stream().noneMatch(scope -> scope.getName().equals(scopeName))) { + throw buildClientError(ErrorMessage.SCOPES_NOT_FOUND, apiResource.getId(), + CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); + } + } + } + private List createAuthorizedScope(List scope) { return scope.stream().map(s -> new AuthorizedScope() diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/resources/META-INF/cxf/applications-server-v1-cxf.xml b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/resources/META-INF/cxf/applications-server-v1-cxf.xml index 2bd0209ff0..0fcc456e02 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/resources/META-INF/cxf/applications-server-v1-cxf.xml +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/resources/META-INF/cxf/applications-server-v1-cxf.xml @@ -58,6 +58,7 @@ class="org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementServiceHolder"> +