Search in sources :

Example 1 with UserPasswordNotMatchException

use of com.ruoyi.common.exception.user.UserPasswordNotMatchException in project RuoYi-Vue by yangzongzhuan.

the class SysLoginService method login.

/**
 * 登录验证
 *
 * @param username 用户名
 * @param password 密码
 * @param code 验证码
 * @param uuid 唯一标识
 * @return 结果
 */
public String login(String username, String password, String code, String uuid) {
    boolean captchaOnOff = configService.selectCaptchaOnOff();
    // 验证码开关
    if (captchaOnOff) {
        validateCaptcha(username, code, uuid);
    }
    // 用户验证
    Authentication authentication = null;
    try {
        // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
        authentication = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password));
    } catch (Exception e) {
        if (e instanceof BadCredentialsException) {
            AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
            throw new UserPasswordNotMatchException();
        } else {
            AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage()));
            throw new ServiceException(e.getMessage());
        }
    }
    AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
    LoginUser loginUser = (LoginUser) authentication.getPrincipal();
    recordLoginInfo(loginUser.getUserId());
    // 生成token
    return tokenService.createToken(loginUser);
}
Also used : ServiceException(com.ruoyi.common.exception.ServiceException) Authentication(org.springframework.security.core.Authentication) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) UserPasswordNotMatchException(com.ruoyi.common.exception.user.UserPasswordNotMatchException) LoginUser(com.ruoyi.common.core.domain.model.LoginUser) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) ServiceException(com.ruoyi.common.exception.ServiceException) CaptchaExpireException(com.ruoyi.common.exception.user.CaptchaExpireException) CaptchaException(com.ruoyi.common.exception.user.CaptchaException) UserPasswordNotMatchException(com.ruoyi.common.exception.user.UserPasswordNotMatchException)

Example 2 with UserPasswordNotMatchException

use of com.ruoyi.common.exception.user.UserPasswordNotMatchException in project RuoYi-Vue-Oracle by yangzongzhuan.

the class SysLoginService method login.

/**
 * 登录验证
 *
 * @param username 用户名
 * @param password 密码
 * @param code 验证码
 * @param uuid 唯一标识
 * @return 结果
 */
public String login(String username, String password, String code, String uuid) {
    boolean captchaOnOff = configService.selectCaptchaOnOff();
    // 验证码开关
    if (captchaOnOff) {
        validateCaptcha(username, code, uuid);
    }
    // 用户验证
    Authentication authentication = null;
    try {
        // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
        authentication = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password));
    } catch (Exception e) {
        if (e instanceof BadCredentialsException) {
            AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
            throw new UserPasswordNotMatchException();
        } else {
            AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage()));
            throw new ServiceException(e.getMessage());
        }
    }
    AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
    LoginUser loginUser = (LoginUser) authentication.getPrincipal();
    recordLoginInfo(loginUser.getUserId());
    // 生成token
    return tokenService.createToken(loginUser);
}
Also used : ServiceException(com.ruoyi.common.exception.ServiceException) Authentication(org.springframework.security.core.Authentication) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) UserPasswordNotMatchException(com.ruoyi.common.exception.user.UserPasswordNotMatchException) LoginUser(com.ruoyi.framework.security.LoginUser) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) ServiceException(com.ruoyi.common.exception.ServiceException) CaptchaExpireException(com.ruoyi.common.exception.user.CaptchaExpireException) CaptchaException(com.ruoyi.common.exception.user.CaptchaException) UserPasswordNotMatchException(com.ruoyi.common.exception.user.UserPasswordNotMatchException)

Example 3 with UserPasswordNotMatchException

use of com.ruoyi.common.exception.user.UserPasswordNotMatchException in project RuoYi-Vue-fast by yangzongzhuan.

the class SysLoginService method login.

/**
 * 登录验证
 *
 * @param username 用户名
 * @param password 密码
 * @param code 验证码
 * @param uuid 唯一标识
 * @return 结果
 */
public String login(String username, String password, String code, String uuid) {
    boolean captchaOnOff = configService.selectCaptchaOnOff();
    // 验证码开关
    if (captchaOnOff) {
        validateCaptcha(username, code, uuid);
    }
    // 用户验证
    Authentication authentication = null;
    try {
        // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
        authentication = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password));
    } catch (Exception e) {
        if (e instanceof BadCredentialsException) {
            AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
            throw new UserPasswordNotMatchException();
        } else {
            AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage()));
            throw new ServiceException(e.getMessage());
        }
    }
    AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
    LoginUser loginUser = (LoginUser) authentication.getPrincipal();
    recordLoginInfo(loginUser.getUserId());
    // 生成token
    return tokenService.createToken(loginUser);
}
Also used : ServiceException(com.ruoyi.common.exception.ServiceException) Authentication(org.springframework.security.core.Authentication) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) UserPasswordNotMatchException(com.ruoyi.common.exception.user.UserPasswordNotMatchException) LoginUser(com.ruoyi.framework.security.LoginUser) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) ServiceException(com.ruoyi.common.exception.ServiceException) CaptchaExpireException(com.ruoyi.common.exception.user.CaptchaExpireException) CaptchaException(com.ruoyi.common.exception.user.CaptchaException) UserPasswordNotMatchException(com.ruoyi.common.exception.user.UserPasswordNotMatchException)

