package de.otto.edison.togglz.configuration;


import de.otto.edison.togglz.authentication.LdapAuthenticationFilter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.embedded.FilterRegistrationBean;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.togglz.console.TogglzConsoleServlet;
import org.togglz.servlet.TogglzFilter;

@Configuration
public class TogglzWebConfiguration {

    @Bean
    @ConditionalOnMissingBean(name = "togglzFilter")
    public FilterRegistrationBean togglzFilter() {
        FilterRegistrationBean filterRegistration = new FilterRegistrationBean();
        filterRegistration.setFilter(new TogglzFilter());
        filterRegistration.addUrlPatterns("/*");
        return filterRegistration;
    }

    @Bean
    @ConditionalOnProperty(prefix = "edison.togglz", name = "ldap-authentication.enabled", havingValue = "true")
    @ConditionalOnMissingBean(name = "togglzAuthenticationFilter")
    public FilterRegistrationBean togglzAuthenticationFilter(@Value("${management.context-path:/internal}") String prefix,
                                                             @Value("${edison.togglz.ldap-authentication.host:}") String host,
                                                             @Value("${edison.togglz.ldap-authentication.port:389}") int port,
                                                             @Value("${edison.togglz.ldap-authentication.base-dn:}") String baseDn,
                                                             @Value("${edison.togglz.ldap-authentication.rdn-identifier:}") String rdnIdentifier) {
        FilterRegistrationBean filterRegistration = new FilterRegistrationBean();
        filterRegistration.setFilter(new LdapAuthenticationFilter(host, port, baseDn, rdnIdentifier));
        filterRegistration.addUrlPatterns(prefix + "/toggles/console");
        return filterRegistration;
    }

    @Bean
    public ServletRegistrationBean togglzServlet(@Value("${management.context-path:/internal}") String prefix) {
        return new ServletRegistrationBean(new TogglzConsoleServlet(), prefix + "/toggles/console/*");
    }


}

@@ -43,79 +43,8 @@
 n;%0A%0A
-%0Aimport de.otto.edison.togglz.authentication.LdapAuthenticationFilter;%0A
 impo
@@ -608,16 +608,87 @@
 ilter;%0A%0A
+import de.otto.edison.togglz.authentication.LdapAuthenticationFilter;%0A%0A
 @Configu
@@ -1757,24 +1757,93 @@
 .base-dn:%7D%22)
+%0A                                                                    
  String base
@@ -1965,24 +1965,93 @@
 entifier:%7D%22)
+%0A                                                                    
  String rdnI
@@ -2368,24 +2368,132 @@
 %0A%0A    @Bean%0A
+    @ConditionalOnProperty(name = %22edison.togglz.web.console%22, havingValue = %22true%22, matchIfMissing = true)%0A
     public S
@@ -2700,14 +2700,12 @@
 %22);%0A
+
     %7D%0A
-%0A%0A
 %7D%0A

Add possibility to disable togglz web interface