Skip to content

Commit

Permalink
IDSDEV-365 Mobile Connect Request Validator Capability in IDGW Relate…
Browse files Browse the repository at this point in the history
…d Development
  • Loading branch information
udithad committed Apr 25, 2017
1 parent 003da12 commit 3404dfa
Show file tree
Hide file tree
Showing 58 changed files with 3,626 additions and 108 deletions.
12 changes: 12 additions & 0 deletions components/auth-proxy-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@
<version>2.2.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.wso2telco.ids</groupId>
<artifactId>sp-seamless-provision</artifactId>
<version>2.2.0-SNAPSHOT</version>

This comment has been minimized.

Copy link
@lahiru823

lahiru823 Apr 30, 2017

Contributor

do we need to mention the artifact version here?

<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.wso2telco.core</groupId>
<artifactId>spprovisionservice</artifactId>
<version>2.0.22-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,62 @@
******************************************************************************/
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;
import com.wso2telco.core.config.model.MobileConnectConfig;
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;
Expand All @@ -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;
Expand Down Expand Up @@ -71,6 +125,7 @@ public class Endpoints {
private static MobileConnectConfig mobileConnectConfigs = null;
private static Map<String, List<MSISDNHeader>> operatorsMSISDNHeadersMap;
private static Map<String, MobileConnectConfig.OPERATOR> operatorPropertiesMap = null;
private static AdminServiceConfig adminServiceConfig = null;

/**
* The Configuration service
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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 &&

This comment has been minimized.

Copy link
@lahiru823

lahiru823 Apr 30, 2017

Contributor

!client_id.isEmpty() && client_id != null should be the other way. (client_id != null && !client_id.isEmpty())
possible null pointer

This comment has been minimized.

Copy link
@udithad

udithad May 2, 2017

Author Collaborator

This should be rectified.

!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
Expand Down
2 changes: 1 addition & 1 deletion components/gsma-authenticators/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
<dependency>
<groupId>com.wso2telco.core</groupId>
<artifactId>sp-config-util</artifactId>
<version>2.0.21</version>
<version>2.0.22-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
6 changes: 3 additions & 3 deletions components/openid-token-builder/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
<version>1.7.2</version>
<version>1.9.0</version>
<executions>
<execution>
<id>generate-scr-scrdescriptor</id>
Expand All @@ -127,7 +127,7 @@
<Bundle-Name>${project.artifactId}</Bundle-Name>
<Bundle-Version>${project.version}</Bundle-Version>
<Bundle-Description>Open ID Token Builder Bundle</Bundle-Description>
<Private-Package>com.wso2telco.internal</Private-Package>
<!-- <Private-Package>com.wso2telco.internal</Private-Package> -->
<Import-Package>
javax.xml.namespace,
javax.xml.stream,
Expand Down Expand Up @@ -193,7 +193,7 @@
<Export-Package>
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.*
</Export-Package>
<Embed-Dependency>
nimbus-jose-jwt|json-smart;scope=compile|runtime;inline=false
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
Expand Down
Loading

0 comments on commit 3404dfa

Please sign in to comment.