【问题标题】:Glassfish Realm Netbeans 8.0.2 Glassfish 4.1Glassfish 领域 Netbeans 8.0.2 Glassfish 4.1
【发布时间】:2015-01-22 16:10:16
【问题描述】:

我正在开发一个 Web 应用程序,试图保护登录用户对 JSP 的访问我决定使用 glassfish 领域我从互联网上做了很多教程,但问题总是一样的。

我无法登录,是不是因为大部分教程都是用 glassfish 3.x 的?

我在这里看到过类似的帖子,但没有人给出答案

<?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">
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <security-constraint>
        <display-name>admin</display-name>
        <web-resource-collection>
            <web-resource-name>prywatne</web-resource-name>
            <description/>
            <url-pattern>/prywatne/*</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>admin</role-name>
        </auth-constraint>
    </security-constraint>
    <login-config>
        <auth-method>BASIC</auth-method>
        <realm-name>annRealm</realm-name>
    </login-config>
    <security-role>
        <description/>
        <role-name>admin</role-name>
    </security-role>
    <security-role>
        <description/>
        <role-name>user</role-name>
    </security-role>
</web-app>

【问题讨论】:

  • 你连个问题都没问...
  • 什么可能出错?一切都与像这样blog.eisele.net/2011/01/jdbc-security-realm-and-form-based.html 的一些教程完全相同,而且它不会登录唯一不同的是 glasfish 和 netbeans 的版本
  • 在大多数情况下,问题出在监视器前面(OSI 级别 8)。如果你不详细描述它,没人能猜出你到底尝试了什么......
  • 好吧,我还不能发布图片来展示所有内容。这个 OSI 8 级怎么样?我所做的与本教程中的完全一样 - 简单的测试完成数据库(两个表一个用户(用户名密码)第二个角色(用户名,角色)完成 jdbc 池,资源,在 web.xml 和 sun-web 中完成所有事情.xml 完成文件夹“受保护”,其中有一个 html 文件 此文件夹在安全约束下采用 url 模式我得到了所有组等推送运行文件​​(表单受保护文件夹)登录(基本,默认)窗口显示在 webbrowser 中,所以我输入用户名和密码就像我在数据库中得到的一样,什么都没有
  • 请编辑问题并添加您的web.xml(文字,您不需要发布图片)。

标签: jakarta-ee netbeans glassfish


【解决方案1】:

问题似乎在于您没有在您的web.xml 中设置FacesServlet

在您的web.xml 中添加以下内容:

<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>*.xhtml</url-pattern>
</servlet-mapping>
<welcome-file-list>
    <welcome-file>loginForm.xhtml</welcome-file>
</welcome-file-list>

您也可以根据需要更改欢迎文件

另请参阅:

【讨论】:

  • 必须包含jsf吗?我只是看了广告 java_ee_6_development_with_netbeans_7 书,jsf 什么都没有,但奇怪的是,即使这本书中的例子也不起作用
  • 是的,如果您像本教程中那样编写 XHTML 代码,这是 JSF,您需要 web.xml 中的条目来“启用”它。
  • 是的,但您不想使用 JSP。这是一种古老且已弃用的技术,不应在新项目中使用。
  • 您好像忘记为 Glassfish 安装 MySQL 驱动程序了。
  • 我已经完成了驱动程序连接现在正在工作我已经完成了另一个测试当我使用领域名文件时它正在工作但是当我使用我自己的领域时它一直要求登录即使在数据库中准确地输入了什么(用户名和密码)Glasfish 日志为“严重:jdbcrealm.invaliduserreason 警告:WEB9102:Web 登录失败:com.sun.enterprise.security.auth.login.common.LoginException:登录失败:安全异常”这是什么原因?在领域中,我将 Password Encryptio Algorithm 设置为 NONE
【解决方案2】:

感谢这个视频https://www.youtube.com/watch?v=1xsU6juUZd0解决问题

我没有使用加密,所以我没有使用。无论如何,问题是在用户表和组表的领域中,只有表名是不够的,但模式 databasename.tablename 有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-22
    • 1970-01-01
    • 2015-03-18
    • 2015-01-10
    • 1970-01-01
    • 1970-01-01
    • 2013-01-04
    相关资源
    最近更新 更多