Search in sources :

Example 1 with AuthenticationException

use of com.topcom.cms.perm.exception.AuthenticationException in project topcom-cloud by 545314690.

the class LoginController method login2.

/**
 * 登录验证 登录成功后返回用户信息(为了测试,去掉验证码信息)
 *
 * @param request
 * @param response
 * @param username
 * @param password
 * @param captcha
 * @return
 * @throws SQLException
 */
@RequestMapping(value = "/login2", method = RequestMethod.POST)
@ResponseBody
public ModelMap login2(HttpServletRequest request, HttpServletResponse response, @RequestParam String username, @RequestParam String password, @RequestParam(required = false) String captcha, @RequestParam(required = false) Boolean admin, @RequestParam(required = false) Boolean rememberMe) throws AuthenticationException {
    ModelMap modelMap = new ModelMap("success", false);
    UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(username, password);
    if (admin != null && admin == true) {
        usernamePasswordToken.setAdmin(admin);
    }
    boolean logined = SubjectUtil.login(usernamePasswordToken);
    // 验证是否登录成功
    if (logined) {
        modelMap.put("success", true);
        modelMap.put("message", "登录成功");
        String token = SubjectUtil.getLoginToken(username);
        User currentUser = SubjectUtil.getCurrentUser(token);
        request.getSession().setAttribute(Constants.CURRENT_USER, currentUser);
        modelMap.put("token", token);
        modelMap.put("user", currentUser.getFullName() == null ? username : currentUser.getFullName());
    } else {
        throw new AuthenticationException();
    }
    return modelMap;
}
Also used : User(com.topcom.cms.domain.User) AuthenticationException(com.topcom.cms.perm.exception.AuthenticationException) ModelMap(org.springframework.ui.ModelMap) UsernamePasswordToken(com.topcom.cms.perm.token.UsernamePasswordToken) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with AuthenticationException

use of com.topcom.cms.perm.exception.AuthenticationException in project topcom-cloud by 545314690.

the class LoginController method loginGet.

@RequestMapping(value = "/loginGet", method = RequestMethod.GET)
@ResponseBody
public ModelMap loginGet(HttpServletRequest request, HttpServletResponse response, @RequestParam String username, @RequestParam String password, @RequestParam(required = false) String captcha, @RequestParam(required = false) Boolean admin, @RequestParam(required = false) Boolean rememberMe) throws AuthenticationException {
    ModelMap modelMap = new ModelMap("success", false);
    UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(username, password);
    if (admin != null && admin == true) {
        usernamePasswordToken.setAdmin(admin);
    }
    boolean logined = SubjectUtil.login(usernamePasswordToken);
    // 验证是否登录成功
    if (logined) {
        modelMap.put("success", true);
        modelMap.put("message", "登录成功");
        String token = SubjectUtil.getLoginToken(username);
        User currentUser = SubjectUtil.getCurrentUser(token);
        request.getSession().setAttribute(Constants.CURRENT_USER, currentUser);
        modelMap.put("token", token);
        modelMap.put("user", currentUser.getFullName() == null ? username : currentUser.getFullName());
    } else {
        throw new AuthenticationException();
    }
    return modelMap;
}
Also used : User(com.topcom.cms.domain.User) AuthenticationException(com.topcom.cms.perm.exception.AuthenticationException) ModelMap(org.springframework.ui.ModelMap) UsernamePasswordToken(com.topcom.cms.perm.token.UsernamePasswordToken) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

User (com.topcom.cms.domain.User)2 AuthenticationException (com.topcom.cms.perm.exception.AuthenticationException)2 UsernamePasswordToken (com.topcom.cms.perm.token.UsernamePasswordToken)2 ModelMap (org.springframework.ui.ModelMap)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2