content: package me.alidg.errors.servlet;
  
  import org.springframework.context.annotation.Configuration;
  import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
  import org.springframework.security.config.annotation.web.builders.HttpSecurity;
  import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
  import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
  import org.springframework.security.web.AuthenticationEntryPoint;
  import org.springframework.security.web.access.AccessDeniedHandler;
  
  @Configuration
  @EnableWebSecurity
  @EnableGlobalMethodSecurity(prePostEnabled = true)
  public class ServletConfig extends WebSecurityConfigurerAdapter {
  
      private final AccessDeniedHandler accessDeniedHandler;
      private final AuthenticationEntryPoint authenticationEntryPoint;
  
      public ServletConfig(AccessDeniedHandler accessDeniedHandler, AuthenticationEntryPoint authenticationEntryPoint) {
          this.accessDeniedHandler = accessDeniedHandler;
          this.authenticationEntryPoint = authenticationEntryPoint;
      }
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http
              .anonymous().disable()
              .csrf().disable()
              .exceptionHandling()
              .accessDeniedHandler(accessDeniedHandler)
              .authenticationEntryPoint(authenticationEntryPoint);
      }
  }
  