我想在请求http url时强制使用https url。我在prettyfaces论坛中找到了this。但是此代码会给出cannot find symbol
错误。我该如何解决?
return ConfigurationBuilder.begin()
.addRule()
.when(URL.captureIn("url").and(Path.matches("/login")).and(Scheme.matches("http")))
.perform(Redirect.permanent(URL.capturedWith("url").toScheme("https")));
答案 0 :(得分:1)
尝试使用参数“换位”:
return ConfigurationBuilder.begin()
.addRule()
.when(URL.captureIn("url").and(Path.matches("/login")).and(Scheme.matches("http")))
.perform(Redirect.permanent("{url}"))
.where("url").transposedBy(new Transposition() { ... convert to HTTPS HERE ... });
您还可以通过自定义操作执行以下操作来实现相同的目的:
public class SchemeChangeConfigurationProvider extends HttpConfigurationProvider
{
@Override
public int priority()
{
return 0;
}
@Override
public Configuration getConfiguration(final ServletContext context)
{
Configuration config = ConfigurationBuilder.begin()
.addRule().when(Scheme.matches("http")).perform(new HttpOperation() {
@Override
public void performHttp(HttpServletRewrite event, EvaluationContext context)
{
String url = event.getRequest().getRequestURL().toString().replaceFirst("http", "https");
Redirect.temporary(url).perform(event, context);
}
});
return config;
}
}