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()) {
      
       identity.addRole(ur.getRoles().getSecRoleRoleName());
       }
       }
      
       log.debug("isLoggedin = " + identity.isLoggedIn());
      
       return true;
       }
      
       catch(NoResultException ex) {
       ex.printStackTrace();
       FacesMessages.instance().add("Invalid username/password");
       return false;
       }
      }


      home.xhtml:

      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
       xmlns:s="http://jboss.com/products/seam/taglib"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:rich="http://richfaces.ajax4jsf.org/rich"
       template="layout/template.xhtml">
      
      <ui:define name="body">
      
       <h:messages globalOnly="true" styleClass="message"/>
      
       <rich:panel>
       <!-- <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>
       <ul>
       <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>
       </ul>
       </rich:panel>
      
      </ui:define>
      </ui:composition>