From 20cfe97bb2792675305c9ba4f43d32036f6b9467 Mon Sep 17 00:00:00 2001 From: Isuru Dilshan Date: Thu, 8 Jun 2017 14:58:22 +0530 Subject: [PATCH 1/2] Changed IPs --- .../mepin/MePinAuthenticator.java | 76 ++++++++++++++++++- .../main/java/com/wso2telco/Endpoints.java | 10 +-- 2 files changed, 78 insertions(+), 8 deletions(-) diff --git a/components/gsma-authenticators/src/main/java/com/wso2telco/gsma/authenticators/mepin/MePinAuthenticator.java b/components/gsma-authenticators/src/main/java/com/wso2telco/gsma/authenticators/mepin/MePinAuthenticator.java index dfebb0b3..c8acf65c 100644 --- a/components/gsma-authenticators/src/main/java/com/wso2telco/gsma/authenticators/mepin/MePinAuthenticator.java +++ b/components/gsma-authenticators/src/main/java/com/wso2telco/gsma/authenticators/mepin/MePinAuthenticator.java @@ -56,6 +56,7 @@ import org.apache.http.message.BasicNameValuePair; import org.apache.http.util.EntityUtils; import org.hashids.Hashids; +import org.json.JSONObject; import org.wso2.carbon.identity.application.authentication.framework.AbstractApplicationAuthenticator; import org.wso2.carbon.identity.application.authentication.framework.AuthenticatorFlowStatus; import org.wso2.carbon.identity.application.authentication.framework.LocalApplicationAuthenticator; @@ -166,15 +167,15 @@ protected void initiateAuthenticationRequest(HttpServletRequest request, mePinTransactionRequest.setAppId("5497e675-ecb8-45e2-83c7-a9b12d3f290e"); mePinTransactionRequest.setIdentifier(idetifier); mePinTransactionRequest - .setCallbackUrl("http://52.53.173.127:9763/sessionupdater/tnspoints/endpoint/mepin/response"); + .setCallbackUrl("http://13.56.46.192:9763/sessionupdater/tnspoints/endpoint/mepin/response"); mePinTransactionRequest.setIdentifier(mePinId); mePinTransactionRequest.setShortMessage("Pending authentication request"); mePinTransactionRequest.setHeader("Welcome to MobileConnect"); mePinTransactionRequest.setExpiryTimeInSeconds(60); - mePinTransactionRequest.setLogoUrl(""); + mePinTransactionRequest.setLogoUrl("http://res.cloudinary.com/dyftvc4kh/image/upload/v1496904154/spark_dwcush.png"); mePinTransactionRequest.setSpName(""); - mePinTransactionRequest.setBgImageName(""); + mePinTransactionRequest.setBgImageName("http://res.cloudinary.com/dyftvc4kh/image/upload/v1496904227/spark_bg2_ij3wid.jpg"); if (acr == 2) { mePinTransactionRequest.setMessage("Please swipe to authenticate"); @@ -446,4 +447,73 @@ private enum UserResponse { APPROVED, REJECTED } + +// public String getOperatorSpecificImageURL(String msisdn) { +// +// String imageURL = null; +// MobileConnectConfig availableConfigs = configurationService.getDataHolder().getMobileConnectConfig(); +// String discoveryUrl = availableConfigs.getDiscoveryURL(); +// String discoveryAuthCode = availableConfigs.getDiscoveryAuthCode(); +// MobileConnectConfig.MePinConfig mePinConfig = availableConfigs.getMePinConfig(); +// if (mePinConfig == null) { +// log.error("MePin related Configurations are not properly set "); +// return imageURL; +// } +// +// Boolean isHubSet = mePinConfig.getIsHub(); +// +// try { +// +// if (!isHubSet) +// imageURL = mePinConfig.getDefaultImageUrl(); +// else +// imageURL = getOperatorSpecificImage(getDiscoveredOperator(msisdn, discoveryUrl, discoveryAuthCode)); +// log.info("imageURL : " + imageURL); +// } catch (Exception e) { +// log.error("Error occurred while discovering operator for msisdn: " + msisdn +// + "via configured discoveryUrl: " + discoveryUrl + "and discoveryAuthCode:" + discoveryAuthCode, e); +// } +// +// return imageURL; +// +// } +// +// private String getDiscoveredOperator(String msisdn, String discoveryURL, String discoveryAuthCode) throws Exception { +// +// String operator = null; +// HttpClient client = new DefaultHttpClient(); +// HttpPost postRequest = new HttpPost(discoveryURL); +// postRequest.addHeader("Authorization", "Basic " + discoveryAuthCode); +// postRequest.addHeader("Cache-Control", "no-cache"); +// postRequest.addHeader("Content-Type", "application/x-www-form-urlencoded"); +// List urlParameters = new ArrayList(); +// urlParameters.add(new BasicNameValuePair("MSISDN", msisdn)); +// UrlEncodedFormEntity requestContent = new UrlEncodedFormEntity(urlParameters); +// +// postRequest.setEntity(requestContent); +// HttpResponse httpResponse = client.execute(postRequest); +// +// if ((httpResponse.getStatusLine().getStatusCode() == 200)) { +// JSONObject responseFullPayload = new JSONObject(EntityUtils.toString(httpResponse.getEntity())); +// JSONObject response = (JSONObject) responseFullPayload.get("response"); +// operator = response.get("serving_operator").toString(); +// } +// +// return operator; +// } +// +// private String getOperatorSpecificImage(String discoveredOperator) { +// +// MobileConnectConfig.MePinConfig mePinConfig = configurationService.getDataHolder().getMobileConnectConfig() +// .getMePinConfig(); +// +// MobileConnectConfig.OperatorDescription[] configOperators = mePinConfig.getOperatorsList() +// .getOperatorDescription(); +// for (int i = 0; i < configOperators.length; i++) { +// if (configOperators[i].getName().equalsIgnoreCase(discoveredOperator)) { +// return configOperators[i].getImageUrl(); +// } +// } +// return null; +// } } \ No newline at end of file diff --git a/components/session-updater/src/main/java/com/wso2telco/Endpoints.java b/components/session-updater/src/main/java/com/wso2telco/Endpoints.java index a0e0a906..02fa2b6f 100644 --- a/components/session-updater/src/main/java/com/wso2telco/Endpoints.java +++ b/components/session-updater/src/main/java/com/wso2telco/Endpoints.java @@ -1388,17 +1388,17 @@ public void verify(String host, SSLSocket ssl) throws IOException { mePinInteractionCreateRequest.setPublicKeyHash(publicKeyHash); mePinInteractionCreateRequest.setShortMessage("Enrollment Completed"); mePinInteractionCreateRequest.setExpiryTimeInSeconds(60); - mePinInteractionCreateRequest.setInteractionUrl("http://52.53.173.127:9763/authenticationendpoint/mcx-user-registration/auth_registration_mepin_complete"); + mePinInteractionCreateRequest.setInteractionUrl("http://13.56.46.192:9763/authenticationendpoint/mcx-user-registration/auth_registration_mepin_complete"); mePinInteractionCreateRequest.setResourceUrl("mepin://authenticator/set_enrollment_status"); mePinInteractionCreateRequest.setDisablePush(true); MePinInteractionRequestResourceParams mePinInteractionRequestResourceParams = new MePinInteractionRequestResourceParams(); mePinInteractionRequestResourceParams.setEnrollmentStatus("ok"); - mePinInteractionRequestResourceParams.setHelpUrl("http://52.53.173.127:9763/authenticationendpoint/mcx-user-registration/auth_registration_mepin_complete"); - mePinInteractionRequestResourceParams.setPrivacyPolicyUrl("http://52.53.173.127:9763/authenticationendpoint/mcx-user-registration/auth_registration_mepin_complete"); - mePinInteractionRequestResourceParams.setServicesUrl("http://52.53.173.127:9763/authenticationendpoint/mcx-user-registration/auth_registration_mepin_complete"); - //mePinInteractionRequestResourceParams.setTermsOfServiceUrl("http://52.53.173.127:9763/authenticationendpoint/mcx-user-registration/auth_registration_mepin_complete"); + mePinInteractionRequestResourceParams.setHelpUrl("http://13.56.46.192:9763/authenticationendpoint/mcx-user-registration/auth_registration_mepin_complete"); + mePinInteractionRequestResourceParams.setPrivacyPolicyUrl("http://13.56.46.192:9763/authenticationendpoint/mcx-user-registration/auth_registration_mepin_complete"); + mePinInteractionRequestResourceParams.setServicesUrl("http://13.56.46.192:9763/authenticationendpoint/mcx-user-registration/auth_registration_mepin_complete"); + //mePinInteractionRequestResourceParams.setTermsOfServiceUrl("http://13.56.46.192:9763/authenticationendpoint/mcx-user-registration/auth_registration_mepin_complete"); mePinInteractionRequestResourceParams.setTermsOfServiceUrl(getOperatorSpecificImageURL(msisdn)); String operator = getMePinOperator(msisdn); From 46237bdfa405a6714ccf4097cc23ad2e76b30f72 Mon Sep 17 00:00:00 2001 From: Isuru Dilshan Date: Mon, 19 Jun 2017 15:16:17 +0530 Subject: [PATCH 2/2] Changed me pin confirmation policy --- .../mepin/MePinAuthenticator.java | 187 ++++++++++-------- .../model/MePinImageDetails.java | 27 +++ 2 files changed, 129 insertions(+), 85 deletions(-) create mode 100644 components/gsma-authenticators/src/main/java/com/wso2telco/gsma/authenticators/model/MePinImageDetails.java diff --git a/components/gsma-authenticators/src/main/java/com/wso2telco/gsma/authenticators/mepin/MePinAuthenticator.java b/components/gsma-authenticators/src/main/java/com/wso2telco/gsma/authenticators/mepin/MePinAuthenticator.java index c8acf65c..f1499e6b 100644 --- a/components/gsma-authenticators/src/main/java/com/wso2telco/gsma/authenticators/mepin/MePinAuthenticator.java +++ b/components/gsma-authenticators/src/main/java/com/wso2telco/gsma/authenticators/mepin/MePinAuthenticator.java @@ -28,6 +28,7 @@ import com.wso2telco.gsma.authenticators.DBUtils; import com.wso2telco.gsma.authenticators.exception.MePinException; import com.wso2telco.gsma.authenticators.exception.SaaException; +import com.wso2telco.gsma.authenticators.model.MePinImageDetails; import com.wso2telco.gsma.authenticators.model.MePinTransactionRequest; import com.wso2telco.gsma.authenticators.model.MePinTransactionResponse; import com.wso2telco.gsma.authenticators.saa.IsRegisteredResponse; @@ -81,15 +82,14 @@ public class MePinAuthenticator extends AbstractApplicationAuthenticator implements LocalApplicationAuthenticator { - private static Log log = LogFactory.getLog(MePinAuthenticator.class); - private static final String IS_FLOW_COMPLETED = "isFlowCompleted"; private static final String PIN_CLAIM = "http://wso2.org/claims/pin"; private static final String MSISDN = "msisdn"; private static final String CLIENT_ID = "relyingParty"; private static final String ACR = "acr_values"; - private SpConfigService spConfigService = new SpConfigServiceImpl(); + private static Log log = LogFactory.getLog(MePinAuthenticator.class); private static ConfigurationService configurationService = new ConfigurationServiceImpl(); + private SpConfigService spConfigService = new SpConfigServiceImpl(); @Override public boolean canHandle(HttpServletRequest request) { @@ -158,31 +158,30 @@ protected void initiateAuthenticationRequest(HttpServletRequest request, throw new MePinException("No me pin registration found"); } + MePinImageDetails operatorSpecificImageDetails = getOperatorSpecificImageDetails(msisdn); Hashids hashids = new Hashids(UUID.randomUUID().toString(), 31); String idetifier = hashids.encode(new java.util.Date().getTime()); mePinTransactionRequest.setMePinId(mePinId); mePinTransactionRequest.setAction("transactions/create"); -// mePinTransactionRequest.setAppId("bcb54836a5a71b698844e8c1923f8a42"); mePinTransactionRequest.setAppId("5497e675-ecb8-45e2-83c7-a9b12d3f290e"); mePinTransactionRequest.setIdentifier(idetifier); - mePinTransactionRequest - .setCallbackUrl("http://13.56.46.192:9763/sessionupdater/tnspoints/endpoint/mepin/response"); + mePinTransactionRequest.setCallbackUrl(mePinConfig.getCallbackUrl()); mePinTransactionRequest.setIdentifier(mePinId); mePinTransactionRequest.setShortMessage("Pending authentication request"); mePinTransactionRequest.setHeader("Welcome to MobileConnect"); mePinTransactionRequest.setExpiryTimeInSeconds(60); - mePinTransactionRequest.setLogoUrl("http://res.cloudinary.com/dyftvc4kh/image/upload/v1496904154/spark_dwcush.png"); + mePinTransactionRequest.setLogoUrl(operatorSpecificImageDetails.getLogoUrl()); mePinTransactionRequest.setSpName(""); - mePinTransactionRequest.setBgImageName("http://res.cloudinary.com/dyftvc4kh/image/upload/v1496904227/spark_bg2_ij3wid.jpg"); + mePinTransactionRequest.setBgImageName(operatorSpecificImageDetails.getBackgroundUrl()); if (acr == 2) { - mePinTransactionRequest.setMessage("Please swipe to authenticate"); - mePinTransactionRequest.setConfirmationPolicy("mepin_swipe"); + mePinTransactionRequest.setMessage(mePinConfig.getBasicConfirmationPolicyMessage()); + mePinTransactionRequest.setConfirmationPolicy(mePinConfig.getBasicConfirmationPolicies()); } else if (acr == 3) { - mePinTransactionRequest.setMessage("Please provide fingerprint to authenticate"); - mePinTransactionRequest.setConfirmationPolicy("mepin_fp"); + mePinTransactionRequest.setMessage(mePinConfig.getAdvancedConfirmationPolicyMessage()); + mePinTransactionRequest.setConfirmationPolicy(mePinConfig.getAdvancedConfirmationPolicies()); } String authHeader = username + ":" + password; @@ -300,7 +299,7 @@ private void handleRedirect(HttpServletResponse response, AuthenticationContext } } - private String getMePinOperator(String msisdn){ + private String getMePinOperator(String msisdn) { MobileConnectConfig.MePinConfig mePinConfig = configurationService.getDataHolder().getMobileConnectConfig() .getMePinConfig(); @@ -387,10 +386,10 @@ protected void processAuthenticationResponse(HttpServletRequest request, AuthenticationContextHelper.setSubject(context, (String) context.getProperty(Constants.MSISDN)); - if("true".equals(request.getParameter(Constants.IS_TERMINATED))){ + if ("true".equals(request.getParameter(Constants.IS_TERMINATED))) { context.setProperty(Constants.IS_TERMINATED, true); throw new AuthenticationFailedException("Authenticator is terminated"); - }else { + } else { context.setProperty(IS_FLOW_COMPLETED, true); context.setProperty(Constants.TERMINATE_BY_REMOVE_FOLLOWING_STEPS, "true"); } @@ -403,7 +402,7 @@ protected void processAuthenticationResponse(HttpServletRequest request, log.info("Msisdn : " + msisdn + " operator : " + operator + " acr : " + acr); - if(isRegistering){ + if (isRegistering) { UserProfileManager userProfileManager = new UserProfileManager(); try { @@ -441,79 +440,97 @@ public String getName() { return Constants.ME_PIN_AUTHENTICATOR_NAME; } + public MePinImageDetails getOperatorSpecificImageDetails(String msisdn) { + + String imageURL = null; + MePinImageDetails mePinImageDetails; + MobileConnectConfig availableConfigs = configurationService.getDataHolder().getMobileConnectConfig(); + String discoveryUrl = availableConfigs.getDiscoveryURL(); + String discoveryAuthCode = availableConfigs.getDiscoveryAuthCode(); + MobileConnectConfig.MePinConfig mePinConfig = availableConfigs.getMePinConfig(); + + Boolean isHubSet = mePinConfig.getIsHub(); + + try { + + if (!isHubSet) { + mePinImageDetails = getDefaultMePinImageDetails(mePinConfig); + } + else { + mePinImageDetails = getOperatorSpecificImage(getDiscoveredOperator(msisdn, discoveryUrl, discoveryAuthCode)); + } + log.info("imageURL : " + imageURL); + } catch (Exception e) { + log.error("Error occurred while discovering operator for msisdn: " + msisdn + + "via configured discoveryUrl: " + discoveryUrl + "and discoveryAuthCode:" + discoveryAuthCode + +" Proceeding with default image urls", + e); + mePinImageDetails = getDefaultMePinImageDetails(mePinConfig); + } + + return mePinImageDetails; + + } + + private String getDiscoveredOperator(String msisdn, String discoveryURL, String discoveryAuthCode) throws Exception { + + String operator = null; + HttpClient client = new DefaultHttpClient(); + HttpPost postRequest = new HttpPost(discoveryURL); + postRequest.addHeader("Authorization", "Basic " + discoveryAuthCode); + postRequest.addHeader("Cache-Control", "no-cache"); + postRequest.addHeader("Content-Type", "application/x-www-form-urlencoded"); + List urlParameters = new ArrayList(); + urlParameters.add(new BasicNameValuePair("MSISDN", msisdn)); + UrlEncodedFormEntity requestContent = new UrlEncodedFormEntity(urlParameters); + + postRequest.setEntity(requestContent); + HttpResponse httpResponse = client.execute(postRequest); + + if ((httpResponse.getStatusLine().getStatusCode() == 200)) { + JSONObject responseFullPayload = new JSONObject(EntityUtils.toString(httpResponse.getEntity())); + JSONObject response = (JSONObject) responseFullPayload.get("response"); + operator = response.get("serving_operator").toString(); + } + + return operator; + } + + private MePinImageDetails getOperatorSpecificImage(String discoveredOperator) { + + MePinImageDetails mePinImageDetails = null; + + MobileConnectConfig.MePinConfig mePinConfig = configurationService.getDataHolder().getMobileConnectConfig() + .getMePinConfig(); + + MobileConnectConfig.OperatorDescription[] configOperators = mePinConfig.getOperatorsList() + .getOperatorDescription(); + for (int i = 0; i < configOperators.length; i++) { + if (configOperators[i].getName().equalsIgnoreCase(discoveredOperator)) { + mePinImageDetails = new MePinImageDetails(); + mePinImageDetails.setLogoUrl(configOperators[i].getImageUrl()); + mePinImageDetails.setBackgroundUrl(configOperators[i].getBackgroundUrl()); + } + } + if (mePinImageDetails == null) { + mePinImageDetails = getDefaultMePinImageDetails(mePinConfig); + } + + return mePinImageDetails; + } + + private MePinImageDetails getDefaultMePinImageDetails(MobileConnectConfig.MePinConfig mePinConfig) { + MePinImageDetails mePinImageDetails; + mePinImageDetails = new MePinImageDetails(); + mePinImageDetails.setBackgroundUrl(mePinConfig.getDefaultBackgroundUrl()); + mePinImageDetails.setLogoUrl(mePinConfig.getDefaultImageUrl()); + return mePinImageDetails; + } + private enum UserResponse { PENDING, APPROVED, REJECTED } - -// public String getOperatorSpecificImageURL(String msisdn) { -// -// String imageURL = null; -// MobileConnectConfig availableConfigs = configurationService.getDataHolder().getMobileConnectConfig(); -// String discoveryUrl = availableConfigs.getDiscoveryURL(); -// String discoveryAuthCode = availableConfigs.getDiscoveryAuthCode(); -// MobileConnectConfig.MePinConfig mePinConfig = availableConfigs.getMePinConfig(); -// if (mePinConfig == null) { -// log.error("MePin related Configurations are not properly set "); -// return imageURL; -// } -// -// Boolean isHubSet = mePinConfig.getIsHub(); -// -// try { -// -// if (!isHubSet) -// imageURL = mePinConfig.getDefaultImageUrl(); -// else -// imageURL = getOperatorSpecificImage(getDiscoveredOperator(msisdn, discoveryUrl, discoveryAuthCode)); -// log.info("imageURL : " + imageURL); -// } catch (Exception e) { -// log.error("Error occurred while discovering operator for msisdn: " + msisdn -// + "via configured discoveryUrl: " + discoveryUrl + "and discoveryAuthCode:" + discoveryAuthCode, e); -// } -// -// return imageURL; -// -// } -// -// private String getDiscoveredOperator(String msisdn, String discoveryURL, String discoveryAuthCode) throws Exception { -// -// String operator = null; -// HttpClient client = new DefaultHttpClient(); -// HttpPost postRequest = new HttpPost(discoveryURL); -// postRequest.addHeader("Authorization", "Basic " + discoveryAuthCode); -// postRequest.addHeader("Cache-Control", "no-cache"); -// postRequest.addHeader("Content-Type", "application/x-www-form-urlencoded"); -// List urlParameters = new ArrayList(); -// urlParameters.add(new BasicNameValuePair("MSISDN", msisdn)); -// UrlEncodedFormEntity requestContent = new UrlEncodedFormEntity(urlParameters); -// -// postRequest.setEntity(requestContent); -// HttpResponse httpResponse = client.execute(postRequest); -// -// if ((httpResponse.getStatusLine().getStatusCode() == 200)) { -// JSONObject responseFullPayload = new JSONObject(EntityUtils.toString(httpResponse.getEntity())); -// JSONObject response = (JSONObject) responseFullPayload.get("response"); -// operator = response.get("serving_operator").toString(); -// } -// -// return operator; -// } -// -// private String getOperatorSpecificImage(String discoveredOperator) { -// -// MobileConnectConfig.MePinConfig mePinConfig = configurationService.getDataHolder().getMobileConnectConfig() -// .getMePinConfig(); -// -// MobileConnectConfig.OperatorDescription[] configOperators = mePinConfig.getOperatorsList() -// .getOperatorDescription(); -// for (int i = 0; i < configOperators.length; i++) { -// if (configOperators[i].getName().equalsIgnoreCase(discoveredOperator)) { -// return configOperators[i].getImageUrl(); -// } -// } -// return null; -// } } \ No newline at end of file diff --git a/components/gsma-authenticators/src/main/java/com/wso2telco/gsma/authenticators/model/MePinImageDetails.java b/components/gsma-authenticators/src/main/java/com/wso2telco/gsma/authenticators/model/MePinImageDetails.java new file mode 100644 index 00000000..625d7004 --- /dev/null +++ b/components/gsma-authenticators/src/main/java/com/wso2telco/gsma/authenticators/model/MePinImageDetails.java @@ -0,0 +1,27 @@ +package com.wso2telco.gsma.authenticators.model; + +/** + * Created by isuru on 6/19/17. + */ +public class MePinImageDetails { + + private String logoUrl; + + private String backgroundUrl; + + public String getLogoUrl() { + return logoUrl; + } + + public void setLogoUrl(String logoUrl) { + this.logoUrl = logoUrl; + } + + public String getBackgroundUrl() { + return backgroundUrl; + } + + public void setBackgroundUrl(String backgroundUrl) { + this.backgroundUrl = backgroundUrl; + } +}