private static String md5Hex(String a2) {
   try {
     return DigestUtils.md5DigestAsHex(a2.getBytes("UTF-8"));
   } catch (UnsupportedEncodingException e) {
     throw new RuntimeException(e);
   }
 }
コード例 #2
0
        @Override
        public void handle(ServerHttpRequest request, ServerHttpResponse response)
            throws IOException {

          if (!HttpMethod.GET.equals(request.getMethod())) {
            sendMethodNotAllowed(response, Arrays.asList(HttpMethod.GET));
            return;
          }

          String content = String.format(IFRAME_CONTENT, getSockJsClientLibraryUrl());
          byte[] contentBytes = content.getBytes(Charset.forName("UTF-8"));
          StringBuilder builder = new StringBuilder("\"0");
          DigestUtils.appendMd5DigestAsHex(contentBytes, builder);
          builder.append('"');
          String etagValue = builder.toString();

          List<String> ifNoneMatch = request.getHeaders().getIfNoneMatch();
          if (!CollectionUtils.isEmpty(ifNoneMatch) && ifNoneMatch.get(0).equals(etagValue)) {
            response.setStatusCode(HttpStatus.NOT_MODIFIED);
            return;
          }

          response
              .getHeaders()
              .setContentType(new MediaType("text", "html", Charset.forName("UTF-8")));
          response.getHeaders().setContentLength(contentBytes.length);

          addCacheHeaders(response);
          response.getHeaders().setETag(etagValue);
          response.getBody().write(contentBytes);
        }
コード例 #3
0
  private ModelAndView authenticateHelper(ModelAndView mav) {
    boolean authenticated = userService.isAuthenticated();
    mav.addObject("auth", authenticated);

    if (authenticated) {
      LOGGER.debug("User={} is authenticated", userService.getUser());
      mav.setViewName("settings");
      mav.addObject("template", "settings");

      mav.addObject("user", userService.getUser());
      mav.addObject(
          "gravatar", DigestUtils.md5DigestAsHex(userService.getUser().getEmail().getBytes()));
    }
    return mav;
  }
コード例 #4
0
ファイル: AddBalanceAction.java プロジェクト: tcbbd/Web-Store
 public String execute() throws Exception {
   errorInfo = "";
   if (!(Boolean) ServletActionContext.getRequest().getSession().getAttribute("isLogin"))
     return "index";
   if (number == null || password == null) return "this";
   User user = (User) ServletActionContext.getRequest().getSession().getAttribute("user");
   if (!user.getPassword().equals(DigestUtils.md5DigestAsHex(password.getBytes()))) {
     errorInfo = "ÃÜÂë´íÎó£¬ÇëÖØÊÔ";
     number = password = null;
     return "this";
   }
   int balance = Integer.parseInt(number) + user.getBalance();
   user.setBalance(balance);
   userService.update(user);
   number = password = null;
   return "success";
 }
コード例 #5
0
 public String encrypt(String username, String password) {
   return DigestUtils.md5DigestAsHex((username + "_._" + password).getBytes());
 }