private Url decryptUrl(final Request request, final Url encryptedUrl) { if (encryptedUrl.getSegments().isEmpty()) { return encryptedUrl; } List<String> encryptedSegments = encryptedUrl.getSegments(); if (encryptedSegments.size() < 1) { return null; } Url url = new Url(request.getCharset()); try { String encryptedUrlString = encryptedSegments.get(0); if (Strings.isEmpty(encryptedUrlString)) { return null; } String decryptedUrl = getCrypt().decryptUrlSafe(encryptedUrlString); if (decryptedUrl == null) { return null; } Url originalUrl = Url.parse(decryptedUrl, request.getCharset()); int originalNumberOfSegments = originalUrl.getSegments().size(); int encryptedNumberOfSegments = encryptedUrl.getSegments().size(); HashedSegmentGenerator generator = new HashedSegmentGenerator(encryptedUrlString); int segNo = 1; for (; segNo < encryptedNumberOfSegments; segNo++) { if (segNo > originalNumberOfSegments) { break; } String next = generator.next(); String encryptedSegment = encryptedSegments.get(segNo); if (!next.equals(encryptedSegment)) { break; } // unmodified segment url.getSegments().add(originalUrl.getSegments().get(segNo - 1)); } for (; segNo < encryptedNumberOfSegments; segNo++) { // modified or additional segment url.getSegments().add(encryptedUrl.getSegments().get(segNo)); } url.getQueryParameters().addAll(originalUrl.getQueryParameters()); } catch (Exception e) { log.error("Error decrypting URL", e); url = null; } return url; }
private Url decryptUrl(final Request request, final Url encryptedUrl) { if (encryptedUrl.getSegments().isEmpty()) { return encryptedUrl; } final List<String> encryptedSegments = (List<String>) encryptedUrl.getSegments(); if (encryptedSegments.size() < 1) { return null; } Url url = new Url(request.getCharset()); try { final String encryptedUrlString = (String) encryptedSegments.get(0); if (Strings.isEmpty((CharSequence) encryptedUrlString)) { return null; } final String decryptedUrl = this.getCrypt().decryptUrlSafe(encryptedUrlString); if (decryptedUrl == null) { return null; } final Url originalUrl = Url.parse(decryptedUrl, request.getCharset()); final int originalNumberOfSegments = originalUrl.getSegments().size(); final int encryptedNumberOfSegments = encryptedUrl.getSegments().size(); final HashedSegmentGenerator generator = new HashedSegmentGenerator(encryptedUrlString); int segNo; for (segNo = 1; segNo < encryptedNumberOfSegments; ++segNo) { if (segNo > originalNumberOfSegments) { break; } final String next = generator.next(); final String encryptedSegment = (String) encryptedSegments.get(segNo); if (!next.equals(encryptedSegment)) { break; } url.getSegments().add(originalUrl.getSegments().get(segNo - 1)); } while (segNo < encryptedNumberOfSegments) { url.getSegments().add(encryptedUrl.getSegments().get(segNo)); ++segNo; } url.getQueryParameters().addAll(originalUrl.getQueryParameters()); } catch (Exception e) { CryptoMapper.log.error("Error decrypting URL", e); url = null; } return url; }
protected void encodePageComponentInfo(Url url, PageComponentInfo info) { Args.notNull(url, "url"); if (info != null && Session.exists() && !Session.get().isSessionInvalidated()) { String s = info.toString(); if (!Strings.isEmpty(s)) { QueryParameter parameter = new QueryParameter(s, ""); url.getQueryParameters().add(parameter); } } }
private Url encryptUrl(final Url url) { if (url.getSegments().isEmpty() && url.getQueryParameters().isEmpty()) { return url; } final String encryptedUrlString = this.getCrypt().encryptUrlSafe(url.toString()); final Url encryptedUrl = new Url(url.getCharset()); encryptedUrl.getSegments().add(encryptedUrlString); final int numberOfSegments = url.getSegments().size(); final HashedSegmentGenerator generator = new HashedSegmentGenerator(encryptedUrlString); for (int segNo = 0; segNo < numberOfSegments; ++segNo) { encryptedUrl.getSegments().add(generator.next()); } return encryptedUrl; }
/** * @see * org.apache.wicket.request.mapper.parameter.IPageParametersEncoder#encodePageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) */ public Url encodePageParameters(final PageParameters pageParameters) { Url url = new Url(); for (int i = 0; i < pageParameters.getIndexedCount(); ++i) { url.getSegments().add(pageParameters.get(i).toString()); } for (PageParameters.NamedPair pair : pageParameters.getAllNamed()) { QueryParameter param = new QueryParameter(pair.getKey(), pair.getValue()); url.getQueryParameters().add(param); } return url; }
/** * Extracts the {@link PageComponentInfo} from the URL. The {@link PageComponentInfo} is encoded * as the very first query parameter and the parameter consists of name only (no value). * * @param url * @return PageComponentInfo instance if one was encoded in URL, <code>null</code> otherwise. */ protected PageComponentInfo getPageComponentInfo(final Url url) { if (url == null) { throw new IllegalStateException("Argument 'url' may not be null."); } else { for (QueryParameter queryParameter : url.getQueryParameters()) { if (Strings.isEmpty(queryParameter.getValue())) { PageComponentInfo pageComponentInfo = PageComponentInfo.parse(queryParameter.getName()); if (pageComponentInfo != null) { return pageComponentInfo; } } } } return null; }
private BrixPageParameters createBrixPageParams(Url url, Path path) { BrixPageParameters parameters = new BrixPageParameters(); Path nodePath = path; Path requestPath = new Path("/" + url.getPath()); if (nodePath.isAncestorOf(requestPath)) { Path remaining = new Path(requestPath.toString(), false).toRelative(nodePath); int i = 0; for (String s : remaining) { parameters.set(i, BrixNodePageUrlMapper.urlDecode(s)); ++i; } } for (QueryParameter parameter : url.getQueryParameters()) { String parameterName = parameter.getName(); if (PageComponentInfo.parse(parameterName) == null) { parameters.add(parameterName, parameter.getValue()); } } return parameters; }