我有一個JSF Web應用程序,它使用Cookie進行自動身份驗證,但不提示輸入用戶名&的密碼。它使用帶有用戶名和隨機UUID的cookie,並使用WebFilter
進行重定向。使用HttpServletRequest和LDAP自動登錄
當客戶端沒有cookie時,認證通過HttpServletRequest #login(String username, String password)完成。在幕後,這種方法使用JAAS認證,並使用後面的LDAP
服務器。
當我的應用程序通過持有userid和UUID的cookie識別用戶時,我的問題就出現了。在這種情況下,
- 應用程序不知道密碼,所以方法
HttpServletRequest #login(String username, String password)
不能使用。 - 我應該通過JNDI向LDAP服務器詢問密碼嗎?這似乎不可能乍一看
- 或者,我可以將密碼存儲在我的分貝。但是這意味着信息的重複,我不喜歡它。
- 我見過around人只是簡單地爲會話設置屬性「角色」,但這似乎並不等同於JAAS登錄。與「等效」我的意思是能夠使用
isUserInRole()
和getUserPrincipal()
方法。
所以,問題是:在這種情況下,我該如何登錄用戶?我希望現在這個問題更清楚。
編輯
爲了讓代碼說話,我添加了Managed Bean的一個簡化版本:
@ManagedBean
@SessionScoped
public class loginBean() {
private String username = null;
private String password = null;
private UUID uuid = null;
private boolean rememberMe = false;
public void doLogin() {
checkCookies(); // this method sets the property values after checking if
// username & uuid match the ones saved previously
if (username != null && uuid != null && rememberMe) {
// authenticate automatically. Here I don't know how to proceed, because
// I don't have the password, unless I have saved it in the application's db,
// duplicating it because it's already in LDAP server.
} else {
httpServletRequest.login(username, password); // this uses LDAP behind JAAS
createCookies(); // this method also saves username & uuid in the app's db
}
}
如果設置正確,則無法從LDAP獲取密碼。你爲什麼認爲你需要它?你沒有。 – EJP 2012-08-11 12:48:36
哇!事實上,我一直無法獲得密碼。我認爲這是一個許可問題。爲什麼我不需要密碼? – perissf 2012-08-11 20:21:20
密碼用於驗證。 LDAP已完成身份驗證。你不需要它。你爲什麼這麼想? – EJP 2012-08-12 00:22:04