Example 4 with UserPasswordNotMatchException

use of com.ruoyi.common.exception.user.UserPasswordNotMatchException in project wumei-smart by kerwincui.

the class SysLoginService method login.

/**
 * 登录验证
 *
 * @param username 用户名
 * @param password 密码
 * @param code 验证码
 * @param uuid 唯一标识
 * @return 结果
 */
public String login(String username, String password, String code, String uuid) {
    boolean captchaOnOff = configService.selectCaptchaOnOff();
    // 验证码开关
    if (captchaOnOff) {
        validateCaptcha(username, code, uuid);
    }
    // 用户验证
    Authentication authentication = null;
    try {
        // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
        authentication = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password));
    } catch (Exception e) {
        if (e instanceof BadCredentialsException) {
            AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
            throw new UserPasswordNotMatchException();
        } else {
            AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage()));
            throw new ServiceException(e.getMessage());
        }
    }
    AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
    LoginUser loginUser = (LoginUser) authentication.getPrincipal();
    recordLoginInfo(loginUser.getUserId());
    // 生成token
    return tokenService.createToken(loginUser);
}
Also used : ServiceException(com.ruoyi.common.exception.ServiceException) Authentication(org.springframework.security.core.Authentication) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) UserPasswordNotMatchException(com.ruoyi.common.exception.user.UserPasswordNotMatchException) LoginUser(com.ruoyi.common.core.domain.model.LoginUser) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) ServiceException(com.ruoyi.common.exception.ServiceException) CaptchaExpireException(com.ruoyi.common.exception.user.CaptchaExpireException) CaptchaException(com.ruoyi.common.exception.user.CaptchaException) UserPasswordNotMatchException(com.ruoyi.common.exception.user.UserPasswordNotMatchException)

Example 5 with UserPasswordNotMatchException

use of com.ruoyi.common.exception.user.UserPasswordNotMatchException in project wumei-smart by kerwincui.

the class SysLoginService method socialLogin.

/**
 * 第三方验证后,调用登录方法
 * @param username 用户名
 * @param password 密码
 * @return token
 */
public String socialLogin(String username, String password) {
    // 用户验证
    Authentication authentication = null;
    try {
        // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
        authentication = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password));
    } catch (Exception e) {
        if (e instanceof BadCredentialsException) {
            AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
            throw new UserPasswordNotMatchException();
        } else {
            AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage()));
            throw new ServiceException(e.getMessage());
        }
    }
    AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
    LoginUser loginUser = (LoginUser) authentication.getPrincipal();
    recordLoginInfo(loginUser.getUserId());
    // 生成token
    return tokenService.createToken(loginUser);
}
Also used : ServiceException(com.ruoyi.common.exception.ServiceException) Authentication(org.springframework.security.core.Authentication) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) UserPasswordNotMatchException(com.ruoyi.common.exception.user.UserPasswordNotMatchException) LoginUser(com.ruoyi.common.core.domain.model.LoginUser) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) ServiceException(com.ruoyi.common.exception.ServiceException) CaptchaExpireException(com.ruoyi.common.exception.user.CaptchaExpireException) CaptchaException(com.ruoyi.common.exception.user.CaptchaException) UserPasswordNotMatchException(com.ruoyi.common.exception.user.UserPasswordNotMatchException)

Aggregations

UserPasswordNotMatchException (com.ruoyi.common.exception.user.UserPasswordNotMatchException)7 CaptchaException (com.ruoyi.common.exception.user.CaptchaException)6 CaptchaExpireException (com.ruoyi.common.exception.user.CaptchaExpireException)6 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)6 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)6 Authentication (org.springframework.security.core.Authentication)6 LoginUser (com.ruoyi.common.core.domain.model.LoginUser)5 ServiceException (com.ruoyi.common.exception.ServiceException)5 LoginUser (com.ruoyi.framework.security.LoginUser)2 CustomException (com.ruoyi.common.exception.CustomException)1 UserDetails (org.springframework.security.core.userdetails.UserDetails)1