带有 PicketLink 的基于 PrimeFaces 的应用程序在登录页面中不显示样式 [英] PrimeFaces based application with PicketLink does not show style in login page

查看:19
本文介绍了带有 PicketLink 的基于 PrimeFaces 的应用程序在登录页面中不显示样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个基于 PrimeFaces 的应用程序,现在我想用 PicketLink 以 CDI 方式保护它.我跟着这个例子 并创建了一个包含多个 PrimeFaces 组件(包括布局)的登录页面).然而,所有样式和功能都丢失了.即使是简化的 login.xhtml 页面(以匹配上面链接的示例)也没有样式.

I developed a PrimeFaces based application that I now want to protect with PicketLink in a CDI way. I followed this example and created a login page with several PrimeFaces components including a layout). All styling and functionality is however lost. Even a simplified login.xhtml page (to match the example linked to above) does not have styling.

<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 应调整为在配置中排除此虚拟文件夹.

The reason the css and js files are not loaded is because the security 'profile' in the original example has all resources protected besides a login.xhtml file. JSF by default loads resources from the 'virtual' javax.faces.resource folder. This needs to be excluded from authentication to. The HttpSecurityConfiguration in the original example should be adapted to exlude this virtual folder in the config.

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");
    }
}

这篇关于带有 PicketLink 的基于 PrimeFaces 的应用程序在登录页面中不显示样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