Search in sources :

Example 1 with AjaxJson

use of com.cdeledu.common.base.AjaxJson in project wechat by dllwh.

the class ShiroHelper method login.

/**
 * ----------------------------------------------------- Fields end
 */
public static AjaxJson login(String userName, String passWord) {
    // 用户名密码令牌
    UsernamePasswordToken token = new UsernamePasswordToken(userName, passWord);
    token.setRememberMe(false);
    String logMsg = "", resultMsg = "";
    AjaxJson ajaxJson = new AjaxJson();
    boolean suc = false;
    // 获得当前登录用户对象Subject,现在状态为 “未认证”
    Subject subject = SecurityUtils.getSubject();
    try {
        subject.login(token);
    } catch (UnknownAccountException uae) {
        logMsg = "对用户[" + userName + "]进行登录验证..验证未通过,未知账户";
        resultMsg = MessageConstant.LOGIN_USER_UNKNOWN;
    } catch (IncorrectCredentialsException ice) {
        logMsg = "对用户[" + userName + "]进行登录验证..验证未通过,错误的凭证";
        resultMsg = MessageConstant.LOGIN_USER_REEOE;
    } catch (LockedAccountException lae) {
        logMsg = "对用户[" + userName + "]进行登录验证..验证未通过,账户已锁定";
        resultMsg = MessageConstant.LOGIN_USER_LOCK;
    } catch (DisabledAccountException dae) {
        logMsg = "对用户[" + userName + "]进行登录验证..验证未通过,帐号已被禁用";
        resultMsg = MessageConstant.LOGIN_USER_DISABLED;
    } catch (ExpiredCredentialsException ece) {
        logMsg = "对用户[" + userName + "]进行登录验证..验证未通过,帐号已过期";
        resultMsg = MessageConstant.LOGIN_USER_EXPIRED;
    } catch (ExcessiveAttemptsException eae) {
        logMsg = "对用户[" + userName + "]进行登录验证..验证未通过,用户名或密码错误次数过多";
        resultMsg = MessageConstant.LOGIN_USER_MORE;
    } catch (UnauthorizedException e) {
        logMsg = "对用户[" + userName + "]进行登录验证..验证未通过,您没有得到相应的授权!";
        resultMsg = MessageConstant.LOGIN_USER_UNAUTHORIZED;
    } catch (AuthenticationException ae) {
        logMsg = "对用户[" + userName + "]进行登录验证..验证未通过," + ae.getMessage();
        resultMsg = MessageConstant.LOGIN_ERROR;
    }
    if (subject.isAuthenticated()) {
        logMsg = "对用户[" + userName + "]进行登录验证..验证通过";
        suc = true;
    } else {
        token.clear();
    }
    ajaxJson.setSuccess(suc);
    ajaxJson.setMsg(resultMsg);
    ajaxJson.setObj(logMsg);
    return ajaxJson;
}
Also used : DisabledAccountException(org.apache.shiro.authc.DisabledAccountException) IncorrectCredentialsException(org.apache.shiro.authc.IncorrectCredentialsException) AuthenticationException(org.apache.shiro.authc.AuthenticationException) UnknownAccountException(org.apache.shiro.authc.UnknownAccountException) ExcessiveAttemptsException(org.apache.shiro.authc.ExcessiveAttemptsException) AjaxJson(com.cdeledu.common.base.AjaxJson) Subject(org.apache.shiro.subject.Subject) ExpiredCredentialsException(org.apache.shiro.authc.ExpiredCredentialsException) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken) UnauthorizedException(org.apache.shiro.authz.UnauthorizedException) LockedAccountException(org.apache.shiro.authc.LockedAccountException)

Example 2 with AjaxJson

use of com.cdeledu.common.base.AjaxJson in project wechat by dllwh.

the class IconController method saveIcon.

/**
 * @方法描述: 上传图标
 * @创建者: 皇族灬战狼
 * @创建时间: 2016年9月22日 下午2:18:32
 * @param request
 * @return
 * @throws Exception
 */
@RequestMapping(value = "saveIcon")
@ResponseBody
public AjaxJson saveIcon(HttpServletRequest request) throws Exception {
    AjaxJson result = new AjaxJson();
    message = "上传成功";
    result.setMsg(message);
    // String css = ".back{background:url('../images/back.png') no-repeat;}";
    return result;
}
Also used : AjaxJson(com.cdeledu.common.base.AjaxJson) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with AjaxJson

use of com.cdeledu.common.base.AjaxJson in project wechat by dllwh.

the class IconController method initIcon.

