示例#1
0
 public Object forceLogoffJson(HttpServletRequest request) {
   SimpleRequestReader reader = new SimpleRequestReader(request);
   String id = reader.getString("id", false);
   OnlineReal onlineReal = onlineManager.getOnlineRealById(id);
   if (null != onlineReal) {
     onlineManager.offline(onlineReal, TypeDefinition.OFFLINE_KICKOFF);
   } else {
     throw new BusinessException(ErrorCode.RESOURCE_NOT_FOUND, "该资源不在线!");
   }
   BaseDTO dto = new BaseDTO();
   dto.setCode(ErrorCode.SUCCESS);
   dto.setMethod(request.getHeader(Header.METHOD));
   dto.setMessage("");
   return dto;
 }
示例#2
0
  public Object userLogin(HttpServletRequest request) {
    SimpleRequestReader reader = new SimpleRequestReader(request);
    String loginName = reader.getString("loginName", false);
    String passwd = reader.getString("password", false);
    String type = reader.getString("clientType", false);
    String ip = reader.getClientIp();

    List<User> users = userManager.getUserByName(loginName);
    if (users.size() <= 0) {
      throw new BusinessException(
          ErrorCode.USER_NOT_FOUND, "login_name [" + loginName + "] not found!");
    }

    User user = users.get(0);

    if (!passwd.equals(MD5Util.MD5(user.getPassword()))) {
      throw new BusinessException(ErrorCode.PASSWORD_ERROR, "password error!");
    }
    // 判断OMC登录权限
    if (type.equals(TypeDefinition.CLIENT_TYPE_OMC)) {
      if (user.getAdminPriv() == 0) {
        throw new BusinessException(
            ErrorCode.USER_ROLE_INVALID, "user [" + user.getLogonName() + "] is not admin");
      }
    }
    // 生成ticket
    String ticket = onlineManager.csLogin(user, type, ip).getTicket();
    // 设置到用户session中
    request.getSession().setAttribute("userId", user.getId());
    request.getSession().setAttribute("userName", user.getName());
    request.getSession().setAttribute("ticket", ticket);
    request.getSession().setAttribute("userGroupId", user.getUserGroupId());

    BaseDTO dto = new BaseDTO();
    dto.setCode(ErrorCode.SUCCESS);
    dto.setMessage("");
    dto.setMethod("UserLogin");

    return dto;
  }
示例#3
0
  public Object loginOut(HttpServletRequest request) {
    SimpleRequestReader reader = new SimpleRequestReader(request);
    Integer kickFlag = reader.getInteger("kickFlag", true);
    String ticket = (String) request.getSession().getAttribute("ticket");
    // kickFlag默认为0正常退出
    if (null == kickFlag) {
      kickFlag = 0;
    }

    OnlineReal onlineReal = onlineManager.getOnlineReal(ticket);
    if (null != onlineReal) {
      if (logger.isDebugEnabled()) {
        logger.debug("Offline Ticket[" + ticket + "]");
      }
      onlineManager.offline(onlineReal, kickFlag);
    }

    BaseDTO dto = new BaseDTO();
    dto.setCode(ErrorCode.SUCCESS);
    dto.setMessage("");
    dto.setMethod("LoginOut");

    return dto;
  }