Skip to content

Injecting custom restrictor into JolokiaServletRegistration #823

Closed

Description

@grgrzybek

Discussed in #822

Originally posted by vbeilin April 6, 2025
Hi,
I wonder if there is am idiomatic way to use a custom restrictor defined in my Spring context with the Spring Boot /actuator/jolokia endpoint.
AgentServlet accepts Restrictor as a constructor parameter, but JolokiaServletRegistration does not use this constructor.
ServletConfig, which could be used to find the application context, is not passed to a custom restrictor constructor.
This seems to leave either replacing JolokiaServletRegistration with a copy that would create an AgentServlet instance with a given restrictor, or making current application context in creation visible in a thread local, or creating a detached application context inside the restrictor class.
Is there anything I'm missing?

Activity

  1. self-assigned this
    on Apr 7, 2025
  2. added theissue type on Apr 7, 2025
  3. added this to the 2.2.9 milestone on Apr 7, 2025
  4. tadayosi commented on Apr 9, 2025

    @tadayosi
    Member

    @grgrzybek Hawtio has extended AgentServlet to support configuration via system properties.
    https://hawt.io/docs/configuration.html#_configuring_jolokia_through_system_properties
    I think that's something that should be ported to Jolokia itself. We can also make configuration possible via Spring Boot and Quarkus' application properties. That should solve the original issue, too.

  5. grgrzybek commented on Apr 28, 2025

    @grgrzybek
    ContributorAuthor

    I added simple ApplicationContext query, so org.jolokia.server.core.service.api.Restrictor instances are looked up in Spring context (or parents in case of separate main and management contexts). Here's the log:

    10:51:58 INFO {http-nio-8181-exec-1} [org.apache.juli.logging.DirectJDKLog] (DirectJDKLog.java:173) : jolokia: Using registered restrictor "customRestrictor".
    

    in this simple application:

    @SpringBootApplication
    public class Application {
    
        public static void main(String[] args) {
            SpringApplication.run(Application.class);
        }
    
        /**
         * This {@link Restrictor} will be available in Spring's context and used later in
         * {@link org.jolokia.server.core.http.AgentServlet}.
         * @return
         */
        @Bean
        public Restrictor customRestrictor() {
            return new Restrictor() {
                @Override
                public boolean isHttpMethodAllowed(HttpMethod pMethod) {
                    return true;
                }
    ...
  6. vbeilin commented on May 16, 2025

    @vbeilin

    Thank you!

  7. added a commit that references this issue on Jun 11, 2025
    49c8dee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions