use of org.maxkey.entity.UserInfo in project MaxKey by dromara.
the class AppListController method forwardAppLoginConfig.
/**
* forwardAppLoginConfig.
* @param protocol protocol
* @param credential credential
* @param appId appId
* @return
*/
@RequestMapping(value = { "/forward/appProtectedConfig/{protocol}/{credential}/{appId}" })
public ModelAndView forwardAppLoginConfig(@PathVariable("protocol") String protocol, @PathVariable("credential") int credential, @PathVariable("appId") String appId) {
ModelAndView modelAndView = new ModelAndView("main/appProtectedConfig");
UserInfo userInfo = WebContext.getUserInfo();
if (userInfo.getProtectedAppsMap().get(appId) != null) {
modelAndView.addObject("protectedappId", true);
} else {
modelAndView.addObject("protectedappId", false);
}
modelAndView.addObject("userId", userInfo.getId());
modelAndView.addObject("appId", appId);
modelAndView.addObject("protocol", protocol);
modelAndView.addObject("credential", credential);
return modelAndView;
}
use of org.maxkey.entity.UserInfo in project MaxKey by dromara.
the class ForgotPasswordContorller method email.
@RequestMapping(value = { "/emailmobile" })
public ModelAndView email(@RequestParam String emailMobile, @RequestParam String captcha) {
_logger.debug("forgotpassword /forgotpassword/emailmobile.");
_logger.debug("emailMobile : " + emailMobile);
int forgotType = ForgotType.NOTFOUND;
UserInfo userInfo = null;
if (captcha != null && captcha.equals(WebContext.getSession().getAttribute(WebConstants.KAPTCHA_SESSION_KEY).toString())) {
if (mobileRegex.matcher(emailMobile).matches()) {
forgotType = ForgotType.MOBILE;
} else if (emailRegex.matcher(emailMobile).matches()) {
forgotType = ForgotType.EMAIL;
} else {
forgotType = ForgotType.EMAIL;
emailMobile = emailMobile + "@" + emailConfig.getSmtpHost().substring(emailConfig.getSmtpHost().indexOf(".") + 1);
}
userInfo = userInfoService.findByEmailMobile(emailMobile);
if (null != userInfo) {
if (forgotType == ForgotType.EMAIL) {
mailOtpAuthn.produce(userInfo);
} else if (forgotType == ForgotType.MOBILE) {
AbstractOtpAuthn smsOtpAuthn = otpAuthnService.getByInstId(userInfo.getInstId());
smsOtpAuthn.produce(userInfo);
}
}
} else {
_logger.debug("login captcha valid error.");
forgotType = ForgotType.CAPTCHAERROR;
}
ModelAndView modelAndView = new ModelAndView("forgotpassword/resetpwd");
modelAndView.addObject("userId", userInfo == null ? "" : userInfo.getId());
modelAndView.addObject("username", userInfo == null ? "" : userInfo.getUsername());
modelAndView.addObject("emailMobile", emailMobile);
modelAndView.addObject("forgotType", forgotType);
return modelAndView;
}
use of org.maxkey.entity.UserInfo in project MaxKey by dromara.
the class OneTimePasswordController method counterbased.
@RequestMapping(value = { "/counterbased" })
public ModelAndView counterbased() {
ModelAndView modelAndView = new ModelAndView("safe/counterBased");
UserInfo userInfo = WebContext.getUserInfo();
String sharedSecret = passwordReciprocal.decoder(userInfo.getSharedSecret());
otpKeyUriFormat.setSecret(sharedSecret);
otpKeyUriFormat.setCounter(Long.parseLong(userInfo.getSharedCounter()));
String otpauth = otpKeyUriFormat.format(userInfo.getUsername());
byte[] byteSharedSecret = Base32Utils.decode(sharedSecret);
String hexSharedSecret = Hex.encodeHexString(byteSharedSecret);
modelAndView.addObject("id", genRqCode(otpauth));
modelAndView.addObject("userInfo", userInfo);
modelAndView.addObject("format", otpKeyUriFormat);
modelAndView.addObject("sharedSecret", sharedSecret);
modelAndView.addObject("hexSharedSecret", hexSharedSecret);
return modelAndView;
}
use of org.maxkey.entity.UserInfo in project MaxKey by dromara.
the class OneTimePasswordController method hotp.
@RequestMapping(value = { "/hotp" })
public ModelAndView hotp() {
ModelAndView modelAndView = new ModelAndView("safe/hotp");
UserInfo userInfo = WebContext.getUserInfo();
String sharedSecret = passwordReciprocal.decoder(userInfo.getSharedSecret());
otpKeyUriFormat.setSecret(sharedSecret);
otpKeyUriFormat.setCounter(Long.parseLong(userInfo.getSharedCounter()));
String otpauth = otpKeyUriFormat.format(userInfo.getUsername());
byte[] byteSharedSecret = Base32Utils.decode(sharedSecret);
String hexSharedSecret = Hex.encodeHexString(byteSharedSecret);
modelAndView.addObject("id", genRqCode(otpauth));
modelAndView.addObject("userInfo", userInfo);
modelAndView.addObject("format", otpKeyUriFormat);
modelAndView.addObject("sharedSecret", sharedSecret);
modelAndView.addObject("hexSharedSecret", hexSharedSecret);
return modelAndView;
}
use of org.maxkey.entity.UserInfo in project MaxKey by dromara.
the class OneTimePasswordController method gentimebased.
@RequestMapping(value = { "gen/timebased" })
public ModelAndView gentimebased() {
UserInfo userInfo = WebContext.getUserInfo();
byte[] byteSharedSecret = OtpSecret.generate(otpKeyUriFormat.getCrypto());
String sharedSecret = Base32Utils.encode(byteSharedSecret);
sharedSecret = passwordReciprocal.encode(sharedSecret);
userInfo.setSharedSecret(sharedSecret);
userInfoService.updateSharedSecret(userInfo);
WebContext.setUserInfo(userInfo);
return WebContext.redirect("/safe/otp/timebased");
}
Aggregations