1 Reply Latest reply on Oct 25, 2007 10:54 PM by Shane Bryzak

    Problem showing content based on identity's role

    Colin Bosman Newbie

      Hi, I'm new here and also this actually is the first time I'm working with a web framework, so I'm guessing the solution might be simple, but still, I can't get it to work. I've Googled, searched this forum and I've seen topics that seemed to have comparable problems, but nothing works, so I'm hoping you can help me.

      I'm using Seam 2.0.0.CR2 and what I'm trying to do is very simple: just a small test to show a link only to users with a certain role.

      I've setup a project with 'seam setup' and then 'seam create-project' and after that, I've changed the following to the generated project:

      I've made Authenticator into an interface and created AuthenticatorAction and the authenticate method as follows:

      @Name(value = "authenticator")
      @Stateless
      public class AuthenticatorAction implements Authenticator {
      
       @PersistenceContext
       private EntityManager em;
       @Logger
       private Log log;
       private User user;
      
       public boolean authenticate() {
       log.info("authenticating #0", Identity.instance().getUsername());
       if (checkLoginInformation()) {
       Identity.instance().addRole(getRole());
       Identity.instance().addRole("test");
       return true;
       } else {
       return false;
       }
       }


      I'm using Identity.instance() now, but before I also tried '@In private Identity identity' as a class variable, changes nothing.

      In components.xml I changed the security:identity part into:
      <security:identity authenticate-method="#{authenticator.authenticate}" />


      So I just removed the securityRules part, but also tried with it left in, didn't change anything.

      Plus I've added the following two links to menu.xhtml:
      <s:link view="/home.xhtml" value="test" rendered="#(identity.hasRole('manager')" />
      <s:link view="/home.xhtml" value="test2" rendered="#(identity.hasRole('test')" />


      Instead of identity.hasRole('test'), I also tried s:hasRole('test') as that's what is also mentioned in the Security documentation of Seam. Also doesn't work. When I remove the 'rendered=....' part, it does show the links...

      Even though I'm adding the role "test" to every user hard-coded, it doesn't show the second link to any logged in user. It seems like the roles are not being 'saved' to the identity, while I think I'm just doing everything like is in the documentation and / or what I found on the web.

      Authentication / logging in works as I can only log in with users that are in the database. What do I miss here? Thanks in advance.