2017-06-11 23 views
0

我爲我的web應用程序項目使用spring-lemon。 Spring-lemon默認使用標準表單登錄,這很好。然而,現在,我需要使用json請求進行身份驗證,如下所示:JSON登錄spring-lemon

{"username":"spring.user", "password":"s3cret"} 

我該如何安全地實現這一目標?我搜索了它,並且看到了不同的解決方案,但是我無法成功地使用它們。

回答

0

春季檸檬不附帶此功能。不過,我想你可以編寫一個終點,你可以手動抓取用戶的匹配密碼,裝飾它,然後設置認證如下:

SecurityContextHolder.getContext().setAuthentication(
       new UsernamePasswordAuthenticationToken(user, 
       user.getPassword(), user.getAuthorities())); 

LemonTokenAuthenticationFilter沒有類似的事情 - 你可以有一個看它。