[英]Disable Spring Security Basic Login - Spring REST web service
[英]spring security login with rest web service
我公司有一個特定的身份驗證提供程序,它是一個內部REST Web服務。 實際上,您向Web服務提供了登錄名/密碼,並且它返回令牌(有效期為幾個小時),該令牌必須在標頭中提供給Web服務的每個下一個業務請求。
我需要創建一個Web應用程序,並將其插入此身份驗證提供程序。 將其與Spring Security集成的最佳方法是什么?
如何在不要求用戶重新登錄的情況下管理Web應用程序中的令牌到期?
如果您想使用帶有身份驗證的Spring Security委托給Web服務,則需要實現springs安全框架提供的AuthenticationProvider接口。 你可以做這樣的事情
public class AuthProviderImpl implements AuthenticationProvider
{
@Override
public Authentication authenticate(Authentication authentication)
throws AuthenticationException
{
WebServiceAuthClient client = //get an handle to your web service
//get user name, password from authenticate object
client.autheticat(username, pwd);
}
}
配置您的Web應用程序以使用Spring Security http://static.springsource.org/spring-security/site/petclinic-tutorial.html
我剛剛遇到了與原始問題非常相似的情況,這就是我將要通過的方法: http : //static.springsource.org/spring-security/site/docs/3.0.x/reference/preauth。 HTML
編輯:
在我們的情況下,會話和與之相關的cookie都是從外部進行管理的,我們只能基於外部會話存儲來驗證和授權每個請求。
因此,我們將改用自定義SecurityContextRepository。
EDIT2:
編寫一個SecurityContextRepository來檢查公共令牌存儲中的每個請求是微不足道的,將其連接到Spring Security中是很瘋狂的:security-context.xml中的http元素不允許自定義securityContextPersistenceFilter,因此我不得不用普通bean來模擬它。 一點都不有趣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.