Search in sources :

Example 6 with UserInfo

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;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) UserInfo(org.maxkey.entity.UserInfo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with UserInfo

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;
}
Also used : AbstractOtpAuthn(org.maxkey.password.onetimepwd.AbstractOtpAuthn) ModelAndView(org.springframework.web.servlet.ModelAndView) UserInfo(org.maxkey.entity.UserInfo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with UserInfo

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;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) UserInfo(org.maxkey.entity.UserInfo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with UserInfo

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;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) UserInfo(org.maxkey.entity.UserInfo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with UserInfo

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");
}
Also used : UserInfo(org.maxkey.entity.UserInfo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

UserInfo (org.maxkey.entity.UserInfo)85 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)42 ModelAndView (org.springframework.web.servlet.ModelAndView)17 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)15 Message (org.maxkey.web.message.Message)8 Date (java.util.Date)7 HashMap (java.util.HashMap)7 Operation (io.swagger.v3.oas.annotations.Operation)6 ConstsOperateMessage (org.maxkey.constants.ConstsOperateMessage)6 Accounts (org.maxkey.entity.Accounts)6 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)6 SigninPrincipal (org.maxkey.authn.SigninPrincipal)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 ServiceResponseBuilder (org.maxkey.authz.cas.endpoint.response.ServiceResponseBuilder)4 AbstractAuthorizeAdapter (org.maxkey.authz.endpoint.adapter.AbstractAuthorizeAdapter)4 SynchroRelated (org.maxkey.entity.SynchroRelated)4 NamingException (javax.naming.NamingException)3 ProxyServiceResponseBuilder (org.maxkey.authz.cas.endpoint.response.ProxyServiceResponseBuilder)3 Ticket (org.maxkey.authz.cas.endpoint.ticket.Ticket)3 Apps (org.maxkey.entity.apps.Apps)3