This content has been marked as final.
Show 6 replies
-
1. Re: RolesAllowed causes exception on client with JBoss5
jaikiran Jan 28, 2009 7:52 AM (in response to draganj)Please post your bean code and also the client code which logs in the user.
-
2. Re: RolesAllowed causes exception on client with JBoss5
draganj Jan 28, 2009 8:16 AM (in response to draganj)Hello,
Here it is.
Clientpublic class TestStatelessClient { public static void main(String[] args) throws Exception { Properties p = new Properties(); //p.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); p.setProperty("java.naming.factory.initial", "org.jboss.security.jndi.JndiLoginInitialContextFactory"); p.setProperty("java.naming.provider.url","localhost:1099"); p.setProperty("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces"); p.setProperty(Context.SECURITY_PRINCIPAL, "kermit"); p.setProperty(Context.SECURITY_CREDENTIALS, "thefrog"); InitialContext ctx = new InitialContext(p); IHelloWorld hw = (IHelloWorld) ctx.lookup("HelloWorldBean/remote"); System.out.println("Got " + hw.helloWorld("Hello server")); } }
Server:package test.ejb.stateless; import javax.annotation.security.RolesAllowed; import javax.ejb.Remote; import javax.ejb.Stateless; import org.jboss.ejb3.annotation.SecurityDomain; @Stateless @SecurityDomain("JBossWS") @Remote(IHelloWorld.class) public class HelloWorldBean implements IHelloWorld { @RolesAllowed({"friend"}) public String helloWorld(String in) { System.out.println("Got " + in); return "Hello Client"; } }
jboss.xml:?xml version="1.0"?> <jboss> <security-domain>JBossWS</security-domain> </jboss>
I used JBossWS security domain.
Regards,
Dragan -
3. Re: RolesAllowed causes exception on client with JBoss5
jaikiran Jan 28, 2009 8:34 AM (in response to draganj)Properties p = new Properties();
//p.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
p.setProperty("java.naming.factory.initial", "org.jboss.security.jndi.JndiLoginInitialContextFactory");
p.setProperty("java.naming.provider.url","localhost:1099");
p.setProperty("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
p.setProperty(Context.SECURITY_PRINCIPAL, "kermit");
p.setProperty(Context.SECURITY_CREDENTIALS, "thefrog");
This has changed in JBossAS-5. Checkout the EJB3 "security" tutorial to see how its done now http://anonsvn.jboss.org/repos/jbossas/projects/ejb3/trunk/docs/tutorial/security/ -
4. Re: RolesAllowed causes exception on client with JBoss5
draganj Jan 28, 2009 9:05 AM (in response to draganj)Hello,
Thanks for the quick answer. It works.
Do you know what is the reason why we can not use "generic" client anymore (SecurityClient is jboss specific).
Thanks again,
Dragan -
5. Re: RolesAllowed causes exception on client with JBoss5
jaikiran Jan 28, 2009 9:37 AM (in response to draganj)Your earlier client too was JBoss specific, remember you were passing the JBoss specific JNDI properties and required JBoss specific jars in the classpath.
-
6. Re: RolesAllowed causes exception on client with JBoss5
wolfgangknauf Jan 28, 2009 10:18 AM (in response to draganj)Hi Dragan,
actually, you use JAAS on the client side (which is a Java standard), there is not much JBoss specific stuff about this.
To login, you need an implementation of "javax.security.auth.callback.CallbackHandler" (which provides user/password), and perform the authentication using this CallbackHandler:javax.security.auth.login.LoginContext loginContext = new LoginContext ("...", callbackHandler); loginContext.login();
The JBoss "SecurityClient" is just an implementation of the CallbackHandler interface.
Hope this helps a bit
Wolfgang