我試圖創建一個登錄到我的應用程序。我正在使用PrimeFaces和Oracle Glassfish 3.1.2。我在Glassfish服務器上的文件領域內創建了一個用戶。並使用表單選擇身份驗證。下面是代碼:使用登錄表單身份驗證時不會呈現PrimeFaces
登錄頁面:
<?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>
事實是,當我不使用Primefaces標籤或JSF標籤輸入,但僅此類型的輸入,它工作正常:
Username: <input type='text' name='j_username' />
Password: <input type='password' name='j_password' />
我想如果blokcking/*我沒有阻止使用primefaces的,但我不知道如何啓用它。
更新: 我更新了web.xml和glassfish-web.xml。這裏也是我的項目目錄(NetBeans)。在WEB-INF只有與GlassFish的web.xml和web.xml:
在添加此聲明後,它是一樣的。我不應該修改限制我將特權撤銷到/ *嗎? – Reshi
確實,你不應該使用'/ *'作爲你想要保護的url。提供您想要保護的所有url模式**不包括您登錄所需的資源(css,jpg等) – phoenix7360
我建議您在'/ *'位置添加'* .xhtml'' – partlov