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

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

问题描述

我开发了一个基于PrimeFaces的应用程序,现在我想用CDI方式用PicketLink保护它.我遵循了此示例,并创建包含多个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天全站免登陆