Tomcat 6 下的 Web 应用程序特定表单验证器

发布于 2024-09-24 07:53:55 字数 827 浏览 4 评论 0原文

在您的帮助下,我成功解决了我提出的问题 此处。我为 Web 应用程序开发了一个自定义 Tomcat 身份验证器,当前身份验证器及其配置文件位于 %CATALINA_HOME%\lib\ 目录中。不幸的是,身份验证器配置文件几乎与身份验证器开发的 Web 应用程序的配置文件(位于 %CATALINA_HOME%\webapps\myapp)重复,并且配置文件显然都是,共享相同的数据库连接设置。这很不方便,因为共享唯一的配置文件是最好的。

我认为有两种方法可以解决该问题:

  1. 在 Tomcat 启动时以某种方式找到 myapp 存在的 webapps 目录,然后读取应用程序配置文件(从当前的情况,并且 myapp\WEB-INF\web.xml 配置正确)。当然,不幸的是这需要重新启动 Tomcat。
  2. 可能有一种方法可以将表单验证器放入相应的Web应用程序目录中,以便能够直接读取共享配置文件。也许这可以消除 Tomcat 重新启动并允许简单的重新部署。

如果可能的话,我想更喜欢第二种解决方案,但我不确定。如果两者都存在,哪种方式更好?或者是否有任何其他甚至更好的解决方案不将网络应用程序特定身份验证器放入%CATALINA_HOME\lib%

预先感谢并抱歉我的英语。

With your help I have successfully resolved a question that I have asked here. I have developed a custom Tomcat authenticator for the web application, and currently the authenticator and its configuration file are located in the %CATALINA_HOME%\lib\ directory. Unfortunately, the authenticator configuration file is almost a duplicate for the configuration file of the web application (located in %CATALINA_HOME%\webapps\myapp) the authenticator was developed for, and the configuration files both, obviously, share the same DB-connection settings. This is inconvenient because sharing the only configuration file would be the best.

I think there could be two ways to resolve the issue:

  1. Find the webapps directory for myapp presence somehow at Tomcat startup, and then read the application configuration file (proceed from the current situation, and the myapp\WEB-INF\web.xml is configured properly). Sure, unfortunately this requires Tomcat restart.
  2. There might be a way to put the form authenticator into the corresponding web application directory to be able to read the shared configuration file directly. Perhaps this might eliminate Tomcat restart and allow simple redeployment.

I would like to prefer the second solution if it's possible, but I'm not sure. Which way is better, if they both exist? Or is there any other and even better solution not putting the web application specific authenticator into %CATALINA_HOME\lib%?

Thanks in advance and sorry for my English.

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

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

发布评论

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

评论(2

久隐师 2024-10-01 07:53:55

您遇到了代码重复的情况。

我建议重构代码,以便 Tomcat 拥有进行身份验证所需的所有代码,然后重构您的应用程序以仅使用 Tomcat 身份验证代码。

如果您的应用程序无法使用 Tomcat 身份验证,您至少可以将公共代码(包括其配置文件)移至 Tomcat 中,然后使用公共代码。

You have a case of code duplication.

I would suggest refactoring the code, so that Tomcat has all the necessary code to to its authentification, and then refactor your application to solely use the Tomcat authentification code.

If your application cannot use the Tomcat authentification you can at least move the common code, including its configuration files, up in Tomcat, and then use the common code.

┾廆蒐ゝ 2024-10-01 07:53:55

啊,这一切都容易多了!主要思想是通过authenticate(...)中的(JDBCRealm) context.getRealm()对象获取连接字符串。这足以解决我的问题。

Ah, it's all much easier! The main idea is just to get connection string through the (JDBCRealm) context.getRealm() object in the authenticate(...). That's enough to resolve my issue.

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