use of com.zimbra.soap.account.message.EnableTwoFactorAuthRequest in project zm-mailbox by Zimbra.
the class ZMailbox method enableTwoFactorAuth.
public EnableTwoFactorAuthResponse enableTwoFactorAuth(String password, TOTPAuthenticator auth) throws ServiceException {
EnableTwoFactorAuthRequest req = new EnableTwoFactorAuthRequest();
req.setName(getName());
req.setPassword(password);
EnableTwoFactorAuthResponse resp = invokeJaxb(req);
String secret = resp.getSecret();
long timestamp = System.currentTimeMillis() / 1000;
String totp = auth.generateCode(secret, timestamp, Encoding.BASE32);
req.setTwoFactorCode(totp);
req.setAuthToken(resp.getAuthToken());
resp = invokeJaxb(req);
resp.setSecret(secret);
initAuthToken(new ZAuthToken(resp.getAuthToken().getValue()));
return resp;
}
Aggregations