-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IDSDEV-678-Add New Publishing Points for Token Failure #256
base: mig-release-2.2.0-integration
Are you sure you want to change the base?
Changes from all commits
3404dfa
bce5805
3a1e0df
18db275
ed9c107
e98d745
a411f81
9465400
271e041
91a8e30
fbbd249
bde3428
49210d2
236fe57
aa4871d
e973522
6da41e8
2b48794
9833050
1ee4444
c1dd271
7bd5469
0fac668
17c4705
8dbe38e
52511f4
a9b3e11
34b2574
ecc013d
906b7e1
c40a4e1
73289ee
b991bda
dcd8943
72e521c
448c23b
3230c0c
a4f3e32
e293348
78fbc52
31ddea6
1810301
7920e79
93f1859
c5296ea
75db0a8
59196b3
bc9d57a
f365d6d
957dc1c
5d9e2b5
de8ada3
5ec36d9
55eecf7
b822f55
b798d63
913f08a
70a6d2a
b36ad46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
import org.apache.commons.logging.Log; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
import org.apache.commons.logging.LogFactory; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
@@ -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 | ||
|
@@ -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); | ||
|
@@ -204,6 +262,13 @@ public void RedirectToAuthorizeEndpoint(@Context HttpServletRequest httpServletR | |
//Validate with Scope wise parameters and throw exceptions | ||
ScopeParam scopeParam = validateAndSetScopeParameters(loginHint, msisdn, scopeName, redirectUrlInfo, | ||
userStatus); | ||
|
||
String apiScopes = null; | ||
if(scopeParam.isConsentPage()==true){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
String[] api_Scopes = scopeName.split("\\s+"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
api_Scopes=Arrays.copyOfRange(api_Scopes, 1, api_Scopes.length); | ||
apiScopes=Arrays.toString(api_Scopes); | ||
} | ||
|
||
String loginhint_msisdn = null; | ||
try { | ||
|
@@ -262,7 +327,9 @@ public void RedirectToAuthorizeEndpoint(@Context HttpServletRequest httpServletR | |
redirectUrlInfo.setQueryString(queryString); | ||
redirectUrlInfo.setIpAddress(ipAddress); | ||
redirectUrlInfo.setTelcoScope(operatorScopeWithClaims); | ||
redirectUrlInfo.setParentScope(scopeParam.getScope()); | ||
redirectUrlInfo.setTransactionId(userStatus.getTransactionId()); | ||
redirectUrlInfo.setApiScopes(apiScopes); | ||
redirectURL = constructRedirectUrl(redirectUrlInfo, userStatus); | ||
|
||
DataPublisherUtil.updateAndPublishUserStatus( | ||
|
@@ -285,6 +352,64 @@ public void RedirectToAuthorizeEndpoint(@Context HttpServletRequest httpServletR | |
httpServletResponse.sendRedirect(redirectURL); | ||
} | ||
|
||
private void serviceProviderSeamlessProvision(String client_id, String redirectURL) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
DiscoveryService discoveryService = new DiscoveryServiceImpl(); | ||
if (mobileConnectConfigs.isSeamlessProvisioningEnabled() && !client_id.isEmpty() && client_id != null && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
!redirectURL.isEmpty() && redirectURL != null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
ServiceProviderDto serviceProviderDto = discoveryService.servceProviderCredentialDiscovery( | ||
TransformUtil.transformDiscoveryConfig(mobileConnectConfigs.getDiscoveryConfig(), | ||
mobileConnectConfigs), | ||
TransformUtil.transofrmDiscoveryDto(client_id, redirectURL,mobileConnectConfigs), | ||
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 | ||
|
@@ -627,16 +752,18 @@ private String constructRedirectUrl(RedirectUrlInfo redirectUrlInfo, UserStatus | |
String loginHintMsisdn = redirectUrlInfo.getLoginhintMsisdn(); | ||
String operatorName = redirectUrlInfo.getOperatorName(); | ||
String telcoScope = redirectUrlInfo.getTelcoScope(); | ||
String parentScope = redirectUrlInfo.getParentScope(); | ||
String ipAddress = redirectUrlInfo.getIpAddress(); | ||
String prompt = redirectUrlInfo.getPrompt(); | ||
String apiScopes = redirectUrlInfo.getApiScopes(); | ||
boolean isShowTnc = redirectUrlInfo.isShowTnc(); | ||
ScopeParam.msisdnMismatchResultTypes headerMismatchResult = redirectUrlInfo.getHeaderMismatchResult(); | ||
ScopeParam.heFailureResults heFailureResult = redirectUrlInfo.getHeFailureResult(); | ||
|
||
String transactionId = redirectUrlInfo.getTransactionId(); | ||
if (authorizeUrl != null) { | ||
redirectURL = authorizeUrl + queryString + "&" + AuthProxyConstants.OPERATOR + "=" + | ||
operatorName + "&" + AuthProxyConstants.TELCO_SCOPE + "=" + telcoScope + "&" + | ||
operatorName + "&" + AuthProxyConstants.TELCO_SCOPE + "=" + telcoScope + "&" + AuthProxyConstants.PARENT_SCOPE + "=" + parentScope + "&" + | ||
AuthProxyConstants.SHOW_TNC + "=" + isShowTnc + "&" + AuthProxyConstants.HEADER_MISMATCH_RESULT + | ||
"=" + headerMismatchResult + "&" + AuthProxyConstants.HE_FAILURE_RESULT + | ||
"=" + heFailureResult; | ||
|
@@ -664,6 +791,12 @@ private String constructRedirectUrl(RedirectUrlInfo redirectUrlInfo, UserStatus | |
redirectURL = redirectURL + "&" + AuthProxyConstants.TELCO_PROMPT + | ||
"=" + prompt; | ||
} | ||
|
||
if(apiScopes != null && !StringUtils.isEmpty(apiScopes)){ | ||
redirectURL = redirectURL + "&" + AuthProxyConstants.API_SCOPES + | ||
"=" + apiScopes; | ||
} | ||
|
||
} else { | ||
String errMsg = "AuthorizeURL could not be found in mobile-connect.xml"; | ||
DataPublisherUtil.updateAndPublishUserStatus(userStatus, DataPublisherUtil.UserState.CONFIGURATION_ERROR, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this unused import 'com.wso2telco.core.spprovisionservice.sp.entity.AdminServiceDto'.