我开发了一个基于 PrimeFaces 的应用程序,现在我想使用 PicketLink 以 CDI 方式对其进行保护。我关注了this example并创建了一个包含多个 PrimeFaces 组件(包括布局)的登录页面。然而,所有样式和功能都丢失了。即使是简化的 login.xhtml 页面(以匹配上面链接的示例)也没有样式。
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head/>
<h:body>
<p:panel>
<h:form method="POST" prependId="false">
<p:inputText id="j_username" />
<p:password id="j_password"/>
<p:commandButton id="login" value="Login" action="#{identity.login()}" ajax="false"/>
</h:form>
</p:panel>
<p>Tip: you can login with a username/password of jane/abcd1234.</p>
</h:body>
</html>
最佳答案
CSS 和 js 文件未加载的原因是原始示例中的安全“配置文件”除了 login.xhtml 文件之外还对所有资源进行了保护。默认情况下,JSF 从“虚拟”javax.faces.resource
文件夹加载资源。这需要从身份验证中排除。应调整原始示例中的 HttpSecurityConfiguration 以在配置中排除此虚拟文件夹。
public class HttpSecurityConfiguration {
public void onInit(@Observes SecurityConfigurationEvent event) {
SecurityConfigurationBuilder builder = event.getBuilder();
builder
.http()
.forPath("/javax.faces.resource/*")
.unprotected()
.forPath("/index.jsf")
.unprotected()
.allPaths()
.authenticateWith()
.form()
.authenticationUri("/login.jsf")
.loginPage("/login.jsf")
.errorPage("/error.jsf")
.restoreOriginalRequest()
.forPath("/logout")
.logout()
.redirectTo("/index.jsf");
}
}
关于jsf-2 - 具有 PicketLink 的基于 PrimeFaces 的应用程序不会在登录页面中显示样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28373178/