@RequestMapping(value = "initIcon")
@ResponseBody
public AjaxJson initIcon() {
    AjaxJson result = new AjaxJson();
    try {
        result.setMsg("数据初始化成功");
        Map<String, String> filePathMap = Maps.newConcurrentMap();
        ClassLoader baseUrl = Thread.currentThread().getContextClassLoader();
        filePathMap.put("bootstrap", baseUrl.getResource("bootstrapIconInfo/bootstrap.css").getPath());
        filePathMap.put("fontAwesome", baseUrl.getResource("bootstrapIconInfo/font-awesome.css").getPath());
        filePathMap.put("simpleLine", baseUrl.getResource("bootstrapIconInfo/simple-line-icons.css").getPath());
        List<Map<String, String>> resultList = BootstrapHelper.getBootstrapIconInfo(filePathMap);
        SysIcon sysIcon = null;
        for (Map<String, String> map : resultList) {
            try {
                sysIcon = new SysIcon();
                sysIcon.setDisplayName(map.get("displayName"));
                sysIcon.setSourceType(map.get("sourceType"));
                if (sysIconService.findOneForJdbc(sysIcon) != null) {
                    sysIcon.setClassName(map.get("className"));
                    sysIconService.insert(sysIcon);
                }
            } catch (Exception e) {
                continue;
            }
        }
    } catch (Exception e) {
        result.setMsg("数据初始化失败,原因" + e.getMessage());
        result.setSuccess(false);
    }
    return result;
}
Also used : SysIcon(com.cdeledu.model.system.SysIcon) AjaxJson(com.cdeledu.common.base.AjaxJson) Map(java.util.Map) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with AjaxJson

use of com.cdeledu.common.base.AjaxJson in project wechat by dllwh.

the class LoginController method checkuser.

/**
 * ----------------------------------------------------- Fields end
 */
/**
 * @方法:登陆验证
 * @创建人:独泪了无痕
 * @param user
 * @return
 */
@RequestMapping(params = "checkuser")
@ResponseBody
public AjaxJson checkuser(HttpServletRequest request, SysUser user) {
    AjaxJson reslutMsg = new AjaxJson();
    HttpSession session = WebUtilHelper.getSession();
    // Session session = ShiroHelper.getSession();
    boolean suc = true;
    String logMsg = "";
    String userName = user.getUserName().trim();
    try {
        String password = PasswordUtil.encrypt(userName, user.getPassword().trim());
        AjaxJson loginResult = ShiroHelper.login(userName, password);
        int loginStatus = 2;
        if (loginResult.isSuccess()) {
            loginStatus = 1;
            session.removeAttribute(GlobalConstants.IMAGECAPTCHA);
        } else {
            logMsg = loginResult.getMsg();
            suc = false;
        }
        try {
            LogManager.getInstance().executeLog(LogTaskFactory.loginLog(userName, String.valueOf(loginResult.getObj()), loginStatus, getIp(request), getBrowser(request)));
        } catch (Exception e) {
        }
    } catch (Exception e) {
        logMsg = "用户名或密码错误,请重新登录!";
        suc = false;
    }
    reslutMsg.setMsg(logMsg);
    reslutMsg.setSuccess(suc);
    return reslutMsg;
}
Also used : HttpSession(javax.servlet.http.HttpSession) AjaxJson(com.cdeledu.common.base.AjaxJson) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with AjaxJson

use of com.cdeledu.common.base.AjaxJson in project wechat by dllwh.

the class LoginController method register.

/**
 * 注册跳转
 *
 * @return
 */
@RequestMapping(value = "register", method = RequestMethod.GET)
public AjaxJson register(SysUser user) {
    AjaxJson result = new AjaxJson();
    boolean namestander = user.getUserName().trim().startsWith("qq") || user.getUserName().trim().startsWith("sina") || user.getUserName().trim().startsWith("github") || user.getUserName().trim().startsWith("baidu") || user.getUserName().trim().startsWith("weixin");
    if (namestander) {
        result.setSuccess(false);
        result.setMsg("不能以qq、sina、weixin、baidu、github 开头注册");
        return result;
    }
    return result;
}
Also used : AjaxJson(com.cdeledu.common.base.AjaxJson) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

AjaxJson (com.cdeledu.common.base.AjaxJson)46 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)44 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)33 SystemLog (com.cdeledu.core.annotation.SystemLog)25 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)12 SysUser (com.cdeledu.model.rbac.SysUser)8 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)6 SysRole (com.cdeledu.model.rbac.SysRole)4 SysMenu (com.cdeledu.model.rbac.SysMenu)3 SysUserRole (com.cdeledu.model.rbac.SysUserRole)2 SysIcon (com.cdeledu.model.system.SysIcon)1 Map (java.util.Map)1 HttpSession (javax.servlet.http.HttpSession)1 AuthenticationException (org.apache.shiro.authc.AuthenticationException)1 DisabledAccountException (org.apache.shiro.authc.DisabledAccountException)1 ExcessiveAttemptsException (org.apache.shiro.authc.ExcessiveAttemptsException)1 ExpiredCredentialsException (org.apache.shiro.authc.ExpiredCredentialsException)1 IncorrectCredentialsException (org.apache.shiro.authc.IncorrectCredentialsException)1 LockedAccountException (org.apache.shiro.authc.LockedAccountException)1 UnknownAccountException (org.apache.shiro.authc.UnknownAccountException)1