[jboss-user] [Beginner's Corner] - Having major problems setting up a user on JNDI Security

Breako Beats do-not-reply at jboss.com
Mon Jun 7 15:49:51 EDT 2010


Breako Beats [http://community.jboss.org/people/breako] created the discussion

"Having major problems setting up a user on JNDI Security"

To view the discussion, visit: http://community.jboss.org/message/546570#546570

--------------------------------------------------------------
Hi,
According to this cool and short article:  http://community.jboss.org/wiki/JndiLoginInitialContextFactory http://community.jboss.org/wiki/JndiLoginInitialContextFactory
I should be able to set up a User / Password on JNDI as described in the article and invoke an EJB method that has security constraints.

Here is my EJB:

@Stateless
@SecurityDomain("TitanIdentityDB")
@RolesAllowed("AUTHORIZED_MERCHANT")
public class TravelAgentBean implements TravelAgentRemote {

    public Cabin findCabin(int pKey) {
        ...
    }
}

Here is the application-policy I added to login-config.xml

<application-policy name="TitanIdentityDB">
    <authentication>
      <login-module code="org.jboss.security.auth.spi.UserRolesLoginModule"
        flag="required">
         <!-- Any existing security context will be restored on logout -->
         <module-option name="usersProperties">props/user-titan.properties</module-option>
         <module-option name="rolesProperties">props/roles-titan.properties</module-option> 
      </login-module>
    </authentication>
  </application-policy>

Here is user-titan.properties

admin=admin

Here is roles-titan.properties

admin=AUTHORIZED_MERCHANT


And here is my stand alone client which runs outside the EJB container.

public class TextClient {

     public static Context getInitialContext() throws NamingException {
        if (context == null){
            Properties p = new Properties();
            p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.security.jndi.JndiLoginInitialContextFactory");
            p.put(Context.PROVIDER_URL, "jnp://localhost:1099");
            p.put(Context.SECURITY_PRINCIPAL, "admin");
            p.put(Context.SECURITY_CREDENTIALS, "admin");
            context = new javax.naming.InitialContext(p);
        } 
        return context;
     }

     public static void main(String[] args) throws Exception{
        java.lang.Object ref = getInitialContext().lookup("TravelAgentBean/remote");
        TravelAgentRemote dao = 
            (TravelAgentRemote)PortableRemoteObject.narrow(ref, TravelAgentRemote.class);
            cabin_2 = dao.findCabin(1);
     }

}

When I run the client I keep getting:

Exception in thread "main" javax.ejb.EJBAccessException: Invalid User
    at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:165)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

And I am tearing my hair out about this all day.

Any ideas?

Thanks in Advance.

--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/546570#546570]

Start a new discussion in Beginner's Corner at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2075]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20100607/7eefc27c/attachment-0001.html 


More information about the jboss-user mailing list