2

我开发了一个基于 PrimeFaces 的应用程序,现在我想用 PicketLink 以 CDI 方式保护它。我按照这个示例创建了一个包含多个 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>
4

1 回答 1

4

未加载 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");
    }
}
于 2015-02-06T19:20:27.347 回答