-1

I tried to login with my own login page and following error:

Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Tue Aug 22 07:52:15 CEST 2017 There was an unexpected error (type=Not Found, status=404). No message available

Here ist my SecurityConfiguration

@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
         http.authorizeRequests().antMatchers("/login", "/css/**",
         "/image/**").permitAll().anyRequest()
         .authenticated().and().formLogin().loginPage("/login.html").permitAll()
        .and().logout().permitAll().and().csrf().disable();
    }

    @Autowired
    protected void configureLDAP(AuthenticationManagerBuilder auth) throws Exception {
        auth.ldapAuthentication().userSearchFilter("uid={0}").contextSource()
                .url("ldap://ldap.forumsys.com:389/dc=example,dc=com").managerPassword("password");
}

Login

<!doctype html>

    <html lang="de">
    <head>
         <meta charset="utf-8">

      <title>Login</title>
      <meta name="description" content="description">
      <meta name="author" content="author">

      <link rel="stylesheet" href="css/styles.css">
    </head>
    <body>
      <div class="container">
            <div class="background"> </div>
            <div class="card">
                        <img style="height:60px; width: auto; margin: 45px 100px;" src="image/picture.png">
                    <form name="f" action="/login" method="POST">
                        <div class="input">
                            <input placeholder="Benutzername" type="text" class="" name="username" required>
                        </div>
                        <div class="input">
                            <input placeholder="Passwort" type="password" class="" name="password" required>
                        </div>
                        <div class="">
                            <input name="submit" value="Login" class="btn" type="submit">
                        </div>
                    </form>
            </div>
      </div>
    </body>
    </html>

With the Login page from Spring it works without problems.

Paddy3108
  • 33
  • 1
  • 6
  • spring can't find the error page.maybe you have to add that in `configure()`. You should google your error message. There are answers out there. Like this https://stackoverflow.com/questions/31134333/this-application-has-no-explicit-mapping-for-error or https://stackoverflow.com/questions/36819277/issue-with-spring-there-was-an-unexpected-error-type-not-found-status-404 – Jack Flamp Aug 22 '17 at 08:14
  • I think the problem is, that spring can't find my login page. – Paddy3108 Aug 22 '17 at 09:02

1 Answers1

0

I think you got confused on what loginPage method does. JavaDoc:

Specifies the URL to send users to if login is required. ...

You must provide an URL to which your client will be redirected.

Change loginPage("/login.html") to loginPage("/login") and configure view resolving for that url. For example you can create another configuration like this:

@Configuration    
public class LoginViewConfig extends WebMvcConfigurerAdapter {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/login").setViewName("login");
    }
}

Or add similar thing to your existing mvc config. This assumes you have view reolving configured somewhere else.

chimmi
  • 2,054
  • 16
  • 30
  • It doesn't work. I get following error now: Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Tue Aug 22 15:53:23 CEST 2017 There was an unexpected error (type=Internal Server Error, status=500). Circular view path [login]: would dispatch back to the current handler URL [/login] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.) – Paddy3108 Aug 22 '17 at 13:54
  • It appears you do not have view resolving configured at all. – chimmi Aug 22 '17 at 14:06