use of org.apache.knox.gateway.util.urltemplate.Template in project knox by apache.
the class UrlRewriteRequest method getTargetUrl.
// Note: Source url was added to the request attributes by the GatewayFilter doFilter method.
private Template getTargetUrl() {
boolean rewriteRequestUrl = true;
Template targetUrl;
if (rewriteRequestUrl) {
targetUrl = (Template) getAttribute(AbstractGatewayFilter.TARGET_REQUEST_URL_ATTRIBUTE_NAME);
if (targetUrl == null) {
Template sourceUrl = getSourceUrl();
targetUrl = rewriter.rewrite(this, sourceUrl, UrlRewriter.Direction.IN, urlRuleName);
setAttribute(AbstractGatewayFilter.TARGET_REQUEST_URL_ATTRIBUTE_NAME, targetUrl);
}
} else {
targetUrl = (Template) getAttribute(AbstractGatewayFilter.SOURCE_REQUEST_URL_ATTRIBUTE_NAME);
}
return targetUrl;
}
use of org.apache.knox.gateway.util.urltemplate.Template in project knox by apache.
the class FormUrlRewriteFilterReader method filterValue.
// TODO: Need to limit which values are attempted to be filtered by the name.
@Override
protected String filterValue(String name, String value, String rule) {
try {
Template input = Parser.parseLiteral(value);
Template output = rewriter.rewrite(resolver, input, direction, rule);
value = output.getPattern();
} catch (URISyntaxException e) {
LOG.failedToParseValueForUrlRewrite(value);
}
return value;
}
use of org.apache.knox.gateway.util.urltemplate.Template in project knox by apache.
the class HtmlUrlRewriteFilterReader method filterValueString.
// TODO: Need to limit which values are attempted to be filtered by the name.
@Override
public String filterValueString(String name, String value, String rule) {
try {
Template input = Parser.parseLiteral(value);
Template output = rewriter.rewrite(resolver, input, direction, rule);
if (output != null) {
value = output.getPattern();
}
} catch (URISyntaxException e) {
LOG.failedToParseValueForUrlRewrite(value);
}
return value;
}
use of org.apache.knox.gateway.util.urltemplate.Template in project knox by apache.
the class SecureQueryDecodeProcessorTest method testSimpleQueryDecode.
@Test
public void testSimpleQueryDecode() throws Exception {
UrlRewriteEnvironment environment = new UrlRewriteEnvironment() {
@Override
public URL getResource(String name) throws IOException {
return null;
}
@Override
public <T> T getAttribute(String name) {
return null;
}
@Override
public List<String> resolve(String name) {
return null;
}
};
BASE64Encoder encoder = new BASE64Encoder();
String encQuery = encoder.encode("test-query".getBytes("utf-8"));
encQuery = encQuery.replaceAll("\\=", "");
String inString = "http://host:0/root/path?_=" + encQuery;
Template inTemplate = Parser.parseLiteral(inString);
UrlRewriteContext context = EasyMock.createNiceMock(UrlRewriteContext.class);
EasyMock.expect(context.getCurrentUrl()).andReturn(inTemplate);
Capture<Template> outTemplate = new Capture<Template>();
context.setCurrentUrl(EasyMock.capture(outTemplate));
EasyMock.replay(context);
SecureQueryDecodeDescriptor descriptor = new SecureQueryDecodeDescriptor();
SecureQueryDecodeProcessor processor = new SecureQueryDecodeProcessor();
processor.initialize(environment, descriptor);
processor.process(context);
String outActual = outTemplate.getValue().toString();
assertThat(outActual, is("http://host:0/root/path?test-query"));
}
use of org.apache.knox.gateway.util.urltemplate.Template in project knox by apache.
the class SecureQueryDecodeProcessorTest method testDecodeQueryWithNonEncodedParams.
@Test
public void testDecodeQueryWithNonEncodedParams() throws Exception {
UrlRewriteEnvironment environment = new UrlRewriteEnvironment() {
@Override
public URL getResource(String name) throws IOException {
return null;
}
@Override
public <T> T getAttribute(String name) {
return null;
}
@Override
public List<String> resolve(String name) {
return null;
}
};
BASE64Encoder encoder = new BASE64Encoder();
String inQuery = "test-query=test-value";
String encQuery = encoder.encode(inQuery.getBytes("utf-8"));
encQuery = encQuery.replaceAll("\\=", "");
String inString = "http://host:0/root/path?_=" + encQuery + "&clear-param=clear-value";
Template inTemplate = Parser.parseLiteral(inString);
UrlRewriteContext context = EasyMock.createNiceMock(UrlRewriteContext.class);
EasyMock.expect(context.getCurrentUrl()).andReturn(inTemplate);
Capture<Template> outTemplate = new Capture<Template>();
context.setCurrentUrl(EasyMock.capture(outTemplate));
EasyMock.replay(context);
SecureQueryDecodeDescriptor descriptor = new SecureQueryDecodeDescriptor();
SecureQueryDecodeProcessor processor = new SecureQueryDecodeProcessor();
processor.initialize(environment, descriptor);
processor.process(context);
String outActual = outTemplate.getValue().toString();
assertThat(outActual, containsString("http://host:0/root/path?"));
assertThat(outActual, containsString("test-query=test-value"));
assertThat(outActual, containsString("clear-param=clear-value"));
assertThat(outActual, not(containsString(encQuery)));
}
Aggregations