Fix SSO related issues

apim420
tcdlpds 1 year ago
parent a17c5c27ab
commit f117e40fc9

@ -65,6 +65,7 @@ import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants; import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/** /**
* This class represents an implementation of APIManagementProviderService. * This class represents an implementation of APIManagementProviderService.
@ -143,31 +144,29 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
APIApplicationManagerExtensionDataHolder.getInstance().getConsumerRESTAPIServices(); APIApplicationManagerExtensionDataHolder.getInstance().getConsumerRESTAPIServices();
try { try {
List<APIInfo> uniqueApiList = new ArrayList<>();
Map<String, String> headerParams = new HashMap<>(); Map<String, String> headerParams = new HashMap<>();
if (!"carbon.super".equals(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true))) { if (!"carbon.super".equals(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true))) {
headerParams.put("X-WSO2-Tenant", "carbon.super"); headerParams.put("X-WSO2-Tenant", "carbon.super");
} }
Map <String, APIInfo> uniqueApiSet = new HashMap<>();
for (String tag : tags) { for (String tag : tags) {
Map<String, String> queryParams = new HashMap<>(); Map<String, String> queryParams = new HashMap<>();
queryParams.put("tag", tag); queryParams.put("tag", tag);
APIInfo[] apiInfos = consumerRESTAPIServices.getAllApis(tokenInfo, queryParams, headerParams); APIInfo[] apiInfos = consumerRESTAPIServices.getAllApis(tokenInfo, queryParams, headerParams);
Arrays.stream(apiInfos).forEach(apiInfo -> uniqueApiSet.putIfAbsent(apiInfo.getName(), apiInfo));
uniqueApiList.addAll(List.of(apiInfos));
Set<APIInfo> taggedAPISet = new HashSet<>(uniqueApiList);
uniqueApiList.clear();
uniqueApiList.addAll(taggedAPISet);
} }
List<APIInfo> uniqueApiList = new ArrayList<>(uniqueApiSet.values());
io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Application[] applications = io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Application[] applications =
consumerRESTAPIServices.getAllApplications(tokenInfo, applicationName); consumerRESTAPIServices.getAllApplications(tokenInfo, applicationName);
io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Application application; io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Application application;
MetadataManagementService metadataManagementService = APIApplicationManagerExtensionDataHolder.getInstance().getMetadataManagementService(); MetadataManagementService metadataManagementService = APIApplicationManagerExtensionDataHolder.getInstance().getMetadataManagementService();
if (applications.length == 0) { if (applications.length == 0) {
return handleNewAPIApplication(applicationName, uniqueApiList, tokenInfo, keyType, validityTime); return handleNewAPIApplication(applicationName, uniqueApiList, tokenInfo, keyType,
validityTime);
} else { } else {
if (applications.length == 1) { if (applications.length == 1) {
Optional<io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Application> applicationOpt = Optional<io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Application> applicationOpt =

@ -222,7 +222,7 @@ public class SsoLoginHandler extends HttpServlet {
} }
// Update the grant types of the application // 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; HandlerConstants.PRODUCTION_KEY;
HttpPut updateApplicationGrantTypesEndpoint = new HttpPut(url); HttpPut updateApplicationGrantTypesEndpoint = new HttpPut(url);
updateApplicationGrantTypesEndpoint.setHeader(HttpHeaders.AUTHORIZATION, HandlerConstants.BEARER + updateApplicationGrantTypesEndpoint.setHeader(HttpHeaders.AUTHORIZATION, HandlerConstants.BEARER +

@ -26,7 +26,7 @@ public class HandlerConstants {
public static final String INTERNAL_TOKEN_ENDPOINT = "/token"; public static final String INTERNAL_TOKEN_ENDPOINT = "/token";
public static final String INTROSPECT_ENDPOINT = "/oauth2/introspect"; public static final String INTROSPECT_ENDPOINT = "/oauth2/introspect";
public static final String AUTHORIZATION_ENDPOINT = "/oauth2/authorize"; 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 IDENTITY_APP_MGT_ENDPOINT = "/services/IdentityApplicationManagementService.IdentityApplicationManagementServiceHttpsSoap11Endpoint";
public static final String LOGIN_PAGE = "/login"; public static final String LOGIN_PAGE = "/login";
public static final String SSO_LOGIN_CALLBACK = "/ssoLoginCallback"; 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 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 PAYLOADS_DIR = "repository/resources/payloads";
public static final String SOAP_ACTION_HEADER = "SOAPAction"; public static final String SOAP_ACTION_HEADER = "SOAPAction";
public static final String REFERER_HEADER = "Referer"; public static final String REFERER_HEADER = "Referer";

Loading…
Cancel
Save