Skip to content
Snippets Groups Projects
Commit 5bed830e authored by Wei Liu's avatar Wei Liu
Browse files

Add MFA handler

parent 8d70c71a
Branches
Tags
No related merge requests found
......@@ -33,7 +33,7 @@
<dependency>
<groupId>com.arcitecta</groupId>
<artifactId>mfclient</artifactId>
<version>4.13.033</version>
<version>4.16.074</version>
</dependency>
<dependency>
<groupId>org.jline</groupId>
......
package unimelb.mf.client.session;
//import arc.mf.client.MultiFactorAuthenticationHandler;
import arc.mf.client.MultiFactorAuthenticationHandler;
import unimelb.utils.AnsiColors;
import unimelb.utils.StringUtils;
public class DefaultMFAHandler /* implements MultiFactorAuthenticationHandler */ {
public class DefaultMFAHandler implements MultiFactorAuthenticationHandler {
/**
* Indicates the server has requested multi-factor verification.
*
* @param deviceModel The model of the device the notification was sent to.
* @param deviceName The name of the device the notification was sent to.
* @param remainingTimeInSecs The amount of time remaining in seconds before the notification request expires.
*/
public void requestedMultiFactor(String deviceModel, String deviceName, long remainingTimeInSecs) {
System.out.printf("Sent notification to %s[%s]%n", deviceName, deviceModel);
System.out.printf("Remaining %03d seconds%n", remainingTimeInSecs);
}
/**
* Indicates the server has requested multi-factor verification.
*
* @param deviceModel The model of the device the notification was sent
* to.
* @param deviceName The name of the device the notification was sent
* to.
* @param remainingTimeInSecs The amount of time remaining in seconds before the
* notification request expires.
*/
public void requestedMultiFactor(String deviceModel, String deviceName, long remainingTimeInSecs) {
System.out.printf("MFA notification sent to %s%s [%s]%s%n", AnsiColors.BLUE, deviceName, deviceModel, AnsiColors.RESET);
System.out.printf("Remaining %s%03d%s seconds", AnsiColors.YELLOW, remainingTimeInSecs, AnsiColors.RESET);
}
/**
* Indicates that user has not yet responded to the request for verification.
*
* @param requestAtTime The time (UTC) that the request was generated.
* @param remainingTimeInSecs The amount of time remaining in seconds before the notification request expires.
*/
public void multifactorIsStillWaiting(long requestAtTime, long remainingTimeInSecs) {
System.out.printf("\rRemaining %03d seconds", remainingTimeInSecs);
}
/**
* Indicates that user has not yet responded to the request for verification.
*
* @param requestAtTime The time (UTC) that the request was generated.
* @param remainingTimeInSecs The amount of time remaining in seconds before the
* notification request expires.
*/
public void multifactorIsStillWaiting(long requestAtTime, long remainingTimeInSecs) {
System.out.printf("\r\rRemaining %s%03d%s seconds", AnsiColors.YELLOW, remainingTimeInSecs, AnsiColors.RESET);
}
/**
* Indicates the system is no longer waiting for multi-factor authentication - typically it was successful.
*/
public void multifactorIsNoLongerWaiting() {
System.out.println("\r\r");
}
/**
* Indicates the system is no longer waiting for multi-factor authentication -
* typically it was successful.
*/
public void multifactorIsNoLongerWaiting() {
String line = StringUtils.repeat(" ", 80);
System.out.printf("\r\r%s\r", line);
}
}
......@@ -158,7 +158,7 @@ public class MFSession {
if (!reconnect && _sessionKey != null && authenticationDetailsEquals(_ad, authenticationDetails)) {
cxn.reconnect(_sessionKey);
} else {
_sessionKey = cxn.connect(authenticationDetails);
_sessionKey = cxn.connect(authenticationDetails, new DefaultMFAHandler());
printConnectionAndAuthenticationSummary(_rs.connectionDetails(), cxn.authenticationDetails());
_ad = authenticationDetails;
}
......@@ -310,7 +310,7 @@ public class MFSession {
} catch (Throwable t) {
if (this._sessionKey != null && nbRetries > 0) {
if (_ad != null && t instanceof ServerClient.ExSessionInvalid) {
_sessionKey = cxn.connect(_ad);
_sessionKey = cxn.connect(_ad, new DefaultMFAHandler());
}
if ((request.hasInput() || request.hasOutput()) && request.canBeReExecuted()) {
// only retry when there is input or output...
......@@ -555,7 +555,7 @@ public class MFSession {
rs.setProxy(config.proxy());
ServerClient.Connection c = rs.open();
try {
String sessionKey = c.connect(config.authenticationDetails());
String sessionKey = c.connect(config.authenticationDetails(), new DefaultMFAHandler());
printConnectionAndAuthenticationSummary(rs.connectionDetails(), config.authenticationDetails());
return new MFSession(config, rs, sessionKey);
} finally {
......
......@@ -37,6 +37,22 @@ public class StringUtils {
}
return sb.toString();
}
public static String repeat(char c, int n) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
sb.append(c);
}
return sb.toString();
}
public static String repeat(String str, int n) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
sb.append(str);
}
return sb.toString();
}
// @formatter:off
// public static void main(String[] args) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment