tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From J.M. Villagrá <villa...@gmail.com>
Subject Re: Set up a custom LoginModule
Date Tue, 15 Jun 2010 13:58:37 GMT
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á <villagra@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 <david.blevins@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á <villagra@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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message