[英]Manually set user's Roles in JSF
我有一些JSF 2應用程序當前正在使用JSF Secutiry LoginModule(auth-method = FORM)。 但是現在將通過一種新的方式來完成身份驗證,這意味着我將不得不手動編程身份驗證交互。
很好,但是現在我在設置角色時遇到問題。 我找不到在哪里可以設置Principals或不受其約束,也無法獲得共享狀態來放置“ javax.security.auth.principal”和“ javax.security.auth.roles”變量。
有辦法嗎? 這是我實際的Bean代碼的示例。
提前致謝!
@ManagedBean
@ViewScoped
public class PrincipalController extends AbstractController implements ExcluirRascunhoService.Presenter {
// has get and set
@ManagedProperty(value = "#{autenticacaoController}")
private AutenticacaoController autenticacaoController;
@PostConstruct
private void init() {
try {
// a previous application redirected the user here,
// giving two parameters, including a valid and calculated HASH
// to be passed to authentication
Map<String, String> requestMap = getContext().getRequestParameterMap();
String user = (String) requestMap.get("login");
String hash = (String) requestMap.get("hash");
// this will do the authentication, communicating with a
// webservice and passing these data so the webservice can
// authenticate the data, telling me if the user is Ok
autenticacaoController.authenticate(user, hash);
// do the other things if authentication doesn't throw an exception
// I should now fill all user's Roles accordingly to my database
// I get them correctly, but how to set them into the JSF Roles?
} catch (AuthenticationException e) {
// catch and quit the page
}
}
}
您不能僅憑JSF做到這一點。 基本上,JSF僅提供一個實用程序來直接從JSF界面獲取用戶及其角色。 因此,如果要從應用程序訪問主體用戶及其角色,則必須首先對用戶進行身份驗證。
要對用戶進行身份驗證,您可以使用第三方解決方案(如JAAS或Apache Shiro)來設置領域,角色並控制應用程序的身份驗證。
您還可以滾動自己的身份驗證層,這可能使您無法使用一些有用的JSF實用程序,例如直接從領域獲取主要用戶或其角色(請注意,自定義層可能會提供其他方式來獲取這些值) ,但還將提供一種自定義方式來執行所需的身份驗證。
我找到了一個很好的有關JAAS認證層的教程(葡萄牙語),它可以幫助您設置認證層。
祝您好運,並隨時詢問您對我所說的是否有任何疑問。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.