Search in sources :

Example 1 with Builder

use of org.apache.knox.gateway.util.urltemplate.Builder in project knox by apache.

the class SecureQueryDecodeProcessor method process.

@Override
public UrlRewriteStepStatus process(UrlRewriteContext context) throws Exception {
    // TODO: Need some way to get a reference to the keystore service and the encryption key in particular.
    Template currUrl = context.getCurrentUrl();
    Builder newUrl = new Builder(currUrl);
    Map<String, Query> map = newUrl.getQuery();
    Query query = map.remove(ENCODED_PARAMETER_NAME);
    if (query != null) {
        String value = query.getFirstValue().getPattern();
        value = decode(value);
        StringTokenizer outerParser = new StringTokenizer(value, "&");
        while (outerParser.hasMoreTokens()) {
            String pair = outerParser.nextToken();
            StringTokenizer innerParser = new StringTokenizer(pair, "=");
            if (innerParser.hasMoreTokens()) {
                String paramName = innerParser.nextToken();
                if (innerParser.hasMoreTokens()) {
                    String paramValue = innerParser.nextToken();
                    // Need to take out any existing query param.
                    // If we don't then someone could override something in the encoded param.
                    map.remove(paramName);
                    newUrl.addQuery(paramName, "", paramValue, true);
                } else {
                    newUrl.addQuery(paramName, "", null, true);
                }
            }
        }
        context.setCurrentUrl(newUrl.build());
    }
    return UrlRewriteStepStatus.SUCCESS;
}
Also used : StringTokenizer(java.util.StringTokenizer) Query(org.apache.knox.gateway.util.urltemplate.Query) Builder(org.apache.knox.gateway.util.urltemplate.Builder) Template(org.apache.knox.gateway.util.urltemplate.Template)

Example 2 with Builder

use of org.apache.knox.gateway.util.urltemplate.Builder in project knox by apache.

the class SecureQueryDecryptProcessor method process.

@Override
public UrlRewriteStepStatus process(UrlRewriteContext context) throws Exception {
    // TODO: Need some way to get a reference to the keystore service and the encryption key in particular.
    Template currUrl = context.getCurrentUrl();
    Builder newUrl = new Builder(currUrl);
    Map<String, Query> map = newUrl.getQuery();
    Query query = map.remove(ENCRYPTED_PARAMETER_NAME);
    UrlRewriteStepStatus status = UrlRewriteStepStatus.FAILURE;
    status = getUrlRewriteStepStatus(context, newUrl, map, query, status);
    return status;
}
Also used : UrlRewriteStepStatus(org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteStepStatus) Query(org.apache.knox.gateway.util.urltemplate.Query) Builder(org.apache.knox.gateway.util.urltemplate.Builder) Template(org.apache.knox.gateway.util.urltemplate.Template)

Aggregations

Builder (org.apache.knox.gateway.util.urltemplate.Builder)2 Query (org.apache.knox.gateway.util.urltemplate.Query)2 Template (org.apache.knox.gateway.util.urltemplate.Template)2 StringTokenizer (java.util.StringTokenizer)1 UrlRewriteStepStatus (org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteStepStatus)1