Exemplo n.º 1
0
  public void set(
      final Request request, final Response response, final String key, final String value) {
    String prefString = cookieUtils.load(PREFMAN_KEY);

    final Map<String, String> current = new HashMap<>();
    if (prefString != null) {
      current.putAll(getPrefs(new String(Base64.decodeBase64(prefString.getBytes()))));
    }

    // after retrieved previous setting in order to overwrite the key ...
    current.put(key, value);

    try {
      cookieUtils.save(PREFMAN_KEY, new String(Base64.encodeBase64(setPrefs(current).getBytes())));
    } catch (IOException e) {
      LOG.error("Could not save {} info: {}", getClass().getSimpleName(), current, e);
    }
  }
Exemplo n.º 2
0
  public void set(
      final Request request, final Response response, final Map<String, List<String>> prefs) {
    Map<String, String> current = new HashMap<>();

    String prefString = cookieUtils.load(PREFMAN_KEY);
    if (prefString != null) {
      current.putAll(getPrefs(new String(Base64.decodeBase64(prefString.getBytes()))));
    }

    // after retrieved previous setting in order to overwrite the key ...
    for (Map.Entry<String, List<String>> entry : prefs.entrySet()) {
      current.put(entry.getKey(), StringUtils.join(entry.getValue(), ";"));
    }

    try {
      cookieUtils.save(PREFMAN_KEY, new String(Base64.encodeBase64(setPrefs(current).getBytes())));
    } catch (IOException e) {
      LOG.error("Could not save {} info: {}", getClass().getSimpleName(), current, e);
    }
  }
Exemplo n.º 3
0
  /**
   * Encodes binary data using the base64 algorithm, optionally chunking the output into 76
   * character blocks.
   *
   * @param binaryData Array containing binary data to encode.
   * @param isChunked if <code>true</code> this encoder will chunk the base64 output into 76
   *     character blocks
   * @param urlSafe if <code>true</code> this encoder will emit - and _ instead of the usual + and /
   *     characters.
   * @param maxResultSize The maximum result size to accept.
   * @return Base64-encoded data.
   * @throws IllegalArgumentException Thrown when the input array needs an output array bigger than
   *     maxResultSize
   * @since 1.4
   */
  public static byte[] encodeBase64(
      final byte[] binaryData,
      final boolean isChunked,
      final boolean urlSafe,
      final int maxResultSize) {
    if ((binaryData == null) || (binaryData.length == 0)) {
      return binaryData;
    }

    long len = getEncodeLength(binaryData, CHUNK_SIZE, CHUNK_SEPARATOR);
    if (len > maxResultSize) {
      throw new IllegalArgumentException(
          "Input array too big, the output array would be bigger ("
              + len
              + ") than the specified maxium size of "
              + maxResultSize);
    }

    Base64 b64 = isChunked ? new Base64(urlSafe) : new Base64(0, CHUNK_SEPARATOR, urlSafe);
    return b64.encode(binaryData);
  }
Exemplo n.º 4
0
  public String get(final Request request, final String key) {
    String result = null;

    String prefString = cookieUtils.load(PREFMAN_KEY);
    if (prefString != null) {
      final Map<String, String> prefs =
          getPrefs(new String(Base64.decodeBase64(prefString.getBytes())));
      result = prefs.get(key);
    }

    return result;
  }
  private Url encodeSharedResourceUrl(Url url) {
    if (url != null) {
      Request request = RequestCycle.get().getRequest();

      StringBuilder urlBuilder = new StringBuilder();
      urlBuilder.append(request.getContextPath());
      urlBuilder.append(request.getFilterPath());
      urlBuilder.append(PortletFilter.SHARED_RESOURCE_URL_PORTLET_WINDOW_ID_PREFIX);
      urlBuilder.append(
          Base64.encodeBase64URLSafeString(ThreadPortletContext.getWindowID().getBytes()));
      urlBuilder.append('/');
      urlBuilder.append(url.toString());

      url = Url.parse(urlBuilder.toString());
    }

    return url;
  }