3 Replies Latest reply on Aug 18, 2009 5:56 AM by Jun Li

    Factory method to get credentials?

    Jun Li Newbie

      Hi there,

      Does anyone know if there is a factory method in seam that can be used to get the credentials?

      I know credentials can be injected with @In, but as we're only use seam in web layer, for services we just use pure ejb, no seam annotations. Therefore, we're looking for a easy way to access credential info such as the current login user name in services.


        • 1. Re: Factory method to get credentials?
          Jun Li Newbie

          I found that I can use the following, anyone has further suggestions?


          • 2. Re: Factory method to get credentials?
            Marco Röösli Newbie

            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)

               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?
              Jun Li Newbie

              Thanks Marco, that's helpful.