You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by "J.M. Villagrá" <vi...@gmail.com> on 2010/06/11 11:39:51 UTC

Set up a custom LoginModule

Hi All,
  We're using openejb to do some tests of our ejbs, but now, i want to use
our custom LoginModule and i dont know how to configure it in openEJB....

  I've created the file openejb.home/config/login.config like this:

TestName {
   com.test.TestLoginModule required debug=true;
};

And, in the context initialization i have this properties:

Properties props = new Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");
props.put("openejb.authentication.realmName", "TestName");
props.put("Entities", "new://Resource?type=DataSource");
props.put("Entities.JdbcDriver", "org.postgresql.Driver");
props.put("Entities.JdbcUrl", "jdbc:postgresql://localhost:5432/......");
props.put("Entities.Password", "....");
props.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");

context = new InitialContext(props);

Do i need any other configuration file??
If i try to do a login i get an error:

LoginContext lc = new LoginContext("¿TestName?");
lc.login();

javax.security.auth.login.LoginException: No se han configurado LoginModules
para TestName
at javax.security.auth.login.LoginContext.init(LoginContext.java:256)
at javax.security.auth.login.LoginContext.<init>(LoginContext.java:334)
at
com.ensenia.server.ejb.SchoolServiceBeanTests.userCrudOperations(SchoolServiceBeanTests.java:38)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)


Thank you very much.

-- 
Jose

Re: Set up a custom LoginModule

Posted by David Blevins <da...@visi.com>.
On Jun 15, 2010, at 6:58 AM, J.M. Villagrá wrote:

> I have found a solution....
> 
> I can login successfully against my LoginModule only if i set up login and
> password in context initialization:
> 
> props.put("openejb.authentication.realmName", "test");
> props.put(Context.SECURITY_PRINCIPAL, "username");
> props.put(Context.SECURITY_CREDENTIALS, "password");

Ah. Somehow I had a brain hiccup and thought you were already doing that.  I looked back and see I was wrong :)

> Otherwise, if i try to use the LoginContext to init session it does not work
> and i always get "guest"
> 
>     CallbackHandler handler = new CallbackHandler() {
> 
>     @Override
>     public void handle(Callback[] callbacks) throws IOException,
>     UnsupportedCallbackException {
> 
>     Callback[] mcallbacks = callbacks;
> 
>     NameCallback nameCallback = (NameCallback) mcallbacks[0];
>     nameCallback.setName("jm.villagra");
>     }
>     };
> 
>     LoginContext lc = new LoginContext("test", handler);
>     lc.login();
> 
>     Subject sub =  lc.getSubject();

Trick with that is creating a subject doesn't do much but build an instance of subject.  Doesn't automatically make it so everyone who is interested can see it.

This sort of shows us basically doing the same as you've done above:

  http://svn.apache.org/repos/asf/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/security/SecurityServiceImpl.java

The LocalInitialContextFactory will basically grab your user/pass and call securityService.login followed by securityService.associate (the magical part that puts the subject on the thread where openejb can see it) and finally will call securityService.disassociate when someone calls initialContext.close();


Open to any improvements if you're interested in hacking.  We could easily have several implementations of SecurityService available for use.  Maybe one that exposes the registerSubject/unregisterSubject methods.  We just need to have a definition for it in our service-jar.xml file (calling it 'AlternativeSecurityService' for example) and then someone can use it in a test like so:

 Properties props = new Properties();
 props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
 props.put("mySecurityService", "new://SecurityService?provider=AlternativeSecurityService");
 props.put("mySecurityService.callbackHandler", MyHandler.class.getName());

As well they could set any config properties for it using the standard properties overrides.


-David








Re: Set up a custom LoginModule

Posted by "J.M. Villagrá" <vi...@gmail.com>.
I have found a solution....

I can login successfully against my LoginModule only if i set up login and
password in context initialization:

props.put("openejb.authentication.realmName", "test");
props.put(Context.SECURITY_PRINCIPAL, "username");
props.put(Context.SECURITY_CREDENTIALS, "password");

