Exemplo n.º 1
0
 @Override
 public String getUrl(
     String path, Map<String, ?> parameters, Parameters frameworkParameters, boolean escapeAmps)
     throws FrameworkException {
   Url link = urlConverter.getUrl(path, parameters, frameworkParameters, escapeAmps);
   log.debug("got " + link + " from " + urlConverter);
   if (link == Url.NOT) {
     return fallbackConverter.getUrl(path, parameters, frameworkParameters, escapeAmps).getUrl();
   } else {
     return link.getUrl();
   }
 }
Exemplo n.º 2
0
 @Override
 public String getProcessUrl(
     String path, Map<String, ?> parameters, Parameters frameworkParameters, boolean escapeAmps)
     throws FrameworkException {
   HttpServletRequest request =
       BasicUrlConverter.getUserRequest(frameworkParameters.get(Parameter.REQUEST));
   State state = State.getState(request);
   frameworkParameters.set(ACTION, state.getId());
   Url url = urlConverter.getProcessUrl(path, parameters, frameworkParameters, escapeAmps);
   if (url == Url.NOT) {
     log.debug("Fall back url");
     return fallbackConverter
         .getProcessUrl(path, parameters, frameworkParameters, escapeAmps)
         .getUrl();
   } else {
     log.debug("Url converter url " + url);
     return url.getUrl();
   }
 }
 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;
 }
Exemplo n.º 4
0
  /**
   * Create a pattern for text parsing
   *
   * @param pattern pattern definition
   * @return pattern pattern
   */
  private ProcPattern createPattern(Pattern pattern) {
    if (pattern.getElements() == null || pattern.getElements().isEmpty()) {
      throw new IllegalStateException("Pattern elements list can't be empty.");
    }

    List<ProcPatternElement> elements = new ArrayList<ProcPatternElement>();
    for (PatternElement element : pattern.getElements()) {
      if (element instanceof Variable) {
        Variable variable = (Variable) element;
        if (variable.getAction() != Action.check) {
          elements.add(
              new ProcVariable(
                  variable.getName(),
                  variable.getRegex(),
                  variable.isGhost(),
                  variable.getAction()));
        } else {
          elements.add(new Check(variable.getName(), variable.isGhost()));
        }
      } else if (element instanceof Text) {
        elements.add(create((Text) element));
      } else if (element instanceof Constant) {
        elements.add(createPatternConstant((Constant) element));
      } else if (element instanceof Junk) {
        elements.add(JUNK);
      } else if (element instanceof Eol) {
        elements.add(new ProcEol(((Eol) element).isGhost()));
      } else if (element instanceof Bol) {
        elements.add(PROC_BOL);
      } else if (element instanceof BlankLine) {
        elements.add(new ProcBlankLine(((BlankLine) element).isGhost()));
      } else if (element instanceof Url) {
        Url url = (Url) element;
        elements.add(new ProcUrl(url.getName(), url.isGhost(), url.isLocal(), url.isSchemaless()));
      }
    }
    return new ProcPattern(elements);
  }
 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;
 }