Search in sources :

Example 11 with SysUser

use of com.cdeledu.model.rbac.SysUser in project wechat by dllwh.

the class ShiroRealm method doGetAuthenticationInfo.

/**
 * @方法描述: 验证当前登录的Subject
 * @说明: 该方法的调用时机为LoginController.login()方法中执行Subject.login()时
 * @param token
 * @return
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authtoken) throws AuthenticationException {
    UsernamePasswordToken token = (UsernamePasswordToken) authtoken;
    // ① 获取当前登录的用户名
    String currentUsername = token.getUsername();
    String passWord = String.valueOf(token.getPassword());
    SysUser sysUser = new SysUser();
    SysUser currentUser = null;
    SimpleAuthenticationInfo authcInfo = null;
    try {
        sysUser.setUserName(currentUsername);
        int userCount = userService.getCountForJdbcParam(sysUser);
        if (userCount <= 0) {
            throw new UnknownAccountException();
        }
        currentUser = userService.checkUserExits(currentUsername, passWord);
    } catch (Exception e) {
        throw new UnknownAccountException();
    }
    if (currentUser != null) {
        // 账号未通过审核
        if (currentUser.getIfEnabled() != 1) {
            throw new DisabledAccountException();
        }
        // 账号未通过审核
        if (currentUser.getIfVisible() != 1) {
            throw new DisabledAccountException("账号未通过审核");
        }
        // 账号不允许登录
        if (currentUser.getLoginFlag() != 1) {
            throw new AuthenticationException("账号不允许登录");
        }
        // 账号被锁定
        if (currentUser.getIfLocked() != 1) {
            throw new ExcessiveAttemptsException("账号被锁定");
        }
        WebUtilHelper.setCurrentLoginUser(currentUser);
        authcInfo = new SimpleAuthenticationInfo(currentUser, currentUser.getPassword(), getName());
    } else {
        throw new LockedAccountException("用户名或密码错误");
    }
    return authcInfo;
}
Also used : DisabledAccountException(org.apache.shiro.authc.DisabledAccountException) SysUser(com.cdeledu.model.rbac.SysUser) SimpleAuthenticationInfo(org.apache.shiro.authc.SimpleAuthenticationInfo) AuthenticationException(org.apache.shiro.authc.AuthenticationException) UnknownAccountException(org.apache.shiro.authc.UnknownAccountException) ExcessiveAttemptsException(org.apache.shiro.authc.ExcessiveAttemptsException) AuthenticationException(org.apache.shiro.authc.AuthenticationException) DisabledAccountException(org.apache.shiro.authc.DisabledAccountException) ExcessiveAttemptsException(org.apache.shiro.authc.ExcessiveAttemptsException) LockedAccountException(org.apache.shiro.authc.LockedAccountException) UnknownAccountException(org.apache.shiro.authc.UnknownAccountException) LockedAccountException(org.apache.shiro.authc.LockedAccountException) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken)

Example 12 with SysUser

use of com.cdeledu.model.rbac.SysUser in project wechat by dllwh.

the class ManagerUserServiceImpl method getUserByName.

@Override
public SysUser getUserByName(String userName) throws Exception {
    if (StringUtils.isNotBlank(userName)) {
        SysUser user = new SysUser();
        user.setUserName(userName);
        return (SysUser) baseDao.findOneForJdbcParam(PREFIX + "findOneForJdbc", user);
    } else {
        return null;
    }
}
Also used : SysUser(com.cdeledu.model.rbac.SysUser)

Example 13 with SysUser

use of com.cdeledu.model.rbac.SysUser in project wechat by dllwh.

the class WebUtilHelper method getCurrenLoginUser.

/**
 * @方法:获取session里的用户对象
 * @创建人:独泪了无痕
 * @return
 */
public static final SysUser getCurrenLoginUser() {
    HttpSession session = getSession();
    SysUser sysUser = null;
    if (session.getAttributeNames().hasMoreElements()) {
        sysUser = (SysUser) session.getAttribute(GlobalConstants.USER_SESSION);
        if (sysUser != null) {
            return sysUser;
        }
    }
    return sysUser;
}
Also used : SysUser(com.cdeledu.model.rbac.SysUser) HttpSession(javax.servlet.http.HttpSession)

Example 14 with SysUser

use of com.cdeledu.model.rbac.SysUser in project wechat by dllwh.

the class SysUserOperateController method updateUserEnable.

