2016-12-14 124 views
0

我想使用彈簧安全認證和授權...但我有一個問題...登錄頁面無法正確加載!... 我不知道什麼我應該替換「登錄」嗎?彈簧安全不能正常工作

 http.authorizeRequests() 
       .anyRequest().authenticated() 
       .and() 
       .formLogin() 
       .loginPage("/login") 
       .permitAll(); 

RenderController.java

@Controller 
@RequestMapping("/") 
public class RenderController { 


@Autowired 
private HRMUserService userService; 


@RequestMapping(method = RequestMethod.GET) 
public String getIndexPage() { 
    return "login"; 
} 
@RequestMapping(value = "login", method = RequestMethod.POST) 
    public String login(HttpServletRequest request, @RequestParam String username, @RequestParam String password, 
         @Valid @ModelAttribute("userForm") HRMUser userForm, BindingResult result) { 
     return "index"; 
} 

這個項目是單個頁面的Web應用程序,並有兩頁:指數和登錄。 它工作正常不進行認證,授權,但添加這些功能我有問題,loginPage後......當我用loginPage(「/登錄」)我得到這個錯誤:

HTTP狀態405 - 請求方法「GET 「不支持

當我使用.loginPage( 」/索引「)

HTTP狀態404 -

當我使用.loginPage(「/」) 頁面加載但css和js無法識別!

+1

能按照配置...你有一個'/ login'但只接受POST請求......還有,爲什麼你會想自己攔截請求,Spring Security的已經做到這一點。您只需要一個返回視圖名稱的GET請求。 –

回答

0

您需要使用RequestMethod.GET添加登錄頁面的映射。類似的東西:

@RequestMapping(value = "login", method = RequestMethod.GET) 
public String getLoginPage() { 
    return "login"; 
} 
+0

我加了這個方法,但是現在css和js不能識別!! – faraa