jsf-2 - 具有 PicketLink 的基于 PrimeFaces 的应用程序不会在登录页面中显示样式

标签 jsf-2 primefaces picketlink

我开发了一个基于 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/

相关文章:

ajax - JSF Ajax 渲染丢失 CSS 与 Jquery Mobile

java - Tomcat 7 生命周期监听器

java - JSF 输出脚本和 JavaScript 未被 EL 解析?

java - @PicketLink 注释类未在 identity.login() 中使用

java - 无法安装 Picketlink Forge 插件 JBoss

javascript - *在* ajax更新后执行Javascript

java - 使用 PrimeFaces 动态生成标签

JSF:使用 ajax 清除 inputTextArea 时出现奇怪的行为

java - 如何通过鼠标悬停和鼠标悬停向按钮添加图像?

java - 纠察线中 Arquillian 未满足的依赖关系