Search code examples
spring-bootjerseytogglz

How to enable togglz-console in spring-boot application


My spring-boot+jersey application has integrated togglz. I added below dependencies as below.

// togglz
compile('org.togglz:togglz-servlet:'+togglzVersion)
compile('org.togglz:togglz-cdi:'+togglzVersion)
compile('javax.enterprise:cdi-api:2.0-EDR1')
compile('org.togglz:togglz-spring-web:'+togglzVersion)
compile("org.togglz:togglz-spring-boot-starter:"+togglzVersion)
compile("org.togglz:togglz-console:"+togglzVersion)
compile("org.togglz:togglz-spring-security:"+togglzVersion)
compile("com.github.heneke.thymeleaf:thymeleaf-extras-togglz:1.0.1.RELEASE")

In my boot class I added below code:

@Bean
public FeatureProvider featureProvider() {
    return new EnumBasedFeatureProvider(AppFeatures.class);
}

after launch the app, I can see the json data from this link:http://localhost:8080/togglz. But I can't access http://localhost:8080/togglz-console. I got "Failed to load resource: the server responded with a status of 403 (Forbidden" error.

I can see below log in my log file but I can't access togglz-console/*.

o.s.b.c.e.ServletRegistrationBean        : Mapping servlet: 'togglzConsoleServlet' to [/togglz-console/*]

below is my togglz property file:

# togglz
togglz:
    feature-enums: com.cooltoo.backend.features.AppFeatures # Comma-separated list of fully-qualified feature enum class names.
    features:
        SMS_CODE: false
    console:
        enabled: true # Enable admin console.
        path: /togglz-console # The path of the admin console when enabled.

what did I miss here?


Solution

  • Step1 Add the below dependency :

       <!-- Togglz Admin Console -->
        <dependency>
           <groupId>org.togglz</groupId>
           <artifactId>togglz-console</artifactId>
           <version>2.3.0.RC1</version>
       </dependency>
    

    Step2 Add the below in your application.yml or application.properties

    togglz:
      console:
        enabled: true # Enable admin console.
    

    or

    togglz.console.enabled: true # Enable admin console.
    

    Step3 Configure the console path by

    togglz:
        console:
         path: /togglz-console # The path of the admin console when enabled.
    

    For authentication : Add a dummy UserProvider which assigns admin privileges to every user:

    public class MyTogglzConfiguration implements TogglzConfig {
            @Override
            public UserProvider getUserProvider() {
                return new UserProvider() {
                    @Override
                    public FeatureUser getCurrentUser() {
                        return new SimpleFeatureUser("admin", true);
                    }
                };
            }
        }
    

    If you want to authenticate the user, instead of the above dummy one , implement your own UserProvider by following this documentation