/*
 * MIT Licence
 * Copyright (c) 2017 Simon Frankenberger
 *
 * Please see LICENCE.md for complete licence text.
 */
package eu.fraho.spring.example;

import eu.fraho.spring.securityJwt.JwtAuthenticationEntryPoint;
import eu.fraho.spring.securityJwt.config.WebSecurityConfig;
import eu.fraho.spring.securityJwt.service.JwtTokenService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.password.PasswordEncoder;

@Configuration
@Slf4j
@Order(101)
public class CustomSecurityConfig extends WebSecurityConfig {
    public CustomSecurityConfig(final JwtAuthenticationEntryPoint unauthorizedHandler,
                                final UserDetailsService userDetailsService,
                                final PasswordEncoder passwordEncoder,
                                final JwtTokenService jwtTokenUtil) {
        super(unauthorizedHandler, userDetailsService, passwordEncoder, jwtTokenUtil);
    }

    @Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {
        super.configure(httpSecurity);

        log.info("Overriding ant matchers");
        httpSecurity
                .authorizeRequests()
                .antMatchers("/public/**").permitAll()
                .anyRequest().authenticated();
    }
}
@@ -349,65 +349,78 @@
 bok.
-RequiredArgsConstructor;%0Aimport lombok.extern.slf4j.Slf4j
+extern.slf4j.Slf4j;%0Aimport org.springframework.context.annotation.Bean
 ;%0Aim
@@ -750,16 +750,162 @@
 Encoder;
+%0Aimport org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;%0A%0Aimport javax.servlet.*;%0Aimport java.io.IOException;
 %0A%0A@Confi
@@ -1610,127 +1610,806 @@
   .a
-uthorizeRequests()%0A                .antMatchers(%22/public/**%22).permitAll()%0A                .anyRequest().authenticated()
+ddFilterBefore(customFilter(), UsernamePasswordAuthenticationFilter.class)%0A                .authorizeRequests()%0A                .anyRequest().authenticated();%0A    %7D%0A%0A    @Bean%0A    public Filter customFilter() %7B%0A        return new Filter() %7B%0A            @Override%0A            public void init(FilterConfig filterConfig) throws ServletException %7B%0A                log.info(%22Initializing%22);%0A            %7D%0A%0A            @Override%0A            public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException %7B%0A                log.info(%22Handling request%22);%0A                chain.doFilter(request, response);%0A            %7D%0A%0A            @Override%0A            public void destroy() %7B%0A                log.info(%22Destroying%22);%0A            %7D%0A        %7D
 ;%0A  

Make custum security-config more verbose and easier to verify it's working