title: spring security + rest doesn't work
body: <p>I have configured all properties, but my app still loads without spring security as if it does not exist... Please help me, what I am doing wrong. </p>
  
  <p>Here I get my rooms without auth with postman:</p>
  
  <p><a href="https://i.stack.imgur.com/xVfZ4.png" rel="nofollow"><img src="https://i.stack.imgur.com/xVfZ4.png" alt="enter image description here"></a></p>
  
  <p>Here below are my classes:</p>
  
  <p>SecurityConfiguration:</p>
  
  <pre><code>package com.vidaflo.config;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
  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.config.http.SessionCreationPolicy;
  
  @Configuration
  @EnableWebSecurity
  @ComponentScan("com.vidaflo")
  public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
  
      @Autowired
      public void configureGlobalSecurity(AuthenticationManagerBuilder auth) throws Exception {
          auth.inMemoryAuthentication().withUser("bill").password("abc123").roles("ADMIN");
          auth.inMemoryAuthentication().withUser("tom").password("abc123").roles("USER");
      }
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http.csrf().disable()
                  .authorizeRequests().antMatchers("/room/**").hasRole("ADMIN")
                  .and()
                  .httpBasic()
                  .and()
                  .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
      }
  }
  </code></pre>
  
  <p>SecurityInitializer:</p>
  
  <pre><code>package com.vidaflo.config;
  
  import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;
  
  public class SecurityInitializer extends AbstractSecurityWebApplicationInitializer {
  }
  </code></pre>
  
  <p>WebConfiguration:</p>
  
  <pre><code>package com.vidaflo.config;
  
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.web.servlet.config.annotation.EnableWebMvc;
  import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
  
  @Configuration
  @EnableWebMvc
  @ComponentScan(basePackages = "com.vidaflo.controllers")
  public class WebConfiguration extends WebMvcConfigurationSupport {
  }
  </code></pre>
  
  <p>Tomcat embedded:</p>
  
  <pre><code>package com.vidaflo.server;
  
  import com.vidaflo.config.ApplicationConfiguration;
  import com.vidaflo.config.DatabaseConfiguration;
  import com.vidaflo.config.SecurityConfiguration;
  import com.vidaflo.config.WebConfiguration;
  import lombok.extern.slf4j.Slf4j;
  import org.apache.catalina.LifecycleException;
  import org.apache.catalina.startup.Tomcat;
  import org.springframework.core.env.PropertiesPropertySource;
  import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
  import org.springframework.web.servlet.DispatcherServlet;
  
  @Slf4j
  public class Application {
      private static final String APPLICATION_PROPERTIES = System.getProperty("app.properties");
      private static final int DEFAULT_PORT = 8080;
      private static final String DEFAULT_CONTEXT_PATH = "/app";
  
      private AppProperties appProperties;
      private AnnotationConfigWebApplicationContext ctx;
  
      public static void main(String[] args) throws LifecycleException {
          Application app = new Application(APPLICATION_PROPERTIES);
          Server server = new TomcatServer(new Tomcat());
          app.run(server);
      }
  
      public Application(String fieldName) {
          loadProperties(fieldName);
      }
  
      public void run(Server server) {
          initApplicationContext();
          server.run(getConfig());
      }
  
      private void loadProperties(String fieldName) {
          appProperties = new AppProperties();
          appProperties.load(fieldName);
      }
  
      private void initApplicationContext() {
          log.info("Initialize application context...");
  
          ctx = new AnnotationConfigWebApplicationContext();
          ctx.register(SecurityConfiguration.class);
          ctx.register(ApplicationConfiguration.class);
          ctx.register(WebConfiguration.class);
          ctx.register(DatabaseConfiguration.class);
          ctx.getEnvironment()
              .getPropertySources()
              .addLast(new PropertiesPropertySource("applicationEnvironment", appProperties.getProperties()));
      }
  
      private ServerConfig getConfig() {
          ServerConfig serverConfig = new ServerConfig();
          serverConfig.setPort(appProperties.getPort(DEFAULT_PORT));
          serverConfig.setContextPath(appProperties.getContextPath(DEFAULT_CONTEXT_PATH));
          serverConfig.setServlet(getServlet());
          return serverConfig;
      }
  
      private DispatcherServlet getServlet() {
          return new DispatcherServlet(ctx);
      }
  }
  </code></pre>
  
  <p>Rest controller:</p>
  
  <pre><code>package com.vidaflo.controllers;
  
  import com.vidaflo.dto.RoomDto;
  import com.vidaflo.model.location.Room;
  import com.vidaflo.repositories.LocationRepository;
  import com.vidaflo.services.RoomService;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.web.bind.annotation.GetMapping;
  import org.springframework.web.bind.annotation.PostMapping;
  import org.springframework.web.bind.annotation.RequestParam;
  import org.springframework.web.bind.annotation.RestController;
  
  import java.util.List;
  import java.util.stream.Collectors;
  
  @RestController
  public class RoomController {
      @Autowired
      private RoomService roomService;
  
      @Autowired
      private LocationRepository locationService;
  
      @PostMapping("/room/save")
      public String save(@RequestParam(name = "name") String name,
                         @RequestParam(name = "location_id") Long locationId) {
          roomService.save(name, locationService.findOne(locationId));
          return "room added";
      }
  
      @GetMapping("/room/all")
      public List&lt;RoomDto&gt; findAll() {
          return roomService.findAll().stream()
                  .map(this::toDto)
                  .collect(Collectors.toList());
      }
  
      private RoomDto toDto(Room room) {
          return RoomDto.builder()
                  .id(room.getId())
                  .name(room.getName())
                  .build();
      }
  }
  </code></pre>
  
  <p>Please tell me if I should add additional details. I rly need help and I can't understand what I'm doing wrong.</p>