No, unfortunately not. I really need the runtime registration of realms,
otherwise the whole design needs to be reworked, which i would like to
avoid:)

Does anyone have any experience with this?

On Tue, Apr 5, 2016 at 2:59 PM, scSynergy <[email protected]>
wrote:

> I am not sure whether this information will help you, but here is some code
> we use to initialize Shiro programmatically from an entry in MongoDB (we
> use
> https://ops4j1.jira.com/wiki/display/PAXSHIRO/OPS4J+Pax+Shiro for CDI
> integration). Notice how we add the realm 'CamelRealm.CAMELREALM (=
> "camelRealm")' through ini.setSectionProperty(...). We do not modify
> Shiro's
> configuration after it has been initialized, so I have no suggestion for
> you
> how to *change* realms, but *adding them programmatically at the time of
> initialization* works:
>
> MongoClientOptions.Builder builder =
> MongoClientOptions.builder().socketKeepAlive(true).connectionsPerHost(1);
> MongoClientURI uri = new MongoClientURI("mongodb://" + hostPort + "/" +
> dbName + "?" + options, builder);
> MongoClient mongo = new MongoClient(uri);
> DBCollection collection = mongo.getDB(dbName).getCollection("shiro-ini");
> DBCursor cursor = collection.find().sort(new BasicDBObject("timestamp",
> -1)).limit(1);
> if (cursor != null && cursor.hasNext()) {
>             String iniFile = cursor.next().get("conf").toString();
>             Ini ini = new Ini();
>             ini.load(iniFile);
>             String realms = ini.getSectionProperty("main",
> "securityManager.realms");
>             if (realms != null && !realms.contains(CamelRealm.CAMELREALM))
> {
>                 ini.setSectionProperty("main", "securityManager.realms",
> realms + ", $" + CamelRealm.CAMELREALM);
>             }
>             IniSecurityManagerFactory factory = new
> CdiIniSecurityManagerFactory(ini, manager);
>             SecurityManager securityManager = (SecurityManager)
> factory.getInstance();
>             SecurityUtils.setSecurityManager(securityManager);
> }
> mongo.close();
>
>
>
> --
> View this message in context:
> http://shiro-user.582556.n2.nabble.com/Using-Shiro-in-OSGi-and-registering-realms-dynamically-tp7581004p7581006.html
> Sent from the Shiro User mailing list archive at Nabble.com.
>

Reply via email to