Search code examples
grailsshirojava-melody

Restrict access to java-melody monitoring url


Is there a way I can restrict access to /monitoring url generated by Java-Melody plugin in Grails using Shiro roles?

Update: a little bit more details. It's no problem so secure most Grails ressources with shiro. But in case of the java melody plugin, it seems that the melody filter is executed before the shiro filter gets executed. This renders shiro useless.

There are some solutions which say that this might be fixed through a change in the web.xml, but this is not a quick hit and I (rdmueller) didn't manage to make it work yet. The web.xml plugin also seems to promise some help, but I don't want to add another plugin just to secure one plugin.

Some older statements found on the web state that this problem should be already solved through the usage of the loadAfter list in this file: https://github.com/javamelody/grails-melody-plugin/blob/master/GrailsMelodyGrailsPlugin.groovy - but it seems that this only worked for older versions of Grails.

Update2: In order to make it easier to propose a solution, I've create a Grails 2.2.4 sample: https://github.com/rdmueller/SO30739581

just clone the project, do a grailsw run-app and navigate to

http://localhost:8080/SO30739581/dbdoc

and you'll get a login screen via shiro. Navigate to

http://localhost:8080/SO30739581/monitoring

and you'll get the melody screen without being logged in :-(


Solution

  • I ended up doing so by making changes to web.xml for HTTP authentication. Add this to you web.config file.

    <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>
    

    Then add a user and role to your tomcat-users.xml

    <user username="yourusername" password="yourpassword" roles="monitoring"/>