Otherwise, if i try to use the LoginContext to init session it does not work
and i always get "guest"

     CallbackHandler handler = new CallbackHandler() {

     @Override
     public void handle(Callback[] callbacks) throws IOException,
     UnsupportedCallbackException {

     Callback[] mcallbacks = callbacks;

     NameCallback nameCallback = (NameCallback) mcallbacks[0];
     nameCallback.setName("jm.villagra");
     }
     };

     LoginContext lc = new LoginContext("test", handler);
     lc.login();

     Subject sub =  lc.getSubject();


Is it correct?
Thanks


On Tue, Jun 15, 2010 at 3:06 PM, J.M. Villagrá <vi...@gmail.com> wrote:

> Thanks, but, unfortunatly, that's not the problem....
>
> I'm debugging and i've seen that the SessionContext injected has this
> properties:
>
> securityService = SecurityServiceImpl
> defaultUser="guest"
> realmName = "PropertiesLogin"
>
> so, why is using this propertiesLogin as realmName?¿?
> I've setup my realmName in contextInitialization:
>
> props.put("openejb.authentication.realmName", "test");
>
> and in the login.config:
>
> test{
>    xxx.xxxLoginModule required;
> };
>
> Any idea?
>
> About config dir, its working as you said... i've moved the login.config to
> src/test/resources and it works.
>
>
> Thanks.
>
> On Fri, Jun 11, 2010 at 8:03 PM, David Blevins <da...@visi.com>wrote:
>
>>
>> On Jun 11, 2010, at 3:55 AM, J.M. Villagrá wrote:
>>
>> > I found the error...
>> > login.config has to be in :
>> >
>> > openejb.home/conf
>> >
>> > not in:
>> >
>> > openejb.home/config
>> >
>> >
>> > Now i have another problem...  althought the login is succesfully i'm
>> always
>> > getting "guest" as the Principal:
>> >
>> > @Stateless(name=SecurityService.BEANNAME)
>> > public class TestBean implements Test {
>> >
>> > @PersistenceContext(unitName = "Entities")
>> > private EntityManager _em;
>> >
>> > @Resource
>> > private SessionContext session;
>> >
>> >        @Override
>> > public void test(){
>> >
>> >        Principal p =  session.getCallerPrincipal();
>> >        //p = "guest"
>> >
>> > }
>> >
>> > }
>> >
>> > Any tip? Thanks
>>
>> Not sure if this is it, but try this:
>>
>>
>> https://blogs.apache.org/openejb/entry/ejbcontext_getcallerprincipal_improvements
>>
>> Note on the conf/ dir thing, it should be possible to put the login.config
>> in the classpath.  Not under META-INF/, but right beside it.  It should get
>> picked up.
>>
>> It can be really inconvenient to have to maintain an external directory
>> structure in tests so we try hard to make sure you never need one if you
>> don't want one.
>>
>> Hope this helps!
>>
>>
>> -David
>>
>>
>>
>>
>> >
>> >
>> > On Fri, Jun 11, 2010 at 11:39 AM, J.M. Villagrá <vi...@gmail.com>
>> wrote:
>> >
>> >> Hi All,
>> >>  We're using openejb to do some tests of our ejbs, but now, i want to
>> use
>> >> our custom LoginModule and i dont know how to configure it in
>> openEJB....
>> >>
>> >>  I've created the file openejb.home/config/login.config like this:
>> >>
>> >> TestName {
>> >>   com.test.TestLoginModule required debug=true;
>> >> };
>> >>
>> >> And, in the context initialization i have this properties:
>> >>
>> >> Properties props = new Properties();
>> >> props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
>> >> "org.apache.openejb.client.LocalInitialContextFactory");
>> >> props.put("openejb.authentication.realmName", "TestName");
>> >> props.put("Entities", "new://Resource?type=DataSource");
>> >> props.put("Entities.JdbcDriver", "org.postgresql.Driver");
>> >> props.put("Entities.JdbcUrl",
>> "jdbc:postgresql://localhost:5432/......");
>> >> props.put("Entities.Password", "....");
>> >> props.put("hibernate.dialect",
>> "org.hibernate.dialect.PostgreSQLDialect");
>> >>
>> >> context = new InitialContext(props);
>> >>
>> >> Do i need any other configuration file??
>> >> If i try to do a login i get an error:
>> >>
>> >> LoginContext lc = new LoginContext("¿TestName?");
>> >> lc.login();
>> >>
>> >> javax.security.auth.login.LoginException: No se han configurado
>> >> LoginModules para TestName
>> >> at javax.security.auth.login.LoginContext.init(LoginContext.java:256)
>> >> at javax.security.auth.login.LoginContext.<init>(LoginContext.java:334)
>> >> at
>> >>
>> com.ensenia.server.ejb.SchoolServiceBeanTests.userCrudOperations(SchoolServiceBeanTests.java:38)
>> >> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> >> at
>> >>
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>> >> at
>> >>
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>> >> at java.lang.reflect.Method.invoke(Method.java:597)
>> >> at
>> >>
>> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
>> >> at
>> >>
>> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>> >> at
>> >>
>> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
>> >> at
>> >>
>> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
>> >> at
>> >>
>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
>> >> at
>> >>
>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
>> >> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
>> >> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
>> >> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
>> >> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
>> >> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
>> >> at
>> >>
>> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
>> >> at
>> >>
>> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
>> >> at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
>> >> at
>> >>
>> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
>> >> at
>> >>
>> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>> >> at
>> >>
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
>> >> at
>> >>
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
>> >> at
>> >>
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
>> >> at
>> >>
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
>> >>
>> >>
>> >> Thank you very much.
>> >>
>> >> --
>> >> Jose
>> >>
>> >
>> >
>> >
>> > --
>> > Jose
>>
>>
>


