-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #10 feat: Capturing configuration for SMS providers
- Loading branch information
1 parent
d5d3a6e
commit 582d9a6
Showing
15 changed files
with
441 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"token": "AKIAI4XIRSGGFIW5VOKQ", | ||
"secret": "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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"token": "AKIAI4XIRSGGFIW5VOKQ", | ||
"secret": "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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
keycloak/sms-provider/src/main/java/org/sunbird/sms/MessageProviderFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.sunbird.sms; | ||
|
||
import org.sunbird.sms.amazonsns.AmazonSnsFactory; | ||
import org.sunbird.sms.msg91.Msg91SmsProviderFactory; | ||
import org.sunbird.sms.provider.ISmsProvider; | ||
|
||
import java.util.Map; | ||
|
||
public class MessageProviderFactory { | ||
|
||
private static Msg91SmsProviderFactory msg91SmsProviderFactory; | ||
private static AmazonSnsFactory amazonSnsFactory = null; | ||
|
||
|
||
public static ISmsProvider getMsg91SmsProvider(Map<String, String> configurations) { | ||
if (msg91SmsProviderFactory == null) { | ||
msg91SmsProviderFactory = new Msg91SmsProviderFactory(); | ||
} | ||
|
||
return msg91SmsProviderFactory.create(configurations); | ||
} | ||
|
||
|
||
public static ISmsProvider getSnsClient(Map<String, String> configurations) { | ||
if (amazonSnsFactory == null) { | ||
amazonSnsFactory = new AmazonSnsFactory(); | ||
} | ||
return amazonSnsFactory.create(configurations); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
keycloak/sms-provider/src/main/java/org/sunbird/sms/SMSAuthenticatorUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.sunbird.sms; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Created by joris on 18/11/2016. | ||
*/ | ||
public class SMSAuthenticatorUtil { | ||
|
||
public static String getConfigString(Map<String, String> config, String configName) { | ||
return getConfigString(config, configName, null); | ||
} | ||
|
||
public static String getConfigString(Map<String, String> config, String configName, String defaultValue) { | ||
|
||
String value = defaultValue; | ||
|
||
if (config.containsKey(configName)) { | ||
// Get value | ||
value = config.get(configName); | ||
} | ||
|
||
return value; | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
keycloak/sms-provider/src/main/java/org/sunbird/sms/SmsConfigurationType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.sunbird.sms; | ||
|
||
public interface SmsConfigurationType { | ||
String CONF_SMS_TOKEN = "token"; | ||
String CONF_SMS_SECRET = "secret"; | ||
String CONF_SMS_URL = "sms_url"; | ||
String CONF_SMS_METHOD_TYPE = "sms_method_type"; | ||
String CONF_SMS_USERNAME = "sms_username"; | ||
String CONF_SMS_PASSWORD = "sms_password"; | ||
String CONF_SMS_AUTHTYPE = "sms_authtype"; | ||
String CONF_SMS_CONTENT_TYPE = "sms_content_type"; | ||
String CONF_SMS_PROXY_URL = "sms_proxy_url"; | ||
String CONF_SMS_PROXY_USERNAME = "sms_proxy_username"; | ||
String CONF_SMS_PROXY_PASSWORD = "sms_proxy_password"; | ||
String CONF_AUTH_METHOD_BASIC = "basic_authentication"; | ||
String CONF_AUTH_METHOD_INMESSAGE = "in_message_authentication"; | ||
} |
20 changes: 20 additions & 0 deletions
20
keycloak/sms-provider/src/main/java/org/sunbird/sms/amazonsns/AmazonSnsFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.sunbird.sms.amazonsns; | ||
|
||
import org.sunbird.sms.provider.ISmsProvider; | ||
import org.sunbird.sms.provider.ISmsProviderFactory; | ||
|
||
import java.util.Map; | ||
|
||
public class AmazonSnsFactory implements ISmsProviderFactory { | ||
private static AmazonSnsProvider amazonSnsProvider = null; | ||
|
||
@Override | ||
public ISmsProvider create(Map<String, String> configurations) { | ||
if (amazonSnsProvider == null) { | ||
amazonSnsProvider = new AmazonSnsProvider(); | ||
amazonSnsProvider.configure(configurations); | ||
} | ||
|
||
return amazonSnsProvider; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
keycloak/sms-provider/src/main/java/org/sunbird/sms/amazonsns/AmazonSnsProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.sunbird.sms.amazonsns; | ||
|
||
import com.amazonaws.services.sns.model.MessageAttributeValue; | ||
import com.amazonaws.services.sns.model.PublishRequest; | ||
import org.jboss.logging.Logger; | ||
import org.sunbird.aws.snsclient.SnsClientFactory; | ||
import org.sunbird.sms.SMSAuthenticatorUtil; | ||
import org.sunbird.sms.SmsConfigurationType; | ||
import org.sunbird.sms.provider.ISmsProvider; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class AmazonSnsProvider implements ISmsProvider { | ||
|
||
private static Logger logger = Logger.getLogger(AmazonSnsProvider.class); | ||
|
||
private Map<String, String> configurations; | ||
|
||
@Override | ||
public boolean send(String phoneNumber, String smsText) { | ||
logger.debug("AmazonSnsProvider@send : phoneNumber - " + phoneNumber + " & Sms text - " + smsText); | ||
|
||
Map<String, MessageAttributeValue> smsAttributes = new HashMap<String, MessageAttributeValue>(); | ||
smsAttributes.put("AWS.SNS.SMS.SenderID", new MessageAttributeValue() | ||
.withStringValue("HomeOffice") | ||
.withDataType("String")); | ||
|
||
String clientToken = SMSAuthenticatorUtil.getConfigString(configurations, SmsConfigurationType.CONF_SMS_TOKEN); | ||
String clientSecret = SMSAuthenticatorUtil.getConfigString(configurations, SmsConfigurationType.CONF_SMS_SECRET); | ||
|
||
logger.debug("AmazonSnsProvider@send : clientToken - " + clientToken + " & clientSecret - " + clientSecret); | ||
|
||
|
||
try { | ||
SnsClientFactory.getSnsClient(clientToken, clientSecret).publish(new PublishRequest() | ||
.withMessage(smsText) | ||
.withPhoneNumber(phoneNumber) | ||
.withMessageAttributes(smsAttributes)); | ||
|
||
return true; | ||
} catch (Exception e) { | ||
logger.debug("AmazonSnsProvider@Send : Exception Caught -" + e.getMessage()); | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public void configure(Map<String, String> configurations) { | ||
this.configurations = configurations; | ||
} | ||
} |
Oops, something went wrong.