users@glassfish.java.net

Re: Client not authorized for this invocation

From: <glassfish_at_javadesktop.org>
Date: Tue, 03 Mar 2009 05:16:44 PST

I am using Glassfish v2.1 b60.
Here is my code:

@Name("authenticator")
@Stateless
[b]//The Bean, which the login-process uses:[/b]
public class AuthenticatorBean implements Authenticator, Serializable
{

  private Log log = LogFactory.getLog(this.getClass());
  private static final long serialVersionUID = 5135915083379548370L;

  @In
  private MyIdentity identity;

  @EJB
  [b]//The Bean which is in the second ejb-Module[/b]
  private AuthenticatorService authenticatorService;

  public boolean authenticate()
  {
    boolean result = true;
    try
    {
      if (identity.getSessionKey() != null)
      {
        AuthenticatorUserDataRightsDTO dataRights = authenticatorService.getUserDataAndRights(identity
            .getSessionKey());
        UserData userData = dataRights.getUserData();
        List<RightData> userRights = dataRights.getRightDataList();

        if (userData != null)
        {
          // Settings of the credentials
          identity.getCredentials().setUsername(userData.getShortname());
          identity.getCredentials().setPassword(userData.getPassword());

          // Adding Roles
          if (userRights != null)
          {
            for (RightData right : userRights)
            {
              identity.addRole(right.getShortname());
            }
          }
        }
      }
      else
      {
        result = false;
      }
    }
    catch (Exception e)
    {
      log.error("Login failed", e);
      result = false;
    }
    return result;
  }

  public boolean login()
  {
    boolean result = true;
    try
    {
      if (identity.getCredentials().getUsername() != null && identity.getCredentials().getPassword() != null)
      {
        // Login at the authentication system
        String sessionKey = authenticatorService.login(identity.getCredentials().getUsername(), identity
            .getCredentials().getPassword());
        if (sessionKey != null)
        {
          identity.setSessionKey(sessionKey);
          result = authenticate();
        }
        else
        {
          result = false;
        }
      }
      else
      {
        result = false;
      }
    }
    catch (Exception e)
    {
      log.error("Login failed", e);
      result = false;
    }
    return result;
  }

}

The structure of the project if it is on the GF deployed:
Content of the application-ear:
->commonEJB_jar
-----> AuthenticatorBean.class
->jboss-seam-2.1.1.GA_jar
->lib
----->commonlib.jar
------------->AuthenticatorService
->application-ejb_jar
----->AuthenticatorBean
->application-war_war

Content of the application-ejb pom.xml:
<dependency>
                <groupId>de.common</groupId>
                  <artifactId>commonLib</artifactId>
                  <version>1.0.0</version>
</dependency>

Content of the application-ear pom.xml:

<dependency>
                <groupId>de.common</groupId>
                  <artifactId>commonLib</artifactId>
                  <version>1.0.0</version>
                  <type>jar</type>
 </dependency>
 <dependency>
                <groupId>de.common</groupId>
                  <artifactId>commonEjb</artifactId>
                  <version>1.0.0</version>
                  <type>ejb</type>
 </dependency>
 <ejbModule>
                 <groupId>de.common</groupId>
                 <artifactId>commonEjb</artifactId>
                 <unpack>${unpack}</unpack>
                 <bundleFileName>common-ejb.jar</bundleFileName>
</ejbModule>

Do you need more information?
[Message sent by forum member 'fenixx' (fenixx)]

http://forums.java.net/jive/thread.jspa?messageID=334784