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;
}
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;
}
Aggregations