-- 
Jose Mª Villagrá Gómez
Microsoft Certified Professional Developer - Enterprise Applications
Tfno CH: +41 789 408686
Tfno ES: +34 625 358724

Re: Set up a custom LoginModule

Posted by "J.M. Villagrá" <vi...@gmail.com>.
Thanks, but, unfortunatly, that's not the problem....

I'm debugging and i've seen that the SessionContext injected has this
properties:

securityService = SecurityServiceImpl
defaultUser="guest"
realmName = "PropertiesLogin"

so, why is using this propertiesLogin as realmName?¿?
I've setup my realmName in contextInitialization:

props.put("openejb.authentication.realmName", "test");

and in the login.config:

test{
   xxx.xxxLoginModule required;
};

Any idea?

About config dir, its working as you said... i've moved the login.config to
src/test/resources and it works.


Thanks.

On Fri, Jun 11, 2010 at 8:03 PM, David Blevins <da...@visi.com>wrote:

>
> On Jun 11, 2010, at 3:55 AM, J.M. Villagrá wrote:
>
> > I found the error...
> > login.config has to be in :
> >
> > openejb.home/conf
> >
> > not in:
> >
> > openejb.home/config
> >
> >
> > Now i have another problem...  althought the login is succesfully i'm
> always
> > getting "guest" as the Principal:
> >
> > @Stateless(name=SecurityService.BEANNAME)
> > public class TestBean implements Test {
> >
> > @PersistenceContext(unitName = "Entities")
> > private EntityManager _em;
> >
> > @Resource
> > private SessionContext session;
> >
> >        @Override
> > public void test(){
> >
> >        Principal p =  session.getCallerPrincipal();
> >        //p = "guest"
> >
> > }
> >
> > }
> >
> > Any tip? Thanks
>
> Not sure if this is it, but try this:
>
>
> https://blogs.apache.org/openejb/entry/ejbcontext_getcallerprincipal_improvements
>
> Note on the conf/ dir thing, it should be possible to put the login.config
> in the classpath.  Not under META-INF/, but right beside it.  It should get
> picked up.
>
> It can be really inconvenient to have to maintain an external directory
> structure in tests so we try hard to make sure you never need one if you
> don't want one.
>
> Hope this helps!
>
>
> -David
>
>
>
>
> >
> >
> > On Fri, Jun 11, 2010 at 11:39 AM, J.M. Villagrá <vi...@gmail.com>
> wrote:
> >
> >> Hi All,
> >>  We're using openejb to do some tests of our ejbs, but now, i want to
> use
> >> our custom LoginModule and i dont know how to configure it in
> openEJB....
> >>
> >>  I've created the file openejb.home/config/login.config like this:
> >>
> >> TestName {
> >>   com.test.TestLoginModule required debug=true;
> >> };
> >>
> >> And, in the context initialization i have this properties:
> >>
> >> Properties props = new Properties();
> >> props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
> >> "org.apache.openejb.client.LocalInitialContextFactory");
> >> props.put("openejb.authentication.realmName", "TestName");
> >> props.put("Entities", "new://Resource?type=DataSource");
> >> props.put("Entities.JdbcDriver", "org.postgresql.Driver");
> >> props.put("Entities.JdbcUrl",
> "jdbc:postgresql://localhost:5432/......");
> >> props.put("Entities.Password", "....");
> >> props.put("hibernate.dialect",
> "org.hibernate.dialect.PostgreSQLDialect");
> >>
> >> context = new InitialContext(props);
> >>
> >> Do i need any other configuration file??
> >> If i try to do a login i get an error:
> >>
> >> LoginContext lc = new LoginContext("¿TestName?");
> >> lc.login();
> >>
> >> javax.security.auth.login.LoginException: No se han configurado
> >> LoginModules para TestName
> >> at javax.security.auth.login.LoginContext.init(LoginContext.java:256)
> >> at javax.security.auth.login.LoginContext.<init>(LoginContext.java:334)
> >> at
> >>
> com.ensenia.server.ejb.SchoolServiceBeanTests.userCrudOperations(SchoolServiceBeanTests.java:38)
> >> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >> at
> >>
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> >> at
> >>
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> >> at java.lang.reflect.Method.invoke(Method.java:597)
> >> at
> >>
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
> >> at
> >>
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
> >> at
> >>
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
> >> at
> >>
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
> >> at
> >>
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
> >> at
> >>
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
> >> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
> >> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
> >> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
> >> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
> >> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
> >> at
> >>
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
> >> at
> >>
> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
> >> at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
> >> at
> >>
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
> >> at
> >>
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> >> at
> >>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
> >> at
> >>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
> >> at
> >>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
> >> at
> >>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> >>
> >>
> >> Thank you very much.
> >>
> >> --
> >> Jose
> >>
> >
> >
> >
> > --
> > Jose
>
>

