PrimeFaces在使用登录表单身份验证时不会呈现 [英] PrimeFaces not rendering when using login form authentication

查看:113
本文介绍了PrimeFaces在使用登录表单身份验证时不会呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的应用程序中创建一个登录名。我正在使用PrimeFaces和Oracle Glassfish 3.1.2。我在Glassfish服务器上的文件领域内创建了一个用户。并使用表单选择身份验证。以下是代码:

登录页面

 <?xml version ='1.0'encoding ='UTF-8'?> 
<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
xmlns:h =http://java.sun.com/jsf/html
xmlns:f =http://java.sun.com/jsf/core
xmlns:ui =http://java.sun.com/jsf/facelets
xmlns:p =http://primefaces.org/ui
xmlns:c =http://java.sun.com/jsp/jstl/core>
< h:头>
< title>测试< /标题>
< / h:头>
< h:body>
< form method =POSTaction =j_security_check>
< h:panelGrid columns =2id =logingridstyle =width:100%;>

< h:outputLabel for =j_usernamevalue =Meno:/>

< h:outputLabel for =j_passwordvalue =Heslo:/>

< f:facet name =footer>
< h:commandButton type =submitvalue =Prihlásstyle =width:100%/>
< / f:facet>
< / h:panelGrid>
< / form>
< / p:面板>
< / h:body>
< / html>

web.xml

 <?xml version =1.0encoding =UTF-8?> 
< web-app version =3.0xmlns =http://java.sun.com/xml/ns/javaeexmlns:xsi =http://www.w3.org/2001/ XMLSchema-instancexsi:schemaLocation =http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd\">
< context-param>
< param-name> javax.faces.PROJECT_STAGE< / param-name>
<参数值>开发< /参数值>
< / context-param>
< servlet>
< servlet-name> Faces Servlet< / servlet-name>
< servlet-class> javax.faces.webapp.FacesServlet< / servlet-class>
<加载启动> 1< /加载启动>
< / servlet>
< servlet-mapping>
< servlet-name> Faces Servlet< / servlet-name>
< url-pattern> / faces / *< / url-pattern>
< / servlet-mapping>
< session-config>
< session-timeout>
30
< / session-timeout>
< / session-config>
< welcome-file-list>
< welcome-file>面临/ secure / temy.xhtml< / welcome-file>
< / welcome-file-list>
< security-constraint>
< display-name> Sec< / display-name>
< web-resource-collection>
< web-resource-name>安全< / web-resource-name>
< description />
< url-pattern> / faces / secure / *< / url-pattern>
< http-method> GET< / http-method>
< http-method> PUT< / http-method>
< http-method> HEAD< / http-method>
< http-method> POST< / http-method>
< http-method> OPTIONS< / http-method>
< http-method> TRACE< / http-method>
< http-method> DELETE< / http-method>
< / web-resource-collection>
< auth-constraint>
< description />
<角色名称> spravcovia< /角色名称>
< / auth-constraint>
< user-data-constraint>
< description />
< transport-guarantee> CONFIDENTIAL< / transport-guarantee>
< / user-data-constraint>
< / security-constraint>
< security-constraint>
< display-name> Pub< / display-name>
< web-resource-collection>
< web-resource-name>公开< / web-resource-name>
< description />
< url-pattern> * .css< / url-pattern>
< url-pattern> *。jpg< / url-pattern>
< url-pattern> * .gif< / url-pattern>
< url-pattern> /error.xhtml< / url-pattern>
< url-pattern> /login.xhtml< / url-pattern>
< http-method> GET< / http-method>
< http-method> PUT< / http-method>
< http-method> HEAD< / http-method>
< http-method> POST< / http-method>
< http-method> OPTIONS< / http-method>
< http-method> TRACE< / http-method>
< http-method> DELETE< / http-method>
< / web-resource-collection>
< user-data-constraint>
< description />
< transport-guarantee> CONFIDENTIAL< / transport-guarantee>
< / user-data-constraint>
< / security-constraint>
< login-config>
< auth-method> FORM< / auth-method>
< realm-name> dbrealm< / realm-name>
< form-login-config>
< form-login-page> /login.xhtml< / form-login-page>
< form-error-page> /error.xhtml< / form-error-page>
< / form-login-config>
< / login-config>
< security-role>
< description />
<角色名称> spravcovia< /角色名称>
< / security-role>
< / web-app>

glassfish-web.xml

 <?xml version =1.0encoding =UTF-8?> 
<!DOCTYPE glassfish-web-app PUBLIC - // GlassFish.org //DTD GlassFish Application Server 3.1 Servlet 3.0 // ENhttp://glassfish.org/dtds/glassfish-web-app_3_0 -1.dtd>
< glassfish-web-app error-url =>
< security-role-mapping>
<角色名称> spravcovia< /角色名称>
< group-name> spravcovia< / group-name>
< / security-role-mapping>
< class-loader delegate =true/>
< jsp-config>
< property name =keepgeneratedvalue =true>
< description>保存生成的servlet类'java代码的副本。< / description>
< / property>
< / jsp-config>
< / glassfish-web-app>

事实是,当我不使用Primefaces标签或jsf标签进行输入时,类型的输入,它工作正常:

 用户名:< input type ='text'name ='j_username'/> 
密码:< input type ='password'name ='j_password'/>

