コード例 #1
0
 public IRequestHandler mapRequest(final Request request) {
   final Url url = this.decryptUrl(request, request.getUrl());
   if (url == null) {
     return this.wrappedMapper.mapRequest(request);
   }
   return this.wrappedMapper.mapRequest(request.cloneWithUrl(url));
 }
コード例 #2
0
 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;
 }