title: Spring Security Custom Login Page Assistance
body: <p>I have been trying to get this configured properly, however I am having some difficulties and I believe it is a small fix that I am not seeing. The default spring security login page works just fine but I can't get the custom html to render. It just reads the get mapping "login" as a String. Any assistance would be greatly appreciated!</p>
  
  <p>1.Security Configuration</p>
  
  <pre><code>@EnableWebSecurity
  public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
  
      @Autowired
      UserDetailsService myUserDetailsServices;
      @Override
      protected void configure(AuthenticationManagerBuilder auth) throws Exception {
          auth.userDetailsService(myUserDetailsServices);
      }
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http.csrf().disable().
          authorizeRequests()
                  .antMatchers("/admin").hasRole("ADMIN")
                  .antMatchers("/user").hasAnyRole("ADMIN", "USER")
                  .antMatchers("/").permitAll()
                  .and().formLogin()
                      .loginPage("/login")
                      .permitAll();
      }
  
  
      @Bean
      public PasswordEncoder getPasswordEncoder() {
          return NoOpPasswordEncoder.getInstance();
      }
  
  }
  </code></pre>
  
  <p>3.Main Controller</p>
  
  <pre><code>@RestController
  @CrossOrigin(origins="http://localhost:4200")
  public class MainController {
  
      private UserRepository userRepository;
      private UserDetailsService myUserDetailsServices;
  
      public MainController(UserRepository userRepository) {
          this.userRepository = userRepository;
      }
  
      @GetMapping("/")
      public String home() { return ("&lt;h1&gt;Welcome&lt;/h1&gt;");
      }
  
      @GetMapping("/login")
      public String login() { return ("login");
      }
  
      @GetMapping("/user")
      public String user() {
          return ("&lt;h1&gt;Welcome User&lt;/h1&gt;");
      }
  
      @GetMapping("/admin")
      public String admin() {
          return ("&lt;h1&gt;Welcome Admin&lt;/h1&gt;");
      }
  
      @GetMapping("/all")
      public @ResponseBody Iterable&lt;User&gt; getAllUsers() {
          // This returns a JSON or XML with the users
          return userRepository.findAll();
  </code></pre>
  
  <p>4.login.html</p>
  
  <pre><code>&lt;html xmlns:th="http://www.thymeleaf.org" xmlns:tiles="http://www.thymeleaf.org"&gt;
  &lt;head&gt;
      &lt;title tiles:fragment="title"&gt;Login&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div tiles:fragment="content"&gt;
      &lt;form name="f" th:action="@{/login}" method="post"&gt;
          &lt;fieldset&gt;
              &lt;legend&gt;Please Login&lt;/legend&gt;
              &lt;div th:if="${param.error}" class="alert alert-error"&gt;
                  Invalid username and password.
              &lt;/div&gt;
              &lt;div th:if="${param.logout}" class="alert alert-success"&gt;
                  You have been logged out.
              &lt;/div&gt;
              &lt;label for="username"&gt;Username&lt;/label&gt;
              &lt;input type="text" id="username" name="username"/&gt;
              &lt;label for="password"&gt;Password&lt;/label&gt;
              &lt;input type="password" id="password" name="password"/&gt;
              &lt;div class="form-actions"&gt;
                  &lt;button type="submit" class="btn"&gt;Log in&lt;/button&gt;
              &lt;/div&gt;
          &lt;/fieldset&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>