gpt4 book ai didi

grails - 限制对 java-melody 监控 url 的访问

转载 作者:行者123 更新时间:2023-12-04 11:50:27 26 4
gpt4 key购买 nike

有没有一种方法可以使用 Shiro 角色限制对 Grails 中 Java-Melody 插件生成的/monitoring url 的访问?

更新:多一点细节。使用 shiro 确保大多数 Grails 资源的安全没问题。但是在 java melody 插件的情况下,似乎在执行 shiro 过滤器之前执行了旋律过滤器。这使得 shiro 无用。

有一些解决方案说这可能会通过更改 web.xml 来解决,但这不是一个快速的解决方案,我 (rdmueller) 还没有设法让它工作。 web.xml 插件似乎也提供了一些帮助,但我不想添加另一个插件只是为了保护一个插件。

在网络上找到的一些较旧的陈述表明这个问题应该已经通过使用 loadAfter 解决了。此文件中的列表:https://github.com/javamelody/grails-melody-plugin/blob/master/GrailsMelodyGrailsPlugin.groovy - 但似乎这只适用于旧版本的 Grails。

更新 2:为了更容易地提出解决方案,我创建了一个 Grails 2.2.4 示例:https://github.com/rdmueller/SO30739581

只需克隆项目,做一个 grailsw run-app并导航到

http://localhost:8080/SO30739581/dbdoc

你会通过 shiro 得到一个登录屏幕。导航
http://localhost:8080/SO30739581/monitoring

并且您无需登录即可获得旋律屏幕:-(

最佳答案

我最终通过更改 web.xml 来进行 HTTP 身份验证。将此添加到您的 web.config 文件中。

<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Monitoring</realm-name>
</login-config>
<security-role>
<role-name>monitoring</role-name>
</security-role>
<security-constraint>
<web-resource-collection>
<web-resource-name>Monitoring</web-resource-name>
<url-pattern>/monitoring</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>monitoring</role-name>
</auth-constraint>
</security-constraint>

然后将用户和角色添加到您的 tomcat-users.xml
<user username="yourusername" password="yourpassword" roles="monitoring"/>

关于grails - 限制对 java-melody 监控 url 的访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30739581/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com