@ResponseBody
@RequestMapping("enable")
@SystemLog(desc = " 启用账户", opType = SysOpType.UPDATE, tableName = { "sys_user" })
public AjaxJson updateUserEnable(int userId) {
    AjaxJson resultMsg = new AjaxJson();
    SysUser user = new SysUser();
    user.setId(userId);
    try {
        SysUser sysUser = manageruserService.findOneForJdbc(user);
        // 超级管理员不能操作
        if (sysUser != null && sysUser.getUserType() != -1 && WebUtilHelper.getCurrentUserId() != userId) {
            sysUser.setIfVisible(1);
            manageruserService.update(sysUser);
        }
        resultMsg.setMsg(MessageConstant.MSG_OPERATION_SUCCESS);
    } catch (Exception e) {
        e.printStackTrace();
        resultMsg.setSuccess(false);
        resultMsg.setResultCode(500);
        resultMsg.setMsg(MessageConstant.MSG_OPERATION_FAILED);
    }
    return resultMsg;
}
Also used : SysUser(com.cdeledu.model.rbac.SysUser) AjaxJson(com.cdeledu.common.base.AjaxJson) SystemLog(com.cdeledu.core.annotation.SystemLog) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with SysUser

use of com.cdeledu.model.rbac.SysUser in project wechat by dllwh.

the class SysUserOperateController method saveRoleUser.

/**
 * @方法描述: 用户-角色录入
 * @创建者: 皇族灬战狼
 * @创建时间: 2016年9月27日 下午4:51:27
 * @param managerUser
 * @param request
 * @return
 */
@ResponseBody
@RequestMapping(value = "roleAssign", params = "saveRoleUser")
@SystemLog(desc = "用户-角色录入(授权)", opType = SysOpType.INSERT, tableName = "sys_user_role")
public AjaxJson saveRoleUser(@RequestParam(value = "userCode", required = true) int id, @RequestParam(value = "roleID", defaultValue = "1", required = false) int roleID) {
    AjaxJson resultMsg = new AjaxJson();
    SysUser user = new SysUser();
    user.setId(id);
    try {
        if (roleID == 1) {
            // 超级管理员不参与分配
            resultMsg.setSuccess(false);
            resultMsg.setMsg("无法授予权限");
        }
        SysUser tSUser = manageruserService.findOneForJdbc(user);
        if (null == tSUser) {
            resultMsg.setMsg("不存在");
            resultMsg.setSuccess(false);
        } else {
            SysUserRole managerUserRole = new SysUserRole();
            managerUserRole.setUserId(tSUser.getId());
            managerUserRole.setRoleId(roleID);
            manageruserService.saveRoleUser(managerUserRole);
        }
    } catch (Exception e) {
        resultMsg.setResultCode(500);
        resultMsg.setMsg("分配角色时出现异常");
        resultMsg.setSuccess(false);
    }
    return resultMsg;
}
Also used : SysUser(com.cdeledu.model.rbac.SysUser) AjaxJson(com.cdeledu.common.base.AjaxJson) SysUserRole(com.cdeledu.model.rbac.SysUserRole) SystemLog(com.cdeledu.core.annotation.SystemLog) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SysUser (com.cdeledu.model.rbac.SysUser)21 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 AjaxJson (com.cdeledu.common.base.AjaxJson)8 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)8 SystemLog (com.cdeledu.core.annotation.SystemLog)7 SysUserRole (com.cdeledu.model.rbac.SysUserRole)4 HttpSession (javax.servlet.http.HttpSession)3 AuthenticationException (org.apache.shiro.authc.AuthenticationException)2 DisabledAccountException (org.apache.shiro.authc.DisabledAccountException)2 ExcessiveAttemptsException (org.apache.shiro.authc.ExcessiveAttemptsException)2 LockedAccountException (org.apache.shiro.authc.LockedAccountException)2 UnknownAccountException (org.apache.shiro.authc.UnknownAccountException)2 Transactional (org.springframework.transaction.annotation.Transactional)2 OnlineUser (com.cdeledu.model.system.OnlineUser)1 HashMap (java.util.HashMap)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 SimpleAuthenticationInfo (org.apache.shiro.authc.SimpleAuthenticationInfo)1 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)1 SimpleAuthorizationInfo (org.apache.shiro.authz.SimpleAuthorizationInfo)1 SimplePrincipalCollection (org.apache.shiro.subject.SimplePrincipalCollection)1