-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from project-sunbird/sms_provider_configuraton
Sms provider configuraton
- Loading branch information
Showing
16 changed files
with
744 additions
and
13 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,156 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.sunbird</groupId> | ||
<artifactId>keycloak-email-phone-autthenticator</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>3.0.0</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<artifactSet> | ||
<excludes> | ||
<exclude>classworlds:classworlds</exclude> | ||
<exclude>junit:junit</exclude> | ||
<exclude>jmock:*</exclude> | ||
<exclude>*:xml-apis</exclude> | ||
<exclude>org.apache.maven:lib:tests</exclude> | ||
</excludes> | ||
</artifactSet> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.keycloak</groupId> | ||
<artifactId>keycloak-core</artifactId> | ||
<version>3.2.0.Final</version> | ||
<scope>provided</scope> | ||
<exclusions> | ||
<exclusion> | ||
<artifactId>keycloak-common</artifactId> | ||
<groupId>org.keycloak</groupId> | ||
</exclusion> | ||
<exclusion> | ||
<artifactId>bcprov-jdk15on</artifactId> | ||
<groupId>org.bouncycastle</groupId> | ||
</exclusion> | ||
<exclusion> | ||
<artifactId>bcpkix-jdk15on</artifactId> | ||
<groupId>org.bouncycastle</groupId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.keycloak</groupId> | ||
<artifactId>keycloak-server-spi</artifactId> | ||
<version>3.2.0.Final</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.keycloak</groupId> | ||
<artifactId>keycloak-server-spi-private</artifactId> | ||
<version>3.2.0.Final</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.logging</groupId> | ||
<artifactId>jboss-logging</artifactId> | ||
<version>3.3.1.Final</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.keycloak</groupId> | ||
<artifactId>keycloak-services</artifactId> | ||
<version>3.2.0.Final</version> | ||
<scope>provided</scope> | ||
<exclusions> | ||
<exclusion> | ||
<artifactId>javax.mail-api</artifactId> | ||
<groupId>javax.mail</groupId> | ||
</exclusion> | ||
<exclusion> | ||
<artifactId>jboss-servlet-api_3.0_spec</artifactId> | ||
<groupId>org.jboss.spec.javax.servlet</groupId> | ||
</exclusion> | ||
<exclusion> | ||
<artifactId>twitter4j-core</artifactId> | ||
<groupId>org.twitter4j</groupId> | ||
</exclusion> | ||
<exclusion> | ||
<artifactId>resteasy-jaxrs</artifactId> | ||
<groupId>org.jboss.resteasy</groupId> | ||
</exclusion> | ||
<exclusion> | ||
<artifactId>jboss-jaxrs-api_2.0_spec</artifactId> | ||
<groupId>org.jboss.spec.javax.ws.rs</groupId> | ||
</exclusion> | ||
<exclusion> | ||
<artifactId>jboss-transaction-api_1.2_spec</artifactId> | ||
<groupId>org.jboss.spec.javax.transaction</groupId> | ||
</exclusion> | ||
<exclusion> | ||
<artifactId>resteasy-multipart-provider</artifactId> | ||
<groupId>org.jboss.resteasy</groupId> | ||
</exclusion> | ||
<exclusion> | ||
<artifactId>javase</artifactId> | ||
<groupId>com.google.zxing</groupId> | ||
</exclusion> | ||
<exclusion> | ||
<artifactId>bcprov-jdk15on</artifactId> | ||
<groupId>org.bouncycastle</groupId> | ||
</exclusion> | ||
<exclusion> | ||
<artifactId>bcpkix-jdk15on</artifactId> | ||
<groupId>org.bouncycastle</groupId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpclient</artifactId> | ||
<version>4.5</version> | ||
<scope>provided</scope> | ||
<exclusions> | ||
<exclusion> | ||
<artifactId>httpcore</artifactId> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
</exclusion> | ||
<exclusion> | ||
<artifactId>commons-codec</artifactId> | ||
<groupId>commons-codec</groupId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<artifactId>hamcrest-core</artifactId> | ||
<groupId>org.hamcrest</groupId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
</dependencies> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
</project> | ||
|
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
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
23 changes: 23 additions & 0 deletions
23
keycloak/sms-provider/src/main/java/org/sunbird/sms/SMSConfigurationUtil.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,23 @@ | ||
package org.sunbird.sms; | ||
|
||
import java.util.Map; | ||
|
||
public class SMSConfigurationUtil { | ||
|
||
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; | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
keycloak/sms-provider/src/main/java/org/sunbird/sms/SmsConfigurationConstants.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,23 @@ | ||
package org.sunbird.sms; | ||
|
||
public final class SmsConfigurationConstants { | ||
public static final String CONF_SMS_TOKEN = "token"; | ||
public static final String CONF_SMS_SECRET = "secret"; | ||
public static final String CONF_SMS_BASE_URL = "sms_base_url"; | ||
public static final String CONF_SMS_GET_URL = "sms_get_url"; | ||
public static final String CONF_SMS_POST_URL = "sms_post_url"; | ||
public static final String CONF_SMS_METHOD_TYPE = "sms_method_type"; | ||
public static final String CONF_SMS_USERNAME = "sms_username"; | ||
public static final String CONF_SMS_PASSWORD = "sms_password"; | ||
public static final String CONF_SMS_AUTHTYPE = "sms_authtype"; | ||
public static final String CONF_SMS_CONTENT_TYPE = "sms_content_type"; | ||
public static final String CONF_SMS_PROXY_URL = "sms_proxy_url"; | ||
public static final String CONF_SMS_PROXY_USERNAME = "sms_proxy_username"; | ||
public static final String CONF_SMS_PROXY_PASSWORD = "sms_proxy_password"; | ||
public static final String CONF_AUTH_METHOD_BASIC = "basic_authentication"; | ||
public static final String CONF_AUTH_METHOD_INMESSAGE = "in_message_authentication"; | ||
public static final String CONF_AUTH_KEY = "auth_key"; | ||
public static final String CONF_SMS_SENDER = "sender"; | ||
public static final String CONF_SMS_COUNTRY = "country"; | ||
public static final String CONF_SMS_ROUTE = "route"; | ||
} |
21 changes: 21 additions & 0 deletions
21
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,21 @@ | ||
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.SMSConfigurationUtil; | ||
import org.sunbird.sms.SmsConfigurationConstants; | ||
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 = SMSConfigurationUtil.getConfigString(configurations, SmsConfigurationConstants.CONF_SMS_TOKEN); | ||
String clientSecret = SMSConfigurationUtil.getConfigString(configurations, SmsConfigurationConstants.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.