簡體   English   中英

如何從Spring Security獲取密碼?

[英]How to get password from Spring Security?

我正在將Apache CXF與WebClient一起使用,並且要將憑證發送到服務器

    WebClient client = WebClient.create("http://localhost:8084", "username", "password", null)

問題是我無法獲得密碼值。

以下方法不起作用

    SecurityContextHolder.getContext().getAuthentication().getCredentials()

假設您已經登錄,並且需要獲取從數據庫中檢索到的公司名稱。 首先,您將需要實現UserDetails的對象,該對象將保存在UserDetailsS​​ervice中並添加所需的任何變量(公司等)。

public class CustomUserDetails implements UserDetails{      
    private String password;
    private String username;
    private String companyName;
}

而不是使用自定義Userdetails實現進行類型轉換。

CustomUserDetails customDetails (CustomUserDetails)SecurityContextHolder.getContext().getAuthentication().getCredentials();

getCredentials將返回您保存到憑證的對象。 無論輸入哪種類型,您都可以隨時將其返回到保存的類中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM