2017-08-22 198 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