Skip to content

Commit 8657ac9

Browse files
committed
Added option for manditory one-time passwords
Added option for manditory one-time passwords. Closes bastillion-io#102
1 parent a1db1ad commit 8657ac9

4 files changed

Lines changed: 11 additions & 4 deletions

File tree

src/main/java/com/keybox/manage/action/LoginAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class LoginAction extends ActionSupport implements ServletRequestAware, S
4444
Auth auth;
4545
private final String AUTH_ERROR="Authentication Failed : Login credentials are invalid";
4646
//check if otp is enabled
47-
boolean otpEnabled="true".equals(AppConfig.getProperty("enableOTP"));
47+
boolean otpEnabled = ("required".equals(AppConfig.getProperty("oneTimePassword")) || "optional".equals(AppConfig.getProperty("oneTimePassword")));
4848

4949
@Action(value = "/login",
5050
results = {

src/main/java/com/keybox/manage/action/OTPAction.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.google.zxing.EncodeHintType;
2020
import com.google.zxing.common.BitMatrix;
2121
import com.google.zxing.qrcode.QRCodeWriter;
22+
import com.keybox.common.util.AppConfig;
2223
import com.keybox.common.util.AuthUtil;
2324
import com.keybox.manage.db.AuthDB;
2425
import com.keybox.manage.db.UserDB;
@@ -43,6 +44,7 @@
4344
public class OTPAction extends ActionSupport implements ServletRequestAware, ServletResponseAware {
4445

4546
private static Logger log = LoggerFactory.getLogger(OTPAction.class);
47+
public static boolean requireOTP = "required".equals(AppConfig.getProperty("oneTimePassword"));
4648

4749
//QR image size
4850
private static final int QR_IMAGE_WIDTH = 325;
@@ -130,6 +132,9 @@ public String qrImage() {
130132
log.error(ex.toString(), ex);
131133
}
132134

135+
if (requireOTP) {
136+
AuthUtil.deleteAllSession(servletRequest.getSession());
137+
}
133138

134139
return null;
135140

src/main/resources/KeyBoxConfig.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ serverAliveInterval=60
2626
websocketTimeout=0
2727
#enable SSH agent forwarding
2828
agentForwarding=false
29-
#enable two-factor authentication
30-
enableOTP=true
29+
#enable two-factor authentication with a one-time password - 'required', 'optional', or 'disabled'
30+
oneTimePassword=optional
3131
#set to false to disable key management. If false, the KeyBox public key will be appended to the authorized_keys file (instead of it being overwritten completely).
3232
keyManagementEnabled=true
3333
#set to true to generate keys when added/managed by users and enforce strong passphrases set to false to allow users to set their own public key

src/main/webapp/admin/two-factor_otp.jsp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@
106106
</tr>
107107
</tbody>
108108
</table>
109-
<button onclick="window.location = 'menu.action'" class="btn btn-danger spacer spacer-left" style="float:left">Skip for Now</button>
109+
<s:if test="%{[email protected]@requireOTP}">
110+
<button onclick="window.location = 'menu.action'" class="btn btn-danger spacer spacer-left" style="float:left">Skip for Now</button>
111+
</s:if>
110112
<s:form action="otpSubmit" theme="simple" >
111113
<s:hidden name="sharedSecret"/>
112114
<s:submit cssClass="btn btn-default spacer spacer-right" value="Got It!"/>

0 commit comments

Comments
 (0)