我想如果通过blokcking / *我没有阻止使用primefaces,但我没有知道如何启用它。



更新:
我更新了web.xml和glassfish-web.xml。这里也是我的项目目录(NetBeans)。在WEB-INF中,只有glassfish-web.xml和web.xml:


解决方案

您的问题是,当用户未登录时,那么即使用户没有登录,也应该让CSS,JavaScript ...等资源得到处理。为此,请在web.xml中添加此部分:

 < security-constraint> 
< web-resource-collection>
< web-resource-name>公开< / web-resource-name>
< url-pattern> * .css< / url-pattern>
< url-pattern> *。jpg< / url-pattern>
< url-pattern> * .gif< / url-pattern>
< url-pattern> /javax.faces.resource / *< / url-pattern>
< / web-resource-collection>
< / security-constraint>


I'm trying to create a login into my application. I'm using PrimeFaces and Oracle Glassfish 3.1.2. I have created a user inside a file realm on Glassfish server. And selected authentication using form. Here is the code:

Login page:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui" 
      xmlns:c="http://java.sun.com/jsp/jstl/core">
    <h:head>
        <title>Test</title>
    </h:head>
    <h:body>    
            <p:panel header="Prihlásenie" style="width: 300px; margin-left: auto; margin-right: auto;">
                <form method="POST" action="j_security_check">
                    <h:panelGrid columns="2" id="logingrid" style="width: 100%;">

                        <h:outputLabel for="j_username" value="Meno:" />
                        <p:inputText id="j_username" required="true" label="j_username" style="width: 100%;"/>

                        <h:outputLabel for="j_password" value="Heslo:" />   
                        <p:password id="j_password" label="Heslo" required="true" style="width: 100%;"/>

                        <f:facet name="footer">
                            <h:commandButton type="submit" value="Prihlás" style="width: 100%"/>
                        </f:facet>
                    </h:panelGrid>
                </form>
            </p:panel>
    </h:body>
</html>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>faces/secure/temy.xhtml</welcome-file>
    </welcome-file-list>
    <security-constraint>
        <display-name>Sec</display-name>
        <web-resource-collection>
            <web-resource-name>Secure</web-resource-name>
            <description/>
            <url-pattern>/faces/secure/*</url-pattern>
            <http-method>GET</http-method>
            <http-method>PUT</http-method>
            <http-method>HEAD</http-method>
            <http-method>POST</http-method>
            <http-method>OPTIONS</http-method>
            <http-method>TRACE</http-method>
            <http-method>DELETE</http-method>
        </web-resource-collection>
        <auth-constraint>
            <description/>
            <role-name>spravcovia</role-name>
        </auth-constraint>
        <user-data-constraint>
            <description/>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>
    <security-constraint>
        <display-name>Pub</display-name>
        <web-resource-collection>
            <web-resource-name>Public</web-resource-name>
            <description/>
            <url-pattern>*.css</url-pattern>
            <url-pattern>*.jpg</url-pattern>
            <url-pattern>*.gif</url-pattern>
            <url-pattern>/error.xhtml</url-pattern>
            <url-pattern>/login.xhtml</url-pattern>
            <http-method>GET</http-method>
            <http-method>PUT</http-method>
            <http-method>HEAD</http-method>
            <http-method>POST</http-method>
            <http-method>OPTIONS</http-method>
            <http-method>TRACE</http-method>
            <http-method>DELETE</http-method>
        </web-resource-collection>
        <user-data-constraint>
            <description/>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>
    <login-config>
        <auth-method>FORM</auth-method>
        <realm-name>dbrealm</realm-name>
        <form-login-config>
            <form-login-page>/login.xhtml</form-login-page>
            <form-error-page>/error.xhtml</form-error-page>
        </form-login-config>
    </login-config>
    <security-role>
        <description/>
        <role-name>spravcovia</role-name>
    </security-role>
</web-app>

glassfish-web.xml

  <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
  <security-role-mapping>
    <role-name>spravcovia</role-name>
    <group-name>spravcovia</group-name>
  </security-role-mapping>
  <class-loader delegate="true"/>
  <jsp-config>
    <property name="keepgenerated" value="true">
      <description>Keep a copy of the generated servlet class' java code.</description>
    </property>
  </jsp-config>
</glassfish-web-app>

The fact is that when I don't use Primefaces tags or jsf tags for input, but only this kinds of inputs, it works fine:

Username: <input type='text' name='j_username' />
Password: <input type='password' name='j_password' />

I thought if by blokcking /* I did not block the use of primefaces, but I don't know how to enable it.

UPDATE: I've updated web.xml and glassfish-web.xml . And here is also my project directory (NetBeans). In WEB-INF there is only glassfish-web.xml and web.xml:

解决方案

Your problem is you are blocking all resources when user is not logged in, you should let resources like CSS, JavaScript... to be processed even if user is not logged in. To do this add this part in your web.xml:

<security-constraint>
  <web-resource-collection>
    <web-resource-name>Public</web-resource-name>
    <url-pattern>*.css</url-pattern>
    <url-pattern>*.jpg</url-pattern>
    <url-pattern>*.gif</url-pattern>
    <url-pattern>/javax.faces.resource/*</url-pattern>
  </web-resource-collection>
</security-constraint>

这篇关于PrimeFaces在使用登录表单身份验证时不会呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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