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.