1 Reply Latest reply on Aug 22, 2007 3:43 AM by Nicklas Karlsson

    identity.isLoggedIn() question

    Arbi Sookazian Master

      in the API doc for org.jboss.seam.security.Identity, isLoggedIn() has the following description: If there is a principal set, then the user is logged in.

      How/when does the principal get set? I'm assuming after the successful execution of identity.setUsername(). In the following code, identity.isLoggedIn() is returning false but is evaluating to true later in an xhtml file. Other test cases (with the same NTLM username) identity.isLoggedIn() returns true. Any ideas why? identity instance is being depency injected earlier in the class...

      public boolean authenticate() {
       try {
       identity.setUsername(((NtlmPasswordAuthentication) sessionContext.get("NtlmHttpAuth")).getUsername());
       Query q = em.createQuery("SELECT r FROM Users r WHERE r.networkLogin = :username");
       q.setParameter("username", identity.getUsername());
       Users user = (Users) q.getSingleResult();
       Set<UserRoles> myRoles = user.getUserRoleses();
       if (user.getUserRoleses() != null) {
       for (UserRoles ur : user.getUserRoleses()) {
       log.debug("isLoggedin = " + identity.isLoggedIn());
       return true;
       catch(NoResultException ex) {
       FacesMessages.instance().add("Invalid username/password");
       return false;


      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
      <ui:define name="body">
       <h:messages globalOnly="true" styleClass="message"/>
       <!-- <f:facet name="header">Welcome!</f:facet> -->
       <h:outputText value="test" />
       <h:outputText value="Welcome, #{identity.username}" rendered="#{identity.loggedIn}"/>
       <p>This empty shell application includes:</p>
       <li>Ant build script</li>
       <li>Deployment to JBoss AS</li>
       <li>Integration testing using TestNG and JBoss Embeddable EJB3</li>
       <li>EJB 3.0 Seam components</li>
       <li>Templated Facelets views</li>
       <li>HSQL (or MySQL) Datasource</li>
       <li>Default CSS stylesheet</li>
       <li>Internationalization support</li>