From 5ffaf8c285a0e56fbc82813ca5a6a11a5aa14702 Mon Sep 17 00:00:00 2001 From: hasithan Date: Fri, 16 Feb 2024 18:12:27 +0530 Subject: [PATCH] Remove identity.application.mgt.stub dependency from key manager component --- .../pom.xml | 6 - .../keymanager/KeyManagerUtil.java | 6 + .../keymanager/OBKeyManagerImpl.java | 126 +++++++----------- .../internal/KeyManagerDataHolder.java | 19 --- .../keymanager/KeyManagerTest.java | 38 ++---- 5 files changed, 63 insertions(+), 132 deletions(-) diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.keymanager/pom.xml b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.keymanager/pom.xml index 909246c1..5bc44c69 100644 --- a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.keymanager/pom.xml +++ b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.keymanager/pom.xml @@ -51,10 +51,6 @@ org.wso2.carbon.apimgt org.wso2.carbon.apimgt.impl - - org.wso2.carbon.identity.framework - org.wso2.carbon.identity.application.mgt.stub - org.mockito mockito-all @@ -204,8 +200,6 @@ org.wso2.carbon.apimgt.impl;version="${org.wso2.carbon.apimgt.version.range}", org.wso2.carbon.apimgt.impl.jwt;version="${org.wso2.carbon.apimgt.version.range}", org.wso2.carbon.authenticator.stub;version="${carbon.kernel.version.range}", - org.wso2.carbon.identity.application.common.model.xsd;version="${carbon.identity.framework.version.range}", - org.wso2.carbon.identity.application.mgt.stub;version="${carbon.identity.framework.version.range}", org.wso2.carbon.user.mgt.stub;version="${carbon.identity.framework.version.range}", org.wso2.carbon.identity.oauth.stub;version="${org.wso2.carbon.identity.oauth.stub.version.range}", org.wso2.carbon.identity.oauth.stub.dto;version="${org.wso2.carbon.identity.oauth.stub.version.range}", diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.keymanager/src/main/java/com/wso2/openbanking/accelerator/keymanager/KeyManagerUtil.java b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.keymanager/src/main/java/com/wso2/openbanking/accelerator/keymanager/KeyManagerUtil.java index 6ef68c55..fed1c6be 100644 --- a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.keymanager/src/main/java/com/wso2/openbanking/accelerator/keymanager/KeyManagerUtil.java +++ b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.keymanager/src/main/java/com/wso2/openbanking/accelerator/keymanager/KeyManagerUtil.java @@ -59,7 +59,10 @@ public class KeyManagerUtil { * * @return Session cookie as a String * @throws APIManagementException When failed to obtain the session cookie + * @deprecated ApplicationManagementService is used instead of SOAP API calls. */ + @Deprecated + @Generated(message = "Excluding from unit test coverage") public static String getSessionCookie() throws APIManagementException { String sessionCookie = ""; @@ -90,7 +93,10 @@ public static String getSessionCookie() throws APIManagementException { * * @param serviceClient Admin service client * @param sessionCookie session cookie as a string + * @deprecated ApplicationManagementService is used instead of SOAP API calls. */ + @Deprecated + @Generated(message = "Excluding from unit test coverage") public static void setAdminServiceSession(ServiceClient serviceClient, String sessionCookie) { Options userAdminOption = serviceClient.getOptions(); diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.keymanager/src/main/java/com/wso2/openbanking/accelerator/keymanager/OBKeyManagerImpl.java b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.keymanager/src/main/java/com/wso2/openbanking/accelerator/keymanager/OBKeyManagerImpl.java index 306eb6ac..ee86cf1c 100644 --- a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.keymanager/src/main/java/com/wso2/openbanking/accelerator/keymanager/OBKeyManagerImpl.java +++ b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.keymanager/src/main/java/com/wso2/openbanking/accelerator/keymanager/OBKeyManagerImpl.java @@ -26,7 +26,6 @@ import net.minidev.json.JSONObject; import net.minidev.json.parser.JSONParser; import net.minidev.json.parser.ParseException; -import org.apache.axis2.client.ServiceClient; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -42,16 +41,13 @@ import org.wso2.carbon.apimgt.impl.AMDefaultKeyManagerImpl; import org.wso2.carbon.apimgt.impl.APIConstants; import org.wso2.carbon.identity.application.common.IdentityApplicationManagementException; -import org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider; -import org.wso2.carbon.identity.application.common.model.xsd.ServiceProviderProperty; +import org.wso2.carbon.identity.application.common.model.ServiceProvider; +import org.wso2.carbon.identity.application.common.model.ServiceProviderProperty; +import org.wso2.carbon.identity.application.common.util.IdentityApplicationConstants; import org.wso2.carbon.identity.application.mgt.ApplicationManagementServiceImpl; -import org.wso2.carbon.identity.application.mgt.stub.IdentityApplicationManagementServiceIdentityApplicationManagementException; import org.wso2.carbon.identity.oauth.IdentityOAuthAdminException; import org.wso2.carbon.identity.oauth.OAuthAdminService; -import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceIdentityOAuthAdminException; -import org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO; -import java.rmi.RemoteException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -65,45 +61,24 @@ public class OBKeyManagerImpl extends AMDefaultKeyManagerImpl implements OBKeyMa private static final Log log = LogFactory.getLog(OBKeyManagerImpl.class); + public static final String OAUTH2 = "oauth2"; + @Override public AccessTokenInfo getNewApplicationAccessToken(AccessTokenRequest tokenRequest) throws APIManagementException { try { - String applicationName = ""; - String sessionCookie = KeyManagerUtil.getSessionCookie(); - ServiceClient userAdminClient = KeyManagerDataHolder.getInstance() - .getUserAdminStub()._getServiceClient(); - KeyManagerUtil.setAdminServiceSession(userAdminClient, sessionCookie); - - ServiceClient oauthAppClient = KeyManagerDataHolder.getInstance().getOauthAdminServiceStub() - ._getServiceClient(); - KeyManagerUtil.setAdminServiceSession(oauthAppClient, sessionCookie); - - OAuthConsumerAppDTO oAuthConsumerAppDTO = KeyManagerDataHolder.getInstance().getOauthAdminServiceStub() - .getOAuthApplicationData(tokenRequest.getClientId()); - - if (oAuthConsumerAppDTO != null) { - applicationName = oAuthConsumerAppDTO.getApplicationName(); - } - - ServiceClient appMgtClient = KeyManagerDataHolder.getInstance() - .getIdentityApplicationManagementServiceStub()._getServiceClient(); - KeyManagerUtil.setAdminServiceSession(appMgtClient, sessionCookie); - - ServiceProvider serviceProvider = KeyManagerDataHolder.getInstance() - .getIdentityApplicationManagementServiceStub().getApplication(applicationName); - ServiceProviderProperty[] serviceProviderProperties = serviceProvider.getSpProperties(); - List spProperties = new ArrayList<>(Arrays.asList(serviceProviderProperties)); - - ServiceProviderProperty regulatoryProperty = spProperties.stream() - .filter(serviceProviderProperty -> serviceProviderProperty.getName() - .equalsIgnoreCase(OpenBankingConstants.REGULATORY)).findAny().orElse(null); - - if (regulatoryProperty != null && "true".equalsIgnoreCase(regulatoryProperty.getValue())) { - return null; + ApplicationManagementServiceImpl applicationManagementService = getApplicationMgmtServiceImpl(); + ServiceProvider serviceProvider = applicationManagementService.getServiceProviderByClientId( + tokenRequest.getClientId(), IdentityApplicationConstants.OAuth2.NAME, tenantDomain); + if (serviceProvider != null) { + ServiceProviderProperty regulatoryProperty = Arrays.stream(serviceProvider.getSpProperties()) + .filter(serviceProviderProperty -> serviceProviderProperty.getName() + .equalsIgnoreCase(OpenBankingConstants.REGULATORY)).findAny().orElse(null); + if (regulatoryProperty != null && "true".equalsIgnoreCase(regulatoryProperty.getValue())) { + return null; + } } - } catch (RemoteException | IdentityApplicationManagementServiceIdentityApplicationManagementException | - OAuthAdminServiceIdentityOAuthAdminException e) { + } catch (IdentityApplicationManagementException e) { log.error("Error while generating keys. ", e); } return super.getNewApplicationAccessToken(tokenRequest); @@ -239,16 +214,16 @@ public OAuthApplicationInfo createApplication(OAuthAppRequest oauthAppRequest) t String tenantDomain = ServiceProviderUtils.getSpTenantDomain(oAuthApplicationInfo.getClientId()); updateSpProperties(appName, tenantDomain, username, additionalProperties, true); - org.wso2.carbon.identity.application.common.model.ServiceProvider appServiceProvider = - getApplicationMgmtServiceImpl().getServiceProvider(appName, tenantDomain); - org.wso2.carbon.identity.application.common.model.ServiceProviderProperty regulatoryProperty = - getSpPropertyFromSPMetaData(OpenBankingConstants.REGULATORY, appServiceProvider.getSpProperties()); + ServiceProvider appServiceProvider = getApplicationMgmtServiceImpl() + .getServiceProvider(appName, tenantDomain); + ServiceProviderProperty regulatoryProperty = getSpPropertyFromSPMetaData( + OpenBankingConstants.REGULATORY, appServiceProvider.getSpProperties()); if (regulatoryProperty != null) { if (Boolean.parseBoolean(regulatoryProperty.getValue())) { OAuthAppRequest updatedOauthAppRequest = oauthAppRequest; - org.wso2.carbon.identity.application.common.model.ServiceProviderProperty appNameProperty = - getSpPropertyFromSPMetaData("DisplayName", appServiceProvider.getSpProperties()); + ServiceProviderProperty appNameProperty = getSpPropertyFromSPMetaData("DisplayName", + appServiceProvider.getSpProperties()); if (appNameProperty != null) { updatedOauthAppRequest.getOAuthApplicationInfo().setClientName(appNameProperty.getValue()); } @@ -280,16 +255,16 @@ public OAuthApplicationInfo updateApplication(OAuthAppRequest oAuthAppRequest) t String clientId = oAuthApplicationInfo.getClientId(); // There is no way to identify the client type in here. So we have to hardcode "oauth2" as the client type try { - org.wso2.carbon.identity.application.common.model.ServiceProvider serviceProvider = - getApplicationMgmtServiceImpl().getServiceProviderByClientId(clientId, "oauth2", tenantDomain); + ServiceProvider serviceProvider = getApplicationMgmtServiceImpl() + .getServiceProviderByClientId(clientId, OAUTH2, tenantDomain); doPreUpdateApplication(oAuthAppRequest, additionalProperties, serviceProvider); String appName = serviceProvider.getApplicationName(); String username = (String) oAuthApplicationInfo.getParameter(ApplicationConstants.OAUTH_CLIENT_USERNAME); updateSpProperties(appName, tenantDomain, username, additionalProperties, false); } catch (IdentityApplicationManagementException e) { String errMsg = "Cannot find Service provider application for client Id " + clientId; - log.error(errMsg); - throw new APIManagementException(errMsg, ExceptionCodes.OAUTH2_APP_RETRIEVAL_FAILED); + log.error(errMsg); + throw new APIManagementException(errMsg, ExceptionCodes.OAUTH2_APP_RETRIEVAL_FAILED); } oAuthApplicationInfo = super.updateApplication(oAuthAppRequest); @@ -308,7 +283,7 @@ public OAuthApplicationInfo retrieveApplication(String consumerKey) throws APIMa getApplicationMgmtServiceImpl().getServiceProvider(name, tenantDomain); // Iterate OB specific additional properties to check whether they override the value of any predefined // sp properties in application management listeners - List spProperties = + List spProperties = new ArrayList<>(Arrays.asList(appServiceProvider.getSpProperties())); return updateAdditionalProperties(oAuthApplicationInfo, spProperties); } catch (IdentityApplicationManagementException | OpenBankingException e) { @@ -332,33 +307,30 @@ protected void updateSpProperties(String spAppName, String tenantDomain, String try { org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO oAuthConsumerAppDTO = getOAuthAdminService(). getOAuthApplicationDataByAppName(spAppName); - org.wso2.carbon.identity.application.common.model.ServiceProvider serviceProvider = - getApplicationMgmtServiceImpl().getServiceProvider(spAppName, tenantDomain); - + ServiceProvider serviceProvider = getApplicationMgmtServiceImpl() + .getServiceProvider(spAppName, tenantDomain); doPreUpdateSpApp(oAuthConsumerAppDTO, serviceProvider, additionalProperties, isCreateApp); // Iterate OB specific additional properties to check whether they override the value of any predefined // sp properties in application management listeners - List spProperties = + List spProperties = new ArrayList<>(Arrays.asList(serviceProvider.getSpProperties())); for (Map.Entry propertyElement : additionalProperties.entrySet()) { - org.wso2.carbon.identity.application.common.model.ServiceProviderProperty overridenSPproperty - = spProperties.stream().filter(serviceProviderProperty -> serviceProviderProperty.getName() - .equalsIgnoreCase(propertyElement.getKey())).findAny().orElse(null); + ServiceProviderProperty overridenSPproperty = spProperties.stream().filter( + serviceProviderProperty -> serviceProviderProperty.getName() + .equalsIgnoreCase(propertyElement.getKey())).findAny().orElse(null); // If SP property is overridden, remove old SP property and add the new one if (overridenSPproperty != null) { spProperties.remove(overridenSPproperty); overridenSPproperty.setValue(propertyElement.getValue()); spProperties.add(overridenSPproperty); } else { - org.wso2.carbon.identity.application.common.model.ServiceProviderProperty additionalProperty = - new org.wso2.carbon.identity.application.common.model.ServiceProviderProperty(); + ServiceProviderProperty additionalProperty = new ServiceProviderProperty(); additionalProperty.setName(propertyElement.getKey()); additionalProperty.setValue(propertyElement.getValue()); spProperties.add(additionalProperty); } } - serviceProvider.setSpProperties(spProperties.toArray( - new org.wso2.carbon.identity.application.common.model.ServiceProviderProperty[0])); + serviceProvider.setSpProperties(spProperties.toArray(new ServiceProviderProperty[0])); try { getApplicationMgmtServiceImpl().updateApplication(serviceProvider, tenantDomain, username); if (log.isDebugEnabled()) { @@ -395,13 +367,12 @@ protected void updateSpProperties(String spAppName, String tenantDomain, String * @return oAuth application Info */ protected OAuthApplicationInfo updateAdditionalProperties(OAuthApplicationInfo oAuthApplicationInfo, - List spProperties) { + List spProperties) { Map> keyManagerAdditionalProperties = OpenBankingConfigParser.getInstance() .getKeyManagerAdditionalProperties(); for (String key : keyManagerAdditionalProperties.keySet()) { - for (org.wso2.carbon.identity.application.common.model.ServiceProviderProperty spProperty : spProperties) { + for (ServiceProviderProperty spProperty : spProperties) { if (spProperty.getName().equalsIgnoreCase(key)) { ((HashMap) oAuthApplicationInfo.getParameter( APIConstants.JSON_ADDITIONAL_PROPERTIES)).put(key, spProperty.getValue()); @@ -421,8 +392,7 @@ protected OAuthApplicationInfo updateAdditionalProperties(OAuthApplicationInfo o public void validateAdditionalProperties(Map obAdditionalProperties) throws APIManagementException { - OBKeyManagerExtensionInterface obKeyManagerExtensionImpl = KeyManagerUtil - .getOBKeyManagerExtensionImpl(); + OBKeyManagerExtensionInterface obKeyManagerExtensionImpl = KeyManagerUtil.getOBKeyManagerExtensionImpl(); if (obKeyManagerExtensionImpl != null) { obKeyManagerExtensionImpl.validateAdditionalProperties(obAdditionalProperties); } @@ -437,8 +407,7 @@ public void validateAdditionalProperties(Map obAdditio @Generated(message = "Excluding from code coverage since the method body is at toolkit") public void doPreCreateApplication(OAuthAppRequest oAuthAppRequest, HashMap additionalProperties) throws APIManagementException { - OBKeyManagerExtensionInterface obKeyManagerExtensionImpl = KeyManagerUtil - .getOBKeyManagerExtensionImpl(); + OBKeyManagerExtensionInterface obKeyManagerExtensionImpl = KeyManagerUtil.getOBKeyManagerExtensionImpl(); if (obKeyManagerExtensionImpl != null) { obKeyManagerExtensionImpl.doPreCreateApplication(oAuthAppRequest, additionalProperties); } @@ -452,11 +421,8 @@ public void doPreCreateApplication(OAuthAppRequest oAuthAppRequest, HashMap additionalProperties, - org.wso2.carbon.identity.application.common.model.ServiceProvider - serviceProvider) - throws APIManagementException { - OBKeyManagerExtensionInterface obKeyManagerExtensionImpl = KeyManagerUtil - .getOBKeyManagerExtensionImpl(); + ServiceProvider serviceProvider) throws APIManagementException { + OBKeyManagerExtensionInterface obKeyManagerExtensionImpl = KeyManagerUtil.getOBKeyManagerExtensionImpl(); if (obKeyManagerExtensionImpl != null) { obKeyManagerExtensionImpl.doPreUpdateApplication(oAuthAppRequest, additionalProperties, serviceProvider); } @@ -472,12 +438,11 @@ public void doPreUpdateApplication(OAuthAppRequest oAuthAppRequest, HashMap additionalProperties, boolean isCreateApp) throws APIManagementException { - OBKeyManagerExtensionInterface obKeyManagerExtensionImpl = KeyManagerUtil - .getOBKeyManagerExtensionImpl(); + OBKeyManagerExtensionInterface obKeyManagerExtensionImpl = KeyManagerUtil.getOBKeyManagerExtensionImpl(); if (obKeyManagerExtensionImpl != null) { obKeyManagerExtensionImpl.doPreUpdateSpApp(oAuthConsumerAppDTO, serviceProvider, additionalProperties, isCreateApp); @@ -495,9 +460,8 @@ protected OAuthAdminService getOAuthAdminService() { return new OAuthAdminService(); } - protected org.wso2.carbon.identity.application.common.model.ServiceProviderProperty getSpPropertyFromSPMetaData( - String propertyName, - org.wso2.carbon.identity.application.common.model.ServiceProviderProperty[] spProperties) { + protected ServiceProviderProperty getSpPropertyFromSPMetaData(String propertyName, + ServiceProviderProperty[] spProperties) { return Arrays.asList(spProperties).stream().filter(serviceProviderProperty -> serviceProviderProperty.getName() .equalsIgnoreCase(propertyName)).findAny().orElse(null); diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.keymanager/src/main/java/com/wso2/openbanking/accelerator/keymanager/internal/KeyManagerDataHolder.java b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.keymanager/src/main/java/com/wso2/openbanking/accelerator/keymanager/internal/KeyManagerDataHolder.java index 6e3b9060..0e35ac0e 100644 --- a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.keymanager/src/main/java/com/wso2/openbanking/accelerator/keymanager/internal/KeyManagerDataHolder.java +++ b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.keymanager/src/main/java/com/wso2/openbanking/accelerator/keymanager/internal/KeyManagerDataHolder.java @@ -22,7 +22,6 @@ import org.wso2.carbon.apimgt.impl.APIConstants; import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService; import org.wso2.carbon.authenticator.stub.AuthenticationAdminStub; -import org.wso2.carbon.identity.application.mgt.stub.IdentityApplicationManagementServiceStub; import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceStub; import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.user.mgt.stub.UserAdminStub; @@ -41,7 +40,6 @@ public class KeyManagerDataHolder { public static final String AUTHENTICATION_ADMIN_SERVICE = "AuthenticationAdmin"; public static final String USER_ADMIN_SERVICE = "UserAdmin"; public static final String OAUTH_ADMIN_SERVICE = "OAuthAdminService"; - private IdentityApplicationManagementServiceStub identityApplicationManagementServiceStub; private AuthenticationAdminStub authenticationAdminStub; private OAuthAdminServiceStub oAuthAdminServiceStub; private UserAdminStub userAdminStub; @@ -75,23 +73,6 @@ public void setUserAdminStub(UserAdminStub userAdminStub) { this.userAdminStub = userAdminStub; } - public IdentityApplicationManagementServiceStub getIdentityApplicationManagementServiceStub() - throws AxisFault { - - if (identityApplicationManagementServiceStub == null) { - String appMgtServiceURL = backendServerURL + IDENTITY_APPLICATION_MGT_SERVICE; - identityApplicationManagementServiceStub = new IdentityApplicationManagementServiceStub( - appMgtServiceURL); - } - return identityApplicationManagementServiceStub; - } - - public void setIdentityApplicationManagementServiceStub(IdentityApplicationManagementServiceStub - identityApplicationManagementServiceStub) { - - this.identityApplicationManagementServiceStub = identityApplicationManagementServiceStub; - } - public AuthenticationAdminStub getAuthenticationAdminStub() throws AxisFault { if (authenticationAdminStub == null) { diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.keymanager/src/test/java/com/wso2/openbanking/accelerator/keymanager/KeyManagerTest.java b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.keymanager/src/test/java/com/wso2/openbanking/accelerator/keymanager/KeyManagerTest.java index a493ff2e..565e0d5b 100644 --- a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.keymanager/src/test/java/com/wso2/openbanking/accelerator/keymanager/KeyManagerTest.java +++ b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.keymanager/src/test/java/com/wso2/openbanking/accelerator/keymanager/KeyManagerTest.java @@ -52,11 +52,10 @@ import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService; import org.wso2.carbon.authenticator.stub.AuthenticationAdminStub; import org.wso2.carbon.authenticator.stub.LoginAuthenticationExceptionException; -import org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider; -import org.wso2.carbon.identity.application.common.model.xsd.ServiceProviderProperty; +import org.wso2.carbon.identity.application.common.IdentityApplicationManagementException; +import org.wso2.carbon.identity.application.common.model.ServiceProvider; +import org.wso2.carbon.identity.application.common.model.ServiceProviderProperty; import org.wso2.carbon.identity.application.mgt.ApplicationManagementServiceImpl; -import org.wso2.carbon.identity.application.mgt.stub.IdentityApplicationManagementServiceIdentityApplicationManagementException; -import org.wso2.carbon.identity.application.mgt.stub.IdentityApplicationManagementServiceStub; import org.wso2.carbon.identity.oauth.OAuthAdminService; import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceIdentityOAuthAdminException; import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceStub; @@ -87,9 +86,6 @@ public class KeyManagerTest extends PowerMockTestCase { @Mock private OAuthAdminServiceStub oAuthAdminServiceStub; - @Mock - private IdentityApplicationManagementServiceStub identityApplicationManagementServiceStub; - @Mock private AuthenticationAdminStub authenticationAdminStub; @@ -174,9 +170,9 @@ public IObjectFactory getObjectFactory() { @Test public void testGetNewApplicationAccessToken() throws APIManagementException, RemoteException, OAuthAdminServiceIdentityOAuthAdminException, - IdentityApplicationManagementServiceIdentityApplicationManagementException, - LoginAuthenticationExceptionException { + LoginAuthenticationExceptionException, IdentityApplicationManagementException { + OBKeyManagerImpl obKeyManager = spy(new OBKeyManagerImplMock()); OAuthConsumerAppDTO oAuthConsumerAppDTO = new OAuthConsumerAppDTO(); oAuthConsumerAppDTO.setApplicationName("AppName"); @@ -204,8 +200,6 @@ public void testGetNewApplicationAccessToken() throws APIManagementException, Re KeyManagerDataHolder.getInstance().setApiManagerConfiguration(apiManagerConfigurationService); KeyManagerDataHolder.getInstance().setAuthenticationAdminStub(authenticationAdminStub); KeyManagerDataHolder.getInstance().setOauthAdminServiceStub(oAuthAdminServiceStub); - KeyManagerDataHolder.getInstance() - .setIdentityApplicationManagementServiceStub(identityApplicationManagementServiceStub); AccessTokenRequest accessTokenRequest = new AccessTokenRequest(); @@ -227,16 +221,10 @@ public void testGetNewApplicationAccessToken() throws APIManagementException, Re Mockito.when(oAuthAdminServiceStub.getOAuthApplicationData(anyString())) .thenReturn(oAuthConsumerAppDTO); - Mockito.when(keyManagerDataHolder.getIdentityApplicationManagementServiceStub()) - .thenReturn(identityApplicationManagementServiceStub); - - Mockito.when(identityApplicationManagementServiceStub._getServiceClient()).thenReturn(serviceClient); - Mockito.when(identityApplicationManagementServiceStub - .getApplication(oAuthConsumerAppDTO.getApplicationName())) - .thenReturn(serviceProvider); - + Mockito.when(obKeyManager.getApplicationMgmtServiceImpl()).thenReturn(applicationManagementServiceImpl); + Mockito.when(applicationManagementServiceImpl.getServiceProviderByClientId( + anyString(), anyString(), anyString())).thenReturn(serviceProvider); AccessTokenInfo accessTokenInfo = obKeyManager.getNewApplicationAccessToken(accessTokenRequest); - Assert.assertTrue(accessTokenInfo == null); } @@ -249,7 +237,7 @@ public void testUpdateAdditionalProperties() { keyManagerAdditionalProperties.put(dummyPropertyName2, property); when(openBankingConfigParser.getKeyManagerAdditionalProperties()).thenReturn(keyManagerAdditionalProperties); - spy(org.wso2.carbon.identity.application.common.model.ServiceProvider.class); + spy(ServiceProvider.class); List spProperties = new ArrayList<>(); @@ -305,8 +293,7 @@ public void testUpdateSpProperties() throws Exception { spProperties[0] = (spProperty1); spProperties[1] = (spProperty2); - org.wso2.carbon.identity.application.common.model.ServiceProvider serviceProvider = - spy(org.wso2.carbon.identity.application.common.model.ServiceProvider.class); + ServiceProvider serviceProvider = spy(ServiceProvider.class); doNothing().when(applicationManagementServiceImpl).updateApplication(Mockito.anyObject(), Mockito.anyString(), Mockito.anyString()); @@ -344,8 +331,7 @@ public void testUpdateSpProperties() throws Exception { org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO oAuthConsumerAppDTOdummy = new org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO(); - org.wso2.carbon.identity.application.common.model.ServiceProvider serviceProviderDummy = - new org.wso2.carbon.identity.application.common.model.ServiceProvider(); + ServiceProvider serviceProviderDummy = new ServiceProvider(); HashMap dummyMap = new HashMap<>(); doNothing().when(obKeyManager).doPreUpdateSpApp(oAuthConsumerAppDTOdummy, serviceProviderDummy, dummyMap, @@ -460,7 +446,7 @@ public Object[][] validateOAuthAppCreationPropertiesDataProvider() { @Test(dataProvider = "validateOAuthAppCreationPropertiesDataProvider", description = "Validate user inputs for application creation") public void testValidateOAuthAppCreationProperties(Map> - keyManagerAdditionalProperties, + keyManagerAdditionalProperties, List applicationConfigurationsList, String valuesForProperties, Class exceptionType) {