2013-04-02 59 views
1

我试图创建一个登录到我的应用程序。我正在使用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:

Project directory structure

回答

4

你的问题是你阻止所有的资源时,不登录的用户,你应该让资源,如CSS,JavaScript的。 ..,即使用户没有登录处理要做到这一点在你的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> 
+0

在添加此声明后,它是一样的。我不应该修改限制我将特权撤销到/ *吗? – Reshi

+0

确实,你不应该使用'/ *'作为你想要保护的url。提供您想要保护的所有url模式**不包括您登录所需的资源(css,jpg等) – phoenix7360

+0

我建议您在'/ *'位置添加'* .xhtml'' – partlov