如何让 Java Servlet 容器将文件保存为“所有者/组”?除了汤姆猫还有什么?
我有一个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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将您的sportsfan用户ftp添加到tomcat组可能是一个很好的解决方案,但在此之前请检查系统中哪些文件具有此权限,并考虑安全风险。
另一个解决方案:创建一个
sportsfan
组并将您的sportsfan
用户添加到其中。然后更改upload
目录的组并将其设置为setgid
:之后
upload
中的新文件将使用创建tomcat:sportsfan
所有者:组。这不完全是您所要求的,但 Linux 不支持更改用户 id(setuid 目录)。维基百科有一篇关于 setuid 和 setgid 目录 的非常好的文章。此外,您必须将tomcat
用户的umask
值设置为 000x(例如 0002)或类似的值,以提供对 tomcat 的完全访问权限。团体。第三种解决方案:设置一个 cron 作业,每 n 分钟更改一次权限。
Adding your
sportsfan
user ftp to thetomcat
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 yoursportsfan
user to it. Then change the group of yourupload
directory and set it assetgid
:After that the new files in the
upload
will be created withtomcat: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 theumask
value of thetomcat
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.