This content has been marked as final.
Show 3 replies
-
1. Re: Factory method to get credentials?
allanjun Aug 17, 2009 7:19 AM (in response to allanjun)I found that I can use the following, anyone has further suggestions?
Identity.instance().getCredentials().getUsername();
-
2. Re: Factory method to get credentials?
mroeoesli Aug 17, 2009 9:24 AM (in response to allanjun)An other way is if you write your own factory:
@Factory(value = LOGGED_IN_USERNAME, scope = ScopeType.SESSION, autoCreate = true) public String getLoggedInUsername() { String username=""; Identity identity= Identity.instance(); if (identity.isLoggedIn() == true) { username = identity.getPrincipal().getName(); } else { username = "none"; } return username; }
or you can save the username in the session context (after login)
@Observer(Identity.EVENT_LOGIN_SUCCESSFUL) public void loginSuccessfull() { Contexts.getSessionContext().set("CURRENT_USER", Identity.instance().getCredentials().getUsername()); }
and you can read it with
String username=Contexts.getSessionContext().get("CURRENT_USER");
-
3. Re: Factory method to get credentials?
allanjun Aug 18, 2009 5:56 AM (in response to allanjun)Thanks Marco, that's helpful.