コード例 #1
0
  public JRadReturnMap innerAdminLogin(HttpServletRequest request) {

    JRadReturnMap returnMap = new JRadReturnMap();

    String username = request.getParameter("username");
    String password = request.getParameter("password");
    String ipAddress = request.getRemoteAddr();

    try {
      AuthResult authResult = authMgr.authUserByLogin(username, password);
      AuthResultType authResultType = authResult.getResultType();

      Errors errors = new Errors();
      String errorCode = null;
      if (AuthResultType.AUTH_ACCOUNT_NOT_EXIST.equals(authResultType)) {
        errorCode = "system.auth.accountNotExist";
      } else if (AuthResultType.AUTH_ACCOUNT_PASSWORD_ERROR.equals(authResultType)) {
        errorCode = "system.auth.passwordError";
      } else if (AuthResultType.AUTH_ACCOUNT_NOT_ACTIVE.equals(authResultType)) {
        errorCode = "system.auth.accountNotActive";
      } else if (AuthResultType.AUTH_ACCOUNT_NOT_LOCAL.equals(authResultType)) {
        //				errorCode = "system.auth.accountNotLocal";
      }

      String signInMsg = null;
      if (errorCode != null) {
        signInMsg = i18nHelper.getMessage(errorCode);
        errors.addGlobalError(errorCode);
        returnMap.setSuccess(false);
        returnMap.setErrors(errors);
      } else {
        IUser user = authResult.getUser();
        loginManager.login(user, request);
        request.getSession().setMaxInactiveInterval(300); // added by nihc 20150710 session超时
        signInMsg = i18nHelper.getMessage("system.auth.success");
      }

      loginLogManager.addSignInLog(username, LoginManager.LOCAL, ipAddress, signInMsg);
    } catch (Exception ex) {
      return WebRequestHelper.processException(ex);
    }

    return returnMap;
  }
コード例 #2
0
  @RequestMapping(value = {"/logout.page"})
  public String logout(HttpServletRequest request) {

    IUser user = loginManager.getLoggedInUser(request);
    String login = user.getLogin();
    String type =
        user.getUserType() == IUser.USER_TYPE_LOCAL ? LoginManager.LOCAL : LoginManager.LDAP;
    String ipAddress = request.getRemoteAddr();
    String signOutMsg = i18nHelper.getMessage("system.auth.success");

    loginManager.logout(request);
    loginLogManager.addSignOutLog(login, type, ipAddress, signOutMsg);

    return "redirect:login.html";
  }