Re: Set up a custom LoginModule

Posted by David Blevins <da...@visi.com>.
On Jun 11, 2010, at 3:55 AM, J.M. Villagrá wrote:

> I found the error...
> login.config has to be in :
> 
> openejb.home/conf
> 
> not in:
> 
> openejb.home/config
> 
> 
> Now i have another problem...  althought the login is succesfully i'm always
> getting "guest" as the Principal:
> 
> @Stateless(name=SecurityService.BEANNAME)
> public class TestBean implements Test {
> 
> @PersistenceContext(unitName = "Entities")
> private EntityManager _em;
> 
> @Resource
> private SessionContext session;
> 
>        @Override
> public void test(){
> 
>        Principal p =  session.getCallerPrincipal();
>        //p = "guest"
> 
> }
> 
> }
> 
> Any tip? Thanks

Not sure if this is it, but try this:

  https://blogs.apache.org/openejb/entry/ejbcontext_getcallerprincipal_improvements

Note on the conf/ dir thing, it should be possible to put the login.config in the classpath.  Not under META-INF/, but right beside it.  It should get picked up.

It can be really inconvenient to have to maintain an external directory structure in tests so we try hard to make sure you never need one if you don't want one.

Hope this helps!


-David




> 
> 
> On Fri, Jun 11, 2010 at 11:39 AM, J.M. Villagrá <vi...@gmail.com> wrote:
> 
>> Hi All,
>>  We're using openejb to do some tests of our ejbs, but now, i want to use
>> our custom LoginModule and i dont know how to configure it in openEJB....
>> 
>>  I've created the file openejb.home/config/login.config like this:
>> 
>> TestName {
>>   com.test.TestLoginModule required debug=true;
>> };
>> 
>> And, in the context initialization i have this properties:
>> 
>> Properties props = new Properties();
>> props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
>> "org.apache.openejb.client.LocalInitialContextFactory");
>> props.put("openejb.authentication.realmName", "TestName");
>> props.put("Entities", "new://Resource?type=DataSource");
>> props.put("Entities.JdbcDriver", "org.postgresql.Driver");
>> props.put("Entities.JdbcUrl", "jdbc:postgresql://localhost:5432/......");
>> props.put("Entities.Password", "....");
>> props.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
>> 
>> context = new InitialContext(props);
>> 
>> Do i need any other configuration file??
>> If i try to do a login i get an error:
>> 
>> LoginContext lc = new LoginContext("¿TestName?");
>> lc.login();
>> 
>> javax.security.auth.login.LoginException: No se han configurado
>> LoginModules para TestName
>> at javax.security.auth.login.LoginContext.init(LoginContext.java:256)
>> at javax.security.auth.login.LoginContext.<init>(LoginContext.java:334)
>> at
>> com.ensenia.server.ejb.SchoolServiceBeanTests.userCrudOperations(SchoolServiceBeanTests.java:38)
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>> at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>> at java.lang.reflect.Method.invoke(Method.java:597)
>> at
>> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
>> at
>> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>> at
>> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
>> at
>> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
>> at
>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
>> at
>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
>> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
>> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
>> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
>> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
>> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
>> at
>> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
>> at
>> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
>> at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
>> at
>> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
>> at
>> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>> at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
>> at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
>> at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
>> at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
>> 
>> 
>> Thank you very much.
>> 
>> --
>> Jose
>> 
> 
> 
> 
> -- 
> Jose


