使用PicketLink的基于PrimeFaces的应用程序不会在登录页面中显示样式

时间:2015-02-06 19:20:27

标签: jsf-2 primefaces picketlink

我开发了一个基于PrimeFaces的应用程序,我现在想用CDI方式用PicketLink保护它。我跟着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>

1 个答案:

答案 0 :(得分:3)

未加载css和js文件的原因是因为安全性&#39;配置文件&#39;在原始示例中,除了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");
    }
}