From f117e40fc908be937c0ef8ecc6321bfc861a3209 Mon Sep 17 00:00:00 2001 From: tcdlpds Date: Sun, 6 Aug 2023 23:38:02 +0530 Subject: [PATCH] Fix SSO related issues --- .../APIManagementProviderServiceImpl.java | 15 +++++++-------- .../ui/request/interceptor/SsoLoginHandler.java | 2 +- .../interceptor/util/HandlerConstants.java | 4 ++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/src/main/java/io/entgra/device/mgt/core/apimgt/application/extension/APIManagementProviderServiceImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/src/main/java/io/entgra/device/mgt/core/apimgt/application/extension/APIManagementProviderServiceImpl.java index 3c62275186..3a3bf5f941 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/src/main/java/io/entgra/device/mgt/core/apimgt/application/extension/APIManagementProviderServiceImpl.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/src/main/java/io/entgra/device/mgt/core/apimgt/application/extension/APIManagementProviderServiceImpl.java @@ -65,6 +65,7 @@ import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; import java.util.*; +import java.util.stream.Collectors; /** * This class represents an implementation of APIManagementProviderService. @@ -143,31 +144,29 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe APIApplicationManagerExtensionDataHolder.getInstance().getConsumerRESTAPIServices(); try { - List uniqueApiList = new ArrayList<>(); - Map headerParams = new HashMap<>(); if (!"carbon.super".equals(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true))) { headerParams.put("X-WSO2-Tenant", "carbon.super"); } + Map uniqueApiSet = new HashMap<>(); for (String tag : tags) { Map queryParams = new HashMap<>(); queryParams.put("tag", tag); APIInfo[] apiInfos = consumerRESTAPIServices.getAllApis(tokenInfo, queryParams, headerParams); - - uniqueApiList.addAll(List.of(apiInfos)); - Set taggedAPISet = new HashSet<>(uniqueApiList); - uniqueApiList.clear(); - uniqueApiList.addAll(taggedAPISet); + Arrays.stream(apiInfos).forEach(apiInfo -> uniqueApiSet.putIfAbsent(apiInfo.getName(), apiInfo)); } + List uniqueApiList = new ArrayList<>(uniqueApiSet.values()); + io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Application[] applications = consumerRESTAPIServices.getAllApplications(tokenInfo, applicationName); io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Application application; MetadataManagementService metadataManagementService = APIApplicationManagerExtensionDataHolder.getInstance().getMetadataManagementService(); if (applications.length == 0) { - return handleNewAPIApplication(applicationName, uniqueApiList, tokenInfo, keyType, validityTime); + return handleNewAPIApplication(applicationName, uniqueApiList, tokenInfo, keyType, + validityTime); } else { if (applications.length == 1) { Optional applicationOpt = diff --git a/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/SsoLoginHandler.java b/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/SsoLoginHandler.java index de037d8bc1..52dc03b79c 100644 --- a/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/SsoLoginHandler.java +++ b/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/SsoLoginHandler.java @@ -222,7 +222,7 @@ public class SsoLoginHandler extends HttpServlet { } // Update the grant types of the application - String url = apiMgtUrl + HandlerConstants.APIM_APPLICATIONS_ENDPOINT + applicationId + "/keys/" + + String url = apiMgtUrl + HandlerConstants.APIM_APPLICATIONS_ENDPOINT + "/" + applicationId + "/keys/" + HandlerConstants.PRODUCTION_KEY; HttpPut updateApplicationGrantTypesEndpoint = new HttpPut(url); updateApplicationGrantTypesEndpoint.setHeader(HttpHeaders.AUTHORIZATION, HandlerConstants.BEARER + diff --git a/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/util/HandlerConstants.java b/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/util/HandlerConstants.java index 9aa9cb9fe6..c6058102b6 100644 --- a/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/util/HandlerConstants.java +++ b/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/util/HandlerConstants.java @@ -26,7 +26,7 @@ public class HandlerConstants { public static final String INTERNAL_TOKEN_ENDPOINT = "/token"; public static final String INTROSPECT_ENDPOINT = "/oauth2/introspect"; public static final String AUTHORIZATION_ENDPOINT = "/oauth2/authorize"; - public static final String APIM_APPLICATIONS_ENDPOINT = "/api/am/devportal/v2/applications/"; + public static final String APIM_APPLICATIONS_ENDPOINT = "/api/am/devportal/v3/applications"; public static final String IDENTITY_APP_MGT_ENDPOINT = "/services/IdentityApplicationManagementService.IdentityApplicationManagementServiceHttpsSoap11Endpoint"; public static final String LOGIN_PAGE = "/login"; public static final String SSO_LOGIN_CALLBACK = "/ssoLoginCallback"; @@ -77,7 +77,7 @@ public class HandlerConstants { public static final String OTP_HEADER = "one-time-token"; - public static final String AX_PREFIX = "ax2251:"; + public static final String AX_PREFIX = "ax2245:"; public static final String PAYLOADS_DIR = "repository/resources/payloads"; public static final String SOAP_ACTION_HEADER = "SOAPAction"; public static final String REFERER_HEADER = "Referer";