如何让 Java Servlet 容器将文件保存为“所有者/组”?除了汤姆猫还有什么?

发布于 2024-12-07 10:09:25 字数 271 浏览 0 评论 0原文

我有一个java servlet。保存文件时,将其保存为tomcat:tomcat(在linux环境中)。我实际上需要它来将其保存为 sportsfan:tomcat,因为 sportsfan 是 FTP 用户,并且还需要访问权限来创建、修改或覆盖这些文件。

我考虑过将 tomcat 作为 sportsfan:tomcat 运行,但我在一个 tomcat 实例下运行多个应用程序。

也许最好的方法是让 FTP 用户作为 tomcat 组的一部分登录。这是正确的方法吗?

请指教。

I have a java servlet. When it saves files, it saves them as tomcat:tomcat (in a linux environment). I actually need it to save it as sportsfan:tomcat as sportsfan is the FTP user and also needs access to create, modify or overwrite these files.

I thought about running tomcat as sportsfan:tomcat, but I'm running multiple applications under the one tomcat instance.

Perhaps the best way to do this would be to have the FTP user log in as part of the tomcat group. Would that be a correct way?

Please advise.

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

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

发布评论

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

评论(1

假装不在乎 2024-12-14 10:09:25

将您的sportsfan用户ftp添加到tomcat组可能是一个很好的解决方案,但在此之前请检查系统中哪些文件具有此权限,并考虑安全风险。

另一个解决方案:创建一个 sportsfan 组并将您的 sportsfan 用户添加到其中。然后更改 upload 目录的组并将其设置为 setgid

chgrp sportsfan upload
chmod g+s upload

之后 upload 中的新文件将使用 创建tomcat:sportsfan 所有者:组。这不完全是您所要求的,但 Linux 不支持更改用户 id(setuid 目录)。维基百科有一篇关于 setuid 和 setgid 目录 的非常好的文章。此外,您必须将 tomcat 用户的 umask 值设置为 000x(例如 0002)或类似的值,以提供对 tomcat 的完全访问权限。团体。

第三种解决方案:设置一个 cron 作业,每 n 分钟更改一次权限。

Adding your sportsfan user ftp to the tomcat group could be a good solution but before that check which are the modifiable files in you system with this permission and consider the security risks.

Another solution: Create a sportsfan group and add your sportsfan user to it. Then change the group of your upload directory and set it as setgid:

chgrp sportsfan upload
chmod g+s upload

After that the new files in the upload will be created with tomcat:sportsfan owner:group. It's not exactly what you asked for but changing the user id (setuid directories) is not supported on Linux. Wikipedia has a pretty good article about setuid and setgid directories. Futhermore, you have to set the umask value of the tomcat user to 000x (e.g. 0002) or a similar value which gives full access to the group.

3rd solution: set up a cron job which changes the permission in every n minutes.

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