From 3404dfab3c748f8ebe5d0fffd7627502521df217 Mon Sep 17 00:00:00 2001 From: uditha Date: Tue, 25 Apr 2017 09:10:38 +0530 Subject: [PATCH] IDSDEV-365 Mobile Connect Request Validator Capability in IDGW Related Development --- components/auth-proxy-service/pom.xml | 12 + .../com/wso2telco/proxy/entity/Endpoints.java | 116 +++++++++ components/gsma-authenticators/pom.xml | 2 +- components/openid-token-builder/pom.xml | 6 +- .../OpenIdTokenBuilderServiceComponent.java | 33 ++- components/sp-seamless-provision/pom.xml | 231 ++++++++++++++++++ .../SeamlessProvisionClientAuthHandler.java | 208 ++++++++++++++++ .../sp/builder/ServiceProviderBuilder.java | 173 +++++++++++++ .../sp/discovery/DiscoveryLocator.java | 40 +++ .../discovery/InlineConnectionStrategies.java | 16 ++ .../sp/discovery/LocalDiscovery.java | 131 ++++++++++ .../discovery/RemoteCredentialDiscovery.java | 92 +++++++ .../sp/discovery/RemoteDiscovery.java | 177 ++++++++++++++ .../RemoteExcKeySecretDiscovery.java | 87 +++++++ .../exception/DicoveryException.java | 40 +++ .../DiscoveryValidationException.java | 28 +++ .../discovery/service/DiscoveryService.java | 33 +++ .../service/impl/DiscoveryServiceImpl.java | 77 ++++++ .../java/com/wso2telco/sp/entity/Apis.java | 35 +++ .../com/wso2telco/sp/entity/Application.java | 136 +++++++++++ .../wso2telco/sp/entity/CrValidateRes.java | 54 ++++ .../com/wso2telco/sp/entity/EksDiscovery.java | 45 ++++ .../java/com/wso2telco/sp/entity/Link.java | 45 ++++ .../com/wso2telco/sp/entity/OperatorId.java | 35 +++ .../com/wso2telco/sp/entity/Response.java | 84 +++++++ .../wso2telco/sp/entity/SupportedApis.java | 33 +++ ...ovisionAppManagementServiceDataHolder.java | 23 ++ ...nAppManagementServiceServiceComponent.java | 44 ++++ .../SpProvisionOauthServiceDataHolder.java | 23 ++ ...ProvisionOauthServiceServiceComponent.java | 43 ++++ .../sp/internal/SpProvisionPcrDataHolder.java | 42 ++++ .../SpProvisionPcrServiceComponent.java | 57 +++++ .../sp/provision/LocalProvisioner.java | 61 +++++ .../wso2telco/sp/provision/Provisioner.java | 38 +++ .../sp/provision/RemoteProvisioner.java | 55 +++++ .../ServiceProviderProvisionFactory.java | 35 +++ .../service/ProvisioningService.java | 33 +++ .../service/impl/ProvisioningServiceImpl.java | 99 ++++++++ .../com/wso2telco/sp/util/TransformUtil.java | 153 ++++++++++++ .../com/wso2telco/sp/util/ValidationUtil.java | 48 ++++ .../sp/discovery/DiscoveryLocatorTest.java | 43 ++++ .../sp/discovery/LocalDiscoveryTest.java | 76 ++++++ .../RemoteCredentialDiscoveryTest.java | 100 ++++++++ .../com/wso2telco/sp/entity/TestApis.java | 36 +++ .../wso2telco/sp/entity/TestApplication.java | 81 ++++++ .../sp/entity/TestCrValidateRes.java | 46 ++++ .../wso2telco/sp/entity/TestEksDiscovery.java | 40 +++ .../com/wso2telco/sp/entity/TestLink.java | 42 ++++ .../wso2telco/sp/entity/TestOperatorId.java | 40 +++ .../com/wso2telco/sp/entity/TestResponse.java | 61 +++++ .../sp/entity/TestSupportedApis.java | 37 +++ .../wso2telco/sp/util/TransformUtilTest.java | 101 ++++++++ .../wso2telco/sp/util/ValidationUtilTest.java | 74 ++++++ components/url-shorten/pom.xml | 4 +- .../pom.xml | 49 ++++ features/pom.xml | 1 + parent/pom.xml | 12 +- pom.xml | 168 ++++++------- 58 files changed, 3626 insertions(+), 108 deletions(-) create mode 100644 components/sp-seamless-provision/pom.xml create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/carbon/identity/oauth2/token/handlers/clientauth/SeamlessProvisionClientAuthHandler.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/builder/ServiceProviderBuilder.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/DiscoveryLocator.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/InlineConnectionStrategies.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/LocalDiscovery.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/RemoteCredentialDiscovery.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/RemoteDiscovery.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/RemoteExcKeySecretDiscovery.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/exception/DicoveryException.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/exception/DiscoveryValidationException.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/service/DiscoveryService.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/service/impl/DiscoveryServiceImpl.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/Apis.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/Application.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/CrValidateRes.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/EksDiscovery.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/Link.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/OperatorId.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/Response.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/SupportedApis.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/internal/SpProvisionAppManagementServiceDataHolder.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/internal/SpProvisionAppManagementServiceServiceComponent.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/internal/SpProvisionOauthServiceDataHolder.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/internal/SpProvisionOauthServiceServiceComponent.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/internal/SpProvisionPcrDataHolder.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/internal/SpProvisionPcrServiceComponent.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/provision/LocalProvisioner.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/provision/Provisioner.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/provision/RemoteProvisioner.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/provision/ServiceProviderProvisionFactory.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/provision/service/ProvisioningService.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/provision/service/impl/ProvisioningServiceImpl.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/util/TransformUtil.java create mode 100644 components/sp-seamless-provision/src/main/java/com/wso2telco/sp/util/ValidationUtil.java create mode 100644 components/sp-seamless-provision/src/test/java/com/wso2telco/sp/discovery/DiscoveryLocatorTest.java create mode 100644 components/sp-seamless-provision/src/test/java/com/wso2telco/sp/discovery/LocalDiscoveryTest.java create mode 100644 components/sp-seamless-provision/src/test/java/com/wso2telco/sp/discovery/RemoteCredentialDiscoveryTest.java create mode 100644 components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestApis.java create mode 100644 components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestApplication.java create mode 100644 components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestCrValidateRes.java create mode 100644 components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestEksDiscovery.java create mode 100644 components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestLink.java create mode 100644 components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestOperatorId.java create mode 100644 components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestResponse.java create mode 100644 components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestSupportedApis.java create mode 100644 components/sp-seamless-provision/src/test/java/com/wso2telco/sp/util/TransformUtilTest.java create mode 100644 components/sp-seamless-provision/src/test/java/com/wso2telco/sp/util/ValidationUtilTest.java create mode 100644 features/com.wso2telco.ids.spseamlessprovision.feature/pom.xml diff --git a/components/auth-proxy-service/pom.xml b/components/auth-proxy-service/pom.xml index 7bfd0d39..253bd9bb 100644 --- a/components/auth-proxy-service/pom.xml +++ b/components/auth-proxy-service/pom.xml @@ -100,6 +100,18 @@ 2.2.0-SNAPSHOT provided + + com.wso2telco.ids + sp-seamless-provision + 2.2.0-SNAPSHOT + provided + + + com.wso2telco.core + spprovisionservice + 2.0.22-SNAPSHOT + provided + diff --git a/components/auth-proxy-service/src/main/java/com/wso2telco/proxy/entity/Endpoints.java b/components/auth-proxy-service/src/main/java/com/wso2telco/proxy/entity/Endpoints.java index 2f4acd8d..981222bc 100755 --- a/components/auth-proxy-service/src/main/java/com/wso2telco/proxy/entity/Endpoints.java +++ b/components/auth-proxy-service/src/main/java/com/wso2telco/proxy/entity/Endpoints.java @@ -15,6 +15,48 @@ ******************************************************************************/ package com.wso2telco.proxy.entity; +import java.io.FileNotFoundException; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.rmi.RemoteException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.UUID; + +import javax.crypto.BadPaddingException; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; +import javax.naming.ConfigurationException; +import javax.naming.NamingException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.UriInfo; + +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.identity.application.authentication.framework.exception.AuthenticationFailedException; +import org.wso2.carbon.identity.user.registration.stub.UserRegistrationAdminService; +import org.wso2.carbon.identity.user.registration.stub.UserRegistrationAdminServiceException; +import org.wso2.carbon.identity.user.registration.stub.UserRegistrationAdminServiceIdentityException; +import org.wso2.carbon.identity.user.registration.stub.UserRegistrationAdminServiceStub; +import org.wso2.carbon.identity.user.registration.stub.UserRegistrationAdminServiceUserRegistrationException; +import org.wso2.carbon.identity.user.registration.stub.dto.UserDTO; +import org.wso2.carbon.identity.user.registration.stub.dto.UserFieldDTO; + import com.google.gdata.util.common.util.Base64DecoderException; import com.sun.jersey.spi.container.ContainerRequest; import com.wso2telco.core.config.model.LoginHintFormatDetails; @@ -22,6 +64,13 @@ import com.wso2telco.core.config.model.ScopeParam; import com.wso2telco.core.config.service.ConfigurationService; import com.wso2telco.core.config.service.ConfigurationServiceImpl; +import com.wso2telco.core.spprovisionservice.sp.entity.AdminServiceConfig; +import com.wso2telco.core.spprovisionservice.sp.entity.AdminServiceDto; +import com.wso2telco.core.spprovisionservice.sp.entity.ProvisionType; +import com.wso2telco.core.spprovisionservice.sp.entity.ServiceProviderDto; +import com.wso2telco.core.spprovisionservice.sp.entity.SpProvisionConfig; +import com.wso2telco.core.spprovisionservice.sp.entity.SpProvisionDto; +import com.wso2telco.core.spprovisionservice.sp.exception.SpProvisionServiceException; import com.wso2telco.ids.datapublisher.model.UserStatus; import com.wso2telco.ids.datapublisher.util.DataPublisherUtil; import com.wso2telco.proxy.MSISDNDecryption; @@ -32,6 +81,11 @@ import com.wso2telco.proxy.util.DBUtils; import com.wso2telco.proxy.util.Decrypt; import com.wso2telco.proxy.util.EncryptAES; +import com.wso2telco.sp.discovery.service.DiscoveryService; +import com.wso2telco.sp.discovery.service.impl.DiscoveryServiceImpl; +import com.wso2telco.sp.provision.service.ProvisioningService; +import com.wso2telco.sp.provision.service.impl.ProvisioningServiceImpl; +import com.wso2telco.sp.util.TransformUtil; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -71,6 +125,7 @@ public class Endpoints { private static MobileConnectConfig mobileConnectConfigs = null; private static Map> operatorsMSISDNHeadersMap; private static Map operatorPropertiesMap = null; + private static AdminServiceConfig adminServiceConfig = null; /** * The Configuration service @@ -104,6 +159,8 @@ public class Endpoints { for (MobileConnectConfig.OPERATOR op : operators) { operatorPropertiesMap.put(op.getOperatorName(), op); } + adminServiceConfig = new AdminServiceConfig(); + getSpProvisionConfig(mobileConnectConfigs); } catch (SQLException e) { log.error("Error occurred while retrieving operator MSISDN properties of operators."); } catch (NamingException e) { @@ -127,6 +184,7 @@ public void RedirectToAuthorizeEndpoint(@Context HttpServletRequest httpServletR String redirectURL = queryParams.get(AuthProxyConstants.REDIRECT_URI).get(0); String scopeName = queryParams.get(AuthProxyConstants.SCOPE).get(0); + serviceProviderSeamlessProvision(httpServletRequest.getParameter("client_id"), redirectURL); //maintain userstatus related to request for data publishing purpose UserStatus userStatus = DataPublisherUtil.buildUserStatusFromRequest(httpServletRequest, null); @@ -285,6 +343,64 @@ public void RedirectToAuthorizeEndpoint(@Context HttpServletRequest httpServletR httpServletResponse.sendRedirect(redirectURL); } + private void serviceProviderSeamlessProvision(String client_id, String redirectURL) { + DiscoveryService discoveryService = new DiscoveryServiceImpl(); + if (mobileConnectConfigs.isSeamlessProvisioningEnabled() && !client_id.isEmpty() && client_id != null && + !redirectURL.isEmpty() && redirectURL != null) { + ServiceProviderDto serviceProviderDto = discoveryService.servceProviderCredentialDiscovery( + TransformUtil.transformDiscoveryConfig(mobileConnectConfigs.getDiscoveryConfig(), + mobileConnectConfigs), + TransformUtil.transofrmDiscoveryDto(client_id, redirectURL), + getServiceProviderDto(null, mobileConnectConfigs)); + + if (serviceProviderDto != null && serviceProviderDto.getExistance().equals(ProvisionType.REMOTE) + && serviceProviderDto.getAdminServiceDto() != null) { + log.info("Provisioning Service Provider to Local data store...."); + serviceProviderSeamlessProvision(serviceProviderDto); + } + } + } + + private void serviceProviderSeamlessProvision(ServiceProviderDto serviceProvider) { + + SpProvisionDto spProvisionDto = null; + + try { + + boolean isSeamlessProvisioningEnabled = mobileConnectConfigs.isSeamlessProvisioningEnabled(); + MobileConnectConfig.Config config = mobileConnectConfigs.getSpProvisionConfig().getConfig(); + + if (isSeamlessProvisioningEnabled && serviceProvider != null) { + if (config != null) { + spProvisionDto = getServiceProviderDto(serviceProvider, mobileConnectConfigs); + ProvisioningService provisioningService = new ProvisioningServiceImpl(); + provisioningService.provisionServiceProvider(spProvisionDto); + } else { + log.error("Config null"); + } + } + } catch (SpProvisionServiceException e) { + log.error("Error occurred in provisioning a Service Provider " + e.getMessage()); + } + } + + private SpProvisionDto getServiceProviderDto(ServiceProviderDto serviceProvider, + MobileConnectConfig config) { + + SpProvisionDto spProvisionDto = TransformUtil.getServiceProviderDto(serviceProvider, config); + spProvisionDto.getSpProvisionConfig().setAdminServiceConfig(adminServiceConfig); + return spProvisionDto; + + } + + private static AdminServiceConfig getSpProvisionConfig(MobileConnectConfig config) { + adminServiceConfig.setAdminServiceUrl(config.getSpProvisionConfig().getAdminServiceUrl()); + adminServiceConfig + .setApplicationManagementHostUrl(config.getSpProvisionConfig().getApplicationManagementHostUrl()); + adminServiceConfig.setStubAccessPassword(config.getSpProvisionConfig().getStubAccessPassword()); + adminServiceConfig.setStubAccessUserName(config.getSpProvisionConfig().getStubAccessUserName()); + return adminServiceConfig; + } /** * Check if the Scope is allowed for SP diff --git a/components/gsma-authenticators/pom.xml b/components/gsma-authenticators/pom.xml index a1b72384..e071b7ce 100644 --- a/components/gsma-authenticators/pom.xml +++ b/components/gsma-authenticators/pom.xml @@ -115,7 +115,7 @@ com.wso2telco.core sp-config-util - 2.0.21 + 2.0.22-SNAPSHOT provided diff --git a/components/openid-token-builder/pom.xml b/components/openid-token-builder/pom.xml index 9fae57d9..ebf58309 100644 --- a/components/openid-token-builder/pom.xml +++ b/components/openid-token-builder/pom.xml @@ -106,7 +106,7 @@ org.apache.felix maven-scr-plugin - 1.7.2 + 1.9.0 generate-scr-scrdescriptor @@ -127,7 +127,7 @@ ${project.artifactId} ${project.version} Open ID Token Builder Bundle - com.wso2telco.internal + javax.xml.namespace, javax.xml.stream, @@ -193,7 +193,7 @@ com.wso2telco.claimhandler.*, com.wso2telco.dao.*, com.wso2telco.model.*, com.wso2telco.openidtokenbuilder.*, com.wso2telco.reqpathsequencehandler.*, - com.wso2telco.transaction.log.*, com.wso2telco.util.*,!com.wso2telco.internal.* + com.wso2telco.transaction.log.*, com.wso2telco.util.*,com.wso2telco.internal.* nimbus-jose-jwt|json-smart;scope=compile|runtime;inline=false diff --git a/components/openid-token-builder/src/main/java/com/wso2telco/internal/OpenIdTokenBuilderServiceComponent.java b/components/openid-token-builder/src/main/java/com/wso2telco/internal/OpenIdTokenBuilderServiceComponent.java index baff0996..c042a5fd 100644 --- a/components/openid-token-builder/src/main/java/com/wso2telco/internal/OpenIdTokenBuilderServiceComponent.java +++ b/components/openid-token-builder/src/main/java/com/wso2telco/internal/OpenIdTokenBuilderServiceComponent.java @@ -1,32 +1,39 @@ package com.wso2telco.internal; import com.wso2telco.core.pcrservice.PCRGeneratable; +import com.wso2telco.core.pcrservice.persistable.UUIDPCRGenarator; + +import org.osgi.framework.BundleContext; +import org.osgi.service.component.ComponentContext; +import org.apache.felix.scr.annotations.*; + + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.osgi.service.component.ComponentContext; -/** - * @scr.component name="com.wso2telco.internal.OpenIdTokenBuilderServiceComponent" immediate="true" - * @scr.reference name="com.wso2telco.core.pcrservice.internal.PCRServiceComponent" - * interface="com.wso2telco.core.pcrservice.PCRGeneratable" - * cardinality="1..1" - * policy="dynamic" - * bind="setPcrService" - * unbind="unsetPcrService" - */ +@Component(name = "com.wso2telco.internal.OpenIdTokenBuilderServiceComponent", immediate = true) +@Reference( + name = "com.wso2telco.core.pcrservice.internal.PCRServiceComponent", + referenceInterface = com.wso2telco.core.pcrservice.PCRGeneratable.class, + cardinality = ReferenceCardinality.MANDATORY_UNARY, + policy = ReferencePolicy.DYNAMIC, + bind = "setPcrService", + unbind = "unsetPcrService" +) public class OpenIdTokenBuilderServiceComponent { private static Log log = LogFactory.getLog(OpenIdTokenBuilderServiceComponent.class); + @Activate protected void activate(ComponentContext componentContext) { log.debug("OpenIdTokenBuilder Bundle Activated"); } - + @Deactivate protected void deactivate(ComponentContext componentContext) { - //do nothing + // do nothing } - + protected void setPcrService(PCRGeneratable pcrGeneratable) { OpenIdTokenBuilderDataHolder.getInstance().setPcrGeneratable(pcrGeneratable); } diff --git a/components/sp-seamless-provision/pom.xml b/components/sp-seamless-provision/pom.xml new file mode 100644 index 00000000..8f4ffabe --- /dev/null +++ b/components/sp-seamless-provision/pom.xml @@ -0,0 +1,231 @@ + + + + + + + com.wso2telco.ids + component-ids-parent + 2.2.0-SNAPSHOT + ../../parent/pom.xml + + + 4.0.0 + sp-seamless-provision + bundle + + Sp Seamless Provisioner + + + true + 4.11 + 1.5.6 + 2.0.22-SNAPSHOT + 3.3 + 1.7 + 2.19 + 1.9.0 + + + + + org.apache.felix + org.apache.felix.scr.annotations + 1.9.0 + + + com.wso2telco.core + config-util + provided + + + org.slf4j + slf4j-log4j12 + + + + + com.wso2telco.core + spprovisionservice + ${com.wso2telco.core.version} + provided + + + org.slf4j + slf4j-log4j12 + + + log4j + log4j + + + org.slf4j + slf4j-jdk14 + + + + + org.wso2.carbon + org.wso2.carbon.logging + + + org.slf4j + slf4j-log4j12 + + + + + + org.wso2.carbon.identity + org.wso2.carbon.identity.oauth + + + org.slf4j + jcl-over-slf4j + + + + org.slf4j + log4j-over-slf4j + + + + org.slf4j + jul-to-slf4j + + + org.slf4j + slf4j-jdk14 + + + org.slf4j + slf4j-log4j12 + + + + + junit + junit + ${junit.version} + test + + + org.slf4j + slf4j-log4j12 + + + + + com.google.code.gson + gson + jar + provided + + + org.slf4j + slf4j-log4j12 + + + + + com.wso2telco.core + pcr-service + ${com.wso2telco.core.version} + compile + + + org.slf4j + slf4j-log4j12 + + + log4j + log4j + + + org.slf4j + slf4j-jdk14 + + + + + + + org.slf4j + slf4j-api + ${org.slf4j.verison} + + + org.slf4j + slf4j-log4j12 + ${org.slf4j.verison} + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${org.apache.maven.compiler.plugins.version} + + ${org.apache.maven.compiler.plugins.config.source.version} + ${org.apache.maven.compiler.plugins.config.source.version} + + + + org.apache.maven.plugins + maven-surefire-plugin + ${org.apache.maven.surefire.plugins.version} + + false + + + + org.apache.felix + maven-scr-plugin + ${org.apache.felix.src.plugin.version} + + + generate-scr-scrdescriptor + + scr + + + + + + org.apache.felix + maven-bundle-plugin + true + ${maven.bundle.plugin.version} + + + ${project.groupId}.${project.artifactId} + ${project.artifactId} + ${project.version} + Open ID Token Builder Bundle + + com.wso2telco.core.spprovisionservice.* + + + com.wso2telco.sp.*,com.wso2telco.carbon.* + + + nimbus-jose-jwt|json-smart;scope=compile|runtime;inline=false + + * + + + + + + diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/carbon/identity/oauth2/token/handlers/clientauth/SeamlessProvisionClientAuthHandler.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/carbon/identity/oauth2/token/handlers/clientauth/SeamlessProvisionClientAuthHandler.java new file mode 100644 index 00000000..7103b3e0 --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/carbon/identity/oauth2/token/handlers/clientauth/SeamlessProvisionClientAuthHandler.java @@ -0,0 +1,208 @@ +/******************************************************************************* + * Copyright (c) 2015-2017, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved. + * + * WSO2.Telco Inc. licences 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +package com.wso2telco.carbon.identity.oauth2.token.handlers.clientauth; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.identity.oauth.IdentityOAuthAdminException; +import org.wso2.carbon.identity.oauth.common.exception.InvalidOAuthClientException; +import org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception; +import org.wso2.carbon.identity.oauth2.dto.OAuth2AccessTokenReqDTO; +import org.wso2.carbon.identity.oauth2.token.OAuthTokenReqMessageContext; +import org.wso2.carbon.identity.oauth2.token.handlers.clientauth.AbstractClientAuthHandler; +import org.wso2.carbon.identity.oauth2.util.OAuth2Util; + +import com.wso2telco.core.config.model.MobileConnectConfig; +import com.wso2telco.core.config.model.MobileConnectConfig.DiscoveryConfig; +import com.wso2telco.core.config.service.ConfigurationService; +import com.wso2telco.core.config.service.ConfigurationServiceImpl; +import com.wso2telco.core.pcrservice.util.SectorUtil; +import com.wso2telco.core.spprovisionservice.sp.entity.AdminServiceConfig; +import com.wso2telco.core.spprovisionservice.sp.entity.DiscoveryServiceConfig; +import com.wso2telco.core.spprovisionservice.sp.entity.DiscoveryServiceDto; +import com.wso2telco.core.spprovisionservice.sp.entity.ProvisionType; +import com.wso2telco.core.spprovisionservice.sp.entity.ServiceProviderDto; +import com.wso2telco.core.spprovisionservice.sp.entity.SpProvisionDto; +import com.wso2telco.core.spprovisionservice.sp.exception.SpProvisionServiceException; +import com.wso2telco.sp.discovery.service.DiscoveryService; +import com.wso2telco.sp.discovery.service.impl.DiscoveryServiceImpl; +import com.wso2telco.sp.provision.service.ProvisioningService; +import com.wso2telco.sp.provision.service.impl.ProvisioningServiceImpl; +import com.wso2telco.sp.util.TransformUtil; + +public class SeamlessProvisionClientAuthHandler extends AbstractClientAuthHandler { + + private static Log log = LogFactory.getLog(SeamlessProvisionClientAuthHandler.class); + private static MobileConnectConfig mobileConnectConfigs = null; + private static ConfigurationService configurationService = new ConfigurationServiceImpl(); + + public SeamlessProvisionClientAuthHandler() { + + mobileConnectConfigs = configurationService.getDataHolder().getMobileConnectConfig(); + } + + @Override + public boolean authenticateClient(OAuthTokenReqMessageContext tokReqMsgCtx) throws IdentityOAuth2Exception { + seamlessProvisioning(tokReqMsgCtx); + boolean isAuthenticated = super.authenticateClient(tokReqMsgCtx); + + if (!isAuthenticated) { + OAuth2AccessTokenReqDTO oAuth2AccessTokenReqDTO = tokReqMsgCtx.getOauth2AccessTokenReqDTO(); + try { + return OAuth2Util.authenticateClient(oAuth2AccessTokenReqDTO.getClientId(), + oAuth2AccessTokenReqDTO.getClientSecret()); + } catch (IdentityOAuthAdminException e) { + throw new IdentityOAuth2Exception("Error while authenticating client", e); + } catch (InvalidOAuthClientException e) { + throw new IdentityOAuth2Exception("Invalid Client : " + oAuth2AccessTokenReqDTO.getClientId(), e); + } + } else { + return true; + } + } + + private void seamlessProvisioning(OAuthTokenReqMessageContext tokReqMsgCtx) throws IdentityOAuth2Exception { + log.info("Initiating seamless provisioning procees"); + if (mobileConnectConfigs.isSeamlessProvisioningEnabled()) { + ServiceProviderDto serviceProviderDto = discoverServiceProvider(tokReqMsgCtx.getOauth2AccessTokenReqDTO()); + clearServiceProviderCredentials(serviceProviderDto); + if (isServiceProviderExistRemotly(serviceProviderDto)) { + log.info("Service Provider does not contain same credentials. Provisioning new credentials..."); + if (isInompleteServiceProviderExistLocally( + serviceProviderDto.getAdminServiceDto().getOauthConsumerKey())) { + provisionServiceProviderKeys(serviceProviderDto); + } else { + log.info("Service Provider does not found LOCALLY... Auth token creation failed..."); + throw new IdentityOAuth2Exception("Service Provider Not Found"); + } + } else if (serviceProviderDto == null) { + log.info("Service Provider does not found LOCALLY OR REMOTELY... Auth token creation failed..."); + throw new IdentityOAuth2Exception("Service Provider Not Found"); + } + } + } + + private void clearServiceProviderCredentials(ServiceProviderDto serviceProvider) { + if (serviceProvider != null && serviceProvider.getAdminServiceDto() != null + && serviceProvider.getAdminServiceDto().getOauthConsumerKey() != null + && !serviceProvider.getAdminServiceDto().getOauthConsumerKey().isEmpty() + && serviceProvider.getAdminServiceDto().getOauthConsumerSecret() != null + && !serviceProvider.getAdminServiceDto().getOauthConsumerSecret().isEmpty()) { + + String cutomerKey = serviceProvider.getAdminServiceDto().getOauthConsumerKey().replaceAll("x-", ""); + String secretKey = serviceProvider.getAdminServiceDto().getOauthConsumerSecret().replaceAll("x-", ""); + serviceProvider.getAdminServiceDto().setOauthConsumerKey(cutomerKey); + serviceProvider.getAdminServiceDto().setOauthConsumerSecret(secretKey); + } + } + + private boolean isInompleteServiceProviderExistLocally(String clinetId) { + boolean isExist = false; + ProvisioningServiceImpl provisioningService = new ProvisioningServiceImpl(); + MobileConnectConfig.Config config = mobileConnectConfigs.getSpProvisionConfig().getConfig(); + if (provisioningService.getOauthServiceProviderData(clinetId, + getServiceProviderDto(null, mobileConnectConfigs)) != null) { + isExist = true; + } + return isExist; + } + + private boolean isServiceProviderExistRemotly(ServiceProviderDto serviceProviderDto) { + boolean isExistRemotly = false; + if (serviceProviderDto != null && serviceProviderDto.getExistance() != null + && serviceProviderDto.getExistance().equals(ProvisionType.REMOTE) + && serviceProviderDto.getAdminServiceDto() != null) { + isExistRemotly = true; + } + return isExistRemotly; + } + + private void provisionServiceProviderKeys(ServiceProviderDto serviceProvider) { + + SpProvisionDto spProvisionDto = null; + ProvisioningService provisioningService = new ProvisioningServiceImpl(); + try { + + boolean isSeamlessProvisioningEnabled = mobileConnectConfigs.isSeamlessProvisioningEnabled(); + MobileConnectConfig.Config config = mobileConnectConfigs.getSpProvisionConfig().getConfig(); + + if (isSeamlessProvisioningEnabled) { + if (config != null) { + spProvisionDto = getServiceProviderDto(serviceProvider, mobileConnectConfigs); + provisioningService.rebuildOauthKeys(spProvisionDto); + } else { + log.error("Config null"); + } + } + } catch (SpProvisionServiceException e) { + log.error("Error occurred in provisioning a Service Provider " + e.getMessage()); + } + } + + private SpProvisionDto getServiceProviderDto(ServiceProviderDto serviceProvider, MobileConnectConfig mConfig) { + SpProvisionDto spProvisionDto = TransformUtil.getServiceProviderDto(serviceProvider, mConfig); + spProvisionDto.getSpProvisionConfig().setAdminServiceConfig(getSpProvisionConfig(mConfig)); + return spProvisionDto; + + } + + private AdminServiceConfig getSpProvisionConfig(MobileConnectConfig config) { + AdminServiceConfig adminServiceConfig = new AdminServiceConfig(); + adminServiceConfig.setAdminServiceUrl(config.getSpProvisionConfig().getAdminServiceUrl()); + adminServiceConfig + .setApplicationManagementHostUrl(config.getSpProvisionConfig().getApplicationManagementHostUrl()); + adminServiceConfig.setStubAccessPassword(config.getSpProvisionConfig().getStubAccessPassword()); + adminServiceConfig.setStubAccessUserName(config.getSpProvisionConfig().getStubAccessUserName()); + return adminServiceConfig; + } + + private ServiceProviderDto discoverServiceProvider(OAuth2AccessTokenReqDTO oAuth2AccessTokenReqDTO) + throws IdentityOAuth2Exception { + ServiceProviderDto serviceProviderDto = null; + DiscoveryService discoveryService = new DiscoveryServiceImpl(); + try { + serviceProviderDto = discoveryService.servceProviderEksDiscovery(readDiscoveryConfigs(), + getDiscoveryServiceDto(oAuth2AccessTokenReqDTO), getServiceProviderDto(null, mobileConnectConfigs)); + } catch (Exception e) { + log.error("" + e.getMessage()); + } + return serviceProviderDto; + } + + private DiscoveryServiceConfig readDiscoveryConfigs() { + return TransformUtil.transformDiscoveryConfig(getDiscoveryConfig(), getMobileConnectConfig()); + } + + private DiscoveryServiceDto getDiscoveryServiceDto(OAuth2AccessTokenReqDTO oAuth2AccessTokenReqDTO) { + DiscoveryServiceDto discoveryServiceDto = new DiscoveryServiceDto(); + discoveryServiceDto.setClientId(oAuth2AccessTokenReqDTO.getClientId()); + discoveryServiceDto.setClientSecret(oAuth2AccessTokenReqDTO.getClientSecret()); + String sectorId = SectorUtil.getSectorIdFromUrl(oAuth2AccessTokenReqDTO.getCallbackURI()); + discoveryServiceDto.setSectorId(sectorId); + return discoveryServiceDto; + } + + private DiscoveryConfig getDiscoveryConfig() { + mobileConnectConfigs = configurationService.getDataHolder().getMobileConnectConfig(); + return mobileConnectConfigs.getDiscoveryConfig(); + } + + private MobileConnectConfig getMobileConnectConfig() { + mobileConnectConfigs = configurationService.getDataHolder().getMobileConnectConfig(); + return mobileConnectConfigs; + } + +} diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/builder/ServiceProviderBuilder.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/builder/ServiceProviderBuilder.java new file mode 100644 index 00000000..a3f8692f --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/builder/ServiceProviderBuilder.java @@ -0,0 +1,173 @@ +/******************************************************************************* + * Copyright (c) 2015-2017, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved. + * + * WSO2.Telco Inc. licences 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +package com.wso2telco.sp.builder; + +import com.wso2telco.core.spprovisionservice.external.admin.service.OauthAdminService; +import com.wso2telco.core.spprovisionservice.external.admin.service.SpAppManagementService; +import com.wso2telco.core.spprovisionservice.external.admin.service.impl.OauthAdminServiceImpl; +import com.wso2telco.core.spprovisionservice.external.admin.service.impl.SpAppManagementServiceImpl; +import com.wso2telco.core.spprovisionservice.sp.entity.AdminServiceDto; +import com.wso2telco.core.spprovisionservice.sp.entity.ServiceProviderDto; +import com.wso2telco.core.spprovisionservice.sp.entity.SpProvisionConfig; +import com.wso2telco.core.spprovisionservice.sp.exception.SpProvisionServiceException; +import com.wso2telco.sp.internal.SpProvisionAppManagementServiceDataHolder; +import com.wso2telco.sp.internal.SpProvisionOauthServiceDataHolder; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider; +import org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO; + +public class ServiceProviderBuilder { + + private OauthAdminService adminService = null; + private SpAppManagementService spAppManagementService = null; + private static Log log = LogFactory.getLog(ServiceProviderBuilder.class); + private SpProvisionConfig spProvisionConfig = null; + + public ServiceProviderBuilder(SpProvisionConfig spProvisionConfig) { + this.spProvisionConfig = spProvisionConfig; + } + + public void reBuildOauthKey(ServiceProviderDto serviceProviderDto) throws SpProvisionServiceException { + if (serviceProviderDto != null) { + reBuildOauthDataStructure(serviceProviderDto.getAdminServiceDto()); + } else { + log.error("Service Provider details are empty"); + } + } + + public void buildServiceProvider(ServiceProviderDto serviceProviderDto) throws SpProvisionServiceException { + if (serviceProviderDto != null) { + + buildOauthDataStructure(serviceProviderDto.getAdminServiceDto()); + buildSpApplicationDataStructure(serviceProviderDto); + } else { + log.error("Service Provider details are empty"); + } + } + + public void reBuildOauthDataStructure(AdminServiceDto adminServiceDto) throws SpProvisionServiceException { + + adminService = SpProvisionOauthServiceDataHolder.getInstance().getOauthAdminService(); + adminService.initialize(this.spProvisionConfig); + + if (adminServiceDto != null) { + try { + OAuthConsumerAppDTO authConsumerAppDTO = adminService.getOAuthApplicationData(adminServiceDto); + if (authConsumerAppDTO != null) { + adminService.rebuildOAuthApplicationData(adminServiceDto, authConsumerAppDTO); + } + } catch (SpProvisionServiceException e) { + throw new SpProvisionServiceException(e.getMessage()); + } + } else { + log.error("oAuth data object doesn't have data for the registration"); + } + } + + public void buildOauthDataStructure(AdminServiceDto adminServiceDto) throws SpProvisionServiceException { + + adminService = SpProvisionOauthServiceDataHolder.getInstance().getOauthAdminService(); + adminService.initialize(this.spProvisionConfig); + + if (adminServiceDto != null) { + try { + OAuthConsumerAppDTO authConsumerAppDTO = adminService.getOAuthApplicationData(adminServiceDto); + if (authConsumerAppDTO == null + && !adminService.isCredentailsEquals(adminServiceDto, authConsumerAppDTO)) { + adminService.registerOAuthApplicationData(adminServiceDto); + } + } catch (SpProvisionServiceException e) { + throw new SpProvisionServiceException(e.getMessage()); + } + } else { + log.error("oAuth data object doesn't have data for the registration"); + } + } + + public ServiceProvider buildSpApplicationDataStructure(ServiceProviderDto serviceProviderDto) + throws SpProvisionServiceException { + + spAppManagementService = SpProvisionAppManagementServiceDataHolder.getInstance().getAppManagementService(); + spAppManagementService.initialize(this.spProvisionConfig); + String applicationName = serviceProviderDto.getApplicationName(); + ServiceProvider serviceProvider = null; + + if (serviceProviderDto != null) { + + spAppManagementService.createSpApplication(serviceProviderDto); + serviceProvider = spAppManagementService.getSpApplicationData(applicationName); + + if (serviceProvider != null) { + spAppManagementService.updateSpApplication(serviceProviderDto); + } + serviceProvider = spAppManagementService.getSpApplicationData(applicationName); + } + + return serviceProvider; + } + + public void reBuildOauthDataStructure(String oldConsumerKey, AdminServiceDto adminServiceDto) + throws SpProvisionServiceException { + + if (adminServiceDto != null) { + adminService = SpProvisionOauthServiceDataHolder.getInstance().getOauthAdminService(); + adminService.initialize(this.spProvisionConfig); + + adminService.removeOAuthApplicationData(oldConsumerKey); + adminService.registerOAuthApplicationData(adminServiceDto); + } + + } + + public void revokeSpApplication(String oldConsumerKey, String applicationName) throws SpProvisionServiceException { + + adminService = SpProvisionOauthServiceDataHolder.getInstance().getOauthAdminService(); + adminService.initialize(this.spProvisionConfig); + + spAppManagementService = SpProvisionAppManagementServiceDataHolder.getInstance().getAppManagementService(); + spAppManagementService.initialize(this.spProvisionConfig); + + if (spAppManagementService.getSpApplicationData(applicationName) != null) { + spAppManagementService.deleteSpApplication(applicationName); + } else { + log.error("Given service Provider is not available"); + } + + adminService.removeOAuthApplicationData(oldConsumerKey); + + } + + public ServiceProviderDto getServiceProviderDetails(String applicationName) throws SpProvisionServiceException { + + ServiceProviderDto serviceProviderDto; + spAppManagementService = SpProvisionAppManagementServiceDataHolder.getInstance().getAppManagementService(); + spAppManagementService.initialize(this.spProvisionConfig); + serviceProviderDto = spAppManagementService.getServiceProviderDetails(applicationName); + return serviceProviderDto; + } + + public AdminServiceDto getOauthServiceProviderData(String consumerKey) throws SpProvisionServiceException { + + AdminServiceDto adminServiceDto; + adminService = SpProvisionOauthServiceDataHolder.getInstance().getOauthAdminService(); + adminService.initialize(this.spProvisionConfig); + adminServiceDto = adminService.getOauthServiceProviderData(consumerKey); + return adminServiceDto; + } +} diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/DiscoveryLocator.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/DiscoveryLocator.java new file mode 100644 index 00000000..479cbe5a --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/DiscoveryLocator.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2015-2017, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved. + * + * WSO2.Telco Inc. licences 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +package com.wso2telco.sp.discovery; + +import com.wso2telco.core.spprovisionservice.sp.entity.DiscoveryServiceConfig; +import com.wso2telco.core.spprovisionservice.sp.entity.DiscoveryServiceDto; +import com.wso2telco.core.spprovisionservice.sp.entity.ServiceProviderDto; +import com.wso2telco.core.spprovisionservice.sp.entity.SpProvisionDto; +import com.wso2telco.sp.discovery.exception.DicoveryException; + +public abstract class DiscoveryLocator { + + private DiscoveryLocator nextDiscovery; + + public abstract ServiceProviderDto servceProviderDiscovery(DiscoveryServiceConfig discoveryServiceConfig, + DiscoveryServiceDto discoveryServiceDto,SpProvisionDto spProvisionDto) throws DicoveryException; + + + public DiscoveryLocator getNextDiscovery() { + return nextDiscovery; + } + + public void setNextDiscovery(DiscoveryLocator nextDiscovery) { + this.nextDiscovery = nextDiscovery; + } + +} diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/InlineConnectionStrategies.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/InlineConnectionStrategies.java new file mode 100644 index 00000000..4d9dbe39 --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/InlineConnectionStrategies.java @@ -0,0 +1,16 @@ +package com.wso2telco.sp.discovery; + +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.ProtocolException; +import java.util.Map; + +public interface InlineConnectionStrategies { + + public void setConnectionRequestMethod(String requestMethod, HttpURLConnection conn) throws ProtocolException; + public void setRequestProperties(Map requestPrperties, HttpURLConnection conn); + public boolean setOutPutStrategy(String data, HttpURLConnection conn); + public void writeToOutputStream(String data, HttpURLConnection conn) throws IOException; + public String getJsonBy(InputStream inputStream) throws IOException; +} diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/LocalDiscovery.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/LocalDiscovery.java new file mode 100644 index 00000000..b5bf30f4 --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/LocalDiscovery.java @@ -0,0 +1,131 @@ +/******************************************************************************* + * Copyright (c) 2015-2017, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved. + * + * WSO2.Telco Inc. licences 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +package com.wso2telco.sp.discovery; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import com.wso2telco.core.pcrservice.PCRGeneratable; +import com.wso2telco.core.pcrservice.Returnable; +import com.wso2telco.core.pcrservice.exception.PCRException; +import com.wso2telco.core.spprovisionservice.sp.entity.AdminServiceDto; +import com.wso2telco.core.spprovisionservice.sp.entity.DiscoveryServiceConfig; +import com.wso2telco.core.spprovisionservice.sp.entity.DiscoveryServiceDto; +import com.wso2telco.core.spprovisionservice.sp.entity.ProvisionType; +import com.wso2telco.core.spprovisionservice.sp.entity.ServiceProviderDto; +import com.wso2telco.core.spprovisionservice.sp.entity.SpProvisionDto; +import com.wso2telco.sp.discovery.exception.DicoveryException; +import com.wso2telco.sp.internal.SpProvisionPcrDataHolder; +import com.wso2telco.sp.provision.service.ProvisioningService; +import com.wso2telco.sp.provision.service.impl.ProvisioningServiceImpl; +import com.wso2telco.sp.util.ValidationUtil; + +public class LocalDiscovery extends DiscoveryLocator { + + private static Log log = LogFactory.getLog(LocalDiscovery.class); + private ProvisioningService provisioningService; + private SpProvisionDto spProvisionDto = null; + + public LocalDiscovery() { + provisioningService = new ProvisioningServiceImpl(); + } + + @Override + public ServiceProviderDto servceProviderDiscovery(DiscoveryServiceConfig discoveryServiceConfig, + DiscoveryServiceDto discoveryServiceDto, SpProvisionDto spProvisionDto) throws DicoveryException { + this.spProvisionDto = spProvisionDto; + log.info("Performing Local Discovery on EKS"); + ServiceProviderDto serviceProviderDto = null; + boolean isAppAvailable = false; + + ValidationUtil.validateInuts(discoveryServiceDto.getSectorId(), discoveryServiceDto.getClientId()); + populateMsisdnFrom(discoveryServiceConfig, discoveryServiceDto); + isAppAvailable = checkLocally(discoveryServiceConfig.isPcrServiceEnabled(), discoveryServiceDto.getSectorId(), + discoveryServiceDto.getClientId(), discoveryServiceDto.getClientSecret()); + if (!isAppAvailable) { + log.info("SP NOT AVAILABLE locally... Fetching remotley ..."); + serviceProviderDto = checkRemotlyDiscovery(discoveryServiceConfig, discoveryServiceDto); + } else { + log.info("Successful -> SP Available locally..."); + serviceProviderDto = constructDefaultSp(); + } + + return serviceProviderDto; + } + + private ServiceProviderDto constructDefaultSp() { + ServiceProviderDto serviceProviderDto = null; + serviceProviderDto = new ServiceProviderDto(); + serviceProviderDto.setExistance(ProvisionType.LOCAL); + return serviceProviderDto; + } + + private ServiceProviderDto checkRemotlyDiscovery(DiscoveryServiceConfig discoveryServiceConfig, + DiscoveryServiceDto discoveryServiceDto) throws DicoveryException { + ServiceProviderDto serviceProviderDto = null; + if (getNextDiscovery() != null) { + serviceProviderDto = getNextDiscovery().servceProviderDiscovery(discoveryServiceConfig, + discoveryServiceDto,spProvisionDto); + } + + return serviceProviderDto; + } + + private boolean checkLocally(boolean isPcrServiceEnabled, String sectorId, String clientId, String clientSecret) + throws DicoveryException { + boolean isAppAvailable = false; + if (isPcrServiceEnabled) { + isAppAvailable = checkSpAvailabilityInmemory(sectorId, clientId); + } else { + + AdminServiceDto adminServiceDto = provisioningService.getOauthServiceProviderData(clientId,this.spProvisionDto); + + if (clientSecret != null && !clientSecret.isEmpty() && adminServiceDto != null + && adminServiceDto.getOauthConsumerSecret() != null + && !adminServiceDto.getOauthConsumerSecret().isEmpty() + && adminServiceDto.getOauthConsumerSecret().equals(clientSecret)) { + isAppAvailable = true; + } + } + return isAppAvailable; + } + + private void populateMsisdnFrom(DiscoveryServiceConfig discoveryServiceConfig, + DiscoveryServiceDto discoveryServiceDto) { + if (discoveryServiceConfig != null && discoveryServiceConfig.getEksDiscoveryConfig() != null + && discoveryServiceConfig.getEksDiscoveryConfig().getMsisdn() != null + && !discoveryServiceConfig.getEksDiscoveryConfig().getMsisdn().isEmpty()) { + discoveryServiceDto.setMsisdn(discoveryServiceConfig.getEksDiscoveryConfig().getMsisdn()); + } + } + + private boolean checkSpAvailabilityInmemory(String sector, String clientId) throws DicoveryException { + boolean isAvailable = false; + log.info("Performing Sp availability in redis."); + Returnable returnable = null; + try { + PCRGeneratable pcrGeneratable = SpProvisionPcrDataHolder.getInstance().getPcrGeneratable(); + returnable = pcrGeneratable.isAppAvailableFor(sector, clientId); + } catch (PCRException e) { + throw new DicoveryException("Error Occured Whicle Local Discovery Operation" + e.getMessage(), true); + } + isAvailable = returnable.getAvailablity(); + return isAvailable; + + } + +} diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/RemoteCredentialDiscovery.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/RemoteCredentialDiscovery.java new file mode 100644 index 00000000..f30f15da --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/RemoteCredentialDiscovery.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2015-2017, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved. + * + * WSO2.Telco Inc. licences 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +package com.wso2telco.sp.discovery; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import com.google.gson.Gson; +import com.wso2telco.core.spprovisionservice.sp.entity.AdminServiceDto; +import com.wso2telco.core.spprovisionservice.sp.entity.DiscoveryServiceConfig; +import com.wso2telco.core.spprovisionservice.sp.entity.DiscoveryServiceDto; +import com.wso2telco.core.spprovisionservice.sp.entity.ProvisionType; +import com.wso2telco.core.spprovisionservice.sp.entity.ServiceProviderDto; +import com.wso2telco.core.spprovisionservice.sp.entity.SpProvisionConfig; +import com.wso2telco.core.spprovisionservice.sp.entity.SpProvisionDto; +import com.wso2telco.sp.discovery.exception.DicoveryException; +import com.wso2telco.sp.entity.CrValidateRes; + +public class RemoteCredentialDiscovery extends RemoteDiscovery { + + private static Log log = LogFactory.getLog(RemoteCredentialDiscovery.class); + + @Override + public ServiceProviderDto servceProviderDiscovery(DiscoveryServiceConfig discoveryServiceConfig, + DiscoveryServiceDto discoveryServiceDto,SpProvisionDto spProvisionDto) throws DicoveryException { + + log.info("CR-> Service Provider Credentail Discovery Call"); + String encodedBasicAuthCode = buildBasicAuthCode(discoveryServiceDto.getClientId(), + discoveryServiceDto.getClientSecret()); + String requestMethod = HTTP_POST; + Map requestProperties = buildRequestProperties(encodedBasicAuthCode); + + CrValidateRes crValidateRes = new Gson() + .fromJson(getJsonWithDiscovery(buildEndPointUrl(discoveryServiceConfig, discoveryServiceDto), + requestMethod, null, requestProperties), CrValidateRes.class); + return createServiceProviderDtoBy(crValidateRes, discoveryServiceDto); + } + + @Override + public Map buildRequestProperties(String encodedBasicAuthCode) { + log.info("CR-> Building request properties."); + Map requestProperties = new HashMap(); + requestProperties.put(ACCEPT, CONTENT_TYPE_HEADER_VAL_TYPE_CR); + requestProperties.put(AUTHORIZATION_HEADER, BASIC + SPACE + encodedBasicAuthCode); + return requestProperties; + } + + @Override + public String buildEndPointUrl(DiscoveryServiceConfig discoveryServiceConfig, + DiscoveryServiceDto discoveryServiceDto) { + log.info("CR-> Build endpoint url"); + String endPointUrl = discoveryServiceConfig.getCrValidateDiscoveryConfig().getServiceUrl() + QES_OPERATOR + + CLIENT_ID + EQA_OPERATOR + discoveryServiceDto.getClientId() + AMP_OPERATOR + CLIENT_SECRET + + EQA_OPERATOR + discoveryServiceDto.getClientSecret(); + return endPointUrl; + } + + @Override + public ServiceProviderDto createServiceProviderDtoBy(K k, T t) { + log.info("CR-> Create Service Provider DTO"); + CrValidateRes crValidateRes = (CrValidateRes) k; + DiscoveryServiceDto discoveryServiceDto = (DiscoveryServiceDto) t; + ServiceProviderDto serviceProviderDto = new ServiceProviderDto(); + if (crValidateRes != null && crValidateRes.getApplication() != null && discoveryServiceDto != null) { + serviceProviderDto.setApplicationName(crValidateRes.getApplication().getAppName()); + AdminServiceDto adminServiceDto = new AdminServiceDto(); + adminServiceDto.setOauthConsumerKey(discoveryServiceDto.getClientId()); + adminServiceDto.setOauthConsumerSecret(discoveryServiceDto.getClientSecret()); + adminServiceDto.setCallbackUrl(crValidateRes.getApplication().getRedirectUri()); + serviceProviderDto.setDescription(crValidateRes.getApplication().getDescription()); + serviceProviderDto.setAdminServiceDto(adminServiceDto); + } + serviceProviderDto.setExistance(ProvisionType.REMOTE); + return serviceProviderDto; + } +} diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/RemoteDiscovery.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/RemoteDiscovery.java new file mode 100644 index 00000000..96ed88d1 --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/RemoteDiscovery.java @@ -0,0 +1,177 @@ +/******************************************************************************* + * Copyright (c) 2015-2017, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved. + * + * WSO2.Telco Inc. licences 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +package com.wso2telco.sp.discovery; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.ProtocolException; +import java.net.URL; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.Base64; +import java.util.HashMap; + +import com.google.gson.Gson; +import com.wso2telco.core.spprovisionservice.sp.entity.AdminServiceDto; +import com.wso2telco.core.spprovisionservice.sp.entity.DiscoveryServiceConfig; +import com.wso2telco.core.spprovisionservice.sp.entity.DiscoveryServiceDto; +import com.wso2telco.core.spprovisionservice.sp.entity.ProvisionType; +import com.wso2telco.core.spprovisionservice.sp.entity.ServiceProviderDto; +import com.wso2telco.sp.discovery.exception.DicoveryException; +import com.wso2telco.sp.entity.CrValidateRes; +import com.wso2telco.sp.entity.EksDiscovery; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public abstract class RemoteDiscovery extends DiscoveryLocator implements InlineConnectionStrategies { + + protected static String ACCEPT = "Accept"; + protected static String CONTENT_TYPE_HEADER_KEY = "Content-Type"; + protected static String CONTENT_TYPE_HEADER_VAL_TYPE_EKS = "application/x-www-form-urlencoded"; + protected static String CONTENT_TYPE_HEADER_VAL_TYPE_CR = "application/json"; + protected static String AUTHORIZATION_HEADER = "Authorization"; + protected static String HTTP_POST = "POST"; + protected static String MSISDN = "msisdn"; + protected static String REDIRECT_URL = "Redirect_URL"; + protected static String CLIENT_ID = "client_id"; + protected static String CLIENT_SECRET = "client_secret"; + protected static String BASIC = "Basic"; + protected static String QES_OPERATOR = "?"; + protected static String EQA_OPERATOR = "="; + protected static String AMP_OPERATOR = "&"; + protected static String SPACE = " "; + protected static String COLON = ":"; + protected static String NEW_LINE = "\n"; + + private static Log log = LogFactory.getLog(RemoteDiscovery.class); + + public abstract Map buildRequestProperties(String encodedBasicAuthCode); + + public abstract String buildEndPointUrl(DiscoveryServiceConfig discoveryServiceConfig, + DiscoveryServiceDto discoveryServiceDto); + + public abstract ServiceProviderDto createServiceProviderDtoBy(K k,T t); + + protected String getJsonWithDiscovery(String endPointUrl, String requestMethod, String data, + Map requestProperties) throws DicoveryException { + String responseJson = null; + HttpURLConnection conn = null; + try { + log.info("Trying dicovery call. < endpoint:" + endPointUrl + " > "); + URL url = new URL(endPointUrl); + conn = (HttpURLConnection) url.openConnection(); + + setConnectionRequestMethod(requestMethod, conn); + setRequestProperties(requestProperties, conn); + boolean isDoOutput = setOutPutStrategy(data, conn); + if (isDoOutput) { + writeToOutputStream(data, conn); + } + + if (conn.getResponseCode() == 401) { + conn.disconnect(); + throw new DicoveryException("Failed : HTTP error code : " + conn.getResponseCode(), false); + } + + if (conn.getResponseCode() != 200) { + conn.disconnect(); + throw new DicoveryException("Failed : HTTP error code : " + conn.getResponseCode(), true); + } + responseJson = getJsonBy(conn.getInputStream()); + conn.disconnect(); + } catch (MalformedURLException e) { + conn.disconnect(); + throw new DicoveryException(e.getMessage(), true); + } catch (IOException e) { + conn.disconnect(); + throw new DicoveryException(e.getMessage(), true); + } + return responseJson; + } + + @Override + public void setConnectionRequestMethod(String requestMethod, HttpURLConnection conn) throws ProtocolException { + log.info("Setting connection request method..."); + conn.setRequestMethod(requestMethod); + } + + @Override + public void setRequestProperties(Map requestPrperties, HttpURLConnection conn) { + log.info("Setting request properties..."); + for (Map.Entry propEntry : requestPrperties.entrySet()) { + conn.setRequestProperty(propEntry.getKey(), propEntry.getValue()); + } + } + + @Override + public boolean setOutPutStrategy(String data, HttpURLConnection conn) { + log.info("Setting output strategy..."); + boolean isDoOutput = false; + if (data != null && !data.isEmpty()) { + conn.setDoOutput(true); + isDoOutput = true; + } + return isDoOutput; + } + + @Override + public void writeToOutputStream(String data, HttpURLConnection conn) throws IOException { + log.info("Writing to output stream start..."); + OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); + wr.write(data); + wr.flush(); + log.info("Writing to output stream end..."); + } + + @Override + public String getJsonBy(InputStream inputStream) throws IOException { + log.info("Concatenating the JSON inputs..."); + BufferedReader br = new BufferedReader(new InputStreamReader((inputStream))); + String output; + StringBuilder jsonStrBuilder = new StringBuilder(); + while ((output = br.readLine()) != null) { + jsonStrBuilder.append(output).append(NEW_LINE); + } + return jsonStrBuilder.toString(); + } + + protected String buildBasicAuthCode(String clientId, String clientSecret) { + log.info("Building the basic authcode for Client Id :" + clientId + " , client secret : " + clientSecret); + String encodedBasicAuthCode = ""; + StringBuilder basicAuthStrBuilder = new StringBuilder(); + if (clientId != null && !clientId.isEmpty()) { + basicAuthStrBuilder.append(clientId); + if (clientSecret != null && !clientSecret.isEmpty()) { + basicAuthStrBuilder.append(COLON).append(clientSecret); + } + if (basicAuthStrBuilder != null && !basicAuthStrBuilder.toString().isEmpty()) { + encodedBasicAuthCode = Base64.getEncoder().encodeToString(basicAuthStrBuilder.toString().getBytes()); + } + } + return encodedBasicAuthCode; + } + +} diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/RemoteExcKeySecretDiscovery.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/RemoteExcKeySecretDiscovery.java new file mode 100644 index 00000000..6157630b --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/RemoteExcKeySecretDiscovery.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2015-2017, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved. + * + * WSO2.Telco Inc. licences 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +package com.wso2telco.sp.discovery; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import com.google.gson.Gson; +import com.wso2telco.core.spprovisionservice.sp.entity.AdminServiceDto; +import com.wso2telco.core.spprovisionservice.sp.entity.DiscoveryServiceConfig; +import com.wso2telco.core.spprovisionservice.sp.entity.DiscoveryServiceDto; +import com.wso2telco.core.spprovisionservice.sp.entity.ProvisionType; +import com.wso2telco.core.spprovisionservice.sp.entity.ServiceProviderDto; +import com.wso2telco.core.spprovisionservice.sp.entity.SpProvisionDto; +import com.wso2telco.sp.discovery.exception.DicoveryException; +import com.wso2telco.sp.entity.EksDiscovery; + +public class RemoteExcKeySecretDiscovery extends RemoteDiscovery { + + private static Log log = LogFactory.getLog(RemoteExcKeySecretDiscovery.class); + + @Override + public ServiceProviderDto servceProviderDiscovery(DiscoveryServiceConfig discoveryServiceConfig, + DiscoveryServiceDto discoveryServiceDto,SpProvisionDto spProvisionDto) throws DicoveryException { + log.info("EKS-> Service Provider Exchange Key Discovery Call"); + String encodedBasicAuthCode = buildBasicAuthCode(discoveryServiceDto.getClientId(), + discoveryServiceDto.getClientSecret()); + String requestMethod = HTTP_POST; + String data = MSISDN + EQA_OPERATOR + discoveryServiceDto.getMsisdn(); + Map requestProperties = buildRequestProperties(encodedBasicAuthCode); + + EksDiscovery eksDiscovery = new Gson() + .fromJson(getJsonWithDiscovery(buildEndPointUrl(discoveryServiceConfig, null), requestMethod, data, + requestProperties), EksDiscovery.class); + return createServiceProviderDtoBy(eksDiscovery,null); + } + + @Override + public String buildEndPointUrl(DiscoveryServiceConfig discoveryServiceConfig, + DiscoveryServiceDto discoveryServiceDto) { + log.info("EKS-> Building end point url..."); + String endPointUrl = discoveryServiceConfig.getEksDiscoveryConfig().getServiceUrl() + QES_OPERATOR + + REDIRECT_URL + EQA_OPERATOR + discoveryServiceConfig.getEksDiscoveryConfig().getRedirectUrl(); + return endPointUrl; + } + + @Override + public Map buildRequestProperties(String encodedBasicAuthCode) { + log.info("EKS-> Building request properties..."); + Map requestProperties = new HashMap(); + requestProperties.put(CONTENT_TYPE_HEADER_KEY, CONTENT_TYPE_HEADER_VAL_TYPE_EKS); + requestProperties.put(AUTHORIZATION_HEADER, BASIC + SPACE + encodedBasicAuthCode); + return requestProperties; + } + + @Override + public ServiceProviderDto createServiceProviderDtoBy(K k,T t) { + log.info("EKS-> Create service provider dto..."); + EksDiscovery eksDiscovery = (EksDiscovery) k; + ServiceProviderDto serviceProviderDto = new ServiceProviderDto(); + if (eksDiscovery != null && eksDiscovery.getResponse() != null) { + AdminServiceDto adminServiceDto = new AdminServiceDto(); + adminServiceDto.setOauthConsumerKey(eksDiscovery.getResponse().getClient_id()); + adminServiceDto.setOauthConsumerSecret(eksDiscovery.getResponse().getClient_secret()); + serviceProviderDto.setAdminServiceDto(adminServiceDto); + } + serviceProviderDto.setExistance(ProvisionType.REMOTE); + return serviceProviderDto; + } + +} diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/exception/DicoveryException.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/exception/DicoveryException.java new file mode 100644 index 00000000..8b87b4b8 --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/exception/DicoveryException.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2015-2017, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved. + * + * WSO2.Telco Inc. licences 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +package com.wso2telco.sp.discovery.exception; + +public class DicoveryException extends Exception { + + private String responseCode = null; + private boolean isSystemError = false; + + public DicoveryException() { + + } + + public DicoveryException(String messageCode, boolean isSystemError) { + super(messageCode); + this.isSystemError = isSystemError; + } + + public String getResponseCode() { + return responseCode; + } + + public boolean isSystemError() { + return isSystemError; + } + +} diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/exception/DiscoveryValidationException.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/exception/DiscoveryValidationException.java new file mode 100644 index 00000000..294ca865 --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/exception/DiscoveryValidationException.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2015-2017, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved. + * + * WSO2.Telco Inc. licences 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +package com.wso2telco.sp.discovery.exception; + +public class DiscoveryValidationException extends Exception { + + public DiscoveryValidationException() { + + } + + public DiscoveryValidationException(String messageCode) { + super(messageCode); + } + +} diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/service/DiscoveryService.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/service/DiscoveryService.java new file mode 100644 index 00000000..3e062860 --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/service/DiscoveryService.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2015-2017, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved. + * + * WSO2.Telco Inc. licences 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +package com.wso2telco.sp.discovery.service; + +import com.wso2telco.core.spprovisionservice.sp.entity.DiscoveryServiceConfig; +import com.wso2telco.core.spprovisionservice.sp.entity.DiscoveryServiceDto; +import com.wso2telco.core.spprovisionservice.sp.entity.ServiceProviderDto; +import com.wso2telco.core.spprovisionservice.sp.entity.SpProvisionDto; +import com.wso2telco.sp.discovery.exception.DicoveryException; + +public interface DiscoveryService { + + public ServiceProviderDto servceProviderCredentialDiscovery(DiscoveryServiceConfig discoveryServiceConfig, + DiscoveryServiceDto discoveryServiceDto,SpProvisionDto spProvisionDto); + + public ServiceProviderDto servceProviderEksDiscovery(DiscoveryServiceConfig discoveryServiceConfig, + DiscoveryServiceDto discoveryServiceDto,SpProvisionDto spProvisionDto); + +} diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/service/impl/DiscoveryServiceImpl.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/service/impl/DiscoveryServiceImpl.java new file mode 100644 index 00000000..24ee5f4a --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/discovery/service/impl/DiscoveryServiceImpl.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2015-2017, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved. + * + * WSO2.Telco Inc. licences 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +package com.wso2telco.sp.discovery.service.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import com.wso2telco.core.spprovisionservice.sp.entity.DiscoveryServiceConfig; +import com.wso2telco.core.spprovisionservice.sp.entity.DiscoveryServiceDto; +import com.wso2telco.core.spprovisionservice.sp.entity.ServiceProviderDto; +import com.wso2telco.core.spprovisionservice.sp.entity.SpProvisionDto; +import com.wso2telco.sp.discovery.DiscoveryLocator; +import com.wso2telco.sp.discovery.LocalDiscovery; +import com.wso2telco.sp.discovery.RemoteCredentialDiscovery; +import com.wso2telco.sp.discovery.RemoteDiscovery; +import com.wso2telco.sp.discovery.RemoteExcKeySecretDiscovery; +import com.wso2telco.sp.discovery.exception.DicoveryException; +import com.wso2telco.sp.discovery.service.DiscoveryService; + +public class DiscoveryServiceImpl implements DiscoveryService { + + private static Log log = LogFactory.getLog(DiscoveryServiceImpl.class); + private DiscoveryLocator discoverSp = null; + + @Override + public ServiceProviderDto servceProviderCredentialDiscovery(DiscoveryServiceConfig discoveryServiceConfig, + DiscoveryServiceDto discoveryServiceDto,SpProvisionDto spProvisionDto) { + ServiceProviderDto serviceProviderDto = null; + try { + log.info("Performing Credentials discovery for CR."); + discoverSp = new LocalDiscovery(); + discoverSp.setNextDiscovery(new RemoteCredentialDiscovery()); + serviceProviderDto = discoverSp.servceProviderDiscovery(discoveryServiceConfig, discoveryServiceDto,spProvisionDto); + } catch (DicoveryException e) { + if (e.isSystemError()) { + log.error("Error Occured While Trying To Fetch Discovery Call :: Message = " + e.getMessage()); + } else { + log.info("Service Provider Does Not Exist." + e.getMessage()); + } + } + return serviceProviderDto; + } + + @Override + public ServiceProviderDto servceProviderEksDiscovery(DiscoveryServiceConfig discoveryServiceConfig, + DiscoveryServiceDto discoveryServiceDto,SpProvisionDto spProvisionDto) { + ServiceProviderDto serviceProviderDto = null; + try { + log.info("Performing Credentials discovery for EKS."); + discoverSp = new LocalDiscovery(); + discoverSp.setNextDiscovery(new RemoteExcKeySecretDiscovery()); + serviceProviderDto = discoverSp.servceProviderDiscovery(discoveryServiceConfig, discoveryServiceDto,spProvisionDto); + } catch (DicoveryException e) { + if (e.isSystemError()) { + log.error("Error Occured While Trying To Fetch Discovery Call " + e.getMessage()); + } else { + log.info("Service Provider Does Not Exist." + e.getMessage()); + } + } + return serviceProviderDto; + } + +} diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/Apis.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/Apis.java new file mode 100644 index 00000000..10ee04d7 --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/Apis.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2015-2017, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved. + * + * WSO2.Telco Inc. licences 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +package com.wso2telco.sp.entity; + +public class Apis { + + private OperatorId operatorid; + + public OperatorId getOperatorid() { + return operatorid; + } + + public void setOperatorid(OperatorId operatorid) { + this.operatorid = operatorid; + } + + @Override + public String toString() { + return "ClassPojo [operatorid = " + operatorid + "]"; + } + +} diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/Application.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/Application.java new file mode 100644 index 00000000..995047e6 --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/Application.java @@ -0,0 +1,136 @@ +/******************************************************************************* + * Copyright (c) 2015-2017, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved. + * + * WSO2.Telco Inc. licences 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +package com.wso2telco.sp.entity; + +public class Application { + private String appName; + + private String appStatus; + + private String description; + + private String devStatus; + + private String devName; + + private SupportedApis[] supportedApis; + + private String devId; + + private String devOrgId; + + private String redirectUri; + + private String appType; + + private String appCredId; + + public String getAppName() { + return appName; + } + + public void setAppName(String appName) { + this.appName = appName; + } + + public String getAppStatus() { + return appStatus; + } + + public void setAppStatus(String appStatus) { + this.appStatus = appStatus; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getDevStatus() { + return devStatus; + } + + public void setDevStatus(String devStatus) { + this.devStatus = devStatus; + } + + public String getDevName() { + return devName; + } + + public void setDevName(String devName) { + this.devName = devName; + } + + public SupportedApis[] getSupportedApis() { + return supportedApis; + } + + public void setSupportedApis(SupportedApis[] supportedApis) { + this.supportedApis = supportedApis; + } + + public String getDevId() { + return devId; + } + + public void setDevId(String devId) { + this.devId = devId; + } + + public String getDevOrgId() { + return devOrgId; + } + + public void setDevOrgId(String devOrgId) { + this.devOrgId = devOrgId; + } + + public String getRedirectUri() { + return redirectUri; + } + + public void setRedirectUri(String redirectUri) { + this.redirectUri = redirectUri; + } + + public String getAppType() { + return appType; + } + + public void setAppType(String appType) { + this.appType = appType; + } + + public String getAppCredId() { + return appCredId; + } + + public void setAppCredId(String appCredId) { + this.appCredId = appCredId; + } + + @Override + public String toString() { + return "ClassPojo [appName = " + appName + ", appStatus = " + appStatus + ", description = " + description + + ", devStatus = " + devStatus + ", devName = " + devName + ", supportedApis = " + supportedApis + + ", devId = " + devId + ", devOrgId = " + devOrgId + ", redirectUri = " + redirectUri + ", appType = " + + appType + ", appCredId = " + appCredId + "]"; + } +} \ No newline at end of file diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/CrValidateRes.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/CrValidateRes.java new file mode 100644 index 00000000..005177ca --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/CrValidateRes.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2015-2017, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved. + * + * WSO2.Telco Inc. licences 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +package com.wso2telco.sp.entity; + +public class CrValidateRes { + private String orgId; + + private Application application; + + private String x_client_id; + + public String getOrgId() { + return orgId; + } + + public void setOrgId(String orgId) { + this.orgId = orgId; + } + + public Application getApplication() { + return application; + } + + public void setApplication(Application application) { + this.application = application; + } + + public String getX_client_id() { + return x_client_id; + } + + public void setX_client_id(String x_client_id) { + this.x_client_id = x_client_id; + } + + @Override + public String toString() { + return "ClassPojo [orgId = " + orgId + ", application = " + application + ", x_client_id = " + x_client_id + + "]"; + } +} diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/EksDiscovery.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/EksDiscovery.java new file mode 100644 index 00000000..f0c5847b --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/EksDiscovery.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2015-2017, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved. + * + * WSO2.Telco Inc. licences 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +package com.wso2telco.sp.entity; + +public class EksDiscovery { + + private Response response; + + private String ttl; + + public Response getResponse() { + return response; + } + + public void setResponse(Response response) { + this.response = response; + } + + public String getTtl() { + return ttl; + } + + public void setTtl(String ttl) { + this.ttl = ttl; + } + + @Override + public String toString() { + return "ClassPojo [response = " + response + ", ttl = " + ttl + "]"; + } + +} diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/Link.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/Link.java new file mode 100644 index 00000000..d0f128e7 --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/Link.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2015-2017, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved. + * + * WSO2.Telco Inc. licences 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +package com.wso2telco.sp.entity; + +public class Link { + + private String rel; + + private String href; + + public String getRel() { + return rel; + } + + public void setRel(String rel) { + this.rel = rel; + } + + public String getHref() { + return href; + } + + public void setHref(String href) { + this.href = href; + } + + @Override + public String toString() { + return "ClassPojo [rel = " + rel + ", href = " + href + "]"; + } + +} diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/OperatorId.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/OperatorId.java new file mode 100644 index 00000000..4d2ca82b --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/OperatorId.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2015-2017, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved. + * + * WSO2.Telco Inc. licences 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +package com.wso2telco.sp.entity; + +public class OperatorId { + + private Link[] link; + + public Link[] getLink() { + return link; + } + + public void setLink(Link[] link) { + this.link = link; + } + + @Override + public String toString() { + return "ClassPojo [link = " + link + "]"; + } + +} diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/Response.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/Response.java new file mode 100644 index 00000000..dfe4c5cf --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/Response.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2015-2017, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved. + * + * WSO2.Telco Inc. licences 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +package com.wso2telco.sp.entity; + +public class Response { + private String serving_operator; + + private String client_secret; + + private Apis apis; + + private String client_id; + + private String currency; + + private String country; + + public String getServing_operator() { + return serving_operator; + } + + public void setServing_operator(String serving_operator) { + this.serving_operator = serving_operator; + } + + public String getClient_secret() { + return client_secret; + } + + public void setClient_secret(String client_secret) { + this.client_secret = client_secret; + } + + public Apis getApis() { + return apis; + } + + public void setApis(Apis apis) { + this.apis = apis; + } + + public String getClient_id() { + return client_id; + } + + public void setClient_id(String client_id) { + this.client_id = client_id; + } + + public String getCurrency() { + return currency; + } + + public void setCurrency(String currency) { + this.currency = currency; + } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } + + @Override + public String toString() { + return "ClassPojo [serving_operator = " + serving_operator + ", client_secret = " + client_secret + ", apis = " + + apis + ", client_id = " + client_id + ", currency = " + currency + ", country = " + country + "]"; + } +} diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/SupportedApis.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/SupportedApis.java new file mode 100644 index 00000000..94532ea3 --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/entity/SupportedApis.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2015-2017, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved. + * + * WSO2.Telco Inc. licences 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +package com.wso2telco.sp.entity; + +public class SupportedApis { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return "ClassPojo [name = " + name + "]"; + } +} \ No newline at end of file diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/internal/SpProvisionAppManagementServiceDataHolder.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/internal/SpProvisionAppManagementServiceDataHolder.java new file mode 100644 index 00000000..4e58a3d0 --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/internal/SpProvisionAppManagementServiceDataHolder.java @@ -0,0 +1,23 @@ +package com.wso2telco.sp.internal; + +import com.wso2telco.core.spprovisionservice.external.admin.service.SpAppManagementService; + +public class SpProvisionAppManagementServiceDataHolder { + + private SpAppManagementService appManagementService; + + private static SpProvisionAppManagementServiceDataHolder dataHolder = new SpProvisionAppManagementServiceDataHolder(); + + public static SpProvisionAppManagementServiceDataHolder getInstance() { + return dataHolder; + } + + public SpAppManagementService getAppManagementService() { + return appManagementService; + } + + public void setAppManagementService(SpAppManagementService appManagementService) { + this.appManagementService = appManagementService; + } + +} diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/internal/SpProvisionAppManagementServiceServiceComponent.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/internal/SpProvisionAppManagementServiceServiceComponent.java new file mode 100644 index 00000000..6db8827f --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/internal/SpProvisionAppManagementServiceServiceComponent.java @@ -0,0 +1,44 @@ +package com.wso2telco.sp.internal; + +import com.wso2telco.core.spprovisionservice.external.admin.service.OauthAdminService; +import com.wso2telco.core.spprovisionservice.external.admin.service.SpAppManagementService; + +import org.osgi.framework.BundleContext; +import org.osgi.service.component.ComponentContext; +import org.apache.felix.scr.annotations.*; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + + +@Component(name = "com.wso2telco.sp.internal.SpProvisionAppManagementServiceServiceComponent", immediate = true) +@Reference( + name = "com.wso2telco.core.spprovisionservice.internal.SpAppManagementServiceComponent", + referenceInterface = com.wso2telco.core.spprovisionservice.external.admin.service.SpAppManagementService.class, + cardinality = ReferenceCardinality.MANDATORY_UNARY, + policy = ReferencePolicy.DYNAMIC, + bind = "setAppManagementService", + unbind = "unsetAppManagementService" +) +public class SpProvisionAppManagementServiceServiceComponent { + + private SpAppManagementService appManagementService; + private static Log log = LogFactory.getLog(SpProvisionPcrServiceComponent.class); + + @Activate + protected void activate(ComponentContext componentContext) { + log.debug("SpProvisionOauthServiceServiceComponent Bundle Activated"); + } + + @Deactivate + protected void deactivate(ComponentContext componentContext) { + //do nothing + } + + protected void setAppManagementService(SpAppManagementService appManagementService) { + SpProvisionAppManagementServiceDataHolder.getInstance().setAppManagementService(appManagementService); + } + + protected void unsetAppManagementService(SpAppManagementService appManagementService) { + SpProvisionAppManagementServiceDataHolder.getInstance().setAppManagementService(null); + } +} diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/internal/SpProvisionOauthServiceDataHolder.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/internal/SpProvisionOauthServiceDataHolder.java new file mode 100644 index 00000000..9b4b9fa2 --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/internal/SpProvisionOauthServiceDataHolder.java @@ -0,0 +1,23 @@ +package com.wso2telco.sp.internal; + +import com.wso2telco.core.spprovisionservice.external.admin.service.OauthAdminService; + +public class SpProvisionOauthServiceDataHolder { + + private OauthAdminService oauthAdminService; + + private static SpProvisionOauthServiceDataHolder dataHolder = new SpProvisionOauthServiceDataHolder(); + + public static SpProvisionOauthServiceDataHolder getInstance() { + return dataHolder; + } + + public OauthAdminService getOauthAdminService() { + return oauthAdminService; + } + + public void setOauthAdminService(OauthAdminService oauthAdminService) { + this.oauthAdminService = oauthAdminService; + } + +} diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/internal/SpProvisionOauthServiceServiceComponent.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/internal/SpProvisionOauthServiceServiceComponent.java new file mode 100644 index 00000000..0cd02050 --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/internal/SpProvisionOauthServiceServiceComponent.java @@ -0,0 +1,43 @@ +package com.wso2telco.sp.internal; + +import com.wso2telco.core.spprovisionservice.external.admin.service.OauthAdminService; + +import org.osgi.framework.BundleContext; +import org.osgi.service.component.ComponentContext; +import org.apache.felix.scr.annotations.*; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + + +@Component(name = "com.wso2telco.sp.internal.SpProvisionOauthServiceServiceComponent", immediate = true) +@Reference( + name = "com.wso2telco.core.spprovisionservice.internal.OAuthAdminServiceComponent", + referenceInterface = com.wso2telco.core.spprovisionservice.external.admin.service.OauthAdminService.class, + cardinality = ReferenceCardinality.MANDATORY_UNARY, + policy = ReferencePolicy.DYNAMIC, + bind = "setOauthService", + unbind = "unsetOauthService" +) +public class SpProvisionOauthServiceServiceComponent { + + private OauthAdminService authAdminService; + private static Log log = LogFactory.getLog(SpProvisionPcrServiceComponent.class); + + @Activate + protected void activate(ComponentContext componentContext) { + log.debug("SpProvisionOauthServiceServiceComponent Bundle Activated"); + } + + @Deactivate + protected void deactivate(ComponentContext componentContext) { + //do nothing + } + + protected void setOauthService(OauthAdminService authAdminService) { + SpProvisionOauthServiceDataHolder.getInstance().setOauthAdminService(authAdminService); + } + + protected void unsetOauthService(OauthAdminService authAdminService) { + SpProvisionOauthServiceDataHolder.getInstance().setOauthAdminService(null); + } +} diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/internal/SpProvisionPcrDataHolder.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/internal/SpProvisionPcrDataHolder.java new file mode 100644 index 00000000..6f4031ee --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/internal/SpProvisionPcrDataHolder.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2015-2017, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved. + * + * WSO2.Telco Inc. licences 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +package com.wso2telco.sp.internal; + +import com.wso2telco.core.pcrservice.PCRGeneratable; + +public class SpProvisionPcrDataHolder { + + private static SpProvisionPcrDataHolder spProvisionPcrDataHolder = new SpProvisionPcrDataHolder(); + + PCRGeneratable pcrGeneratable; + + private SpProvisionPcrDataHolder() { + + } + + public static SpProvisionPcrDataHolder getInstance() { + return spProvisionPcrDataHolder; + } + + public PCRGeneratable getPcrGeneratable() { + return pcrGeneratable; + } + + public void setPcrGeneratable(PCRGeneratable pcrGeneratable) { + this.pcrGeneratable = pcrGeneratable; + } + +} diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/internal/SpProvisionPcrServiceComponent.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/internal/SpProvisionPcrServiceComponent.java new file mode 100644 index 00000000..e0504c86 --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/internal/SpProvisionPcrServiceComponent.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2015-2017, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved. + * + * WSO2.Telco Inc. licences 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +package com.wso2telco.sp.internal; + +import com.wso2telco.core.pcrservice.PCRGeneratable; + +import org.osgi.framework.BundleContext; +import org.osgi.service.component.ComponentContext; +import org.apache.felix.scr.annotations.*; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + + +@Component(name = "com.wso2telco.internal.SpProvisionPcrServiceComponent", immediate = true) +@Reference( + name = "com.wso2telco.core.pcrservice.internal.PCRServiceComponent", + referenceInterface = com.wso2telco.core.pcrservice.PCRGeneratable.class, + cardinality = ReferenceCardinality.MANDATORY_UNARY, + policy = ReferencePolicy.DYNAMIC, + bind = "setPcrService", + unbind = "unsetPcrService" +) +public class SpProvisionPcrServiceComponent { + + private static Log log = LogFactory.getLog(SpProvisionPcrServiceComponent.class); + + @Activate + protected void activate(ComponentContext componentContext) { + log.debug("SpProvision Bundle Activated"); + } + + @Deactivate + protected void deactivate(ComponentContext componentContext) { + //do nothing + } + + protected void setPcrService(PCRGeneratable pcrGeneratable) { + SpProvisionPcrDataHolder.getInstance().setPcrGeneratable(pcrGeneratable); + } + + protected void unsetPcrService(PCRGeneratable pcrGeneratable) { + SpProvisionPcrDataHolder.getInstance().setPcrGeneratable(null); + } +} diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/provision/LocalProvisioner.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/provision/LocalProvisioner.java new file mode 100644 index 00000000..f00ecffb --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/provision/LocalProvisioner.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2015-2017, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved. + * + * WSO2.Telco Inc. licences 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +package com.wso2telco.sp.provision; + +import com.wso2telco.core.spprovisionservice.sp.entity.AdminServiceDto; +import com.wso2telco.core.spprovisionservice.sp.entity.ServiceProviderDto; +import com.wso2telco.core.spprovisionservice.sp.entity.SpProvisionConfig; +import com.wso2telco.core.spprovisionservice.sp.entity.SpProvisionDto; +import com.wso2telco.core.spprovisionservice.sp.exception.SpProvisionServiceException; +import com.wso2telco.sp.builder.ServiceProviderBuilder; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class LocalProvisioner extends Provisioner { + + private ServiceProviderBuilder serviceProviderBuilder = null; + private static Log log = LogFactory.getLog(LocalProvisioner.class); + + @Override + public void provisionServiceProvider(ServiceProviderDto serviceProviderDto, SpProvisionConfig spProvisionConfig) + throws SpProvisionServiceException { + + serviceProviderBuilder = new ServiceProviderBuilder(spProvisionConfig); + serviceProviderBuilder.buildServiceProvider(serviceProviderDto); + } + + @Override + public void updateOauthkeys(ServiceProviderDto serviceProviderDto, SpProvisionConfig spProvisionConfig) + throws SpProvisionServiceException { + serviceProviderBuilder = new ServiceProviderBuilder(spProvisionConfig); + serviceProviderBuilder.reBuildOauthKey(serviceProviderDto); + + } + + public ServiceProviderDto getServiceApplicationDetails(String applicationName, SpProvisionConfig spProvisionConfig) + throws SpProvisionServiceException { + serviceProviderBuilder = new ServiceProviderBuilder(spProvisionConfig); + return serviceProviderBuilder.getServiceProviderDetails(applicationName); + } + + public AdminServiceDto getOauthServiceProviderData(String consumerKey, SpProvisionDto dto) + throws SpProvisionServiceException { + serviceProviderBuilder = new ServiceProviderBuilder(dto.getSpProvisionConfig()); + return serviceProviderBuilder.getOauthServiceProviderData(consumerKey); + } + +} diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/provision/Provisioner.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/provision/Provisioner.java new file mode 100644 index 00000000..a50c3aab --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/provision/Provisioner.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2015-2017, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved. + * + * WSO2.Telco Inc. licences 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +package com.wso2telco.sp.provision; + +import com.wso2telco.core.spprovisionservice.sp.entity.AdminServiceDto; +import com.wso2telco.core.spprovisionservice.sp.entity.ServiceProviderDto; +import com.wso2telco.core.spprovisionservice.sp.entity.SpProvisionConfig; +import com.wso2telco.core.spprovisionservice.sp.entity.SpProvisionDto; +import com.wso2telco.core.spprovisionservice.sp.exception.SpProvisionServiceException; + +public abstract class Provisioner { + + public abstract void provisionServiceProvider(ServiceProviderDto serviceProviderDto, + SpProvisionConfig spProvisionConfig) throws SpProvisionServiceException; + + public abstract void updateOauthkeys(ServiceProviderDto serviceProviderDto, SpProvisionConfig spProvisionConfig) + throws SpProvisionServiceException; + + public abstract ServiceProviderDto getServiceApplicationDetails(String applicationName, + SpProvisionConfig spProvisionConfig) throws SpProvisionServiceException; + + public abstract AdminServiceDto getOauthServiceProviderData(String consumerKey, SpProvisionDto spProvisionDto) + throws SpProvisionServiceException; +} diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/provision/RemoteProvisioner.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/provision/RemoteProvisioner.java new file mode 100644 index 00000000..34321164 --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/provision/RemoteProvisioner.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2015-2017, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved. + * + * WSO2.Telco Inc. licences 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +package com.wso2telco.sp.provision; + +import com.wso2telco.core.spprovisionservice.sp.entity.AdminServiceDto; +import com.wso2telco.core.spprovisionservice.sp.entity.ServiceProviderDto; +import com.wso2telco.core.spprovisionservice.sp.entity.SpProvisionConfig; +import com.wso2telco.core.spprovisionservice.sp.entity.SpProvisionDto; +import com.wso2telco.core.spprovisionservice.sp.exception.SpProvisionServiceException; + +public class RemoteProvisioner extends Provisioner { + + @Override + public void provisionServiceProvider(ServiceProviderDto serviceProviderDto, SpProvisionConfig spProvisionConfig) + throws SpProvisionServiceException { + + // todo OutBound Provisioning + + } + + @Override + public void updateOauthkeys(ServiceProviderDto serviceProviderDto, SpProvisionConfig spProvisionConfig) + throws SpProvisionServiceException { + // TODO Auto-generated method stub + + } + + @Override + public ServiceProviderDto getServiceApplicationDetails(String applicationName, SpProvisionConfig spProvisionConfig) + throws SpProvisionServiceException { + // TODO Auto-generated method stub + return null; + } + + @Override + public AdminServiceDto getOauthServiceProviderData(String consumerKey, SpProvisionDto spProvisionDto) + throws SpProvisionServiceException { + // TODO Auto-generated method stub + return null; + } +} diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/provision/ServiceProviderProvisionFactory.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/provision/ServiceProviderProvisionFactory.java new file mode 100644 index 00000000..89ed9489 --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/provision/ServiceProviderProvisionFactory.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2015-2017, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved. + * + * WSO2.Telco Inc. licences 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +package com.wso2telco.sp.provision; + +import com.wso2telco.core.spprovisionservice.sp.entity.ProvisionType; + +public class ServiceProviderProvisionFactory { + + private Provisioner provisioner = null; + + public Provisioner getProvisioner(ProvisionType provisionType) { + + if (provisionType == ProvisionType.LOCAL) { + provisioner = new LocalProvisioner(); + } else { + provisioner = new RemoteProvisioner(); + } + return provisioner; + } + +} diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/provision/service/ProvisioningService.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/provision/service/ProvisioningService.java new file mode 100644 index 00000000..2cf0b47c --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/provision/service/ProvisioningService.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2015-2017, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved. + * + * WSO2.Telco Inc. licences 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +package com.wso2telco.sp.provision.service; + +import com.wso2telco.core.spprovisionservice.sp.entity.AdminServiceDto; +import com.wso2telco.core.spprovisionservice.sp.entity.ServiceProviderDto; +import com.wso2telco.core.spprovisionservice.sp.entity.SpProvisionDto; +import com.wso2telco.core.spprovisionservice.sp.exception.SpProvisionServiceException; + +public interface ProvisioningService { + + public void provisionServiceProvider(SpProvisionDto spProvisionDto) throws SpProvisionServiceException; + + public ServiceProviderDto getServiceProviderDetails(String applicationName, SpProvisionDto spProvisionDto); + + public AdminServiceDto getOauthServiceProviderData(String consumerKey, SpProvisionDto spProvisionDto); + + public void rebuildOauthKeys(SpProvisionDto spProvisionDto) throws SpProvisionServiceException; +} diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/provision/service/impl/ProvisioningServiceImpl.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/provision/service/impl/ProvisioningServiceImpl.java new file mode 100644 index 00000000..1c00a253 --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/provision/service/impl/ProvisioningServiceImpl.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2015-2017, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved. + * + * WSO2.Telco Inc. licences 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +package com.wso2telco.sp.provision.service.impl; + +import com.wso2telco.core.spprovisionservice.sp.entity.AdminServiceDto; +import com.wso2telco.core.spprovisionservice.sp.entity.ProvisionType; +import com.wso2telco.core.spprovisionservice.sp.entity.ServiceProviderDto; +import com.wso2telco.core.spprovisionservice.sp.entity.SpProvisionDto; +import com.wso2telco.core.spprovisionservice.sp.exception.SpProvisionServiceException; +import com.wso2telco.sp.provision.Provisioner; +import com.wso2telco.sp.provision.ServiceProviderProvisionFactory; +import com.wso2telco.sp.provision.service.ProvisioningService; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class ProvisioningServiceImpl implements ProvisioningService { + + private static Log log = LogFactory.getLog(ProvisioningServiceImpl.class); + private ServiceProviderProvisionFactory serviceProviderProvisionFactory = null; + private ProvisionType provisionType = null; + private Provisioner provisioner = null; + + @Override + public void provisionServiceProvider(SpProvisionDto spProvisionDto) throws SpProvisionServiceException { + serviceProviderProvisionFactory = new ServiceProviderProvisionFactory(); + provisionType = spProvisionDto.getProvisionType(); + provisioner = serviceProviderProvisionFactory.getProvisioner(provisionType); + AdminServiceDto adminServiceDto = spProvisionDto.getServiceProviderDto().getAdminServiceDto(); + + if ((provisioner != null) && (adminServiceDto.getOauthConsumerKey() != null)) { + provisioner.provisionServiceProvider(spProvisionDto.getServiceProviderDto(), + spProvisionDto.getSpProvisionConfig()); + } else { + log.error("Provisioner object doesn't contain mandatory details"); + return; + } + } + + @Override + public void rebuildOauthKeys(SpProvisionDto spProvisionDto) throws SpProvisionServiceException { + serviceProviderProvisionFactory = new ServiceProviderProvisionFactory(); + provisionType = spProvisionDto.getProvisionType(); + provisioner = serviceProviderProvisionFactory.getProvisioner(provisionType); + AdminServiceDto adminServiceDto = spProvisionDto.getServiceProviderDto().getAdminServiceDto(); + + if ((provisioner != null) && (adminServiceDto.getOauthConsumerKey() != null)) { + provisioner.updateOauthkeys(spProvisionDto.getServiceProviderDto(), spProvisionDto.getSpProvisionConfig()); + } else { + log.error("Provisioner object doesn't contain mandatory details"); + return; + } + } + + @Override + public ServiceProviderDto getServiceProviderDetails(String applicationName, SpProvisionDto spProvisionDto) { + serviceProviderProvisionFactory = new ServiceProviderProvisionFactory(); + provisioner = serviceProviderProvisionFactory.getProvisioner(provisionType); + ServiceProviderDto serviceProviderDto = null; + try { + serviceProviderDto = provisioner.getServiceApplicationDetails(applicationName, + spProvisionDto.getSpProvisionConfig()); + } catch (SpProvisionServiceException e) { + log.error("Error occurred while taking details of the Service Provider"); + } catch (NullPointerException e) { + log.error(applicationName + " is not registered"); + } + return serviceProviderDto; + } + + @Override + public AdminServiceDto getOauthServiceProviderData(String consumerKey, SpProvisionDto spProvisionDto) { + serviceProviderProvisionFactory = new ServiceProviderProvisionFactory(); + provisionType = spProvisionDto.getProvisionType(); + provisioner = serviceProviderProvisionFactory.getProvisioner(provisionType); + AdminServiceDto adminServiceDto = null; + try { + adminServiceDto = provisioner.getOauthServiceProviderData(consumerKey, spProvisionDto); + } catch (SpProvisionServiceException e) { + log.error("Error occurred while taking details of the Service Provider"); + } catch (NullPointerException e) { + log.error("Application with consumer key " + consumerKey + " is not registered"); + } + return adminServiceDto; + } +} diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/util/TransformUtil.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/util/TransformUtil.java new file mode 100644 index 00000000..43001df5 --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/util/TransformUtil.java @@ -0,0 +1,153 @@ +/******************************************************************************* + * Copyright (c) 2015-2017, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved. + * + * WSO2.Telco Inc. licences 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +package com.wso2telco.sp.util; + +import com.wso2telco.core.config.model.MobileConnectConfig; +import com.wso2telco.core.config.model.MobileConnectConfig.CrValidateDiscoveryConfig; +import com.wso2telco.core.config.model.MobileConnectConfig.DiscoveryConfig; +import com.wso2telco.core.config.model.MobileConnectConfig.EksDiscoveryConfig; +import com.wso2telco.core.pcrservice.util.SectorUtil; +import com.wso2telco.core.spprovisionservice.sp.entity.AdminServiceDto; +import com.wso2telco.core.spprovisionservice.sp.entity.DiscoveryServiceConfig; +import com.wso2telco.core.spprovisionservice.sp.entity.DiscoveryServiceDto; +import com.wso2telco.core.spprovisionservice.sp.entity.EksDisConfig; +import com.wso2telco.core.spprovisionservice.sp.entity.ProvisionType; +import com.wso2telco.core.spprovisionservice.sp.entity.ServiceProviderDto; +import com.wso2telco.core.spprovisionservice.sp.entity.SpProvisionConfig; +import com.wso2telco.core.spprovisionservice.sp.entity.SpProvisionDto; + +public class TransformUtil { + + public static DiscoveryServiceConfig transformDiscoveryConfig(DiscoveryConfig discoveryConfig, + MobileConnectConfig mobileConnectConfig) { + DiscoveryServiceConfig config = new DiscoveryServiceConfig(); + + config.setEksDiscoveryConfig(transformEksDiscoveryConfig(discoveryConfig.getEksDiscoveryConfig())); + config.setCrValidateDiscoveryConfig( + transoformCrValidateDiscoveryConfig(discoveryConfig.getCrValidateDiscoveryConfig())); + config.setPcrServiceEnabled(mobileConnectConfig.isPcrServiceEnabled()); + return config; + } + + public static com.wso2telco.core.spprovisionservice.sp.entity.CrValidateDiscoveryConfig transoformCrValidateDiscoveryConfig( + CrValidateDiscoveryConfig discoveryConf) { + com.wso2telco.core.spprovisionservice.sp.entity.CrValidateDiscoveryConfig crValidateDiscoveryConfig = new com.wso2telco.core.spprovisionservice.sp.entity.CrValidateDiscoveryConfig(); + if (discoveryConf != null) { + crValidateDiscoveryConfig.setServiceUrl(discoveryConf.getServiceUrl()); + } + return crValidateDiscoveryConfig; + } + + public static EksDisConfig transformEksDiscoveryConfig(EksDiscoveryConfig discoveryConf) { + EksDisConfig eksDiscoveryConfig = new EksDisConfig(); + if (discoveryConf != null) { + eksDiscoveryConfig.setRedirectUrl(discoveryConf.getRedirectUrl()); + eksDiscoveryConfig.setServiceUrl(discoveryConf.getServiceUrl()); + eksDiscoveryConfig.setMsisdn(discoveryConf.getMsisdn()); + } + return eksDiscoveryConfig; + } + + public static DiscoveryServiceDto transofrmDiscoveryDto(String clientId, String callbackUrl) { + DiscoveryServiceDto discoveryServiceDto = new DiscoveryServiceDto(); + discoveryServiceDto.setClientId(clientId); + String sectorId = null; + if (callbackUrl != null && !callbackUrl.isEmpty()) { + sectorId = SectorUtil.getSectorIdFromUrl(callbackUrl); + } + discoveryServiceDto.setSectorId(sectorId); + return discoveryServiceDto; + } + + public static SpProvisionDto getServiceProviderDto(ServiceProviderDto serviceProvider, + MobileConnectConfig mConfig) { + SpProvisionDto spProvisionDto = new SpProvisionDto(); + SpProvisionConfig spProvisionConfig = new SpProvisionConfig(); + MobileConnectConfig.Config config = mConfig.getSpProvisionConfig().getConfig(); + + if (serviceProvider != null && serviceProvider.getAdminServiceDto() != null + && serviceProvider.getAdminServiceDto().getOauthConsumerKey() != null + && !serviceProvider.getAdminServiceDto().getOauthConsumerKey().isEmpty()) { + + String applicationName = serviceProvider.getApplicationName(); + String description = serviceProvider.getDescription(); + + ServiceProviderDto serviceProviderDto = new ServiceProviderDto(); + serviceProviderDto.setApplicationName(applicationName); + serviceProviderDto.setDescription(description); + serviceProviderDto.setInboundAuthKey(serviceProvider.getAdminServiceDto().getOauthConsumerKey()); + if (serviceProvider.getAdminServiceDto().getOauthConsumerSecret() != null + && !serviceProvider.getAdminServiceDto().getOauthConsumerSecret().isEmpty()) { + serviceProviderDto.setPropertyValue(serviceProvider.getAdminServiceDto().getOauthConsumerSecret()); + } + + serviceProviderDto.setAlwaysSendMappedLocalSubjectId(config.isAlwaysSendMappedLocalSubjectId()); + serviceProviderDto.setLocalClaimDialect(config.isLocalClaimDialect()); + serviceProviderDto.setInboundAuthType(config.getInboundAuthType()); + serviceProviderDto.setConfidential(config.isConfidential()); + serviceProviderDto.setDefaultValue(config.getDefaultValue()); + serviceProviderDto.setPropertyName(config.getPropertyName()); + serviceProviderDto.setPropertyRequired(config.isPropertyRequired()); + serviceProviderDto.setProvisioningEnabled(config.isProvisioningEnabled()); + serviceProviderDto.setProvisioningUserStore(config.getProvisioningUserStore()); + String idpRoles[] = { applicationName }; + serviceProviderDto.setIdpRoles(idpRoles); + serviceProviderDto.setSaasApp(config.isSaasApp()); + serviceProviderDto + .setLocalAuthenticatorConfigsDisplayName(config.getLocalAuthenticatorConfigsDisplayName()); + serviceProviderDto.setLocalAuthenticatorConfigsEnabled(config.isLocalAuthenticatorConfigsEnabled()); + serviceProviderDto.setLocalAuthenticatorConfigsName(config.getLocalAuthenticatorConfigsName()); + serviceProviderDto.setLocalAuthenticatorConfigsValid(config.isLocalAuthenticatorConfigsValid()); + serviceProviderDto.setLocalAuthenticatorConfigsAuthenticationType( + config.getLocalAuthenticatorConfigsAuthenticationType()); + + // Set values for spProvisionConfig + + serviceProviderDto.setAdminServiceDto(getAdminServiceDto(serviceProvider, config)); + serviceProviderDto.setExistance(ProvisionType.LOCAL); + + // Set Values for SpProvisionDTO + spProvisionDto.setServiceProviderDto(serviceProviderDto); + spProvisionDto.setDiscoveryServiceDto(null); + } + spProvisionDto.setProvisionType(ProvisionType.LOCAL); + spProvisionDto.setSpProvisionConfig(spProvisionConfig); + return spProvisionDto; + + } + + private static AdminServiceDto getAdminServiceDto(ServiceProviderDto serviceProvider, + MobileConnectConfig.Config config) { + + String applicationName = serviceProvider.getApplicationName(); + String cutomerKey = serviceProvider.getAdminServiceDto().getOauthConsumerKey(); + String secretKey = serviceProvider.getAdminServiceDto().getOauthConsumerSecret(); + String callbackUrl = serviceProvider.getAdminServiceDto().getCallbackUrl(); + + AdminServiceDto adminServiceDto = new AdminServiceDto(); + adminServiceDto.setApplicationName(applicationName); + adminServiceDto.setCallbackUrl(callbackUrl); + adminServiceDto.setOauthVersion(config.getoAuthVersion()); + adminServiceDto.setGrantTypes(config.getGrantTypes()); + adminServiceDto.setOauthConsumerKey(cutomerKey); + adminServiceDto.setOauthConsumerSecret(secretKey); + adminServiceDto.setPkceMandatory(config.isPkceMandatory()); + adminServiceDto.setPkceSupportPlain(config.isPkceSupportPlain()); + return adminServiceDto; + + } + +} diff --git a/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/util/ValidationUtil.java b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/util/ValidationUtil.java new file mode 100644 index 00000000..4ebcabb4 --- /dev/null +++ b/components/sp-seamless-provision/src/main/java/com/wso2telco/sp/util/ValidationUtil.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2015-2017, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved. + * + * WSO2.Telco Inc. licences 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +package com.wso2telco.sp.util; + +import com.wso2telco.sp.discovery.exception.DicoveryException; + +public class ValidationUtil { + + public static boolean validateInuts(String sector, String clientId) throws DicoveryException { + if (!validateClientId(clientId)) { + throw new DicoveryException("Empty clientId found", true); + } + if (!validateSectorId(sector)) { + throw new DicoveryException("Empty sector found", true); + } + return true; + } + + private static boolean validateSectorId(String sector) { + boolean isValied = true; + if (sector == null || sector.isEmpty()) { + isValied = false; + } + return isValied; + } + + private static boolean validateClientId(String clientId) { + boolean isValied = true; + if (clientId == null || clientId.isEmpty()) { + isValied = false; + } + return isValied; + } + +} diff --git a/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/discovery/DiscoveryLocatorTest.java b/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/discovery/DiscoveryLocatorTest.java new file mode 100644 index 00000000..11432a4a --- /dev/null +++ b/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/discovery/DiscoveryLocatorTest.java @@ -0,0 +1,43 @@ +package com.wso2telco.sp.discovery; + +import org.junit.*; + + +import junit.framework.TestCase; + +public class DiscoveryLocatorTest extends TestCase { + + /* + * @BeforeClass + * public static void initialize() { + * ignore = 1; + * } + */ + + @Test + public void testLocalDiscoveryLocators() { + // Apis ps = new Apis(); + DiscoveryLocator discoveryLocator = new LocalDiscovery(); + RemoteCredentialDiscovery remoteCredentialDiscovery = new RemoteCredentialDiscovery(); + discoveryLocator.setNextDiscovery(remoteCredentialDiscovery); + + Assert.assertEquals(discoveryLocator.getNextDiscovery(), remoteCredentialDiscovery); + + } + + public DiscoveryLocatorTest(String name){ + super(name); + } + + + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(DiscoveryLocatorTest.class); + } + /* + * @After + * public void collector() { + * ignore = 0; + * } + */ + +} diff --git a/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/discovery/LocalDiscoveryTest.java b/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/discovery/LocalDiscoveryTest.java new file mode 100644 index 00000000..ef51b4b7 --- /dev/null +++ b/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/discovery/LocalDiscoveryTest.java @@ -0,0 +1,76 @@ +package com.wso2telco.sp.discovery; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.wso2telco.core.spprovisionservice.sp.entity.CrValidateDiscoveryConfig; +import com.wso2telco.core.spprovisionservice.sp.entity.DiscoveryServiceConfig; +import com.wso2telco.core.spprovisionservice.sp.entity.DiscoveryServiceDto; +import com.wso2telco.core.spprovisionservice.sp.entity.EksDisConfig; +import com.wso2telco.core.spprovisionservice.sp.entity.ServiceProviderDto; + + +import junit.framework.TestCase; + +public class LocalDiscoveryTest { + + private DiscoveryServiceDto discoveryServiceDto = null; + private DiscoveryServiceConfig discoveryServiceConfig = null; + + private ServiceProviderDto serviceProviderDto = null; + private CrValidateDiscoveryConfig crValidateDiscoveryConfig = null; + private EksDisConfig eksDiscoveryConfig = null; + + private static final String URL = "https://localhost:9443/playground2/oauth2.jsp"; + private static final String SERVICE_URL_CR = "https://india.discover.mobileconnect.io/rv/v1/exchange/organizations/gsma/validate"; + private static final String SERVICE_URL_EKS = "https://india.discover.mobileconnect.io/gsma/v2/discovery/"; + private static final String CLIENT_ID = "56233566988556222365223"; + private static final String CLIENT_SECRET = "90992999292002992020"; + private static final String SECTOR = "localhost"; + private static final String MSISDN = "0094719531809"; + private static final String EMPTY = ""; + + @Before + public void before() { + discoveryServiceDto = new DiscoveryServiceDto(); + discoveryServiceDto.setClientId(CLIENT_ID); + discoveryServiceDto.setClientSecret(CLIENT_SECRET); + discoveryServiceDto.setMsisdn(MSISDN); + discoveryServiceDto.setSectorId(SECTOR); + + crValidateDiscoveryConfig = new CrValidateDiscoveryConfig(); + crValidateDiscoveryConfig.setServiceUrl(SERVICE_URL_CR); + + eksDiscoveryConfig = new EksDisConfig(); + eksDiscoveryConfig.setRedirectUrl(URL); + eksDiscoveryConfig.setServiceUrl(SERVICE_URL_EKS); + + discoveryServiceConfig = new DiscoveryServiceConfig(); + discoveryServiceConfig.setCrValidateDiscoveryConfig(crValidateDiscoveryConfig); + discoveryServiceConfig.setEksDiscoveryConfig(eksDiscoveryConfig); + discoveryServiceConfig.setPcrServiceEnabled(false); + discoveryServiceConfig.setDiscoverOnlyLocal(false); + discoveryServiceConfig.setCrValidateDiscoveryConfig(crValidateDiscoveryConfig); + discoveryServiceConfig.setEksDiscoveryConfig(eksDiscoveryConfig); + + } +/* + @Test + public void testServceProviderDiscovery() { + + LocalDiscovery localDiscovery = new LocalDiscovery(); + localDiscovery.setNextDiscovery(new RemoteCredentialDiscovery()); + + try { + // serviceProviderDto = localDiscovery.servceProviderDiscovery(discoveryServiceConfig, discoveryServiceDto); + } catch (DicoveryException e) { + serviceProviderDto = null; + } + + Assert.assertEquals(serviceProviderDto, null); + + } +*/ + +} diff --git a/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/discovery/RemoteCredentialDiscoveryTest.java b/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/discovery/RemoteCredentialDiscoveryTest.java new file mode 100644 index 00000000..aae5a071 --- /dev/null +++ b/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/discovery/RemoteCredentialDiscoveryTest.java @@ -0,0 +1,100 @@ +package com.wso2telco.sp.discovery; + +import java.util.Map; + +import org.junit.*; + +import com.wso2telco.core.spprovisionservice.sp.entity.CrValidateDiscoveryConfig; +import com.wso2telco.core.spprovisionservice.sp.entity.DiscoveryServiceConfig; +import com.wso2telco.core.spprovisionservice.sp.entity.DiscoveryServiceDto; +import com.wso2telco.core.spprovisionservice.sp.entity.ServiceProviderDto; +import com.wso2telco.sp.entity.Application; +import com.wso2telco.sp.entity.CrValidateRes; + +import junit.framework.TestCase; + +public class RemoteCredentialDiscoveryTest extends TestCase { + + protected static String ACCEPT = "Accept"; + protected static String CONTENT_TYPE_HEADER_KEY = "Content-Type"; + protected static String CONTENT_TYPE_HEADER_VAL_TYPE_EKS = "application/x-www-form-urlencoded"; + protected static String CONTENT_TYPE_HEADER_VAL_TYPE_CR = "application/json"; + protected static String AUTHORIZATION_HEADER = "Authorization"; + protected static String HTTP_POST = "POST"; + protected static String MSISDN = "msisdn"; + protected static String REDIRECT_URL = "Redirect_URL"; + protected static String CLIENT_ID = "client_id"; + protected static String CLIENT_SECRET = "client_secret"; + protected static String BASIC = "Basic"; + protected static String QES_OPERATOR = "?"; + protected static String EQA_OPERATOR = "="; + protected static String AMP_OPERATOR = "&"; + protected static String SPACE = " "; + protected static String COLON = ":"; + protected static String NEW_LINE = "\n"; + + private static String APP_NAME = "APPNAME"; + private static String APP_DESCRIPTION = "APP-DESCRIPTION"; + + protected static String BASIC_AUTH_CODE = "42552362-522633-5522333-522141525252"; + + private RemoteCredentialDiscovery remoteDiscovery = null; + private DiscoveryServiceConfig discoveryServiceConfig; + private DiscoveryServiceDto discoveryServiceDto; + private Application application; + + public void init() { + remoteDiscovery = new RemoteCredentialDiscovery(); + discoveryServiceConfig = new DiscoveryServiceConfig(); + CrValidateDiscoveryConfig crValidateDiscoveryConfig = new CrValidateDiscoveryConfig(); + discoveryServiceConfig.setCrValidateDiscoveryConfig(crValidateDiscoveryConfig); + discoveryServiceDto = new DiscoveryServiceDto(); + } + + @Test + public void testBuildEndPointUrl() { + String url = remoteDiscovery.buildEndPointUrl(discoveryServiceConfig, discoveryServiceDto); + Assert.assertEquals(url, buildEndPointUrl(discoveryServiceConfig, discoveryServiceDto)); + } + + @Test + public void testBuildRequestProperties() { + Map reqProperies = remoteDiscovery.buildRequestProperties(BASIC_AUTH_CODE); + Assert.assertNotEquals(reqProperies, null); + Assert.assertEquals(CONTENT_TYPE_HEADER_VAL_TYPE_CR, reqProperies.get(ACCEPT)); + Assert.assertEquals(BASIC + SPACE + BASIC_AUTH_CODE, reqProperies.get(AUTHORIZATION_HEADER)); + } + + @Test + public void testCreateServiceProviderDto() { + CrValidateRes crValidateRes = new CrValidateRes(); + application = new Application(); + + application.setAppName(APP_NAME); + application.setDescription(APP_DESCRIPTION); + crValidateRes.setApplication(application); + DiscoveryServiceDto discoveryServiceDto = new DiscoveryServiceDto(); + crValidateRes.setApplication(application); + ServiceProviderDto serviceProviderDto = remoteDiscovery.createServiceProviderDtoBy(crValidateRes, + discoveryServiceDto); + Assert.assertEquals(APP_DESCRIPTION,serviceProviderDto.getDescription()); + } + + public RemoteCredentialDiscoveryTest(String name) { + super(name); + init(); + } + + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(RemoteCredentialDiscoveryTest.class); + } + + public String buildEndPointUrl(DiscoveryServiceConfig discoveryServiceConfig, + DiscoveryServiceDto discoveryServiceDto) { + String endPointUrl = discoveryServiceConfig.getCrValidateDiscoveryConfig().getServiceUrl() + QES_OPERATOR + + CLIENT_ID + EQA_OPERATOR + discoveryServiceDto.getClientId() + AMP_OPERATOR + CLIENT_SECRET + + EQA_OPERATOR + discoveryServiceDto.getClientSecret(); + return endPointUrl; + } + +} diff --git a/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestApis.java b/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestApis.java new file mode 100644 index 00000000..819a34b4 --- /dev/null +++ b/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestApis.java @@ -0,0 +1,36 @@ +package com.wso2telco.sp.entity; + +import org.junit.*; + +import junit.framework.TestCase; + +public class TestApis extends TestCase { + + private OperatorId operatorId = null; + + @Before + public void init() { + operatorId = new OperatorId(); + } + + @Test + public void testApisClazz() { + init(); + Apis apis = new Apis(); + apis.setOperatorid(operatorId); + + Assert.assertEquals(operatorId, apis.getOperatorid()); + } + + private String apisToString(OperatorId operatorId) { + return "ClassPojo [operatorid = " + operatorId + "]"; + } + + public TestApis(String name) { + super(name); + } + + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(TestApis.class); + } +} diff --git a/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestApplication.java b/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestApplication.java new file mode 100644 index 00000000..1c53db9b --- /dev/null +++ b/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestApplication.java @@ -0,0 +1,81 @@ +package com.wso2telco.sp.entity; + +import org.junit.*; + +import junit.framework.TestCase; + +public class TestApplication extends TestCase { + + private static final String APPNAME = "APPNAME"; + private static final String APPCREDID = "APPCREDID"; + private static final String APPSTATUS = "APPSTATUS"; + private static final String APPTYPE = "APPTYPE"; + private static final String DESCRIPTION = "DESCRIPTION"; + private static final String DEVID = "DEVID"; + private static final String DEVNAME = "DEVNAME"; + private static final String DEVORGID = "DEVORGID"; + private static final String DEVSTATUS = "DEVSTATUS"; + private static final String REDIRECTURI = "REDIRECTURI"; + private static SupportedApis[] supportedApis = null; + private static SupportedApis supportedApis_1 = null; + private static SupportedApis supportedApis_2 = null; + + private Application application; + + + public void init() { + + supportedApis = new SupportedApis[2]; + supportedApis_1 = new SupportedApis(); + supportedApis_2 = new SupportedApis(); + supportedApis[0] = supportedApis_1; + supportedApis[1] = supportedApis_2; + + application = new Application(); + application.setAppName(APPNAME); + application.setAppCredId(APPCREDID); + application.setAppStatus(APPSTATUS); + application.setAppType(APPTYPE); + application.setDescription(DESCRIPTION); + application.setDevId(DEVID); + application.setDevName(DEVNAME); + application.setDevOrgId(DEVORGID); + application.setDevStatus(DEVSTATUS); + application.setRedirectUri(REDIRECTURI); + application.setSupportedApis(supportedApis); + + } + + + public void testApplicationClazz() { + init(); + Assert.assertEquals(application.getAppCredId(), APPCREDID); + Assert.assertEquals(application.getAppName(), APPNAME); + Assert.assertEquals(application.getAppStatus(), APPSTATUS); + Assert.assertEquals(application.getAppType(), APPTYPE); + Assert.assertEquals(application.getDescription(), DESCRIPTION); + Assert.assertEquals(application.getDevId(), DEVID); + Assert.assertEquals(application.getDevName(), DEVNAME); + Assert.assertEquals(application.getDevOrgId(), DEVORGID); + Assert.assertEquals(application.getDevStatus(), DEVSTATUS); + Assert.assertEquals(application.getRedirectUri(), REDIRECTURI); + Assert.assertEquals(application.getSupportedApis(), supportedApis); + + } + + public TestApplication(String name) { + super(name); + } + + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(TestApplication.class); + } + + private String getApplicationToStting() { + return "ClassPojo [appName = " + APPNAME + ", appStatus = " + APPSTATUS + ", description = " + DESCRIPTION + + ", devStatus = " + DEVSTATUS + ", devName = " + DEVNAME + ", supportedApis = " + supportedApis + + ", devId = " + DEVID + ", devOrgId = " + DEVORGID + ", redirectUri = " + REDIRECTURI + ", appType = " + + APPTYPE + ", appCredId = " + APPCREDID + "]"; + } + +} diff --git a/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestCrValidateRes.java b/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestCrValidateRes.java new file mode 100644 index 00000000..d39c36de --- /dev/null +++ b/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestCrValidateRes.java @@ -0,0 +1,46 @@ +package com.wso2telco.sp.entity; + +import org.junit.Assert; +import org.junit.Test; + +import junit.framework.TestCase; + +public class TestCrValidateRes extends TestCase { + + private CrValidateRes crValidateRes = null; + private Application application; + private String ORGID = "G8569"; + private String X_CLIENT_ID = "4556481-321364"; + + public void init() { + application = new Application(); + crValidateRes = new CrValidateRes(); + } + + @Test + public void testCrValidateResClazz() { + init(); + crValidateRes.setApplication(application); + crValidateRes.setOrgId(ORGID); + crValidateRes.setX_client_id(X_CLIENT_ID); + + Assert.assertEquals(crValidateRes.getApplication(), application); + Assert.assertEquals(crValidateRes.getX_client_id(), X_CLIENT_ID); + Assert.assertEquals(crValidateRes.getOrgId(), ORGID); + Assert.assertEquals(getToString(), crValidateRes.toString()); + } + + public TestCrValidateRes(String name) { + super(name); + } + + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(TestCrValidateRes.class); + } + + public String getToString() { + return "ClassPojo [orgId = " + ORGID + ", application = " + application + ", x_client_id = " + X_CLIENT_ID + + "]"; + } + +} diff --git a/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestEksDiscovery.java b/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestEksDiscovery.java new file mode 100644 index 00000000..664cbfaf --- /dev/null +++ b/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestEksDiscovery.java @@ -0,0 +1,40 @@ +package com.wso2telco.sp.entity; + +import org.junit.*; + +import junit.framework.TestCase; + + +public class TestEksDiscovery extends TestCase { + + private EksDiscovery eksDiscovery; + private String TTL="6322563"; + private Response response; + + public void init(){ + eksDiscovery = new EksDiscovery(); + response = new Response(); + eksDiscovery.setResponse(response); + eksDiscovery.setTtl(TTL); + } + + @Test + public void testEksDiscoveryClazz(){ + init(); + Assert.assertEquals(eksDiscovery.getTtl(), TTL); + Assert.assertEquals(eksDiscovery.getResponse(), response); + Assert.assertEquals(eksDiscovery.toString(), getEksDiscoveryToString()); + } + + public String getEksDiscoveryToString() { + return "ClassPojo [response = " + response + ", ttl = " + TTL + "]"; + } + + public TestEksDiscovery(String name){ + super(name); + } + + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(TestEksDiscovery.class); + } +} diff --git a/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestLink.java b/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestLink.java new file mode 100644 index 00000000..2657dd75 --- /dev/null +++ b/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestLink.java @@ -0,0 +1,42 @@ +package com.wso2telco.sp.entity; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import junit.framework.TestCase; + +public class TestLink extends TestCase { + + private Link link = null; + private static String HREF = "href"; + private static String REL = "rel"; + + @Before + public void init() { + link = new Link(); + link.setHref(HREF); + link.setRel(REL); + } + + @Test + public void testLink() { + init(); + Assert.assertEquals(link.getHref(), HREF); + Assert.assertEquals(link.getRel(), REL); + Assert.assertEquals(link.toString(), getLinkToString()); + } + + public TestLink(String name) { + super(name); + } + + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(TestLink.class); + } + + public String getLinkToString() { + return "ClassPojo [rel = " + REL + ", href = " + HREF + "]"; + } + +} diff --git a/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestOperatorId.java b/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestOperatorId.java new file mode 100644 index 00000000..57050216 --- /dev/null +++ b/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestOperatorId.java @@ -0,0 +1,40 @@ +package com.wso2telco.sp.entity; + +import org.junit.*; + +import junit.framework.TestCase; + +public class TestOperatorId extends TestCase { + + private OperatorId operatorId = null; + private Link[] links = null; + + public void init() { + operatorId = new OperatorId(); + links = new Link[1]; + Link link_1 = new Link(); + links[0] = link_1; + } + + @Test + public void testOperatorIdClazz() { + init(); + operatorId.setLink(links); + Assert.assertEquals(operatorId.getLink(), links); + Assert.assertEquals(operatorId.toString(), getToString()); + + } + + public TestOperatorId(String name) { + super(name); + } + + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(TestOperatorId.class); + } + + public String getToString() { + return "ClassPojo [link = " + links + "]"; + } + +} diff --git a/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestResponse.java b/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestResponse.java new file mode 100644 index 00000000..379be728 --- /dev/null +++ b/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestResponse.java @@ -0,0 +1,61 @@ +package com.wso2telco.sp.entity; + +import org.junit.*; + +import junit.framework.TestCase; + +public class TestResponse extends TestCase { + + private Response response = null; + + private String SERVING_OPERATOR = "SERVING_OPERATOR"; + + private String CLIENT_SECRET = "CLIENT_SECRET"; + + private Apis apis = null; + + private String CLIENT_ID = "CLIENT_ID"; + + private String CURRENCY = "CURRENCY"; + + private String COUNTRY = "COUNTRY"; + + @Before + public void init() { + response = new Response(); + apis = new Apis(); + + response.setApis(apis); + response.setClient_id(CLIENT_ID); + response.setClient_secret(CLIENT_SECRET); + response.setCountry(COUNTRY); + response.setCurrency(CURRENCY); + response.setServing_operator(SERVING_OPERATOR); + } + + public void testResponseClazz() { + init(); + Assert.assertEquals(response.getClient_id(), CLIENT_ID); + Assert.assertEquals(response.getClient_secret(), CLIENT_SECRET); + Assert.assertEquals(response.getCountry(), COUNTRY); + Assert.assertEquals(response.getCurrency(), CURRENCY); + Assert.assertEquals(response.getApis(), apis); + Assert.assertEquals(response.getServing_operator(), SERVING_OPERATOR); + Assert.assertEquals(response.toString(), getResponseToString()); + } + + public TestResponse(String name) { + super(name); + } + + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(TestResponse.class); + } + + public String getResponseToString() { + return "ClassPojo [serving_operator = " + SERVING_OPERATOR + ", client_secret = " + CLIENT_SECRET + ", apis = " + + apis + ", client_id = " + CLIENT_ID + ", currency = " + CURRENCY + ", country = " + COUNTRY + "]"; + + } + +} diff --git a/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestSupportedApis.java b/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestSupportedApis.java new file mode 100644 index 00000000..214d3896 --- /dev/null +++ b/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/entity/TestSupportedApis.java @@ -0,0 +1,37 @@ +package com.wso2telco.sp.entity; + +import org.junit.*; + +import junit.framework.TestCase; + +public class TestSupportedApis extends TestCase { + + private static final String NAME = "NAME"; + private SupportedApis supportedApis = null; + + @Before + public void init() { + supportedApis = new SupportedApis(); + supportedApis.setName(NAME); + } + + @Test + public void testSupportedApisClazz() { + init(); + Assert.assertEquals(supportedApis.getName(), NAME); + Assert.assertEquals(supportedApis.toString(), getSupportedApisToString()); + } + + private String getSupportedApisToString() { + return "ClassPojo [name = " + NAME + "]"; + } + + public TestSupportedApis(String name) { + super(name); + } + + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(TestSupportedApis.class); + } + +} diff --git a/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/util/TransformUtilTest.java b/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/util/TransformUtilTest.java new file mode 100644 index 00000000..68af96b3 --- /dev/null +++ b/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/util/TransformUtilTest.java @@ -0,0 +1,101 @@ +package com.wso2telco.sp.util; + +import org.junit.*; + +import com.wso2telco.core.spprovisionservice.sp.entity.CrValidateDiscoveryConfig; +import com.wso2telco.core.spprovisionservice.sp.entity.DiscoveryServiceConfig; +import com.wso2telco.core.spprovisionservice.sp.entity.DiscoveryServiceDto; +import com.wso2telco.core.spprovisionservice.sp.entity.EksDisConfig; +import com.wso2telco.sp.discovery.DiscoveryLocatorTest; +import com.wso2telco.sp.discovery.LocalDiscoveryTest; + +import junit.framework.TestCase; + +import com.wso2telco.core.config.model.MobileConnectConfig; +import com.wso2telco.core.config.model.MobileConnectConfig.DiscoveryConfig; +import com.wso2telco.core.config.model.MobileConnectConfig.EksDiscoveryConfig; + +public class TransformUtilTest extends TestCase{ + + private static final String URL = "https://localhost:9443/playground2/oauth2.jsp"; + private static final String CLIENT_ID = "56233566988556222365223"; + private static final String SECTOR = "localhost"; + private static final String MSISDN = "0094719531809"; + private static final String EMPTY = ""; + + /* + * @BeforeClass + * public static void initialize() { + * ignore = 1; + * } + */ + + @Test + public void testTransofrmDiscoveryDto() { + DiscoveryServiceDto discoveryDto = TransformUtil.transofrmDiscoveryDto(CLIENT_ID, URL); + + Assert.assertEquals(discoveryDto.getClientId(), CLIENT_ID); + Assert.assertEquals(discoveryDto.getSectorId(), SECTOR); + } + + @Test + public void testTransofrmDiscoveryDtoEmptyURL() { + DiscoveryServiceDto discoveryDto = TransformUtil.transofrmDiscoveryDto(CLIENT_ID, EMPTY); + + Assert.assertEquals(discoveryDto.getClientId(), CLIENT_ID); + Assert.assertEquals(discoveryDto.getSectorId(), null); + } + + @Test + public void testTransformEksDiscoveryConfig() { + EksDiscoveryConfig discoveryConf = new EksDiscoveryConfig(); + discoveryConf.setMsisdn(MSISDN); + discoveryConf.setRedirectUrl(URL); + discoveryConf.setServiceUrl(URL); + EksDisConfig discoveryDto = TransformUtil.transformEksDiscoveryConfig(discoveryConf); + Assert.assertEquals(discoveryDto.getMsisdn(), MSISDN); + Assert.assertEquals(discoveryDto.getRedirectUrl(), URL); + Assert.assertEquals(discoveryDto.getServiceUrl(), URL); + } + + @Test + public void testTransoformCrValidateDiscoveryConfig() { + CrValidateDiscoveryConfig v = new CrValidateDiscoveryConfig(); + com.wso2telco.core.config.model.MobileConnectConfig.CrValidateDiscoveryConfig conf = new com.wso2telco.core.config.model.MobileConnectConfig.CrValidateDiscoveryConfig(); + conf.setServiceUrl(URL); + v = TransformUtil.transoformCrValidateDiscoveryConfig(conf); + Assert.assertEquals(v.getServiceUrl(), URL); + } + + @Test + public void testTransformDiscoveryConfig() { + MobileConnectConfig mobileConnectConfig = new MobileConnectConfig(); + DiscoveryServiceConfig discoveryServiceConfig = new DiscoveryServiceConfig(); + DiscoveryConfig discoveryConfig = new DiscoveryConfig(); + TransformUtil.transformDiscoveryConfig(discoveryConfig, mobileConnectConfig); + Assert.assertEquals(discoveryServiceConfig.getCrValidateDiscoveryConfig(), null); + Assert.assertEquals(discoveryServiceConfig.getEksDiscoveryConfig(), null); + } + + @Test + public void testValidationUtil() { + ValidationUtil validationUtil = new ValidationUtil(); + } + + public TransformUtilTest(String name){ + super(name); + } + + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(TransformUtilTest.class); + } + + + + /* + * @After + * public void collector() { + * ignore = 0; + * } + */ +} diff --git a/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/util/ValidationUtilTest.java b/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/util/ValidationUtilTest.java new file mode 100644 index 00000000..c5b1bc63 --- /dev/null +++ b/components/sp-seamless-provision/src/test/java/com/wso2telco/sp/util/ValidationUtilTest.java @@ -0,0 +1,74 @@ +package com.wso2telco.sp.util; + +import org.junit.*; + +import com.wso2telco.sp.discovery.exception.DicoveryException; + +import junit.framework.TestCase; + +public class ValidationUtilTest extends TestCase{ + + private static final String CLIENT_ID = "56233566988556222365223"; + private static final String SECTOR = "localhost"; + private static final boolean TRUE = true; + private static final boolean FALSE = false; + private static final String EMPTY = ""; + + @Test + public void testValidateInuts() { + boolean isValid = false; + try { + isValid = ValidationUtil.validateInuts(SECTOR, CLIENT_ID); + } catch (DicoveryException e) { + } + Assert.assertEquals(isValid, TRUE); + } + + @Test + public void testValidateInutsEmptyClient() { + boolean isValid = false; + try { + isValid = ValidationUtil.validateInuts(SECTOR, EMPTY); + } catch (DicoveryException e) { + } + Assert.assertEquals(isValid, FALSE); + } + + @Test + public void testValidateInutsNullClient() { + boolean isValid = false; + try { + isValid = ValidationUtil.validateInuts(SECTOR, null); + } catch (DicoveryException e) { + } + Assert.assertEquals(isValid, FALSE); + } + + @Test + public void testValidateInutsEmptySector() { + boolean isValid = false; + try { + isValid = ValidationUtil.validateInuts(EMPTY, CLIENT_ID); + } catch (DicoveryException e) { + } + Assert.assertEquals(isValid, FALSE); + } + + @Test + public void testValidateInutsNullSector() { + boolean isValid = false; + try { + isValid = ValidationUtil.validateInuts(null, CLIENT_ID); + } catch (DicoveryException e) { + } + Assert.assertEquals(isValid, FALSE); + } + + public ValidationUtilTest(String name){ + super(name); + } + + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(ValidationUtilTest.class); + } +} diff --git a/components/url-shorten/pom.xml b/components/url-shorten/pom.xml index 207c15ce..34ddc2e5 100644 --- a/components/url-shorten/pom.xml +++ b/components/url-shorten/pom.xml @@ -11,8 +11,8 @@ com.wso2telco.ids component-ids-parent - 2.2.0-SNAPSHOT - ../../parent/pom.xml + 2.2.0-SNAPSHOT + ../../parent/pom.xml url-shorten diff --git a/features/com.wso2telco.ids.spseamlessprovision.feature/pom.xml b/features/com.wso2telco.ids.spseamlessprovision.feature/pom.xml new file mode 100644 index 00000000..0fc01d9e --- /dev/null +++ b/features/com.wso2telco.ids.spseamlessprovision.feature/pom.xml @@ -0,0 +1,49 @@ + + + + com.wso2telco.ids + component-ids-feature + 2.2.0-SNAPSHOT + ../pom.xml + + 4.0.0 + + com.wso2telco.ids.spseamlessprovision.feature + pom + Seamless SP Provisioning Feature + http://wso2.org + This feature contains the server bundles required for service provider provisioning. + + + + + org.wso2.maven + carbon-p2-plugin + ${carbon.p2.plugin.version} + + + p2-feature-generation + package + + p2-feature-gen + + + com.wso2telco.ids.spseamlessprovision + ../feature.properties + + + org.wso2.carbon.p2.category.type:server + org.eclipse.equinox.p2.type.group:true + + + + com.wso2telco.ids:sp-seamless-provision:${com.wso2telco.ids.version} + + + + + + + + + diff --git a/features/pom.xml b/features/pom.xml index 5f789f87..480971a2 100644 --- a/features/pom.xml +++ b/features/pom.xml @@ -26,6 +26,7 @@ com.wso2telco.ids.sign.ui.feature com.wso2telco.ids.datapublisher.feature com.wso2telco.ids.saaserver.feature + com.wso2telco.ids.spseamlessprovision.feature diff --git a/parent/pom.xml b/parent/pom.xml index 20324fe8..dd75bd80 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -1328,11 +1328,11 @@ org.wso2.carbon.identity.workflow.mgt.stub ${identity.framework.version} - - org.wso2.carbon.identity - org.wso2.carbon.identity.workflow.impl.stub - ${identity.framework.version} - + + + + + org.wso2.carbon.identity org.wso2.carbon.user.mgt.workflow.stub @@ -1666,7 +1666,7 @@ 3.0.0.wso2v1 1.9.6 - 2.0.21 + 2.0.22-SNAPSHOT 4.0 4.3 diff --git a/pom.xml b/pom.xml index 4fbf0cf4..fbc79670 100644 --- a/pom.xml +++ b/pom.xml @@ -6,26 +6,27 @@ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for - the specific language governing permissions and limitations under the License. - folk test M --> - + the specific language governing permissions and limitations under the License. + folk test M --> + 4.0.0 - - - commons-logging - commons-logging - 1.2 - - - + + + commons-logging + commons-logging + 1.2 + + + - org.wso2 - wso2 - 1 - + org.wso2 + wso2 + 1 + com.wso2telco.ids component-ids pom @@ -43,40 +44,41 @@ 3.0.0 - + - - wso2Telco.snapshots - Snapshot repo - http://maven.wso2telco.com/nexus/content/repositories/snapshots - - - - wso2telco.releases - release repo - http://maven.wso2telco.com/nexus/content/repositories/releases/ - - + + wso2Telco.snapshots + Snapshot repo + http://maven.wso2telco.com/nexus/content/repositories/snapshots + + + + wso2telco.releases + release repo + http://maven.wso2telco.com/nexus/content/repositories/releases/ + + + - parent - components/ids-data-publisher + components/sp-seamless-provision + components/ids-data-publisher components/url-shorten components/user-claim-retriever - components/authenticate-selector + components/authenticate-selector components/openid-token-builder - components/gsma-authenticators + components/gsma-authenticators components/auth-proxy-service components/sign components/session-updater components/portal components/dashboard components/authentication-endpoint - components/saa-server + components/saa-server features - components/openid-extension - + components/openid-extension + https://github.com/WSO2Telco/component-ids.git @@ -87,52 +89,52 @@ - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.7 - 1.7 - - - - - org.apache.maven.plugins - maven-release-plugin - - clean install - true - - - - org.apache.maven.scm - maven-scm-provider-gitexe - 1.9 - - - - - org.apache.maven.plugins - maven-deploy-plugin - - - org.apache.maven.plugins - maven-javadoc-plugin - - - docs - compile - - javadoc - - - - - - + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.7 + 1.7 + + + + + org.apache.maven.plugins + maven-release-plugin + + clean install + true + + + + org.apache.maven.scm + maven-scm-provider-gitexe + 1.9 + + + + + org.apache.maven.plugins + maven-deploy-plugin + + + org.apache.maven.plugins + maven-javadoc-plugin + + + docs + compile + + javadoc + + + + + +