Re: Set up a custom LoginModule

Posted by "J.M. Villagrá" <vi...@gmail.com>.
I found the error...
login.config has to be in :

openejb.home/conf

not in:

openejb.home/config


Now i have another problem...  althought the login is succesfully i'm always
getting "guest" as the Principal:

@Stateless(name=SecurityService.BEANNAME)
public class TestBean implements Test {

@PersistenceContext(unitName = "Entities")
private EntityManager _em;

@Resource
private SessionContext session;

        @Override
public void test(){

        Principal p =  session.getCallerPrincipal();
        //p = "guest"

}

}

Any tip? Thanks


On Fri, Jun 11, 2010 at 11:39 AM, J.M. Villagrá <vi...@gmail.com> wrote:

> Hi All,
>   We're using openejb to do some tests of our ejbs, but now, i want to use
> our custom LoginModule and i dont know how to configure it in openEJB....
>
>   I've created the file openejb.home/config/login.config like this:
>
> TestName {
>    com.test.TestLoginModule required debug=true;
> };
>
> And, in the context initialization i have this properties:
>
> Properties props = new Properties();
> props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
> "org.apache.openejb.client.LocalInitialContextFactory");
> props.put("openejb.authentication.realmName", "TestName");
> props.put("Entities", "new://Resource?type=DataSource");
> props.put("Entities.JdbcDriver", "org.postgresql.Driver");
> props.put("Entities.JdbcUrl", "jdbc:postgresql://localhost:5432/......");
> props.put("Entities.Password", "....");
> props.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
>
> context = new InitialContext(props);
>
> Do i need any other configuration file??
> If i try to do a login i get an error:
>
> LoginContext lc = new LoginContext("¿TestName?");
> lc.login();
>
> javax.security.auth.login.LoginException: No se han configurado
> LoginModules para TestName
> at javax.security.auth.login.LoginContext.init(LoginContext.java:256)
>  at javax.security.auth.login.LoginContext.<init>(LoginContext.java:334)
> at
> com.ensenia.server.ejb.SchoolServiceBeanTests.userCrudOperations(SchoolServiceBeanTests.java:38)
>  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>  at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
>  at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
> at
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>  at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
> at
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
>  at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
>  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
>  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
>  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
> at
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
>  at
> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
>  at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
> at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>  at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
>  at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
>
>
> Thank you very much.
>
> --
> Jose
>



-- 
Jose