/* * * Copyright (c) 1999 - 2011 my-Channels Ltd * Copyright (c) 2012 - 2017 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors. * * Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG. * */ using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Xml.Serialization; namespace com.pcbsys.nirvana.nAdminAPI.apps { using com.pcbsys.nirvana.client; using com.pcbsys.nirvana.nAdminAPI; using com.pcbsys.nirvana.nAdminAPI.xml; /// /// * This application can be used to import the objects into a realm. /// * /// * The program will import realm acl entries and permissions, and configurations /// * for all channels, queues, interfaces and schedulers. /// * /// public class XMLImport { private string realmUrl = null; private nRealmNode node = null; private string fileName = null; internal bool realms = false; internal bool cluster = false; private bool realmAcl = false; private bool realmCfg = false; private bool channels = false; private bool datagroups = false; private bool channelAcls = false; private bool joins = false; private bool queues = false; private bool queueAcls = false; private bool interfaces = false; private bool iplugins = false; private bool via = false; private bool scheduler = false; private NirvanaRealm realm = null; /// /// * Constructor for the class, takes the string realm url /// * /// public XMLImport(string[] args) { try { getOptions(args); report("Connecting to " + realmUrl); // construct the session attributes for the realm nSessionAttributes attr = new nSessionAttributes(realmUrl); // construct the realm node node = new nRealmNode(attr); node.waitForEntireNameSpace(5000); // create a NirvanaRealm StreamReader reader = new StreamReader(fileName); XmlSerializer serializer = new XmlSerializer(typeof(NirvanaRealm)); realm = (NirvanaRealm)serializer.Deserialize(reader); if (realmAcl || channelAcls || queueAcls) { report("Importing security groups."); importSecurityGroups(realm, node); report("Imported security groups."); } // if specified, import the realm acl entries and set them if (realmAcl) { RealmACLEntry[] realmPerms = realm.RealmPermissionSet.RealmACLEntry; if (realmPerms != null) { report("Importing Realm ACLs"); importRealmACL(realmPerms); if (realm.RealmPermissionSet.RealmGroupACLEntry != null) importRealmGroupACL(realm.RealmPermissionSet.RealmGroupACLEntry); report("Imported Realm ACLs"); } else { report("No realm permissins to load"); } } // if specified, import the cluster information if (cluster) { ClusterEntry[] clusterset =realm.ClusterSet; if (clusterset != null) { report("Importing Cluster configuration"); importClusters(clusterset, node); report("Imported Cluster configuration"); } else { report("No cluster configuration to load"); } } // if specified, import the realm entries if (realms) { RealmEntry[] realmSet = realm.RealmSet; if (realmSet != null) { report("Importing known realms configuration"); importRealms(realmSet, node); report("Imported known realms configuration"); } else { report("No realm configuration to load"); } } // if specified, import the realm config groups and items if (realmCfg) { ConfigGroup[] cfg = realm.RealmConfiguration; if (cfg != null) { report("Importing Realm configuration"); //importRealmConfig(cfg); report("Imported Realm configuration"); } else { report("No realm configuration to load"); } } // if specified, import the interfaces if (interfaces) { RealmInterfaceSet iSet = realm.RealmInterfaces; if (iSet != null) { report("Importing Interface configuration"); importInterfaces(iSet); report("Imported Interface configuration"); } else { report("No Interface configuration to load"); } } // if specified, import the channels and their acls if (channels) { ChannelEntry[] chanSet = realm.ChannelSet; report("Importing topic configuration"); if (chanSet == null) { chanSet = new ChannelEntry[0]; } importChannels(chanSet); report("Imported topic configuration"); } // if specified, import the channels and their acls if (joins) { ChannelEntry[] chanSet = realm.ChannelSet; report("Importing Join configuration"); if (chanSet == null) { chanSet = new ChannelEntry[0]; } importChannelJoins(chanSet); report("Imported Join configuration"); } // if specified, import the queues and their acls if (queues) { report("Importing Queue configuration"); QueueEntry[] qSet = realm.QueueSet; if (qSet == null) { qSet = new QueueEntry[0]; } importQueues(qSet); report("Imported Queue configuration"); } // if specified, import the queues and their acls if (datagroups) { report("Importing DataGroup configuration"); List dgSet = new List(); if (realm.DataGroupSet != null) { dgSet = new List(realm.DataGroupSet); } importDataGroups(dgSet); report("Imported DataGroup configuration"); } if (via) { report("Importing Interface VIA configuration"); RealmInterfaceSet iSet = (RealmInterfaceSet)realm.RealmInterfaces; if (iSet != null) { importInterfaceViaList(iSet); } report("Imported Interface VIA configuration"); } // if specified, import the cluster information if (cluster) { ClusterEntry[] clusterset = realm.ClusterSet; if (clusterset != null) { report("Importing Cluster configuration"); importClusters(clusterset, node); report("Imported Cluster configuration"); } else { report("No cluster configuration to load"); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { if (node != null) { node.close(); nSessionFactory.shutdown(); } } } private void importDataGroups(List dataGroupList) { Hashtable dgnamemap = new Hashtable(); Dictionary dgnestedmap = new Dictionary(); for (int i = 0; i < dataGroupList.Count; i++) { DataGroupEntry groupEntry = dataGroupList[i]; DataGroupAttributesEntry dgattrib = groupEntry.DataGroupAttributesEntry; nConflationAttributes cattrib = getConflationAttributes(groupEntry.ConflationAttributesEntry); nDataGroup newgroup = node.getSession().createDataGroup(dgattrib.name, null, cattrib, dgattrib.multicastenabled, false, dgattrib.priority); //create data group //create data group DataGroupPublisherEntry[] publishers = groupEntry.DataGroupPublisherEntry; for (int j = 0;publishers!=null&& j < publishers.Length; j++) { //add group publishers DataGroupPublisherEntry publisherEntry = publishers[j]; String spubentry = publisherEntry.name + "@" + publisherEntry.host; newgroup.addPublisher(spubentry); } dgnamemap.Add(dgattrib.name, newgroup); NestedGroupEntry[] nestedgroups = groupEntry.NestedGroupEntry; if (nestedgroups != null && nestedgroups.Length > 0) dgnestedmap.Add(dgattrib.name, nestedgroups); //Store newsted group list in map } IEnumerable groupswithchildreniterator = dgnestedmap.Keys; foreach (String groupwithchildrenname in groupswithchildreniterator) { NestedGroupEntry[] nestedgroups = dgnestedmap[groupwithchildrenname]; for (int j = 0; j < nestedgroups.Length; j++) { NestedGroupEntry ngentry = nestedgroups[j]; nDataGroup parent = (nDataGroup) dgnamemap[groupwithchildrenname]; nDataGroup child = (nDataGroup) dgnamemap[(ngentry.name)]; parent.add(child); } } } private nConflationAttributes getConflationAttributes(ConflationAttributesEntry caentry) { if (caentry == null) return null; int catype = caentry.type.Equals("DROP_EVENTS_TYPE") ? nConflationAttributes.sDropEvents : nConflationAttributes.sMergeEvents; nConflationAttributes returnvalue = new nConflationAttributes(catype, caentry.interval); return returnvalue; } /// /// * Main program thread, takes a realm URL as the parameter to start the search /// static void Main(string[] args) { new XMLImport(args); } /// /// * Set the program variables and flags based on command line args /// public virtual void getOptions(string[] args) { if (args == null || args.Length == 0) { Usage(); System.Environment.Exit(1); } realmUrl = args[0]; if (realmUrl == null) { Usage(); System.Environment.Exit(1); } fileName = args[1]; if (fileName == null) { Usage(); System.Environment.Exit(1); } if (args == null) { Usage(); System.Environment.Exit(1); } // set what will be imported based on command line arguments bool foundNoCluster = false; for (int x = 0; x < args.Length; x++) { if (args[x].Equals("-all")) { realms = true; cluster = true; realmAcl = true; realmCfg = true; channels = true; channelAcls = true; joins = true; queues = true; queueAcls = true; interfaces = true; iplugins = true; scheduler = true; via = true; datagroups = true; } if (args[x].Equals("-nocluster")) { foundNoCluster = true; } if (args[x].Equals("-realms")) { realms = true; } if (args[x].Equals("-cluster")) { cluster = true; } if (args[x].Equals("-realmacl")) { realmAcl = true; } if (args[x].Equals("-realmcfg")) { realmCfg = true; } if (args[x].Equals("-channels")) { channels = true; } if (args[x].Equals("-channelacls")) { channelAcls = true; } if (args[x].Equals("-joins")) { joins = true; } if (args[x].Equals("-queues")) { queues = true; } if (args[x].Equals("-queueacls")) { queueAcls = true; } if (args[x].Equals("-interfaces")) { interfaces = true; } if (args[x].Equals("-plugins")) { iplugins = true; } if (args[x].Equals("-via")) { via = true; } if (args[x].Equals("-datagroups")) { datagroups = true; } } if (foundNoCluster) { report("Cluster configuration not being loaded due to -noCluster flag"); cluster = false; } } /// /// * Method to import additional realms to the namespace /// private void importClusters(ClusterEntry[] entries, nRealmNode rnode) { try { if (entries == null) return; for (int x = 0; x < entries.Length; x++) { ClusterEntry entry = entries[x]; string clusterName = entry.name; report("Creating cluster " + clusterName); ClusterMember[] members = entry.ClusterMember; nSessionAttributes[] sessionAttribs = new nSessionAttributes[members.Length]; nClusterMemberConfiguration[] memCfgs = new nClusterMemberConfiguration[members.Length]; for (int y = 0; y < members.Length; y++) { ClusterMember member = members[y]; string name = member.name; string rname = member.rname; report("\tAdding member " + name + " at RNAME=" + rname); sessionAttribs[y] = new nSessionAttributes(rname); memCfgs[y] = new nClusterMemberConfiguration(sessionAttribs[y], true); } report("Establishing cluster " + clusterName); nClusterNode cluster = nClusterNode.create(clusterName, memCfgs); ClusterSite[] sites = entry.ClusterSite; for (int y = 0; y < sites.Length; y++) { ClusterSite site = sites[y]; string name = site.name; report("Adding new cluster site" + name); SiteMember[] smembers = site.SiteMember; SiteMember firstmember = (SiteMember)smembers[0]; nClusterSite cSite = cluster.createSite(name, firstmember.name); for (int z = 1; z < smembers.Length; z++) { SiteMember smember = smembers[z]; cSite.addMember(smember.name); } } report("Established cluster " + clusterName); } } catch (Exception e) { throw e; } } /// /// * Method to import additional realms to the namespace /// private void importRealms(RealmEntry[] entries, nRealmNode rnode) { try { if (entries == null) return; for (int x = 0; x < entries.Length; x++) { RealmEntry entry = (RealmEntry)entries[x]; try { string name = entry.name; string rname = entry.rname; string mount = entry.mountpoint; if (rname.Equals("")) { return; } if ((mount != null) && (!mount.Equals(""))) { if (!mount.StartsWith("/")) { mount = "/" + mount; } } string[] conns = new string[1]; conns[0] = rname; nSession session = rnode.getSession(); nRealm realm = new nRealm(name, conns); if (!mount.Equals("")) { realm.setMountPoint(mount); } session.addRealm(realm); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } catch (Exception e) { throw e; } } private void importSecurityGroups(NirvanaRealm realm, nRealmNode rnode) { RealmSecurityGroup[] realmSecurityGroups = realm.RealmSecurityGroupSet ?? new RealmSecurityGroup[0]; nSecurityGroupManager securityGroupManager = rnode.getSecurityGroupManager(); foreach (RealmSecurityGroup realmSecurityGroup in realmSecurityGroups) { String groupName = realmSecurityGroup.RealmSecurityGroupEntry.groupname; try{ securityGroupManager.registerSecurityGroup(groupName); }catch (Exception ex){ Console.WriteLine(ex.Message);//todo::remove } nSecurityGroup group = securityGroupManager.getGroup(groupName); SecurityGroupSubjectEntry[] securityGroupSubjectEntries = realmSecurityGroup.SecurityGroupSubjectEntry; if (securityGroupSubjectEntries != null) { foreach (SecurityGroupSubjectEntry securityGroupSubjectEntry in securityGroupSubjectEntries) { try { securityGroupManager.registerGroupMember(group, new nSubject(securityGroupSubjectEntry.name + "@" + securityGroupSubjectEntry.host)); } catch (Exception ex) { Console.WriteLine(ex.Message); //todo::remove } } } SecurityGroupReferenceEntry[] securityGroupReferenceEntries = realmSecurityGroup.SecurityGroupReferenceEntry; if (securityGroupReferenceEntries != null) { foreach (SecurityGroupReferenceEntry securityGroupReferenceEntry in securityGroupReferenceEntries) { try { nSecurityGroup grp = securityGroupManager.getGroup(securityGroupReferenceEntry.groupname); if (grp == null) { securityGroupManager.registerSecurityGroup(securityGroupReferenceEntry.groupname); grp = securityGroupManager.getGroup(securityGroupReferenceEntry.groupname); } securityGroupManager.registerGroupMember(group, grp); } catch (Exception ex) { Console.WriteLine(ex.Message); //todo::remove } } } } } /// /// * Method to import contents of a realm acl /// private void importRealmACL(RealmACLEntry[] entries) { try { if (entries == null) return; nACL realmAcl = node.getACLs(); for (int x = 0; x < entries.Length; x++) { RealmACLEntry entry = entries[x]; try { nRealmACLEntry newentry = createRealmACLEntry(entry); realmAcl.add(newentry); realmAcl.notifyObservers(newentry); } catch (nDuplicateACLEntryException dup) { // if entry exists, replace it with the imported one nRealmACLEntry modify = (nRealmACLEntry)realmAcl.find(entry.name + "@" + entry.host); modify = modifyRealmACLEntry(entry, modify); realmAcl.replace(modify); realmAcl.notifyObservers(modify); } catch (nAdminIllegalArgumentException illegal) { } } // set the acl for the realm node.setACLs(realmAcl); } catch (Exception e) { throw e; } } private void importRealmGroupACL(RealmGroupACLEntry[] entries) { nACL rAcl = node.getACLs(); foreach (Object entry1 in entries) { RealmGroupACLEntry entry = (RealmGroupACLEntry) entry1; try { nRealmACLEntry newentry = createRealmGroupACLEntry(entry); rAcl.add(newentry); rAcl.notifyObservers(newentry); } catch (nDuplicateACLEntryException ) { // if entry exists, replace it with the imported one nRealmACLEntry modify = (nRealmACLEntry) rAcl.find(entry.groupname); modify = modifyRealmACLEntry(entry, modify); rAcl.replace(modify); rAcl.notifyObservers(modify); } catch (nAdminIllegalArgumentException ) { } } } /// /// * Construct a new realm acl entry based on the imported xml /// private nRealmACLEntry createRealmACLEntry(RealmACLEntry entry) { nRealmACLEntry newAcl = null; try { newAcl = new nRealmACLEntry(entry.name, entry.host); newAcl.setAccessTheRealm(entry.connectToRealm); newAcl.setConfigureRealm(entry.changeRealmConfig); newAcl.setFullPrivileges(entry.fullControl); newAcl.setList(entry.listACLEntries); newAcl.setModify(entry.modifyACLEntries); newAcl.setManageChannels(entry.addremoveChannels); newAcl.setManageJoins(entry.addremoveJoins); newAcl.setManageRealm(entry.addremoveRealms); newAcl.setOverrideConnectionCount(entry.overrideConnectionCount); newAcl.setUseAdminAPI(entry.useAdminAPI); newAcl.setManageDataGroups(entry.manageDatagroups); newAcl.setTakeOwnershipOfDataGroup(entry.ownDatagroups); newAcl.setPublishToGlobalDataGroup(entry.publishDatagroups); } catch (Exception e) { throw e; } return newAcl; } /// /// * Construct a new realm acl entry based on the imported xml /// private nRealmACLEntry createRealmGroupACLEntry(RealmGroupACLEntry entry) { nRealmACLEntry newAcl = null; try { newAcl = new nRealmACLEntry(new nSecurityGroup(entry.groupname)); newAcl.setAccessTheRealm(entry.connectToRealm); newAcl.setConfigureRealm(entry.changeRealmConfig); newAcl.setFullPrivileges(entry.fullControl); newAcl.setList(entry.listACLEntries); newAcl.setModify(entry.modifyACLEntries); newAcl.setManageChannels(entry.addremoveChannels); newAcl.setManageJoins(entry.addremoveJoins); newAcl.setManageRealm(entry.addremoveRealms); newAcl.setOverrideConnectionCount(entry.overrideConnectionCount); newAcl.setUseAdminAPI(entry.useAdminAPI); newAcl.setManageDataGroups(entry.manageDatagroups); newAcl.setTakeOwnershipOfDataGroup(entry.ownDatagroups); newAcl.setPublishToGlobalDataGroup(entry.publishDatagroups); } catch (Exception e) { throw e; } return newAcl; } /// /// * Modify an existing realm acl entry based on the imported xml /// private nRealmACLEntry modifyRealmACLEntry(RealmACLEntry entry, nRealmACLEntry mod) { try { mod.setAccessTheRealm(entry.connectToRealm); mod.setConfigureRealm(entry.changeRealmConfig); mod.setFullPrivileges(entry.fullControl); mod.setList(entry.listACLEntries); mod.setModify(entry.modifyACLEntries); mod.setManageChannels(entry.addremoveChannels); mod.setManageJoins(entry.addremoveJoins); mod.setManageRealm(entry.addremoveRealms); mod.setOverrideConnectionCount(entry.overrideConnectionCount); mod.setUseAdminAPI(entry.useAdminAPI); mod.setManageDataGroups(entry.manageDatagroups); mod.setTakeOwnershipOfDataGroup(entry.ownDatagroups); mod.setPublishToGlobalDataGroup(entry.publishDatagroups); } catch (Exception e) { throw e; } return mod; } /// /// * Modify an existing realm acl entry based on the imported xml /// private nRealmACLEntry modifyRealmACLEntry(RealmGroupACLEntry entry, nRealmACLEntry mod) { try { mod.setAccessTheRealm(entry.connectToRealm); mod.setConfigureRealm(entry.changeRealmConfig); mod.setFullPrivileges(entry.fullControl); mod.setList(entry.listACLEntries); mod.setModify(entry.modifyACLEntries); mod.setManageChannels(entry.addremoveChannels); mod.setManageJoins(entry.addremoveJoins); mod.setManageRealm(entry.addremoveRealms); mod.setOverrideConnectionCount(entry.overrideConnectionCount); mod.setUseAdminAPI(entry.useAdminAPI); mod.setManageDataGroups(entry.manageDatagroups); mod.setTakeOwnershipOfDataGroup(entry.ownDatagroups); mod.setPublishToGlobalDataGroup(entry.publishDatagroups); } catch (Exception e) { throw e; } return mod; } /// /// * Construct a new realm acl entry based on the imported xml /// private nACLEntry createInterfaceACLEntry(InterfaceACLEntry entry) { nInterfaceViaEntry newAcl = null; try { newAcl = new nInterfaceViaEntry(entry.name, entry.host); } catch (Exception e) { throw e; } return newAcl; } /// /// * Construct a new realm acl entry based on the imported xml /// private nACLEntry createInterfaceGroupACLEntry(InterfaceGroupACLEntry entry) { nInterfaceViaEntry newAcl = null; try { newAcl = new nInterfaceViaEntry(new nSecurityGroup(entry.groupname)); } catch (Exception e) { throw e; } return newAcl; } /// /// * Import the realm configuration groups and their item values /// private void importRealmConfig(ConfigGroup[] cfgGrps) { try { if (cfgGrps == null) return; for (int x = 0; x < cfgGrps.Length; x++) { ConfigGroup grp = cfgGrps[x]; string grpName = grp.name; nConfigGroup nGrp = node.findConfigGroup(grpName); if (nGrp != null) { if (!nGrp.isReadOnly()) { ConfigItem[] cfgItems = grp.ConfigItem; for (int y = 0; y < cfgItems.Length; y++) { ConfigItem item = cfgItems[y]; nConfigEntry nItem = nGrp.find(item.name); nItem.Value = item.value; } node.commitConfig(nGrp); } else { report("\tConfiguration group " + nGrp.Name + " is read only and will not be imported"); } } } } catch (Exception e) { throw e; } } /// /// * Import the channels and their acls if specified /// private void importChannels(ChannelEntry[] chanList) { try { if (chanList == null) return; for (int x = 0; x < chanList.Length; x++) { ChannelEntry chan = chanList[x]; nChannelAttributes nAttr = createChanAttributes(chan.ChannelAttributesEntry); createStoreProperties(nAttr, chan.StorePropertiesEntry); nChannelPublishKeys[] keys = createChannelPublishKeys(chan); if (keys != null) nAttr.setPublishKeys(keys); nLeafNode nChan = null; nACL chanAcl = null; if (channelAcls) { ChannelACLEntry[] chanPerms = chan.ChannelPermissionSet.ChannelACLEntry; nChan = (nLeafNode)node.findNode(nAttr.getName(), false); if (nChan != null) { chanAcl = nChan.getACLs(); } else { chanAcl = nLeafNode.createACL(); } for (int y = 0;chanPerms!=null&& y < chanPerms.Length; y++) { ChannelACLEntry entry = chanPerms[y]; nChannelACLEntry nEntry = createChannelACLEntry(entry); try { chanAcl.add(nEntry); } catch (nDuplicateACLEntryException ) { chanAcl.replace(nEntry); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } ChannelPermissionSet perms = chan.ChannelPermissionSet; ChannelGroupACLEntry[] chanGroupPerms = perms.ChannelGroupACLEntry; foreach (Object chanPerm in chanGroupPerms) { ChannelGroupACLEntry entry = (ChannelGroupACLEntry) chanPerm; nChannelACLEntry nEntry = createChannelGroupACLEntry(entry); try { chanAcl.add(nEntry); } catch (nDuplicateACLEntryException dup) { chanAcl.replace(nEntry); } catch (Exception ex) { Console.WriteLine(ex.Message); } } if (nChan == null) { if (channelAcls && channels) { node.createChannel(nAttr, chan.ChannelAttributesEntry.EID, chanAcl); } else if (channels) { node.createChannel(nAttr, chan.ChannelAttributesEntry.EID); } } else if (channelAcls) { nChan.setACLs(chanAcl); } } report("Imported " + chanList.Length + " topics"); } catch (Exception e) { throw e; } } /// /// * Import the channel joins /// private void importChannelJoins(ChannelEntry[] chanList) { try { if (chanList == null) return; for (int x = 0; x < chanList.Length; x++) { ChannelEntry chan = chanList[x]; nChannelAttributes nAttr = createChanAttributes(chan.ChannelAttributesEntry); nLeafNode from = null; nLeafNode to = null; if (joins) { ChannelJoinEntry[] joinList = chan.ChannelJoinSet; if (joinList == null || joinList.Length == 0) continue; from = (nLeafNode)node.findNode(nAttr.getName()); for (int y = 0; y < joinList.Length; y++) { ChannelJoinEntry join = (ChannelJoinEntry)joinList[y]; if (from != null) { to = (nLeafNode)node.findNode(join.to); if (to != null) { try { from.join(to, true, join.hopcount, join.filter, join.allowPurge); } catch (Exception e) { //if it is already there removed it and then recreate it so we pick up any changed attributes if (e.Message.IndexOf("is already joined") > 0) { //System.out.println("duplicate join for [" +from.getAbsolutePath() +"] > [" +to.getAbsolutePath() +"]"); try { from.deleteJoin(to); from.join(to, true, join.hopcount, join.filter, join.allowPurge); //System.out.println("recreated join for [" +from.getAbsolutePath() +"] > [" +to.getAbsolutePath() +"]"); } catch (Exception ) { Console.WriteLine("join error for [" + from.getAbsolutePath() + "] > [" + to.getAbsolutePath() + "]"); Console.WriteLine(e.Message); } } else { Console.WriteLine("join error for [" + from.getAbsolutePath() + "] > [" + to.getAbsolutePath() + "]"); Console.WriteLine(e.Message); } } } } } } } } catch (Exception e) { throw e; } } private nChannelAttributes createChanAttributes(ChannelAttributesEntry attribs) { nChannelAttributes nAttr = new nChannelAttributes(); try { nAttr.setName(attribs.name); nAttr.setTTL(attribs.TTL); nAttr.setMaxEvents(attribs.capacity); if (attribs.type.Equals("SIMPLE_TYPE")) { nAttr.setType(nChannelAttributes.SIMPLE_TYPE); } else if (attribs.type.Equals("TRANSIENT_TYPE")) { nAttr.setType(nChannelAttributes.TRANSIENT_TYPE); } else if (attribs.type.Equals("RELIABLE_TYPE")) { nAttr.setType(nChannelAttributes.RELIABLE_TYPE); } else if (attribs.type.Equals("PERSISTENT_TYPE")) { nAttr.setType(nChannelAttributes.PERSISTENT_TYPE); } else if (attribs.type.Equals("OFF_HEAP_TYPE")) { nAttr.setType(nChannelAttributes.OFF_HEAP_TYPE); } else if (attribs.type.Equals("PAGE_TYPE")) { nAttr.setType(nChannelAttributes.PAGE_TYPE); } else if (attribs.type.Equals("MIXED_TYPE")) { nAttr.setType(nChannelAttributes.MIXED_TYPE); } nAttr.setClusterWide(attribs.clusterWide); nAttr.useJMSEngine(attribs.jmsEngine); nAttr.useMergeEngine(attribs.mergeEngine); } catch (Exception e) { throw e; } return nAttr; } private void createStoreProperties(nChannelAttributes nAttr, StorePropertiesEntry attribs) { if (attribs != null) { nChannelAttributes tmp = new nChannelAttributes(); nStoreProperties test = tmp.getProperties(); // // If flow control will slow down / stop publishes if we exceed capacity // if (test.getHonorCapacityWhenFull() != attribs.HonorCapacityWhenFull) { nStoreProperties props = nAttr.getProperties(); props.setHonorCapacityWhenFull(attribs.HonorCapacityWhenFull); } // // I/O Sync flags // if (attribs.SyncOnEachWrite!=null) { nStoreProperties props = nAttr.getProperties(); props.setSyncOnEachWrite(attribs.SyncOnEachWrite); } if (attribs.SyncBatchTime!=null) { nStoreProperties props = nAttr.getProperties(); props.setSyncBatchTime(attribs.SyncBatchTime); } if (attribs.SyncMaxBatchSize!=null) { nStoreProperties props = nAttr.getProperties(); props.setSyncMaxBatchSize(attribs.SyncMaxBatchSize); } // // Client class name to use to merge events // if (attribs.ClientMergeEngineClassname != null) { nStoreProperties props = nAttr.getProperties(); props.setClientMergeEngineClassname(attribs.ClientMergeEngineClassname); } // // Fanout archive target store name // if (attribs.FanoutArchiveTarget != null) { nStoreProperties props = nAttr.getProperties(); props.setFanoutArchiveTarget(attribs.FanoutArchiveTarget); } // // Enable / disable event caching for the store // if (attribs.CacheOnReload!=null) { nStoreProperties props = nAttr.getProperties(); props.setCacheOnReload(attribs.CacheOnReload); } if (attribs.EnableCaching!=null) { nStoreProperties props = nAttr.getProperties(); props.setEnableCaching(attribs.EnableCaching); } // // Indicate if read buffering is allowed, this, by default is true since it is faster // if (attribs.EnableReadBuffering!=null) { nStoreProperties props = nAttr.getProperties(); props.setEnableReadBuffering(attribs.EnableReadBuffering); } if (attribs.ReadBufferSize!=null) { nStoreProperties props = nAttr.getProperties(); props.setReadBufferSize(attribs.ReadBufferSize); } if (attribs.PerformAutomaticMaintenance!=null) { nStoreProperties props = nAttr.getProperties(); props.setPerformAutomaticMaintenance(attribs.PerformAutomaticMaintenance); } if (attribs.Priority != null) { nStoreProperties props = nAttr.getProperties(); props.setPriority(attribs.Priority); } if (attribs.StampDictionary != null) { nStoreProperties props = nAttr.getProperties(); props.setStampDictionary(attribs.StampDictionary); } } } private nChannelPublishKeys[] createChannelPublishKeys(ChannelEntry chan) { if (!channels) { return null; } nChannelPublishKeys[] keys = null; ChannelKeyEntry[] chankeylist = chan.ChannelKeySet; if (chankeylist == null || chankeylist.Length == 0) return null; if (channels) { if ((chankeylist != null) && (chankeylist.Length > 0)) { keys = new nChannelPublishKeys[chankeylist.Length]; for (int x = 0; x < chankeylist.Length; x++) { ChannelKeyEntry chankeyentry = (ChannelKeyEntry)chankeylist[x]; keys[x] = new nChannelPublishKeys(chankeyentry.keyName, chankeyentry.keyDepth); } } } else { return null; } return keys; } private nChannelACLEntry createChannelACLEntry(ChannelACLEntry entry) { nChannelACLEntry newAcl = null; try { newAcl = new nChannelACLEntry(entry.name, entry.host); newAcl.setFullPrivileges(entry.fullControl); newAcl.setGetLastEID(entry.getLastEID); newAcl.setList(entry.listACLEntries); newAcl.setModify(entry.modifyACLEntries); newAcl.setPurge(entry.purgeEvents); newAcl.setRead(entry.subscribe); newAcl.setUseNamedSubscription(entry.useNamedSubcription); newAcl.setWrite(entry.publish); } catch (Exception e) { throw e; } return newAcl; } private nChannelACLEntry createChannelGroupACLEntry(ChannelGroupACLEntry entry) { nChannelACLEntry newAcl = null; try { newAcl = new nChannelACLEntry(new nSecurityGroup(entry.groupname)); newAcl.setFullPrivileges(entry.fullControl); newAcl.setGetLastEID(entry.getLastEID); newAcl.setList(entry.listACLEntries); newAcl.setModify(entry.modifyACLEntries); newAcl.setPurge(entry.purgeEvents); newAcl.setRead(entry.subscribe); newAcl.setUseNamedSubscription(entry.useNamedSubcription); newAcl.setWrite(entry.publish); } catch (Exception e) { throw e; } return newAcl; } private nChannelACLEntry modifyChannelACLEntry(ChannelACLEntry entry, nChannelACLEntry mod) { try { mod.setFullPrivileges(entry.fullControl); mod.setGetLastEID(entry.getLastEID); mod.setList(entry.listACLEntries); mod.setModify(entry.modifyACLEntries); mod.setPurge(entry.purgeEvents); mod.setRead(entry.subscribe); mod.setUseNamedSubscription(entry.useNamedSubcription); mod.setWrite(entry.publish); } catch (Exception e) { throw e; } return mod; } private nChannelACLEntry createQueueACLEntry(QueueACLEntry entry) { nChannelACLEntry newAcl = null; try { newAcl = new nChannelACLEntry(entry.name, entry.host); newAcl.setFullPrivileges(entry.fullControl); newAcl.setList(entry.listACLEntries); newAcl.setModify(entry.modifyACLEntries); newAcl.setPop(entry.pop); newAcl.setRead(entry.peek); newAcl.setWrite(entry.push); newAcl.setPurge(entry.purge); } catch (Exception e) { throw e; } return newAcl; } private nChannelACLEntry createQueueGroupACLEntry(QueueGroupACLEntry entry) { nChannelACLEntry newAcl = null; try { newAcl = new nChannelACLEntry(new nSecurityGroup(entry.groupname)); newAcl.setFullPrivileges(entry.fullControl); newAcl.setList(entry.listACLEntries); newAcl.setModify(entry.modifyACLEntries); newAcl.setPop(entry.pop); newAcl.setRead(entry.peek); newAcl.setWrite(entry.push); newAcl.setPurge(entry.purge); } catch (Exception e) { throw e; } return newAcl; } private nChannelACLEntry modifyQueueACLEntry(QueueACLEntry entry, nChannelACLEntry mod) { try { mod.setFullPrivileges(entry.fullControl); mod.setList(entry.listACLEntries); mod.setModify(entry.modifyACLEntries); mod.setPop(entry.pop); mod.setRead(entry.peek); mod.setWrite(entry.push); mod.setPurge(entry.purge); } catch (Exception e) { throw e; } return mod; } private void importQueues(QueueEntry[] qList) { try { if (qList == null) return; for (int x = 0; x < qList.Length; x++) { QueueEntry q = (QueueEntry)qList[x]; nChannelAttributes nAttr = createChanAttributes(q.ChannelAttributesEntry); createStoreProperties(nAttr, q.StorePropertiesEntry); nLeafNode nqueue = null; nACL qAcl = null; if (queueAcls) { QueueACLEntry[] qPerms = q.QueuePermissionSet.QueueACLEntry; nqueue = (nLeafNode)node.findNode(nAttr.getName(), false); qAcl = null; if (nqueue != null) { qAcl = nqueue.getACLs(); } else { qAcl = nLeafNode.createACL(); } for (int y = 0;qPerms!=null && y < qPerms.Length; y++) { QueueACLEntry entry = (QueueACLEntry)qPerms[y]; nChannelACLEntry nEntry = createQueueACLEntry(entry); try { qAcl.add(nEntry); qAcl.notifyObservers(nEntry); } catch (nDuplicateACLEntryException dup) { qAcl.replace(nEntry); qAcl.notifyObservers(nEntry); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } QueuePermissionSet perms = q.QueuePermissionSet; QueueGroupACLEntry[] qGroupPerms = perms.QueueGroupACLEntry; foreach (Object qPerm in qGroupPerms) { QueueGroupACLEntry entry = (QueueGroupACLEntry) qPerm; nChannelACLEntry nEntry = createQueueGroupACLEntry(entry); try { qAcl.add(nEntry); qAcl.notifyObservers(nEntry); } catch (nDuplicateACLEntryException ) { qAcl.replace(nEntry); qAcl.notifyObservers(nEntry); } catch (Exception ex) { Console.WriteLine(ex.Message); } } if (nqueue == null) { if (queueAcls) { node.createQueue(nAttr, qAcl); } else { node.createQueue(nAttr); } } else { if (queueAcls) { nqueue.setACLs(qAcl); } } } } catch (Exception e) { throw e; } } private nSharedMemoryInterface createSHMInterface(RealmSHMConfigurationEntry iface) { nSharedMemoryInterface shmif; shmif = new nSharedMemoryInterface(iface.timeout); shmif.setBufferSize((int)iface.buffersize); shmif.setDirectoryPath(iface.directory); shmif.setAutostart(true); return shmif; } private nMulticastConfiguration createMulticastConfiguration(RealmMulticastConfigurationEntry entry){ //basic configuration RealmMulticastBasicConfigurationEntry basicentry=entry.RealmMulticastBasicConfigurationEntry; nMulticastConfiguration mconfig=new nMulticastConfiguration(basicentry.MulticastAddress,basicentry.AdapterAddress, true); mconfig.setAdapterBufferSize((int) basicentry.AdapterBufferSize); mconfig.setClientEstablishmentTimeout(basicentry.Clientestablishmenttimeout); mconfig.setUseForCluster(basicentry.useforClusters); mconfig.setUseForDataGroups(basicentry.useforDatagroups); mconfig.setUseForStatusUpdae(basicentry.useforStatusUpdates); //Security RealmMulticastSecurityConfigurationEntry secentry=entry.RealmMulticastSecurityConfigurationEntry; RealmMulticastSecurityConfigurationEntryCRCtype sCRCTYPE = secentry.CRCtype; if (sCRCTYPE.Equals("NONE")) mconfig.setCRCType(0); else if (sCRCTYPE.Equals("CRC")) mconfig.setCRCType(1); else if (sCRCTYPE.Equals("MD5")) mconfig.setCRCType(2); else if (sCRCTYPE.Equals("SHA")) mconfig.setCRCType(3); RealmMulticastSecurityConfigurationEntryEncryptionlevel sEncryptionLevel = secentry.encryptionlevel; if (sEncryptionLevel.Equals("NONE")) mconfig.setEncryptionLevel((byte) 0); else if (sEncryptionLevel.Equals("AES-128")) mconfig.setEncryptionLevel((byte)1); else if (sEncryptionLevel.Equals("AES-192")) mconfig.setEncryptionLevel((byte)2); else if (sEncryptionLevel.Equals("AES-256")) mconfig.setEncryptionLevel((byte)3); mconfig.setRotateEncryptionKeyTime((int) secentry.RotateEncryptionKeyTime); mconfig.setRotateEncryptionKeyCount((int) secentry.RotateEnryptionKeyWait); mconfig.setUniqueSessionIDSize((int) secentry.SessionIDSize); //advanced configuration RealmMulticastAdvancedConfigurationEntry aentry=entry.RealmMulticastAdvancedConfigurationEntry; RealmMulticastAdvancedConfigurationEntryACKmode sMode = aentry.ACKmode; if (sMode.Equals("ACK-WINDOW")) mconfig.setMode((byte) 0); else if (sMode.Equals("NACK-WINDOW")) mconfig.setMode((byte) 1); else if (sMode.Equals("BROADCAST")) mconfig.setMode((byte) 2); mconfig.setKeepAliveInterval((int) aentry.KeepAliveInterval); mconfig.setTTL((short) aentry.PacketTTL); mconfig.setTrafficClass((byte) aentry.TrafficClass); mconfig.setFlusherInterval((int) aentry.FlusherInterval); mconfig.setAckWindowSize((int) aentry.AckWindowsize); mconfig.setUnAckedWindowSize((int) aentry.UnackedWindowsize); mconfig.setPacketSize((int) aentry.PacketSize); mconfig.setMaxOutstandingPackets((int) aentry.ReceiverOutstandingPacketSize); mconfig.setOutstandingPacketsQueueSize((int) aentry.SenderOutstandingPacketSize); mconfig.setPeakRate((int) aentry.PeakDetectionRate); return mconfig; } private void importInterfaces(RealmInterfaceSet iSet) { nMulticastManager multimgr=node.getMulticastManager(); RealmMulticastConfigurationEntry[] multiList=iSet.RealmMulticastConfiguration; if (multiList != null) { for (int i = 0; i < multiList.Length; i++) { RealmMulticastConfigurationEntry mentry = multiList[i]; nMulticastConfiguration multiconfig = createMulticastConfiguration(mentry); multimgr.addMulticastConfiguration(multiconfig); } } nInterfaceManager mgr = node.getInterfaceManager(); RealmSHMConfigurationEntry[] shmList=iSet.RealmSHMConfiguration; if (shmList != null) { for (int i = 0; i < shmList.Length; i++) { RealmSHMConfigurationEntry shmentry = shmList[i]; nSharedMemoryInterface shmif = createSHMInterface(shmentry); mgr.addInterface(shmif); } } try { RealmNSPInterfaceEntry[] nspList = iSet.RealmNSPInterface; if (nspList != null) { for (int x = 0; x < nspList.Length; x++) { RealmNSPInterfaceEntry iface = (RealmNSPInterfaceEntry)nspList[x]; nSocketInterface socks = createSocketInterface(iface); mgr.addInterface(socks); } } RealmNHPInterfaceEntry[] nhpList = iSet.RealmNHPInterface; if (nhpList != null) { for (int x = 0; x < nhpList.Length; x++) { RealmNHPInterfaceEntry iface = (RealmNHPInterfaceEntry)nhpList[x]; nHTTPInterface http = createHTTPInterface(iface); try { mgr.findInterface(iface.RealmInterface.name); http = (nHTTPInterface)mgr.findInterface(iface.RealmInterface.name).getInterface(); if (iplugins) { createPlugin(http, iface); } mgr.modInterface(http); } catch(Exception ) { if (iplugins) { createPlugin(http, iface); } mgr.addInterface(http); } } } RealmNSPSInterfaceEntry[] nspsList = iSet.RealmNSPSInterface; if (nspsList != null) { for (int x = 0; x < nspsList.Length; x++) { RealmNSPSInterfaceEntry iface = (RealmNSPSInterfaceEntry)nspsList[x]; nSSLInterface nsps = createSSLInterface(iface); mgr.addInterface(nsps); } } RealmNHPSInterfaceEntry[] nhpsList = iSet.RealmNHPSInterface; if (nhpsList != null) { for (int x = 0; x < nhpsList.Length; x++) { RealmNHPSInterfaceEntry iface = (RealmNHPSInterfaceEntry)nhpsList[x]; nHTTPSInterface nhps = createHTTPSInterface(iface); try { mgr.findInterface(iface.RealmInterface.name); nhps = (nHTTPSInterface)mgr.findInterface(iface.RealmInterface.name).getInterface(); if (iplugins) { createPlugin(nhps, iface); } mgr.modInterface(nhps); } catch(Exception ) { if (iplugins) { createPlugin(nhps, iface); } mgr.addInterface(nhps); } } } } catch (Exception e) { throw e; } } /// /// * Method to import contents of a realm acl /// private void importInterfaceViaList(RealmInterfaceSet iSet) { nInterfaceManager mgr = node.getInterfaceManager(); try { RealmNSPInterfaceEntry[] nspList = iSet.RealmNSPInterface; if (nspList != null) { for (int x = 0; x < nspList.Length; x++) { RealmNSPInterfaceEntry iface = (RealmNSPInterfaceEntry)nspList[x]; nInterfaceStatus status = mgr.findInterface(iface.RealmInterface.name); nSocketInterface socks = null; if (status != null) { socks = (nSocketInterface)status.getInterface(); importViaList(iface.InterfacePermissionSet.InterfaceACLEntry, (nInterface)socks); } } } RealmNHPInterfaceEntry[] nhpList = iSet.RealmNHPInterface; if (nhpList != null) { for (int x = 0; x < nhpList.Length; x++) { RealmNHPInterfaceEntry iface = (RealmNHPInterfaceEntry)nhpList[x]; nInterfaceStatus status = mgr.findInterface(iface.RealmInterface.name); nHTTPInterface http = null; if (status != null) { http = (nHTTPInterface)status.getInterface(); importViaList(iface.InterfacePermissionSet.InterfaceACLEntry, (nInterface)http); } } } RealmNSPSInterfaceEntry[] nspsList = iSet.RealmNSPSInterface; if (nspsList != null) { for (int x = 0; x < nspsList.Length; x++) { RealmNSPSInterfaceEntry iface = (RealmNSPSInterfaceEntry)nspsList[x]; nInterfaceStatus status = mgr.findInterface(iface.RealmInterface.name); nSSLInterface nsps = null; if (status != null) { nsps = (nSSLInterface)status.getInterface(); importViaList(iface.InterfacePermissionSet.InterfaceACLEntry, (nInterface)nsps); } } } RealmNHPSInterfaceEntry[] nhpsList = iSet.RealmNHPSInterface; if (nhpsList != null) { for (int x = 0; x < nhpsList.Length; x++) { RealmNHPSInterfaceEntry iface = (RealmNHPSInterfaceEntry)nhpsList[x]; nInterfaceStatus status = mgr.findInterface(iface.RealmInterface.name); nHTTPSInterface nhps = null; if (status != null) { nhps = (nHTTPSInterface)status.getInterface(); importViaList(iface.InterfacePermissionSet.InterfaceACLEntry, (nInterface)nhps); } } } } catch (Exception e) { throw e; } } /// /// * Method to import contents of a realm acl /// private void importViaList(InterfaceACLEntry[] entries, nInterface iface) { try { if (entries == null || entries.Length == 0) return; nACL ifaceAcl = iface.getViaList(); if (ifaceAcl == null) { if (entries.Length == 0) { return; } else { ifaceAcl = nRealmNode.createACL(); } } for (int x = 0; x < entries.Length; x++) { InterfaceACLEntry entry = (InterfaceACLEntry)entries[x]; try { nACLEntry newentry = createInterfaceACLEntry(entry); ifaceAcl.add(newentry); ifaceAcl.notifyObservers(newentry); } catch (nDuplicateACLEntryException dup) { // if entry exists, do nothing } catch (nAdminIllegalArgumentException illegal) { } } // set the acl for the realm iface.setViaList(ifaceAcl); } catch (Exception e) { throw e; } } private nSocketInterface createSocketInterface(RealmNSPInterfaceEntry iface) { nSocketInterface socks = null; try { socks = new nSocketInterface(iface.RealmInterface.adapter, iface.RealmInterface.port, iface.RealmInterface.autostart); socks.setAdvertise(iface.RealmInterface.advertise); socks.setAuthTimeOut((int)iface.RealmInterface.authtime); socks.setBacklog(iface.RealmInterface.backlog); socks.setThreadCount(iface.RealmInterface.acceptThreads); socks.setAdvertise(iface.RealmInterface.advertise); socks.setAutostart(iface.RealmInterface.autostart); socks.setRecvBufferSize((int)iface.RealmInterface.receivebuffersize); socks.setSendBufferSize((int)iface.RealmInterface.sendbuffersize); socks.setInterRealmAllow(iface.RealmInterface.allowforinterrealm); socks.setAllowClientConnections(iface.RealmInterface.allowclientconnections); socks.setAdapterAlias(iface.RealmInterface.alias); report("Creating socket interface on " + iface.RealmInterface.adapter + " port " + iface.RealmInterface.port); } catch (Exception e) { throw e; } return socks; } private nHTTPInterface createHTTPInterface(RealmNHPInterfaceEntry iface) { nHTTPInterface http = null; try { http = new nHTTPInterface(iface.RealmInterface.adapter, iface.RealmInterface.port, iface.RealmInterface.autostart); http.setAdvertise(iface.RealmInterface.advertise); http.setAuthTimeOut((int)iface.RealmInterface.authtime); http.setBacklog(iface.RealmInterface.backlog); http.setThreadCount(iface.RealmInterface.acceptThreads); http.setAdvertise(iface.RealmInterface.advertise); http.setAutostart(iface.RealmInterface.autostart); http.setRecvBufferSize((int)iface.RealmInterface.receivebuffersize); http.setSendBufferSize((int)iface.RealmInterface.sendbuffersize); http.setInterRealmAllow(iface.RealmInterface.allowforinterrealm); http.setAllowClientConnections(iface.RealmInterface.allowclientconnections); JavascriptConfigEntryType jsconfig = iface.JavascriptConfigEntry; if (jsconfig != null) { http.enabledWebSockets(jsconfig.EnableWebSockets); http.setNativeCometAllowed(jsconfig.EnableNativeComet); http.setAjaxLPActiveDelay(jsconfig.AjaxLPActiveDelay); http.setAjaxLPIdleDelay(jsconfig.AjaxLPIdleDelay); // http.setInitialJavascript((jsconfig.InitialJavascript)); CustomHeadersConfigEntryType[] customheaderlist = jsconfig.CustomHeadersConfig; if (customheaderlist != null && customheaderlist.Length > 0) { List httpcustomheaderlist = new List(); for (int i = 0; i < customheaderlist.Length; i++) { CustomHeadersConfigEntryType customHeadersConfigEntryType = customheaderlist[i]; nCustomHeader headerconfigentry = new nCustomHeader(customHeadersConfigEntryType.Key, customHeadersConfigEntryType.Value, customHeadersConfigEntryType.UserAgents); httpcustomheaderlist.Add(headerconfigentry); } http.setCustomHeaders(httpcustomheaderlist); } } http.setAdapterAlias(iface.RealmInterface.alias); report("Creating HTTP interface on " + iface.RealmInterface.adapter + " port " + iface.RealmInterface.port); } catch (Exception e) { throw e; } return http; } private nSSLInterface createSSLInterface(RealmNSPSInterfaceEntry iface) { nSSLInterface nsps = null; try { nsps = new nSSLInterface(iface.RealmInterface.adapter, iface.RealmInterface.port, iface.RealmInterface.autostart); nsps.setAdvertise(iface.RealmInterface.advertise); nsps.setAuthTimeOut((int)iface.RealmInterface.authtime); nsps.setBacklog(iface.RealmInterface.backlog); nsps.setThreadCount(iface.RealmInterface.acceptThreads); nsps.setAdvertise(iface.RealmInterface.advertise); nsps.setAutostart(iface.RealmInterface.autostart); nsps.setRecvBufferSize((int)iface.RealmInterface.receivebuffersize); nsps.setSendBufferSize((int)iface.RealmInterface.sendbuffersize); nsps.setInterRealmAllow(iface.RealmInterface.allowforinterrealm); nsps.setAllowClientConnections(iface.RealmInterface.allowclientconnections); nsps.setAdapterAlias(iface.RealmInterface.alias); if (iface.RealmInterfaceSSLConfig.CRLFile != null && iface.RealmInterfaceSSLConfig.CRLFile.Trim().Length > 0) { nsps.setCRLFile(iface.RealmInterfaceSSLConfig.CRLFile); } // // Now load the SSL configuration // if (iface.RealmInterfaceSSLConfig.certificateAlias != null) { if (iface.RealmInterfaceSSLConfig.certificateAlias.Trim().Length > 0) { nsps.setAlias(iface.RealmInterfaceSSLConfig.certificateAlias); } } nsps.setCertRequired(iface.RealmInterfaceSSLConfig.enableClientValidation); if (iface.RealmInterfaceSSLConfig.keyStorePath.Trim().Length > 0) { nsps.setKeyStore(iface.RealmInterfaceSSLConfig.keyStorePath); } if (iface.RealmInterfaceSSLConfig.trustStorePath.Trim().Length > 0) { nsps.setTrustStore(iface.RealmInterfaceSSLConfig.trustStorePath); } RealmInterfaceSupportedCipher[] cipherList = iface.RealmInterfaceSupportedCipherSet; string[] supported = new string[cipherList.Length]; for (int x = 0; x < cipherList.Length; x++) { RealmInterfaceSupportedCipher cipher = (RealmInterfaceSupportedCipher)cipherList[x]; supported[x] = cipher.name; report("\tSupporting : " + supported[x]); } nsps.setEnabledCiphers(supported, false); // // Since the passwords are write only, we can never export them so we need to prompt the user for them // report("Please enter the password for the keystore on interface " + nsps.getProtocol() + "://" + nsps.getAdapter() + ":" + nsps.getPort()); Console.Write("Store " + nsps.getKeyStore() + " : "); string password = Console.ReadLine(); nsps.setKeyStorePassword(password); report("Please enter the password for the trust store on interface " + nsps.getProtocol() + "://" + nsps.getAdapter() + ":" + nsps.getPort()); Console.Write("Trust Store " + nsps.getTrustStore() + " : "); password = Console.ReadLine(); nsps.setTrustStorePassword(password); report("Please enter the password for the private key on interface " + nsps.getProtocol() + "://" + nsps.getAdapter() + ":" + nsps.getPort()); Console.Write("Password : "); password = Console.ReadLine(); nsps.setPrivateKeyPassword(password); report("Creating SSL interface on " + iface.RealmInterface.adapter + " port " + iface.RealmInterface.port); } catch (Exception e) { throw e; } return nsps; } private nHTTPSInterface createHTTPSInterface(RealmNHPSInterfaceEntry iface) { nHTTPSInterface nhps = null; try { nhps = new nHTTPSInterface(iface.RealmInterface.adapter, iface.RealmInterface.port, iface.RealmInterface.autostart); nhps.setAdvertise(iface.RealmInterface.advertise); nhps.setAuthTimeOut((int)iface.RealmInterface.authtime); nhps.setBacklog(iface.RealmInterface.backlog); nhps.setThreadCount(iface.RealmInterface.acceptThreads); nhps.setAdvertise(iface.RealmInterface.advertise); nhps.setAutostart(iface.RealmInterface.autostart); nhps.setRecvBufferSize((int)iface.RealmInterface.receivebuffersize); nhps.setSendBufferSize((int)iface.RealmInterface.sendbuffersize); nhps.setInterRealmAllow(iface.RealmInterface.allowforinterrealm); nhps.setAllowClientConnections(iface.RealmInterface.allowclientconnections); nhps.setAdapterAlias(iface.RealmInterface.alias); nhps.enabledWebSockets(iface.EnableWebSockets); nhps.setNativeCometAllowed(iface.EnableNativeComet); nhps.setAjaxLPActiveDelay(iface.AjaxLPActiveDelay); nhps.setAjaxLPIdleDelay(iface.AjaxLPIdleDelay); // nhps.setInitialJavascript((iface.InitialJavascript)); if (iface.RealmInterfaceSSLConfig.CRLFile != null && iface.RealmInterfaceSSLConfig.CRLFile.Trim().Length > 0) { nhps.setCRLFile(iface.RealmInterfaceSSLConfig.CRLFile); } // // Now load the SSL configuration // if (iface.RealmInterfaceSSLConfig.certificateAlias != null) { if (iface.RealmInterfaceSSLConfig.certificateAlias.Trim().Length > 0) { nhps.setAlias(iface.RealmInterfaceSSLConfig.certificateAlias); } } nhps.setCertRequired(iface.RealmInterfaceSSLConfig.enableClientValidation); if (iface.RealmInterfaceSSLConfig.keyStorePath.Trim().Length > 0) { nhps.setKeyStore(iface.RealmInterfaceSSLConfig.keyStorePath); } if (iface.RealmInterfaceSSLConfig.trustStorePath.Trim().Length > 0) { nhps.setTrustStore(iface.RealmInterfaceSSLConfig.trustStorePath); } RealmInterfaceSupportedCipher[] cipherList = iface.RealmInterfaceSupportedCipherSet; string[] supported = new string[cipherList.Length]; for (int x = 0; x < cipherList.Length; x++) { RealmInterfaceSupportedCipher cipher = (RealmInterfaceSupportedCipher)cipherList[x]; supported[x] = cipher.name; report("\tSupporting : " + supported[x]); } nhps.setEnabledCiphers(supported, false); // // Since the passwords are write only, we can never export them so we need to prompt the user for them // report("Please enter the password for the keystore on interface " + nhps.getProtocol() + "://" + nhps.getAdapter() + ":" + nhps.getPort()); Console.Write("Store " + nhps.getKeyStore() + " : "); string password = Console.ReadLine(); nhps.setKeyStorePassword(password); report("Please enter the password for the trust store on interface " + nhps.getProtocol() + "://" + nhps.getAdapter() + ":" + nhps.getPort()); Console.Write("Trust Store " + nhps.getTrustStore() + " : "); password = Console.ReadLine(); nhps.setTrustStorePassword(password); report("Please enter the password for the private key on interface " + nhps.getProtocol() + "://" + nhps.getAdapter() + ":" + nhps.getPort()); Console.Write("Password : "); password = Console.ReadLine(); nhps.setPrivateKeyPassword(password); report("Creating HTTPS interface on " + iface.RealmInterface.adapter + " port " + iface.RealmInterface.port); } catch (Exception e) { throw e; } return nhps; } private void createPlugin(nHTTPInterface niface, RealmNHPInterfaceEntry iface) { try { RealmInterfacePluginEntry[] plugins = iface.RealmInterfacePlugin; if (plugins != null && plugins.Length == 0) { return; } ArrayList pluginCfg = new ArrayList(); for (int x = 0; x < plugins.Length; x++) { RealmInterfacePluginEntry plugin = (RealmInterfacePluginEntry)plugins[x]; nPluginConfig cfg = new nPluginConfig(plugin.name, plugin.mountPoint); PluginConfigEntryType[] configEntries = plugin.PluginConfigEntry; for (int y = 0; y < configEntries.Length; y++) { PluginConfigEntryType entry = (PluginConfigEntryType)configEntries[y]; nPluginConfigEntry nEntry = new nPluginEntry(entry.name, entry.description, entry.value); cfg.AddCfg(nEntry); } pluginCfg.Add(cfg); niface.setPlugin(pluginCfg); } } catch (Exception e) { throw e; } } private void createPlugin(nHTTPSInterface niface, RealmNHPSInterfaceEntry iface) { try { RealmInterfacePluginEntry[] plugins = iface.RealmInterfacePlugin; if (plugins != null && plugins.Length == 0) { return; } ArrayList pluginCfg = new ArrayList(); for (int x = 0; x < plugins.Length; x++) { RealmInterfacePluginEntry plugin = (RealmInterfacePluginEntry)plugins[x]; nPluginConfig cfg = new nPluginConfig(plugin.name, plugin.mountPoint); PluginConfigEntryType[] configEntries = plugin.PluginConfigEntry; for (int y = 0; y < configEntries.Length; y++) { PluginConfigEntryType entry = (PluginConfigEntryType)configEntries[y]; nPluginConfigEntry nEntry = new nPluginEntry(entry.name, entry.description, entry.value); cfg.AddCfg(nEntry); } pluginCfg.Add(cfg); } niface.setPlugin(pluginCfg); } catch (Exception e) { throw e; } } /// /// * Prints the usage message for this class /// private static void Usage() { Console.WriteLine("Usage ...\n"); Console.WriteLine("nimportrealmxml \n"); Console.WriteLine(" -all -realmacl -realmcfg -channels -channeacls -queues -queueacls -interfaces -datagroups\n"); } internal class nPluginEntry : nPluginConfigEntry { internal nPluginEntry(string name, string desc, string @value) : base(name, desc, @value) { } } internal class nPluginConfig : nPluginConfiguration { internal nPluginConfig(string name, string mount) : base(name, mount) { } public void AddCfg(nPluginConfigEntry entry) { add(entry); } } public static void report(string line) { DateTime dt = DateTime.Now; Console.WriteLine(dt.ToString() + " > " + line); } } }