package it.w0rd.filters;

import it.w0rd.api.auth.AdminAuthenticationCredentialsError;
import it.w0rd.api.auth.AuthenticationProvider;
import it.w0rd.api.auth.SingleAdminAuthentication;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Base64;
import java.util.logging.Logger;

@Component
@Order(Ordered.HIGHEST_PRECEDENCE - 2)
public class AdminFilter implements Filter {

    private final AuthenticationProvider authenticationProvider;

    public AdminFilter() throws AdminAuthenticationCredentialsError {
        authenticationProvider = new SingleAdminAuthentication("admin", "default");
    }

    public AdminFilter(AuthenticationProvider authenticationProvider) {
        this.authenticationProvider = authenticationProvider;
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest httpRequest = (HttpServletRequest) request;
        HttpServletResponse httpResponse = (HttpServletResponse) response;

        final String requestURI = httpRequest.getRequestURI();
        if(!requestURI.matches("/admin/.*") && !requestURI.matches("/api/admin.*")){
            Logger.getLogger("AdminFilter").info("Request does need not be authorized: " + httpRequest.getRequestURI());
            chain.doFilter(request, response);
            return;
        }

        final String authKey = httpRequest.getHeader("Authorization");
        if(authKey != null && authKey.startsWith("Basic ")) {
            final String[] authInfo = new String(Base64.getDecoder().decode(authKey.substring(6))).split(":");
            final String userName = authInfo[0];
            final String password = authInfo[1];
            if(authenticationProvider.isAdministrator(userName, password)) {
                Logger.getLogger("AdminFilter").info("User " + userName + " has successfully logged in");
                chain.doFilter(request, response);
                return;
            }
        }

        challenge(httpResponse);
    }

    private void challenge(HttpServletResponse httpResponse) {
        Logger.getLogger("AdminFilter").info("No or wrong credentials");
        httpResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        httpResponse.setHeader("WWW-Authenticate", "Basic");
    }

    @Override
    public void destroy() {

    }
}

@@ -175,24 +175,56 @@
 entication;%0A
+import org.slf4j.LoggerFactory;%0A
 import org.s
@@ -252,16 +252,16 @@
 rdered;%0A
-
 import o
@@ -525,41 +525,8 @@
 e64;
-%0Aimport java.util.logging.Logger;
 %0A%0A@C
@@ -683,16 +683,110 @@
 rovider;
+%0A    public static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(AdminFilter.class);
 %0A%0A    pu
@@ -1636,38 +1636,13 @@
    L
-ogger.getLogger(%22AdminFilter%22)
+OGGER
 .inf
@@ -2233,38 +2233,13 @@
    L
-ogger.getLogger(%22AdminFilter%22)
+OGGER
 .inf
@@ -2509,38 +2509,13 @@
    L
-ogger.getLogger(%22AdminFilter%22)
+OGGER
 .inf

Use slf4j logger in AdminFilter