【问题标题】:Glassfish create more than one http session in realm authenticationGlassfish 在领域身份验证中创建多个 http 会话
【发布时间】:2012-08-04 06:05:57
【问题描述】:

我有一个关于领域身份验证的问题,其中 glassfish 创建了多个 http 会话。这是一个例子

Web.xml:

<security-constraint>
    <web-resource-collection>
      <web-resource-name>AllPages</web-resource-name>
      <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
      <role-name>user</role-name>
    </auth-constraint>
  </security-constraint>
  <login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>FileRealm</realm-name>
  </login-config>
<security-constraint>

glassfish-web.xml:

  <security-role-mapping>
    <role-name>user</role-name>
    <group-name>users</group-name>
  </security-role-mapping>

login.jsp:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Welcome Page</title>
</head>
<body>
<p>You have successfully logged into the application.</p>
<a href="./home.jsp">go to home</a>
</body>
</html>

会话监听器:

@WebListener 公共类 SessionListener 实现 HttpSessionListener {

public void sessionCreated(HttpSessionEvent arg0) {

System.out.println("会话创建id:"+arg0.getSession().getId());
}

public void sessionDestroyed(HttpSessionEvent arg0) {

  System.out.println("Session destroyed id:"+arg0.getSession().getId());

}

}

当我进行身份验证时,glassfish 会创建一个新会话:

信息:会话创建 ID:29c5d904db0e40b9cfbdac40aa5e

当我点击“转到主页”链接或刷新页面时,glassfish 会创建另一个 http 会话:

信息:会话创建 ID:2a67270137e38c150bf3690e2e46

而且我还注意到 glassfish 永远不会破坏第一个创建的会话。

感谢您的帮助

【问题讨论】:

    标签: glassfish httpsession realm


    【解决方案1】:

    这可能是 Glassfish 错误。 尝试使用此选项将 context.xml 添加到您的 META-INF 目录:

    <?xml version='1.0' encoding='utf-8'?>
    <Context>
    <Valve className="org.apache.catalina.authenticator.BasicAuthenticator"
    changeSessionIdOnAuthentication="false" />
    </Context>
    

    或(如果是 Web 表单身份验证):

    <?xml version='1.0' encoding='utf-8'?>
    <Context>
    <Valve className="org.apache.catalina.authenticator.FormAuthenticator"
    changeSessionIdOnAuthentication="false" />
    </Context>
    

    这应该(暂时)解决您的问题!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-15
      • 2012-12-26
      • 1970-01-01
      • 2015-02-10
      • 1970-01-01
      • 2011-01-12
      相关资源
      最近更新 更多