Skip to content

Commit

Permalink
Merge branch 'release/v0.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
michallis committed Mar 1, 2018
2 parents 5cac983 + ae72a90 commit d08aa03
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 73 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ To install the OCRA Authenticator one has to:
algorithm: "<ocra_algo>",
}
}`
The config will be applicable to all realms using OCRA execution in a flow.

* Add the jar to the Keycloak server:
* `$ cp target/keycloak-ocra-authenticator-*.jar _KEYCLOAK_HOME_/providers/`
Expand Down Expand Up @@ -45,9 +46,9 @@ Under Authentication > Required Actions:
* Make sure that for the 'Mobile Number' both the 'Enabled' and 'Default Action' check boxes are checked.

# Additional tips
Run a docker jboss/keycloak:
Run a docker jboss/keycloak (-p hostport:containerport):

`docker run --name keycloak -p 8080:8080 -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=test -e KEYCLOAK_LOGLEVEL=DEBUG jboss/keycloak`
`docker run --name keycloak -p 9000:8080 -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin -e KEYCLOAK_LOGLEVEL=DEBUG jboss/keycloak:3.4.3.Final`

The jboss/keycloak is a centos:7, if you want to login as root using docker (use user ID=0) and attach your terminal (in order to deploy the ear)

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.t1t.keycloak</groupId>
<artifactId>ocra-auth</artifactId>
<version>0.1.0-SNAPSHOT</version>
<version>0.1.0</version>
<packaging>jar</packaging>

<organization>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @Since 2017
*/
public class KeycloakOcraMobileNumberRequiredAction implements RequiredActionProvider {
private static Logger logger = Logger.getLogger(KeycloakOcraMobileNumberRequiredAction.class);
private static Logger logger = Logger.getLogger(RequiredActionProvider.class);
public static final String PROVIDER_ID = "sms_auth_check_mobile";

public void evaluateTriggers(RequiredActionContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @Since 2017
*/
public class KeycloakOcraMobileNumberRequiredActionFactory implements RequiredActionFactory {
private static Logger logger = Logger.getLogger(KeycloakOcraMobileNumberRequiredActionFactory.class);
private static Logger logger = Logger.getLogger(RequiredActionFactory.class);
private static final KeycloakOcraMobileNumberRequiredAction SINGLETON = new KeycloakOcraMobileNumberRequiredAction();

public RequiredActionProvider create(KeycloakSession session) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class KeycloakOcraAuthenticatorFactory implements AuthenticatorFactory, C

public static final String PROVIDER_ID = "ocra-authentication";

private static Logger logger = Logger.getLogger(KeycloakOcraAuthenticatorFactory.class);
private static Logger logger = Logger.getLogger(AuthenticatorFactory.class);
private static KeycloakOcraAuthenticator SINGLETON;


Expand All @@ -38,28 +38,6 @@ public class KeycloakOcraAuthenticatorFactory implements AuthenticatorFactory, C
static {
ProviderConfigProperty property;

// API URLs
property = new ProviderConfigProperty();
property.setName(KeycloakOcraAuthenticatorConstants.CONF_PRP_URL_OCRA_API);
property.setLabel("OCRA API URL");
property.setType(ProviderConfigProperty.STRING_TYPE);
property.setHelpText("The full URL and context path for the OCRA API.");
configProperties.add(property);

property = new ProviderConfigProperty();
property.setName(KeycloakOcraAuthenticatorConstants.CONF_PRP_URL_SMS_API);
property.setLabel("SMS API URL");
property.setType(ProviderConfigProperty.STRING_TYPE);
property.setHelpText("The full URL and context path for the SMS API.");
configProperties.add(property);

property = new ProviderConfigProperty();
property.setName(KeycloakOcraAuthenticatorConstants.CONF_PRP_API_KEY);
property.setLabel("Api-key");
property.setType(ProviderConfigProperty.STRING_TYPE);
property.setHelpText("The T1G api-key after contracting the SMS API and the OCRA API.");
configProperties.add(property);

// SMS Text
property = new ProviderConfigProperty();
property.setName(KeycloakOcraAuthenticatorConstants.CONF_PRP_OCRA_TEXT);
Expand All @@ -68,28 +46,6 @@ public class KeycloakOcraAuthenticatorFactory implements AuthenticatorFactory, C
property.setHelpText("Use %sms-code% as placeholder for the generated OCRA code. Use %user% and %password% as placeholder when 'In message' authentication is used.");
configProperties.add(property);

// OCRA Config
property = new ProviderConfigProperty();
property.setName(KeycloakOcraAuthenticatorConstants.CONF_PRP_OCRA_ALGO);
property.setLabel("OCRA Algorithm");
property.setType(ProviderConfigProperty.STRING_TYPE);
property.setHelpText("OCRA Algorithm following RFC6287: for example: 'OCRA-1:HOTP-SHA256-8:QN08'");
configProperties.add(property);

property = new ProviderConfigProperty();
property.setName(KeycloakOcraAuthenticatorConstants.CONF_PRP_OCRA_SEED);
property.setLabel("OCRA Seed");
property.setHelpText("OCRA Seed, shared secret between OCRA API and Keycloak");
property.setType(ProviderConfigProperty.STRING_TYPE);
configProperties.add(property);

property = new ProviderConfigProperty();
property.setName(KeycloakOcraAuthenticatorConstants.CONF_PRP_OCRA_TTL);
property.setLabel("OCRA TTL");
property.setHelpText("OCRA time-to-live in seconds");
property.setType(ProviderConfigProperty.STRING_TYPE);
configProperties.add(property);

try {
SINGLETON = new KeycloakOcraAuthenticator(new OcraService(), new SmsService());
logger.info("Kc Ocra Authenticator instance created.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@

import com.t1t.keycloak.client.sms.model.SmsService;
import org.jboss.logging.Logger;
import org.keycloak.authentication.Authenticator;
import org.keycloak.models.AuthenticatorConfigModel;
import org.keycloak.models.UserModel;
import java.util.List;
import java.util.Random;

/**
* @Author Michallis Pashidis
* @Since 2017
*/
public class KeycloakOcraAuthenticatorUtil {

private static Logger logger = Logger.getLogger(KeycloakOcraAuthenticatorUtil.class);
private static Logger logger = Logger.getLogger(Authenticator.class);

public static String getAttributeValue(UserModel user, String attributeName) {
String result = null;
Expand Down Expand Up @@ -70,14 +70,6 @@ public static String createMessage(String code, String mobileNumber, Authenticat
return text;
}

public static String setDefaultCountryCodeIfZero(String mobileNumber) {
if (mobileNumber.startsWith("07")) {
mobileNumber = "+44" + mobileNumber.substring(1);
}

return mobileNumber;
}

static boolean sendSmsCode(SmsService smsService, String mobileNumber, String code, AuthenticatorConfigModel config) {
// Send an SMS
KeycloakOcraAuthenticatorUtil.logger.debug("Sending " + code + " to mobileNumber " + mobileNumber);
Expand All @@ -91,18 +83,6 @@ static boolean sendSmsCode(SmsService smsService, String mobileNumber, String co
}
}

static String getSmsCode(long nrOfDigits) {
if (nrOfDigits < 1) {
throw new RuntimeException("Number of digits must be bigger than 0");
}

//TODO ocra
double maxValue = Math.pow(10.0, nrOfDigits); // 10 ^ nrOfDigits;
Random r = new Random();
long code = (long) (r.nextFloat() * maxValue);
return Long.toString(code);
}

public static boolean validateTelephoneNumber(String telephoneNumber) {
return true;
//return telephoneNumber.matches("^(?:(?:\\(?(?:0(?:0|11)\\)?[\\s-]?\\(?|\\+)44\\)?[\\s-]?(?:\\(?0\\)?[\\s-]?)?)|(?:\\(?0))(?:(?:\\d{5}\\)?[\\s-]?\\d{4,5})|(?:\\d{4}\\)?[\\s-]?(?:\\d{5}|\\d{3}[\\s-]?\\d{3}))|(?:\\d{3}\\)?[\\s-]?\\d{3}[\\s-]?\\d{3,4})|(?:\\d{2}\\)?[\\s-]?\\d{4}[\\s-]?\\d{4}))(?:[\\s-]?(?:x|ext\\.?|\\#)\\d{3,4})?$");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class OcraServiceTest {
private static final Logger log = LoggerFactory.getLogger(OcraServiceTest.class.getName());
private RandomString randomGenerator;


@Test
public void testOcraService() throws Exception {
randomGenerator = new RandomString(16, new SecureRandom(),RandomString.alphanum);
Expand Down

0 comments on commit d08aa03

Please sign in to comment.