0

In my Shiro application, I am using the JndiRealmFactory to define my realms. I Register my realms like this:

Hashtable<String, String> args = new Hashtable<>();
args.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
InitialContext ctx = new InitialContext(args);
ctx.bind("realms/MyRealm", myRealm);

However, Shiro cannot find realms/MyRealm. I think the reason is, that I Need to define the JndiRealmFactory's jndiEnvironment, which contains the Context.INITIAL_CONTEXT_FACTORY property. However, I don't know how to set this property in my shiro.ini:

realmFactory.jndiEnvironment = ?

I am running my application on TomEE.

My current shiro.ini looks like this:

realmFactory = org.apache.shiro.realm.jndi.JndiRealmFactory
realmFactory.jndiNames = realms/MyRealm
user2035039
  • 961
  • 3
  • 16
  • 30

1 Answers1

0

you are not supposed to bind at runtime anything in the EE context. You can probably define it in tomcat as a resource or resources.xml (tomee specific) then just use a standard lookup to read the value (no special properties passed to InitialContext.

Romain Manni-Bucau
  • 3,354
  • 1
  • 16
  • 13
  • I tried to implement the second answer from here: http://stackoverflow.com/questions/18507629/inject-cdi-managed-bean-in-custom-shiro-authorizingrealm How do I accomplish this using resources? How do I instantiate my realms and do constructor injection? – user2035039 Dec 14 '16 at 08:23
  • before going in the explanation which are quite long I wonder if it wouldn't be easier to just use the cdi integration of pax https://ops4j1.jira.com/wiki/display/PAXSHIRO/CDI+Support ? Would make the referencing not relying on JNDI at all. If not it is a matter of defining your realm through https://tomcat.apache.org/tomcat-8.5-doc/config/context.html – Romain Manni-Bucau Dec 14 '16 at 14:49