2017-08-22 118 views
-1

我想用我自己的登录页面,以下错误登录:Spring Security的登录与自己的登录页面无法正常工作

白色标签错误页面 此应用对/错误没有明确的映射,所以你看到这是一个后备。 Tue Aug 22 07:52:15 CEST 2017 有一个意外的错误(type = Not Found,status = 404)。 无

消息北京时间这里我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"); 
} 

登录

<!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> 

登录页面从春天它的工作原理没有问题。

+0

spring无法找到错误page.maybe你必须在'configure()'中加入它。你应该谷歌你的错误信息。那里有答案。像这样https://stackoverflow.com/questions/31134333/this-application-has-no-explicit-mapping-for-error或https://stackoverflow.com/questions/36819277/issue-with-spring-there- was-an-unexpected-error-type-not-found-status-404 –

+0

我认为问题在于,那春天找不到我的登录页面。 – Paddy3108

回答

0

我认为你对loginPage方法有什么困惑。 JavaDoc:

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

您必须提供将客户端重定向到的URL。

loginPage("/login.html")更改为loginPage("/login")并为该url配置视图解析。例如,您可以创建另一个配置,如下所示:

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

或者添加类似的东西到您现有的mvc配置中。这假定你在其他地方配置了视图回滚。

+0

它不起作用。我现在得到以下错误: 白标签错误页面 此应用程序没有显式映射/错误,因此您将此视为后备。 8月22日星期二15:53:23 CEST 2017 发生意外错误(type = Internal Server Error,status = 500)。 圆形视图路径[登录]:将重新发送回当前的处理程序URL [/ login]。检查你的ViewResolver设置! (提示:由于默认视图名称的生成,这可能是未指定视图的结果。) – Paddy3108

+0

看起来您没有视图解析配置。 – chimmi