Package org.lilystudio.ordinary.web

Examples of org.lilystudio.ordinary.web.UserInformation


  private String groupName = "group";

  @SuppressWarnings("unchecked")
  public void execute(IRelay relay) throws Exception {
    // 分组session操作不会自己创建session
    UserInformation info = relay.getUserInformation(false);
    if (info != null) {
      Object group = relay.get(groupName);
      if (group == null) {
        info.setProperty(NAME, null);
      } else if (group.equals("")) {
        group = Long.toString(System.currentTimeMillis());
        info.setProperty(NAME, new HashMap<String, Object>(relay.getDataMap()));
      } else {
        Map<String, Object> tmpData = (Map<String, Object>) info
            .getProperty(NAME);
        if (tmpData == null || !group.equals(tmpData.get(groupName))) {
          throw new GroupException();
        }
        Map<String, Object> data = relay.getDataMap();
View Full Code Here


    private static final long serialVersionUID = 1L;
  }
 
  @Override
  public void execute(IRelay relay, Object value) throws FilterException {
    UserInformation info = relay.getUserInformation(true);
    if (info == null || !value.equals(info.getProperty(ValidateImage.ATTRIBUTE_NAME))) {
      // 没有验证码, 或者验证码不相等将产生异常
      throw new ValidateException();
    } else {
      // 验证成功将清除上次的信息
      info.setProperty(ValidateImage.ATTRIBUTE_NAME, null);
    }
  }
View Full Code Here

        String name = cookie.getName();
        if (!name.equals("JSESSIONID")) {
          s.append(name).append('=').append(cookie.getValue()).append(';');
        }
      }
      UserInformation info = relay.getUserInformation(false);
      if (info != null) {
        Object o = info.getProperty(SESSION_COOKIE_KEY);
        if (o != null) {
          s.append(o);
        }
      }
      int len = s.length();
      if (len > 0) {
        s.setLength(len - 1);
      }
      httpMethod.setRequestHeader("Cookie", s.toString());
    }
    HttpClient httpClient = new HttpClient();
    httpClient.setAutoDecode(true);
    try {
      if (param != null) {
        if (!isGet) {
          PostMethod method = (PostMethod) httpMethod;
          int size = param.size();
          for (int i = 0; i < size; i++) {
            Parameter item = param.get(i);
            Object value = item.getValue(relay);
            method.addRequestBody(item.name, value != null ? URLDecoder.decode(
                value.toString(), encoding) : "");
          }
        }
      }
      while (true) {
        // 计算是否需要跳转
        int statusCode = 0;
        statusCode = httpClient.execute(httpMethod);
        if (statusCode == HttpServletResponse.SC_MOVED_PERMANENTLY
            || statusCode == HttpServletResponse.SC_MOVED_TEMPORARILY) {
          String locationHeader = httpClient.getResponseHeader("Location");
          if (locationHeader != null) {
            httpMethod = new GetMethod(locationHeader);
            continue;
          }
        }
        response.setStatus(statusCode);
        break;
      }

      // 将得到的结果的头部输出
      Map<String, String> headers = httpClient.getResponseHeaders();
      for (Map.Entry<String, String> header : headers.entrySet()) {
        String name = header.getKey();
        String value = header.getValue();
        if (name.equalsIgnoreCase("Set-Cookie")) {
          // 如果返回的cookie中有jsessionid, 为防止冲突,
          // 保存在用户的专属信息中
          int index = value.indexOf("JSESSIONID");
          if (index >= 0) {
            int len = value.length();
            int endIndex = (value.indexOf(';', index + 10) + len) % len + 1;
            String sessionId = value.substring(index, endIndex);
            value = value.substring(0, index) + value.substring(endIndex);
            response.setHeader(name, value);
            UserInformation info = relay.getUserInformation(true);
            info.setProperty("_JSESSIONID", sessionId);
            continue;
          }
        }
        response.setHeader(name, value);
      }
View Full Code Here

TOP

Related Classes of org.lilystudio.ordinary.web.UserInformation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.