如何使用 JMeter 在 Tomcat 中模拟表单身份验证?

发布于 2024-12-02 01:17:17 字数 1013 浏览 4 评论 0原文

我对 JMeter 很陌生,但我对 JMeter 的用途有一些想法。我还有一个启用了表单身份验证的 Tomcat 应用程序。我尝试使用的线程包括:

  • HTTP 请求默认值
  • HTTP Cookie 管理器
  • HTTP 标头管理器

和以下一组 HTTP 采样器:

  • 注销页面 (/app/logout.jsp)
  • 登录页面 (/app/login.jsp)
  • j_security_check (/app/j_security_check)

,其中启用了“跟随重定向”和“使用 KeepAlive”。我无法弄清楚为什么 j_security_check 请求响应重定向到 logout.jsp。在检查 Chrome 中的 HTTP 响应后,我注意到此类请求会重定向到 index.jsp,但如果凭据正常,则永远不会重定向到注销页面。首先,我有一个想法,我没有模仿所有浏览器HTTP标头,但是在将它们全部添加到HTTP标头管理器后我失败了:

User-Agent  Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.859.0 Safari/535.2
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding gzip,deflate,sdch
Accept-Language en-US,en;q=0.8
Host    localhost:8080
Referer http://localhost:8080/whapp/index.jsp

但即使在指定了所有这些标头之后,我也无法模拟身份验证..有什么想法吗?提前致谢。

I'm very new to JMeter, but I have some ideas of what JMeter could be used for. Also I have a Tomcat application with form authentication enabled. The thread I'm trying to use consists of:

  • HTTP Request Defaults
  • HTTP Cookie Manager
  • HTTP Header Manager

and the following set of HTTP samplers:

  • logout page (/app/logout.jsp)
  • login page (/app/login.jsp)
  • j_security_check (/app/j_security_check)

where Follow Redirects and Use KeepAlive are enabled. I cannot figure out why the j_security_check request response redirects to logout.jsp. After checking the HTTP response in Chrome, I've noticed that such request redirects to index.jsp, but never to the log out page if the credentials are fine. First of all, I had an idea that I didn't imitate all browser HTTP headers, but I've failed after I added all of them to HTTP Header Manager:

User-Agent  Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.859.0 Safari/535.2
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding gzip,deflate,sdch
Accept-Language en-US,en;q=0.8
Host    localhost:8080
Referer http://localhost:8080/whapp/index.jsp

But even after specifying all of them, I cannot simulate the authentication... Any ideas? Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

极度宠爱 2024-12-09 01:17:17

您是否尝试记录登录过程,或者这些都是手动完成的?

如果手动,您的请求之一可能会缺少参数。

如果记录,可能存在需要动态的硬编码参数(JSessionID 等)。您可能需要添加带有正则表达式的 GET 来检索该值并将其传递给您的 POST。

如果 JSessionID 需要作为参数,您将无法通过 cookie 管理器传递它,您需要将其作为 HTTP 参数来执行。

有关记录的概要,请参阅 http://jmeter.apache.org/usermanual/jmeter_proxy_step_by_step.pdf

Did you try recording the login process, or were these all done manually?

If manually, there could be a parameter missing from one of your requests.

If recorded, there could be a hardcoded parameter that needs to be dynamic (JSessionID, etc.) You may need to add a GET with a regex to retrieve this value and pass to your POST.

If the JSessionID is expected as a parameter, you won't be able to pass it through the cookie manager, you'll need to do it as an HTTP parameter.

For a rundown on recording, please see http://jmeter.apache.org/usermanual/jmeter_proxy_step_by_step.pdf

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文