/* Copyright 1999-2011 (c) My-Channels Copyright (c) 2012-2015 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. */ package com.pcbsys.nirvana.nAdminAPI.apps; import com.pcbsys.foundation.utils.fEnvironment; import com.pcbsys.nirvana.base.nRuntime; import com.pcbsys.nirvana.client.nBaseClientException; import com.pcbsys.nirvana.client.nChannel; import com.pcbsys.nirvana.client.nChannelAttributes; import com.pcbsys.nirvana.client.nChannelIterator; import com.pcbsys.nirvana.client.nChannelPublishKeys; import com.pcbsys.nirvana.client.nConflationAttributes; import com.pcbsys.nirvana.client.nConsumeEvent; import com.pcbsys.nirvana.client.nDataGroup; import com.pcbsys.nirvana.client.nDataGroupDeletedException; import com.pcbsys.nirvana.client.nEventAttributes; import com.pcbsys.nirvana.client.nEventListener; import com.pcbsys.nirvana.client.nEventProperties; import com.pcbsys.nirvana.client.nEventPropertiesIterator; import com.pcbsys.nirvana.client.nRequestTimedOutException; import com.pcbsys.nirvana.client.nSecurityException; import com.pcbsys.nirvana.client.nSessionAttributes; import com.pcbsys.nirvana.client.nSessionNotConnectedException; import com.pcbsys.nirvana.client.nSessionPausedException; import com.pcbsys.nirvana.client.nStoreProperties; import com.pcbsys.nirvana.client.nSubject; import com.pcbsys.nirvana.client.nUnexpectedResponseException; import com.pcbsys.nirvana.nAdminAPI.nACL; import com.pcbsys.nirvana.nAdminAPI.nBaseAdminException; import com.pcbsys.nirvana.nAdminAPI.nChannelACLEntry; import com.pcbsys.nirvana.nAdminAPI.nClusterNode; import com.pcbsys.nirvana.nAdminAPI.nClusterSite; import com.pcbsys.nirvana.nAdminAPI.nConfigEntry; import com.pcbsys.nirvana.nAdminAPI.nConfigGroup; import com.pcbsys.nirvana.nAdminAPI.nContainer; import com.pcbsys.nirvana.nAdminAPI.nCustomHeader; import com.pcbsys.nirvana.nAdminAPI.nHTTPInterface; import com.pcbsys.nirvana.nAdminAPI.nHTTPSInterface; import com.pcbsys.nirvana.nAdminAPI.nInterface; import com.pcbsys.nirvana.nAdminAPI.nInterfaceManager; import com.pcbsys.nirvana.nAdminAPI.nInterfaceStatus; import com.pcbsys.nirvana.nAdminAPI.nInterfaceViaEntry; import com.pcbsys.nirvana.nAdminAPI.nJoinDetails; import com.pcbsys.nirvana.nAdminAPI.nLeafNode; import com.pcbsys.nirvana.nAdminAPI.nMulticastConfiguration; import com.pcbsys.nirvana.nAdminAPI.nMulticastManager; import com.pcbsys.nirvana.nAdminAPI.nNode; import com.pcbsys.nirvana.nAdminAPI.nPluginConfigEntry; import com.pcbsys.nirvana.nAdminAPI.nPluginConfiguration; import com.pcbsys.nirvana.nAdminAPI.nRealmACLEntry; import com.pcbsys.nirvana.nAdminAPI.nRealmNode; import com.pcbsys.nirvana.nAdminAPI.nSSLInterface; import com.pcbsys.nirvana.nAdminAPI.nScheduler; import com.pcbsys.nirvana.nAdminAPI.nSchedulerManager; import com.pcbsys.nirvana.nAdminAPI.nSecurityGroup; import com.pcbsys.nirvana.nAdminAPI.nSharedMemoryInterface; import com.pcbsys.nirvana.nAdminAPI.nSocketInterface; import com.pcbsys.nirvana.nAdminAPI.xml.*; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; import java.math.BigInteger; import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.Enumeration; import java.util.GregorianCalendar; import java.util.Iterator; import java.util.List; import java.util.Vector; /** * This application can be used to export the objects within a realm into an xml format. *

* The program will search through the realm and output the acl entries and permissions, configuration, * for all channels, queues, interfaces and scheduler information */ public class nExportRealmXML{ private String realmUrl = null; private nRealmNode node = null; private String fileName = null; private ObjectFactory objFactory = null; private boolean realms = false; private boolean cluster = false; private boolean realmAcl = false; private boolean realmCfg = false; private boolean channels = false; private Filter channelfilter = null; private boolean channelAcls = false; private boolean joins = false; private boolean queues = false; private Filter queuefilter = null; private boolean queueAcls = false; private boolean datagroups = false; private Filter datagroupfilter = null; private boolean interfaces = false; private boolean iplugins = false; private boolean via = false; private boolean scheduler = false; private boolean jndi = false; /** * Constructor for the class, takes the string realm url */ public nExportRealmXML(String[] args) { Writer writer = null; try { processArgs(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(); // create a JAXBContext JAXBContext jc = JAXBContext.newInstance("com.pcbsys.nirvana.nAdminAPI.xml"); // create an ObjectFactory instance. // if the JAXBContext had been created with mutiple pacakge names, // we would have to explicitly use the correct package name when // creating the ObjectFactory. objFactory = new ObjectFactory(); NirvanaRealm realm = objFactory.createNirvanaRealm(); StringBuffer commentbuffer = new StringBuffer(); commentbuffer.append("Realm configuration from ").append(realmUrl); if (channelfilter != null) commentbuffer.append(" using channel filter " + channelfilter.myFilterValue); if (queuefilter != null) commentbuffer.append(" using queue filter " + queuefilter.myFilterValue); if (datagroupfilter != null) commentbuffer.append(" using datagroup filter " + datagroupfilter.myFilterValue); realm.setComment(commentbuffer.toString()); realm.setName(node.getRealm().getName()); GregorianCalendar cal = new GregorianCalendar(); XMLGregorianCalendar xmlCal = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal); realm.setExportDate(xmlCal); if (cluster) { createCluster(realm, node); } // create the realm objects if (realms) { createRealms(realm, node); } // create the realm acl, the channels, queues and their acls createObjects(realm, node); // create the configuration objects if (realmCfg) { createConfiguration(realm, node); } // create the interfaces if (interfaces) { createInterfaces(realm, node); } if (scheduler) { createSchedulers(realm, node); } // create a Marshaller and marshal to System.out Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); writer = new OutputStreamWriter(new FileOutputStream(fileName), "UTF-8"); m.marshal(realm, writer); // close the node, which closes all sessions made to the namespace } catch (Exception ex) { ex.printStackTrace(); } finally { closeNode(node); } if (writer != null) { try { writer.close(); } catch (IOException e) { e.printStackTrace(); } } } /** * Main program thread, takes a realm URL as the parameter to start the search */ public static void main(String[] args) { //Process Environment Variables processEnvironmentVariable("RNAME"); processEnvironmentVariable("LOGLEVEL"); processEnvironmentVariable("HPROXY"); processEnvironmentVariable("HAUTH"); processEnvironmentVariable("CKEYSTORE"); processEnvironmentVariable("CKEYSTOREPASSWD"); processEnvironmentVariable("CAKEYSTORE"); processEnvironmentVariable("CAKEYSTOREPASSWD"); // Install any proxy server settings fEnvironment.setProxyEnvironments(); // Install JSSE SSL Environement settings fEnvironment.setSSLEnvironments(); nExportRealmXML dump = new nExportRealmXML(args); } private void processArgs(String[] args) { switch (args.length) { case 0: Usage(); UsageEnv(); System.exit(1); case 1: if (args[0].equals("-?")) UsageEnv(); System.setProperty("FILE", args[0]); getOptions(null); break; default: System.setProperty("FILE", args[0]); getOptions(args); } } private static void processEnvironmentVariable(String variable) { String laxVAR = System.getProperty("lax.nl.env." + variable); if (laxVAR != null) { System.setProperty(variable, laxVAR); } } /** * Set the program variables and flags based on command line args */ public void getOptions(String[] args) { realmUrl = System.getProperty("RNAME", null); if (realmUrl == null) { Usage(); System.exit(1); } fileName = System.getProperty("FILE"); if (fileName == null) { Usage(); System.exit(1); } if (args == null) { Usage(); System.exit(1); } // set what will be exported based on command line arguments 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; via = true; scheduler = true; datagroups = true; jndi = true; } if (args[x].equals("-realmacl")) { realmAcl = true; } if (args[x].equals("-realms")) { realms = true; } if (args[x].equals("-cluster")) { cluster = true; } if (args[x].equals("-realmcfg")) { realmCfg = true; } if (args[x].equals("-channels")) { channels = true; } if (args[x].startsWith("-channelfilter")) { this.channelfilter = new Filter(args[x].split("=")[1]); } if (args[x].equals("-channelacls")) { channelAcls = true; } if (args[x].equals("-jndi")) { jndi = true; } if (args[x].equals("-joins")) { joins = true; } if (args[x].equals("-queues")) { queues = true; } if (args[x].startsWith("-queuefilter")) { this.queuefilter = new Filter(args[x].split("=")[1]); } 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("-scheduler")) { scheduler = true; } if (args[x].equals("-datagroups")) { datagroups = true; } if (args[x].startsWith("-datagroupfilter")) { this.datagroupfilter = new Filter(args[x].split("=")[1]); } } } /** * Method to output contents of a realm node */ private void createObjects(NirvanaRealm realm, nRealmNode node) throws JAXBException, Exception { RealmPermissionSet rpermset = null; try { // call the method to output the acl entries for the realm if (realmAcl) { rpermset = objFactory.createRealmPermissionSet(); createRealmACL(rpermset, node.getACLs()); } // call the method to search the child nodes within the realm node Enumeration enum1 = node.getNodes(); while (enum1.hasMoreElements()) { nNode o = (nNode) enum1.nextElement(); if (o instanceof nLeafNode) { createLeafACL(realm, (nLeafNode) o); } else if (o instanceof nContainer) { createContainerACL(realm, (nContainer) o); } } realm.setRealmPermissionSet(rpermset); if (datagroups) { createDataGroups(realm); } } catch (Exception ex) { throw ex; } } private void createDataGroups(NirvanaRealm realm) throws nDataGroupDeletedException, nSecurityException, nRequestTimedOutException, nSessionPausedException, nSessionNotConnectedException, nUnexpectedResponseException { nDataGroup[] alldatagroups = node.getSession().getDataGroups(); DataGroupSet dgset = realm.getDataGroupSet(); for (int i = 0; i < alldatagroups.length; i++) { nDataGroup dataGroup = alldatagroups[i]; if (datagroupfilter != null && !datagroupfilter.matches(dataGroup.getName())) { report("DataGroup " + dataGroup.getName() + " ignored as it does not match filter"); continue; } if (dgset == null) dgset = objFactory.createDataGroupSet(); //Create Entry DataGroupEntry dgentry = createDataGroupDetails(dataGroup); dgset.getDataGroupEntry().add(dgentry); } if (dgset != null) realm.setDataGroupSet(dgset); } private DataGroupEntry createDataGroupDetails(nDataGroup dataGroup) throws nDataGroupDeletedException { DataGroupEntry dgentry = objFactory.createDataGroupEntry(); //Create attributes DataGroupAttributesEntry dgattrib = objFactory.createDataGroupAttributesEntry(); dgattrib.setId(dataGroup.getID()); dgattrib.setName(dataGroup.getName()); dgattrib.setMulticastenabled(dataGroup.isMulticastEnabled()); dgattrib.setPriority(dataGroup.getPriority()); dgentry.setDataGroupAttributesEntry(dgattrib); if (dataGroup.getConflationAttributes() != null) { //Conflation Attributes nConflationAttributes ca = dataGroup.getConflationAttributes(); ConflationAttributesEntry cattribentry = objFactory.createConflationAttributesEntry(); if (ca.getAction() == nConflationAttributes.sDropEvents) cattribentry.setType("DROP_EVENTS_TYPE"); else if (ca.getAction() == nConflationAttributes.sMergeEvents) cattribentry.setType("MERGE_EVENTS_TYPE"); cattribentry.setInterval(ca.getInterval()); dgentry.setConflationAttributesEntry(cattribentry); } Iterator dgpubs = dataGroup.getPublishers(); // Publishers while (dgpubs.hasNext()) { String somepublisher = dgpubs.next(); String user = somepublisher.substring(0, somepublisher.indexOf("@")); String host = somepublisher.substring(somepublisher.indexOf("@") + 1); DataGroupPublisherEntry dgpubentry = objFactory.createDataGroupPublisherEntry(); dgpubentry.setName(user); dgpubentry.setHost(host); dgentry.getDataGroupPublisherEntry().add(dgpubentry); } Iterator nestediterator = dataGroup.getGroups(); while (nestediterator.hasNext()) { nDataGroup nestedgroup = nestediterator.next(); NestedGroupEntry ndge = objFactory.createNestedGroupEntry(); ndge.setName(nestedgroup.getName()); dgentry.getNestedGroupEntry().add(ndge); } return dgentry; } /** * Method to output contents of known realm nodes */ private void createRealms(NirvanaRealm realm, nRealmNode node) throws JAXBException, Exception { RealmSet realmset = null; try { // call the method to output the acl entries for the realm if (realms) { realmset = objFactory.createRealmSet(); createRealm(realm, realmset, node.getRealmList()); } } catch (Exception ex) { throw ex; } } /** * Method to output contents of known clusters */ private void createCluster(NirvanaRealm realm, nRealmNode node) throws JAXBException, Exception { ClusterSet clusterset = null; try { if (cluster) { nClusterNode clusterNode = node.getCluster(); if (clusterNode != null) { clusterset = objFactory.createClusterSet(); List clusterlist = clusterset.getClusterEntry(); createCluster(clusterlist, clusterNode); realm.setClusterSet(clusterset); } else { report("Cluster export selected, however this realm is not part of a cluster"); } } } catch (Exception ex) { throw ex; } } /** * Method to output contents of a known cluster node */ private void createCluster(List clusters, nClusterNode cluster) throws JAXBException, Exception { try { Enumeration realms = cluster.getNodes(); ClusterEntry entry = objFactory.createClusterEntry(); List members = entry.getClusterMember(); while (realms.hasMoreElements()) { nRealmNode realm = (nRealmNode) realms.nextElement(); ClusterMember member = objFactory.createClusterMember(); member.setName(realm.getName()); member.setRname(realm.getSession().getAttributes().getConnectionDetail(0)); member.setCanBeMaster(cluster.canBeMaster(realm)); members.add(member); } Iterator sites = cluster.getSites(); List csites = entry.getClusterSite(); while (sites.hasNext()) { nClusterSite site = (nClusterSite) sites.next(); ClusterSite csite = objFactory.createClusterSite(); csite.setName(site.getName()); csite.setIsPrime(site.isPrime()); csites.add(csite); Iterator siterealms = site.getIterator(); List smembers = csite.getSiteMember(); while (siterealms.hasNext()) { String node = (String) siterealms.next(); SiteMember smember = objFactory.createSiteMember(); smember.setName(node); smembers.add(smember); } } entry.setName(cluster.getName()); clusters.add(entry); } catch (Exception ex) { throw ex; } } /** * Method to output contents of a realm node */ private void createRealm(NirvanaRealm realm, RealmSet realmset, Vector realms) throws JAXBException, Exception { try { //Security Groups RealmSecurityGroupSet realmSecurityGroupSet = objFactory.createRealmSecurityGroupSet(); List realmgroupList = realmSecurityGroupSet.getRealmSecurityGroup(); Collection groups = node.getSecurityGroupManager().getGroups(); for (Iterator iterator = groups.iterator(); iterator.hasNext(); ) { nSecurityGroup next = iterator.next(); if (!next.getName().equalsIgnoreCase("Everyone")) { RealmSecurityGroup secGroup = objFactory.createRealmSecurityGroup(); RealmSecurityGroupEntry realmSecurityGroupEntry = objFactory.createRealmSecurityGroupEntry(); realmSecurityGroupEntry.setGroupname(next.getName()); secGroup.setRealmSecurityGroupEntry(realmSecurityGroupEntry); List securityGroupReferenceEntries = secGroup.getSecurityGroupReferenceEntry(); List securityGroupSubjectEntries = secGroup.getSecurityGroupSubjectEntry(); //secGroup.setName(next.getName()); Collection subjs = next.getMembers(); for (nSubject subj : subjs) { if (subj instanceof nSecurityGroup) { SecurityGroupReferenceEntry refEnt = objFactory.createSecurityGroupReferenceEntry(); refEnt.setGroupname(subj.getName()); securityGroupReferenceEntries.add(refEnt); } else { SecurityGroupSubjectEntry subjEnt = objFactory.createSecurityGroupSubjectEntry(); subjEnt.setName(subj.getUser()); subjEnt.setHost(subj.getHost()); securityGroupSubjectEntries.add(subjEnt); } } realmgroupList.add(secGroup); } } realm.setRealmSecurityGroupSet(realmSecurityGroupSet); /////////////////////////////////////////////////// if (realms.size() == 0) return; List realmlist = realmset.getRealmEntry(); for (int x = 0; x < realms.size(); x++) { RealmEntry realmentry = objFactory.createRealmEntry(); nRealmNode rNode = (nRealmNode) realms.elementAt(x); realmentry.setName(rNode.getName()); String tmp = nRuntime.sReleaseDetails; String[] releaseDetails = tmp.split("\\."); realm.setVersion(releaseDetails[0] + "." + releaseDetails[1]); realm.setBuildInfo(nRuntime.sReleaseDetails); Vector connections = rNode.getRealm().getConnections(); realmentry.setRname((String) connections.elementAt(0)); String mountPoint = rNode.getRealm().getMountPoint(); realmentry.setMountpoint(mountPoint); realmlist.add(realmentry); } realm.setRealmSet(realmset); } catch (Exception ex) { throw ex; } } /** * Method to output contents of a realm node */ private void createConfiguration(NirvanaRealm realm, nRealmNode node) throws JAXBException, Exception { RealmConfiguration cfg = null; try { // create the configuration object and construct each group cfg = objFactory.createRealmConfiguration(); Enumeration enum1 = node.getConfigGroups(); while (enum1.hasMoreElements()) { nConfigGroup ngrp = (nConfigGroup) enum1.nextElement(); ConfigGroup grp = objFactory.createConfigGroup(); List grpList = cfg.getConfigGroup(); grp.setName(ngrp.getName()); Enumeration items = ngrp.getItems(); while (items.hasMoreElements()) { // construct each config item and add to the item list List itemList = grp.getConfigItem(); nConfigEntry nitem = (nConfigEntry) items.nextElement(); ConfigItem item = objFactory.createConfigItem(); item.setName(nitem.getName()); item.setValue(nitem.getValue()); itemList.add(item); } // add the group to the group list grpList.add(grp); } // add the configuration to the realm object realm.setRealmConfiguration(cfg); } catch (Exception ex) { throw ex; } } private RealmMulticastConfigurationEntry createMulticastConfiguration(nMulticastConfiguration mconfig) { RealmMulticastConfigurationEntry entry = objFactory.createRealmMulticastConfigurationEntry(); //basic configuration RealmMulticastBasicConfigurationEntry basicentry = entry.getRealmMulticastBasicConfigurationEntry(); if (basicentry == null) { basicentry = objFactory.createRealmMulticastBasicConfigurationEntry(); entry.setRealmMulticastBasicConfigurationEntry(basicentry); } basicentry.setName(mconfig.getName()); basicentry.setAdapterAddress(mconfig.getAdapter()); basicentry.setMulticastAddress(mconfig.getMulticastAddress()); basicentry.setAdapterBufferSize((long) mconfig.getAdapterBufferSize()); basicentry.setClientestablishmenttimeout(mconfig.getClientEstablishmentTimeout()); basicentry.setUseforClusters(mconfig.isUseForCluster()); basicentry.setUseforDatagroups(mconfig.isUseForDataGroups()); basicentry.setUseforStatusUpdates(mconfig.isUseForStatusUpdates()); basicentry.setUseforChannels(mconfig.isUseForChannels()); basicentry.setAllowLoopback(mconfig.isAllowLoopback()); //Security RealmMulticastSecurityConfigurationEntry secentry = entry.getRealmMulticastSecurityConfigurationEntry(); if (secentry == null) { secentry = objFactory.createRealmMulticastSecurityConfigurationEntry(); entry.setRealmMulticastSecurityConfigurationEntry(secentry); } switch (mconfig.getCRCType()) { case 0: default: { secentry.setCRCtype("NONE"); break; } case 1: { secentry.setCRCtype("CRC"); break; } case 2: { secentry.setCRCtype("MD5"); break; } case 3: { secentry.setCRCtype("SHA"); break; } } switch (mconfig.getEncryptionLevel()) { case 0: default: { secentry.setEncryptionlevel("NONE"); break; } case 1: { secentry.setEncryptionlevel("AES-128"); break; } case 2: { secentry.setEncryptionlevel("AES-192"); break; } case 3: { secentry.setEncryptionlevel("AES-256"); break; } } secentry.setRotateEncryptionKeyTime(Long.valueOf(mconfig.getRotateEncryptionKeyTime())); secentry.setRotateEnryptionKeyWait(Long.valueOf(mconfig.getMaxOutstandingPackets())); //advanced configuration RealmMulticastAdvancedConfigurationEntry aentry = entry.getRealmMulticastAdvancedConfigurationEntry(); if (aentry == null) { aentry = objFactory.createRealmMulticastAdvancedConfigurationEntry(); entry.setRealmMulticastAdvancedConfigurationEntry(aentry); } switch (mconfig.getMode()) { case 0: default: { aentry.setACKmode("ACK-WINDOW"); break; } case 1: { aentry.setACKmode("NACK-WINDOW"); break; } case 2: { aentry.setACKmode("BROADCAST"); break; } } aentry.setKeepAliveInterval(Long.valueOf(mconfig.getKeepAliveInterval())); aentry.setPacketTTL(Long.valueOf(mconfig.getTTL())); aentry.setTrafficClass(Long.valueOf(mconfig.getTrafficClass())); aentry.setFlusherInterval(Long.valueOf(mconfig.getFlusherInterval())); aentry.setAckWindowsize(Long.valueOf(mconfig.getAckWindowSize())); aentry.setUnackedWindowsize(Long.valueOf(mconfig.getUnAckedWindowSize())); aentry.setPacketSize(Long.valueOf(mconfig.getPacketSize())); aentry.setReceiverOutstandingPacketSize(Long.valueOf(mconfig.getMaxOutstandingPackets())); aentry.setSenderOutstandingPacketSize(Long.valueOf(mconfig.getOutstandingPacketsQueueSize())); aentry.setPeakDetectionRate(Long.valueOf(mconfig.getPeakRate())); return entry; } private void createInterfaces(NirvanaRealm realm, nRealmNode node) throws JAXBException, Exception { try { // construct each interface from the nInterfaceManager nInterfaceManager mgr = node.getInterfaceManager(); RealmInterfaceSet iSet = objFactory.createRealmInterfaceSet(); List nspList = iSet.getRealmNSPInterface(); List nhpList = iSet.getRealmNHPInterface(); List nspsList = iSet.getRealmNSPSInterface(); List nhpsList = iSet.getRealmNHPSInterface(); List shmList = iSet.getRealmSHMConfiguration(); List multicastList = iSet.getRealmMulticastConfiguration(); nMulticastManager multimgr = node.getMulticastManager(); Vector multiconfigs = multimgr.getMulticastConfigurations(); for (int i = 0; i < multiconfigs.size(); i++) { nMulticastConfiguration mconfig = (nMulticastConfiguration) multiconfigs.elementAt(i); RealmMulticastConfigurationEntry entry = createMulticastConfiguration(mconfig); multicastList.add(entry); } Vector ifaces = mgr.getInterfaces(); // loop through all known interfaces for (int x = 0; x < ifaces.size(); x++) { nInterfaceStatus status = (nInterfaceStatus) ifaces.elementAt(x); nInterface iface = status.getInterface(); if (iface instanceof nSharedMemoryInterface) { nSharedMemoryInterface shmif = (nSharedMemoryInterface) iface; RealmSHMConfigurationEntry entry = objFactory.createRealmSHMConfigurationEntry(); entry.setName(shmif.getName()); entry.setBuffersize(shmif.getBufferSize()); entry.setDirectory(shmif.getDirectoryPath()); entry.setTimeout(shmif.getTimeout()); shmList.add(entry); } else { RealmInterfaceEntry entry = objFactory.createRealmInterfaceEntry(); // set the values for the interface object entry.setAcceptThreads(iface.getThreadCount()); entry.setAdapter(iface.getAdapter()); entry.setAuthtime(iface.getAuthTimeOut()); entry.setAdvertise(iface.canAdvertise()); entry.setAutostart(iface.willAutostart()); entry.setEnableNIO(iface.isAllowNIO()); entry.setName(iface.getName()); entry.setPort(iface.getPort()); entry.setBacklog(iface.getBacklog()); entry.setAllowforinterrealm(iface.isInterRealmAllow()); entry.setReceivebuffersize(iface.getRecvBufferSize()); entry.setSendbuffersize(iface.getSendBufferSize()); entry.setAlias(iface.getAdapaterAlias()); entry.setAllowclientconnections(iface.isClientConnectionsAllowed()); // set the interface entry to be the actual interface of the right type List pluginlist = null; nACL viaList = null; InterfacePermissionSet viaAcl = null; if (via) { viaList = iface.getViaList(); viaAcl = objFactory.createInterfacePermissionSet(); createViaPermissions(viaAcl, viaList); } if (iface instanceof nSSLInterface) { RealmNSPSInterfaceEntry ssl = objFactory.createRealmNSPSInterfaceEntry(); ssl.setRealmInterface(entry); if ((via) && (viaList.size() > 0)) { ssl.setInterfacePermissionSet(viaAcl); } RealmInterfaceSupportedCipherSet cSet = objFactory.createRealmInterfaceSupportedCipherSet(); String ciphers[] = ((nSSLInterface) iface).getEnabledCiphers(); if (ciphers != null) { List cipherList = cSet.getRealmInterfaceSupportedCipher(); for (int y = 0; y < ciphers.length; y++) { RealmInterfaceSupportedCipher cipher = objFactory.createRealmInterfaceSupportedCipher(); cipher.setName(ciphers[y]); cipherList.add(cipher); } } else { List cipherList = cSet.getRealmInterfaceSupportedCipher(); RealmInterfaceSupportedCipher cipher = objFactory.createRealmInterfaceSupportedCipher(); cipher.setName(""); cipherList.add(cipher); } ssl.setRealmInterfaceSupportedCipherSet(cSet); RealmInterfaceSSLConfig sslConfig = objFactory.createRealmInterfaceSSLConfig(); nSSLInterface ssli = (nSSLInterface) iface; sslConfig.setEnableClientValidation(ssli.getCertRequired()); sslConfig.setCertificateAlias(ssli.getAlias()); sslConfig.setKeyStorePath(ssli.getKeyStore()); sslConfig.setTrustStorePath(ssli.getTrustStore()); ssl.setRealmInterfaceSSLConfig(sslConfig); if (ssli.getCRLFile() != null) { sslConfig.setCRLFile(ssli.getCRLFile()); } nspsList.add(ssl); } else if (iface instanceof nSocketInterface) { RealmNSPInterfaceEntry sock = objFactory.createRealmNSPInterfaceEntry(); sock.setRealmInterface(entry); if ((via) && (viaList.size() > 0)) { sock.setInterfacePermissionSet(viaAcl); } nspList.add(sock); } else if (iface instanceof nHTTPSInterface) { RealmNHPSInterfaceEntry https = objFactory.createRealmNHPSInterfaceEntry(); https.setRealmInterface(entry); if ((via) && (viaList.size() > 0)) { https.setInterfacePermissionSet(viaAcl); } nHTTPSInterface nhps = (nHTTPSInterface) iface; JavascriptConfigEntryType jsconfigentry = objFactory.createJavascriptConfigEntryType(); jsconfigentry.setEnableWebSockets(nhps.isWebSocketEnabled()); jsconfigentry.setEnableJavaScript(nhps.isNativeCometAllowed()); jsconfigentry.setAjaxLPActiveDelay(nhps.getAjaxLPActiveDelay()); jsconfigentry.setAjaxLPIdleDelay(nhps.getAjaxLPIdleDelay()); jsconfigentry.setCORSAllowCredentials(nhps.isAllowCrossOriginCredentials()); jsconfigentry.setEnableGZipLP(nhps.isEnableGZIP()); jsconfigentry.setCORSAllowedOrigins(nhps.getAllowedOrigins()); jsconfigentry.setMinimumBytesBeforeGZIP(nhps.getMinimumBytesBeforeGZIP()); List customheaderlist=jsconfigentry.getCustomHeadersConfig(); ArrayList httpscustomheaderlist=nhps.getCustomHeaders(); if (httpscustomheaderlist!=null && httpscustomheaderlist.size()>0){ for (int i = 0; i < httpscustomheaderlist.size(); i++) { nCustomHeader customHeader = httpscustomheaderlist.get(i); CustomHeadersConfigEntryType chentry=objFactory.createCustomHeadersConfigEntryType(); chentry.setKey(customHeader.getKey()); chentry.setValue(customHeader.getValue()); chentry.setUserAgents(customHeader.getUserAgents()); customheaderlist.add(chentry); } } https.setJavascriptConfigEntry(jsconfigentry); if (iplugins) { Vector plugins = nhps.getPlugin(); if ((plugins != null) && (plugins.size() > 0)) { pluginlist = https.getRealmInterfacePlugin(); createPlugins(pluginlist, plugins); } } RealmInterfaceSupportedCipherSet cSet = objFactory.createRealmInterfaceSupportedCipherSet(); String ciphers[] = nhps.getEnabledCiphers(); if (ciphers != null) { List cipherList = cSet.getRealmInterfaceSupportedCipher(); for (int y = 0; y < ciphers.length; y++) { RealmInterfaceSupportedCipher cipher = objFactory.createRealmInterfaceSupportedCipher(); cipher.setName(ciphers[y]); cipherList.add(cipher); } } else { List cipherList = cSet.getRealmInterfaceSupportedCipher(); RealmInterfaceSupportedCipher cipher = objFactory.createRealmInterfaceSupportedCipher(); cipher.setName(""); cipherList.add(cipher); } https.setRealmInterfaceSupportedCipherSet(cSet); RealmInterfaceSSLConfig sslConfig = objFactory.createRealmInterfaceSSLConfig(); sslConfig.setEnableClientValidation(nhps.getCertRequired()); sslConfig.setCertificateAlias(nhps.getAlias()); sslConfig.setKeyStorePath(nhps.getKeyStore()); sslConfig.setTrustStorePath(nhps.getTrustStore()); if (nhps.getCRLFile() != null) { sslConfig.setCRLFile(nhps.getCRLFile()); } https.setRealmInterfaceSSLConfig(sslConfig); nhpsList.add(https); } else if (iface instanceof nHTTPInterface) { RealmNHPInterfaceEntry http = objFactory.createRealmNHPInterfaceEntry(); http.setRealmInterface(entry); if ((via) && (viaList.size() > 0)) { http.setInterfacePermissionSet(viaAcl); } nHTTPInterface nhp = (nHTTPInterface) iface; JavascriptConfigEntryType jsconfigentry = objFactory.createJavascriptConfigEntryType(); jsconfigentry.setEnableWebSockets(nhp.isWebSocketEnabled()); jsconfigentry.setEnableJavaScript(nhp.isNativeCometAllowed()); jsconfigentry.setAjaxLPActiveDelay(nhp.getAjaxLPActiveDelay()); jsconfigentry.setAjaxLPIdleDelay(nhp.getAjaxLPIdleDelay()); jsconfigentry.setCORSAllowCredentials(nhp.isAllowCrossOriginCredentials()); jsconfigentry.setEnableGZipLP(nhp.isEnableGZIP()); jsconfigentry.setCORSAllowedOrigins(nhp.getAllowedOrigins()); jsconfigentry.setMinimumBytesBeforeGZIP(nhp.getMinimumBytesBeforeGZIP()); List customheaderlist = jsconfigentry.getCustomHeadersConfig(); ArrayList httpcustomheaderlist = nhp.getCustomHeaders(); if (httpcustomheaderlist != null && httpcustomheaderlist.size() > 0) { for (int i = 0; i < httpcustomheaderlist.size(); i++) { nCustomHeader customHeader = httpcustomheaderlist.get(i); CustomHeadersConfigEntryType chentry = objFactory.createCustomHeadersConfigEntryType(); chentry.setKey(customHeader.getKey()); chentry.setValue(customHeader.getValue()); chentry.setUserAgents(customHeader.getUserAgents()); customheaderlist.add(chentry); } } http.setJavascriptConfigEntry(jsconfigentry); if (iplugins) { Vector plugins = nhp.getPlugin(); if ((plugins != null) && (plugins.size() > 0)) { pluginlist = http.getRealmInterfacePlugin(); createPlugins(pluginlist, plugins); } } nhpList.add(http); } } } // set the interfaces set in the realm object realm.setRealmInterfaces(iSet); } catch (Exception ex) { throw ex; } } private void createPlugins(List list, Vector plugins) throws Exception { try { for (int x = 0; x < plugins.size(); x++) { nPluginConfiguration cfg = (nPluginConfiguration) plugins.elementAt(x); String type = cfg.getName(); RealmInterfacePluginEntry pluginentry = objFactory.createRealmInterfacePluginEntry(); if (type.equalsIgnoreCase("File Plugin")) { NirvanaFilePluginEntry file = objFactory.createNirvanaFilePluginEntry(); createFilePlugin(file, cfg); pluginentry.setNirvanaFilePlugin(file); } else if (type.equalsIgnoreCase("Nirvana XML Plugin")) { NirvanaXMLPluginEntry xml = objFactory.createNirvanaXMLPluginEntry(); createXMLPlugin(xml, cfg); pluginentry.setNirvanaXMLPlugin(xml); } else if (type.equalsIgnoreCase("Proxy Pass through Plugin")) { NirvanaProxyPassThroughPluginEntry proxy = objFactory.createNirvanaProxyPassThroughPluginEntry(); createProxyPlugin(proxy, cfg); pluginentry.setNirvanaProxyPassThroughPlugin(proxy); } else if (type.equalsIgnoreCase("Nirvana SOAP Plugin")) { NirvanaSOAPPluginEntry soap = objFactory.createNirvanaSOAPPluginEntry(); createSOAPPlugin(soap, cfg); pluginentry.setNirvanaSOAPPlugin(soap); } else if (type.equalsIgnoreCase("Nirvana REST plugin")) { NirvanaRESTPluginEntry restPluginEntry = objFactory.createNirvanaRESTPluginEntry(); createRESTPlugin(restPluginEntry, cfg); pluginentry.setNirvanaRESTPlugin(restPluginEntry); } else if (type.equalsIgnoreCase("Realm Status Plugin")) { NirvanaStatusPluginEntry status = objFactory.createNirvanaStatusPluginEntry(); createStatusPlugin(status, cfg); pluginentry.setNirvanaStatusPlugin(status); } else if (type.equalsIgnoreCase("ServletPlugin")) { NirvanaServletPluginEntry servlet = objFactory.createNirvanaServletPluginEntry(); createServletlugin(servlet, cfg); pluginentry.setNirvanaServletPlugin(servlet); } else if (type.equalsIgnoreCase("Change Password Plugin")) { NirvanaPasswordPluginEntry passwd = objFactory.createNirvanaPasswordPluginEntry(); createPasswordPlugin(passwd, cfg); pluginentry.setNirvanaPasswordPlugin(passwd); } pluginentry.setMountPoint(cfg.getMountPoint()); pluginentry.setName(cfg.getName()); list.add(pluginentry); } } catch (Exception e) { throw e; } } private void createViaPermissions(InterfacePermissionSet ipermset, nACL entries) throws Exception { List ipermlist = ipermset.getInterfaceACLEntry(); Enumeration enum1 = entries.getEntries(); while (enum1.hasMoreElements()) { Object obj = enum1.nextElement(); nInterfaceViaEntry obj1 = (nInterfaceViaEntry) obj; if (obj1.isGroup()) { InterfaceGroupACLEntry xmlentry = createInterfaceGroupACLEntry(obj1); ipermlist.add(xmlentry); } else { InterfaceACLEntry xmlentry = createInterfaceACLEntry(obj1); ipermlist.add(xmlentry); } } } private void createContainerACL(NirvanaRealm realm, nContainer node) throws Exception { try { // call the method to search the child nodes within the realm node Enumeration enum1 = node.getNodes(); while (enum1.hasMoreElements()) { nNode o = (nNode) enum1.nextElement(); if (o instanceof nLeafNode) { createLeafACL(realm, (nLeafNode) o); } else if (o instanceof nContainer) { createContainerACL(realm, (nContainer) o); } } } catch (Exception ex) { throw ex; } } /** * Method to output the contents of a leaf node, i.e. a channel or a queue */ private void createLeafACL(NirvanaRealm realm, nLeafNode node) throws JAXBException, nBaseAdminException, nBaseClientException, Exception { // detect if the node is a channel or a queue if (node.isChannel()) { createChannelACL(realm, node); } else { createQueueACL(realm, node); } } private ChannelAttributesEntry createChannelAttributes(nLeafNode node) throws JAXBException, nBaseClientException, Exception { if ((!channels) && (!channelAcls)) { if ((!queues) && (!queueAcls)) { return null; } } ChannelAttributesEntry entry = null; nChannelAttributes nca = null; if (((!channels) && (channelAcls)) || ((!queues) && (queueAcls))) { entry = objFactory.createChannelAttributesEntry(); nca = node.getAttributes(); entry.setName(nca.getFullName()); } else if (channels || queues) { entry = objFactory.createChannelAttributesEntry(); nca = node.getAttributes(); entry.setName(nca.getFullName()); entry.setTTL(nca.getTTL()); entry.setCapacity(nca.getMaxEvents()); long eid = node.getLastEID(); if (eid < 0) eid = 0; // Since it is illegal to import a -1 entry.setEID(eid); entry.setJmsEngine(nca.isJMSEngine()); entry.setMergeEngine(nca.isMergeEngine()); //entry.setMulticastenabled(nca.isMulticastEnabled()); switch (nca.getType()) { case nChannelAttributes.SIMPLE_TYPE: entry.setType("SIMPLE_TYPE"); break; case nChannelAttributes.TRANSIENT_TYPE: entry.setType("TRANSIENT_TYPE"); break; case nChannelAttributes.RELIABLE_TYPE: entry.setType("RELIABLE_TYPE"); break; case nChannelAttributes.PERSISTENT_TYPE: entry.setType("PERSISTENT_TYPE"); break; case nChannelAttributes.MIXED_TYPE: entry.setType("MIXED_TYPE"); break; } entry.setClusterWide(nca.isClusterWide()); } return entry; } private EventsSet createJndiEventsSet(nLeafNode node) throws JAXBException, nBaseClientException, Exception { if (!jndi) return null; nChannelAttributes chanAttrib = node.getAttributes(); if (chanAttrib == null || !chanAttrib.getFullName().equals("/naming/defaultContext")) return null;//Export only events from /naming/defaultContext channel nChannel myChannel = node.getRealm().getSession().findChannel(chanAttrib); EventsSet evtSet = objFactory.createEventsSet(); long startEID = 0; final int EVENT_WAIT_TIMEOUT = 5000; List evtList = evtSet.getEvent(); nChannelIterator iterator = myChannel.createIterator(startEID); while (true) { try { nConsumeEvent evt = iterator.getNext(EVENT_WAIT_TIMEOUT); if (evt != null) { ExportEventToXML(evt, evtList); } } catch (nRequestTimedOutException timeOut) { // no event to consume break; } catch (Exception e) { break; } } iterator.close(); return evtSet; } private void ExportEventToXML(nConsumeEvent e, List evtList) throws nBaseClientException { Event evt = objFactory.createEvent(); evt.setTag(e.getEventTag()); evt.setId(BigInteger.valueOf(e.getEventID())); try{ //Export event's attributes if (e.hasAttributes()) { nEventAttributes attributes = e.getAttributes(); Enumeration attrEnum = attributes.getAttributeNamesEnumeration(); EventAttribSet evtAttribSet = objFactory.createEventAttribSet(); List evtAttribList = evtAttribSet.getEventAttrib(); while (attrEnum.hasMoreElements()) { String key = attrEnum.nextElement().toString(); Object val = attributes.getAttribute(key); if (val != null){ EventAttrib evtAttrib = objFactory.createEventAttrib(); evtAttrib.setName(key.toString()); evtAttrib.setValue(val.toString()); evtAttrib.setType(val.getClass().getSimpleName()); evtAttribList.add(evtAttrib); } } evt.setEventAttribSet(evtAttribSet); } } catch(Exception ex){ System.out.println("\nEx while exporting event's attributes: " + ex.toString()); throw new nBaseClientException(ex.getMessage()); } try { //Export event's properties nEventProperties props = e.getProperties(); if (props != null) { EventPropSet evtPropSet = objFactory.createEventPropSet(); List evtPropList = evtPropSet.getEventProp(); nEventPropertiesIterator keys = props.getKeyIterator(); while (keys.hasNext()) { String key = keys.next().toString(); Object val = props.get(key); if (val != null) { EventProp evtProp = objFactory.createEventProp(); evtProp.setName(key.toString()); evtProp.setValue(val.toString()); evtProp.setType(val.getClass().getSimpleName()); evtPropList.add(evtProp); } } evt.setEventPropSet(evtPropSet); } } catch(Exception ex){ System.out.println("\nEx while exporting event's props: " + ex.toString()); throw new nBaseClientException(ex.getMessage()); } evtList.add(evt); } private StorePropertiesEntry createStoreProperties(nLeafNode node) throws JAXBException, nBaseClientException, Exception { StorePropertiesEntry entry = null; nStoreProperties props = null; if (channels || queues) { props = node.getAttributes().getProperties(); nChannelAttributes att = new nChannelAttributes(); nStoreProperties test = att.getProperties(); if (test.getCacheOnReload() != props.getCacheOnReload()) { entry = objFactory.createStorePropertiesEntry(); entry.setCacheOnReload(props.getCacheOnReload()); } if (props.getClientMergeEngineClassname() != null) { if (entry == null) entry = objFactory.createStorePropertiesEntry(); entry.setClientMergeEngineClassname(props.getClientMergeEngineClassname()); } if (props.getFanoutArchiveTarget() != null) { if (entry == null) entry = objFactory.createStorePropertiesEntry(); entry.setFanoutArchiveTarget(props.getFanoutArchiveTarget()); } if (test.getEnableCaching() != props.getEnableCaching()) { if (entry == null) entry = objFactory.createStorePropertiesEntry(); entry.setEnableCaching(props.getEnableCaching()); } if (test.getEnableReadBuffering() != props.getEnableReadBuffering()) { if (entry == null) entry = objFactory.createStorePropertiesEntry(); entry.setEnableReadBuffering(props.getEnableReadBuffering()); } if (test.getSyncMaxBatchSize() != props.getSyncMaxBatchSize()) { if (entry == null) entry = objFactory.createStorePropertiesEntry(); entry.setSyncMaxBatchSize(props.getSyncMaxBatchSize()); } if (test.getHonorCapacityWhenFull() != props.getHonorCapacityWhenFull()) { if (entry == null) entry = objFactory.createStorePropertiesEntry(); entry.setHonorCapacityWhenFull(props.getHonorCapacityWhenFull()); } if (test.getPerformAutomaticMaintenance() != props.getPerformAutomaticMaintenance()) { if (entry == null) entry = objFactory.createStorePropertiesEntry(); entry.setPerformAutomaticMaintenance(props.getPerformAutomaticMaintenance()); } if (test.getReadBufferSize() != props.getReadBufferSize()) { if (entry == null) entry = objFactory.createStorePropertiesEntry(); entry.setReadBufferSize(props.getReadBufferSize()); } if (test.getSyncBatchTime() != props.getSyncBatchTime()) { if (entry == null) entry = objFactory.createStorePropertiesEntry(); entry.setSyncBatchTime(props.getSyncBatchTime()); } if (test.canSyncOnEachWrite() != props.canSyncOnEachWrite()) { if (entry == null) entry = objFactory.createStorePropertiesEntry(); entry.setSyncOnEachWrite(props.canSyncOnEachWrite()); } if (test.getPriority() != props.getPriority()) { if (entry == null) entry = objFactory.createStorePropertiesEntry(); entry.setPriority(props.getPriority()); } if (test.enableMulticast() != props.enableMulticast()) { if (entry == null) entry = objFactory.createStorePropertiesEntry(); entry.setEnableMulticast(props.enableMulticast()); } if (test.getStampDictionary() != props.getStampDictionary()) { if (entry == null) entry = objFactory.createStorePropertiesEntry(); entry.setStampDictionary(props.getStampDictionary()); } } return entry; } private ChannelKeySet createChannelKeySet(nLeafNode node) throws JAXBException, nBaseClientException, Exception { if (!channels) { return null; } nChannelAttributes nca = null; nChannelPublishKeys[] keys = null; ChannelKeySet chankeyset = objFactory.createChannelKeySet(); List chankeylist = chankeyset.getChannelKeyEntry(); nca = node.getAttributes(); keys = nca.getPublishKeys(); if ((keys != null) && (keys.length > 0)) { for (int x = 0; x < keys.length; x++) { nChannelPublishKeys key = keys[x]; ChannelKeyEntry chankeyentry = objFactory.createChannelKeyEntry(); chankeyentry.setKeyName(key.getName()); chankeyentry.setKeyDepth(key.getDepth()); chankeylist.add(chankeyentry); } } return chankeyset; } private ChannelJoinSet createChannelJoinSet(nLeafNode node) throws JAXBException, nBaseClientException, Exception { if (!channels) { if (!joins) { return null; } } Enumeration enum1 = null; ChannelJoinSet chanjoinset = objFactory.createChannelJoinSet(); List chanjoinlist = chanjoinset.getChannelJoinEntry(); boolean isClustered = (node.getRealm().getCluster() != null); int count = 0; if (joins) { enum1 = node.getOutboundJoins(); if (enum1 != null) { while (enum1.hasMoreElements()) { nJoinDetails join = (nJoinDetails) enum1.nextElement(); String from = node.getAbsolutePath(); String to = join.getRemoteNode().getAbsolutePath(); if (isClustered) { from = node.getAttributes().getFullName(); to = join.getRemoteNode().getAttributes().getFullName(); } ChannelJoinEntry chanjoinentry = objFactory.createChannelJoinEntry(); chanjoinentry.setTo(to); chanjoinentry.setFilter(join.getSelector()); chanjoinentry.setHopcount(join.getHopCount()); chanjoinentry.setAllowPurge(join.allowPurgeRequests()); chanjoinentry.setFrom(from); chanjoinentry.setArchival(join.isArchival()); chanjoinlist.add(chanjoinentry); count++; } } } if (count > 0) { return chanjoinset; } return null; } private void createQueueACL(NirvanaRealm realm, nLeafNode node) throws JAXBException, nBaseAdminException, nBaseClientException, Exception { if ((!queues) && (!queueAcls)) { return; } if (queuefilter != null && !queuefilter.matches(node.getAbsolutePath())) { report("Queue " + node.getAbsolutePath() + " ignored as it does not match filter"); return; } QueueSet queueset = null; if (realm.getQueueSet() == null) { queueset = objFactory.createQueueSet(); realm.setQueueSet(queueset); } else { queueset = (QueueSet) realm.getQueueSet(); } List chanlist = queueset.getQueueEntry(); QueueEntry qentry = objFactory.createQueueEntry(); qentry.setChannelAttributesEntry(createChannelAttributes(node)); qentry.setStorePropertiesEntry(createStoreProperties(node)); if (queueAcls) { QueuePermissionSet qpermset = objFactory.createQueuePermissionSet(); List qpermlist = qpermset.getQueueACLEntry(); List qpermgrouplist = qpermset.getQueueGroupACLEntry(); Enumeration aclenum = node.getACLs().getEntries(); while (aclenum.hasMoreElements()) { nChannelACLEntry o = (nChannelACLEntry) aclenum.nextElement(); if (o.isGroup()) { QueueGroupACLEntry qaclentry = objFactory.createQueueGroupACLEntry(); qaclentry.setGroupname(o.getName()); qaclentry.setListACLEntries(o.canList()); qaclentry.setModifyACLEntries(o.canModify()); qaclentry.setFullControl(o.hasFullPrivileges()); qaclentry.setPeek(o.canRead()); qaclentry.setPop(o.canPop()); qaclentry.setPush(o.canWrite()); qaclentry.setPurge(o.canPurge()); qpermgrouplist.add(qaclentry); } else { QueueACLEntry qaclentry = objFactory.createQueueACLEntry(); qaclentry.setHost(o.getHost()); qaclentry.setName(o.getName()); qaclentry.setListACLEntries(o.canList()); qaclentry.setModifyACLEntries(o.canModify()); qaclentry.setFullControl(o.hasFullPrivileges()); qaclentry.setPeek(o.canRead()); qaclentry.setPop(o.canPop()); qaclentry.setPush(o.canWrite()); qaclentry.setPurge(o.canPurge()); qpermlist.add(qaclentry); } } qentry.setQueuePermissionSet(qpermset); } chanlist.add(qentry); } private void createChannelACL(NirvanaRealm realm, nLeafNode node) throws JAXBException, nBaseAdminException, nBaseClientException, Exception { if ((!channels) && (!channelAcls) && (!jndi)) { return; } if (channelfilter != null && !channelfilter.matches(node.getAbsolutePath())) { report("Channel " + node.getAbsolutePath() + " ignored as it does not match filter"); return; } ChannelSet chanset = null; if (realm.getChannelSet() == null) { chanset = objFactory.createChannelSet(); realm.setChannelSet(chanset); } else { chanset = (ChannelSet) realm.getChannelSet(); } List chanlist = chanset.getChannelEntry(); ChannelEntry chanentry = objFactory.createChannelEntry(); //Setting permanently 'channels' to true if this is JNDI channel //Ugly Hack to make possible export of full jndi channel, if exporting channels is not set //To make it properly need to change a lot of logic, which I won't risk to do it currently boolean oldChannels = channels; try { if (jndi) { EventsSet evtSet = createJndiEventsSet(node); if (evtSet != null) { chanentry.setEventsSet(evtSet); channels = true; } } chanentry.setChannelAttributesEntry(createChannelAttributes(node)); chanentry.setStorePropertiesEntry(createStoreProperties(node)); if ((node.getAttributes().getPublishKeys() != null) && (node.getAttributes().getPublishKeys().length > 0)) { chanentry.setChannelKeySet(createChannelKeySet(node)); } } finally { channels = oldChannels; } if (joins) { ChannelJoinSet joinSet = createChannelJoinSet(node); if (joinSet != null) { chanentry.setChannelJoinSet(joinSet); } } if (jndi) { EventsSet evtSet = createJndiEventsSet(node); if (evtSet != null) chanentry.setEventsSet(evtSet); } if (channelAcls) { ChannelPermissionSet chanpermset = objFactory.createChannelPermissionSet(); List chanpermlist = chanpermset.getChannelACLEntry(); List chanpermgrouplist = chanpermset.getChannelGroupACLEntry(); Enumeration aclenum = node.getACLs().getEntries(); while (aclenum.hasMoreElements()) { nChannelACLEntry o = (nChannelACLEntry) aclenum.nextElement(); if (o.isGroup()) { ChannelGroupACLEntry chanaclentry = objFactory.createChannelGroupACLEntry(); chanaclentry.setGroupname(o.getName()); chanaclentry.setListACLEntries(o.canList()); chanaclentry.setModifyACLEntries(o.canModify()); chanaclentry.setFullControl(o.hasFullPrivileges()); chanaclentry.setGetLastEID(o.canGetLastEID()); chanaclentry.setPublish(o.canWrite()); chanaclentry.setSubscribe(o.canRead()); chanaclentry.setPurgeEvents(o.canPurge()); chanaclentry.setUseNamedSubcription(o.canUseNamedSubscription()); chanpermgrouplist.add(chanaclentry); } else { ChannelACLEntry chanaclentry = objFactory.createChannelACLEntry(); chanaclentry.setHost(o.getHost()); chanaclentry.setName(o.getName()); chanaclentry.setListACLEntries(o.canList()); chanaclentry.setModifyACLEntries(o.canModify()); chanaclentry.setFullControl(o.hasFullPrivileges()); chanaclentry.setGetLastEID(o.canGetLastEID()); chanaclentry.setPublish(o.canWrite()); chanaclentry.setSubscribe(o.canRead()); chanaclentry.setPurgeEvents(o.canPurge()); chanaclentry.setUseNamedSubcription(o.canUseNamedSubscription()); chanpermlist.add(chanaclentry); } } chanentry.setChannelPermissionSet(chanpermset); } chanlist.add(chanentry); } /** * Method to search an enumeration of nodes, these could be realm acl * entries, channel acl entries, leaf nodes or realm nodes */ private void createRealmACLList(RealmPermissionSet rpermset, Enumeration enum1) throws JAXBException, Exception { List rpermlist = rpermset.getRealmACLEntry(); List rpermgrouplist = rpermset.getRealmGroupACLEntry(); while (enum1.hasMoreElements()) { Object obj = enum1.nextElement(); // if the node is a realm, call the method to output the acls for a realm node nRealmACLEntry racl = (nRealmACLEntry) obj; if (racl.isGroup()) { RealmGroupACLEntry xmlentry = createRealmGroupACLEntry(racl); rpermgrouplist.add(xmlentry); } else { RealmACLEntry xmlentry = createRealmACLEntry(racl); rpermlist.add(xmlentry); } } } /** * Method that outputs the entries of an acl object, by passing the enumeration of acl entries */ private void createRealmACL(RealmPermissionSet rpermset, nACL acl) throws JAXBException, Exception { createRealmACLList(rpermset, acl.getEntries()); } /** * Method to output the permissions for a realm acl entry */ private RealmACLEntry createRealmACLEntry(nRealmACLEntry entry) throws JAXBException, Exception { RealmACLEntry xmlentry = objFactory.createRealmACLEntry(); xmlentry.setName(entry.getName()); xmlentry.setHost(entry.getHost()); xmlentry.setConnectToRealm(entry.canAccessTheRealm()); xmlentry.setChangeRealmConfig(entry.canConfigureRealm()); xmlentry.setAddremoveChannels(entry.canManageChannels()); xmlentry.setAddremoveJoins(entry.canManageJoins()); xmlentry.setOverrideConnectionCount(entry.canOverrideConnectionCount()); xmlentry.setAddremoveRealms(entry.canManageRealm()); xmlentry.setFullControl(entry.hasFullPrivileges()); xmlentry.setListACLEntries(entry.canList()); xmlentry.setModifyACLEntries(entry.canModify()); xmlentry.setUseAdminAPI(entry.canUseAdminAPI()); xmlentry.setCreateP2PService(entry.canManageP2PServices()); xmlentry.setManageDatagroups(entry.canManageDataGroups()); xmlentry.setOwnDatagroups(entry.canTakeOwnershipOfDataGroup()); xmlentry.setPublishDatagroups(entry.canPublishToGlobalDataGroup()); return xmlentry; } private RealmGroupACLEntry createRealmGroupACLEntry(nRealmACLEntry entry) throws JAXBException, Exception { RealmGroupACLEntry xmlentry = objFactory.createRealmGroupACLEntry(); xmlentry.setGroupname(entry.getName()); xmlentry.setConnectToRealm(entry.canAccessTheRealm()); xmlentry.setChangeRealmConfig(entry.canConfigureRealm()); xmlentry.setAddremoveChannels(entry.canManageChannels()); xmlentry.setAddremoveJoins(entry.canManageJoins()); xmlentry.setOverrideConnectionCount(entry.canOverrideConnectionCount()); xmlentry.setAddremoveRealms(entry.canManageRealm()); xmlentry.setFullControl(entry.hasFullPrivileges()); xmlentry.setListACLEntries(entry.canList()); xmlentry.setModifyACLEntries(entry.canModify()); xmlentry.setUseAdminAPI(entry.canUseAdminAPI()); xmlentry.setCreateP2PService(entry.canManageP2PServices()); xmlentry.setManageDatagroups(entry.canManageDataGroups()); xmlentry.setOwnDatagroups(entry.canTakeOwnershipOfDataGroup()); xmlentry.setPublishDatagroups(entry.canPublishToGlobalDataGroup()); return xmlentry; } /** * Method to output the permissions for a realm acl entry */ private InterfaceACLEntry createInterfaceACLEntry(nInterfaceViaEntry entry) throws JAXBException, Exception { InterfaceACLEntry xmlentry = objFactory.createInterfaceACLEntry(); xmlentry.setName(entry.getName()); xmlentry.setHost(entry.getHost()); return xmlentry; } /** * Method to output the permissions for a realm acl entry */ private InterfaceGroupACLEntry createInterfaceGroupACLEntry(nInterfaceViaEntry entry) throws JAXBException, Exception { InterfaceGroupACLEntry xmlentry = objFactory.createInterfaceGroupACLEntry(); xmlentry.setGroupname(entry.getName()); return xmlentry; } private void createPasswordPlugin(NirvanaPasswordPluginEntry file, nPluginConfiguration configurations) throws Exception { try { List configEntryList = file.getPluginConfigEntry(); for (int y = 0; y < configurations.size(); y++) { nPluginConfigEntry nEntry = (nPluginConfigEntry) configurations.elementAt(y); PluginConfigEntryType entry = objFactory.createPluginConfigEntryType(); entry.setName(nEntry.getName()); entry.setValue(nEntry.getValue()); entry.setDescription(nEntry.getDescription()); configEntryList.add(entry); } } catch (Exception e) { throw e; } } private void createServletlugin(NirvanaServletPluginEntry file, nPluginConfiguration configurations) throws Exception { try { List configEntryList = file.getPluginConfigEntry(); for (int y = 0; y < configurations.size(); y++) { nPluginConfigEntry nEntry = (nPluginConfigEntry) configurations.elementAt(y); PluginConfigEntryType entry = objFactory.createPluginConfigEntryType(); entry.setName(nEntry.getName()); entry.setValue(nEntry.getValue()); entry.setDescription(nEntry.getDescription()); configEntryList.add(entry); } } catch (Exception e) { throw e; } } private void createStatusPlugin(NirvanaStatusPluginEntry file, nPluginConfiguration configurations) throws Exception { try { List configEntryList = file.getPluginConfigEntry(); for (int y = 0; y < configurations.size(); y++) { nPluginConfigEntry nEntry = (nPluginConfigEntry) configurations.elementAt(y); PluginConfigEntryType entry = objFactory.createPluginConfigEntryType(); entry.setName(nEntry.getName()); entry.setValue(nEntry.getValue()); entry.setDescription(nEntry.getDescription()); configEntryList.add(entry); } } catch (Exception e) { throw e; } } private void createFilePlugin(NirvanaFilePluginEntry file, nPluginConfiguration configurations) throws Exception { try { List configEntryList = file.getPluginConfigEntry(); for (int y = 0; y < configurations.size(); y++) { nPluginConfigEntry nEntry = (nPluginConfigEntry) configurations.elementAt(y); PluginConfigEntryType entry = objFactory.createPluginConfigEntryType(); entry.setName(nEntry.getName()); entry.setValue(nEntry.getValue()); entry.setDescription(nEntry.getDescription()); configEntryList.add(entry); } } catch (Exception e) { throw e; } } private void createXMLPlugin(NirvanaXMLPluginEntry xml, nPluginConfiguration configurations) throws Exception { try { List configEntryList = xml.getPluginConfigEntry(); for (int y = 0; y < configurations.size(); y++) { nPluginConfigEntry nEntry = (nPluginConfigEntry) configurations.elementAt(y); PluginConfigEntryType entry = objFactory.createPluginConfigEntryType(); entry.setName(nEntry.getName()); entry.setValue(nEntry.getValue()); entry.setDescription(nEntry.getDescription()); configEntryList.add(entry); } } catch (Exception e) { throw e; } } private void createProxyPlugin(NirvanaProxyPassThroughPluginEntry proxy, nPluginConfiguration configurations) throws Exception { try { List configEntryList = proxy.getPluginConfigEntry(); for (int y = 0; y < configurations.size(); y++) { nPluginConfigEntry nEntry = (nPluginConfigEntry) configurations.elementAt(y); PluginConfigEntryType entry = objFactory.createPluginConfigEntryType(); entry.setName(nEntry.getName()); entry.setValue(nEntry.getValue()); entry.setDescription(nEntry.getDescription()); configEntryList.add(entry); } } catch (Exception e) { throw e; } } private void createSOAPPlugin(NirvanaSOAPPluginEntry soap, nPluginConfiguration configurations) throws Exception { try { List configEntryList = soap.getPluginConfigEntry(); for (int y = 0; y < configurations.size(); y++) { nPluginConfigEntry nEntry = (nPluginConfigEntry) configurations.elementAt(y); PluginConfigEntryType entry = objFactory.createPluginConfigEntryType(); entry.setName(nEntry.getName()); entry.setValue(nEntry.getValue()); entry.setDescription(nEntry.getDescription()); configEntryList.add(entry); } } catch (Exception e) { throw e; } } private void createRESTPlugin(NirvanaRESTPluginEntry restPluginEntry, nPluginConfiguration configurations) throws Exception { try { List configEntryList = restPluginEntry.getPluginConfigEntry(); for (int y = 0; y < configurations.size(); y++) { nPluginConfigEntry nEntry = (nPluginConfigEntry) configurations.elementAt(y); PluginConfigEntryType entry = objFactory.createPluginConfigEntryType(); entry.setName(nEntry.getName()); entry.setValue(nEntry.getValue()); entry.setDescription(nEntry.getDescription()); configEntryList.add(entry); } } catch (Exception e) { throw e; } } private void createSchedulers(NirvanaRealm realm, nRealmNode node) throws JAXBException, Exception { try { // construct each scheduler from the nSchedulerManager nSchedulerManager mgr = node.getSchedulerManager(); if (mgr == null || mgr.getSize() == 0) return; RealmSchedulerSet sSet = objFactory.createRealmSchedulerSet(); List schedulerList = sSet.getScheduler(); if (schedulerList.size() == 0) return; Enumeration schedulers = mgr.getNodes(); // loop through all known schedulers while (schedulers.hasMoreElements()) { nScheduler aScheduler = (nScheduler) schedulers.nextElement(); Scheduler scheduler = objFactory.createScheduler(); String source = aScheduler.getSource(); scheduler.setSource(source); scheduler.setSubject(aScheduler.getSubject()); scheduler.setClusterWide(aScheduler.isClusterWide()); schedulerList.add(scheduler); } // set the schedulers set in the realm object realm.setRealmSchedulerSet(sSet); } catch (Exception ex) { throw ex; } } private void closeNode(nRealmNode node) { if (node != null) { nClusterNode nClusterNode = node.getCluster(); if (nClusterNode != null) { nClusterNode.close(); } else { node.close(); } } } /** * Prints the usage message for this class */ private static void Usage() { System.out.println("Usage ...\n"); System.out.println("nexportrealmxml [export_file_location]\n"); System.out.println(" -all -realms -cluster -realmacl -realmcfg -channels -jndi -channelfilter= -channeacls -datagroups -datagroupfilter= -joins -queues -queuefilter= -queueacls -interfaces -plugins -via\n"); System.out.println("\n values are a comma separated list of java regular expressions that can filter channel, queue or datagroup names respectively."); System.out.println("\nExample 1: nexportrealmxml test.xml -channels -channelfilter=/perf.+ \n will export only channels whose absolute path starts with /perf"); System.out.println("\nExample 2: nexportrealmxml test.xml -channels -channelfilter=.+test \n will export only channels whose absolute path ends in test"); System.out.println("\nExample 3: nexportrealmxml test.xml -channels -channelfilter=.*test.* \n will export only channels whose absolute path contains test"); System.out.println("\nExample 4: nexportrealmxml test.xml -all -channelfilter=.*test.*,/perf.* \n will export everything with channels being restricted to those with absolute path containing test or starting with /perf"); System.out.println("\n\nNote: -? provides help on environment variables \n"); } private static void UsageEnv() { System.out.println("\n\n(Environment Variables) \n"); System.out.println("(RNAME) - One or more RNAME entries in the form protocol://host:port"); System.out.println(" protocol - Can be one of nsp, nhp, nsps, or nhps, where:"); System.out.println(" nsp - Specifies Nirvana Socket Protocol (nsp)"); System.out.println(" nhp - Specifies Nirvana HTTP Protocol (nhp)"); System.out.println(" nsps - Specifies Nirvana Socket Protocol Secure (nsps), i.e. using SSL/TLS"); System.out.println(" nhps - Specifies Nirvana HTTP Protocol Secure (nhps), i.e. using SSL/TLS"); System.out.println(" port - The port number of the server"); System.out.println("\nHint: - For multiple RNAME entries, use comma separated values which will be attempted in connection weight order\n"); System.out.println("(LOGLEVEL) - This determines how much information the nirvana api will output 0 = verbose 7 = quiet\n"); System.out.println("(CKEYSTORE) - If using SSL, the location of the keystore containing the client cert\n"); System.out.println("(CKEYSTOREPASSWD) - If using SSL, the password for the keystore containing the client cert\n"); System.out.println("(CAKEYSTORE) - If using SSL, the location of the ca truststore\n"); System.out.println("(CAKEYSTOREPASSWD) - If using SSL, the password for the ca truststore\n"); System.out.println("(HPROXY) - HTTP Proxy details in the form proxyhost:proxyport, where:"); System.out.println(" proxyhost - The HTTP proxy host"); System.out.println(" proxyport - The HTTP proxy port\n"); System.out.println("(HAUTH) - HTTP Proxy authentication details in the form user:pass, where:"); System.out.println(" user - The HTTP proxy authentication username"); System.out.println(" pass - The HTTP proxy authentication password\n"); System.exit(1); } public static void report(String line) { Date dt = new Date(); System.out.println(dt.toString() + " > " + line); } public class Filter { private String myFilterValue; protected Filter(String filter) { String[] filters = filter.split(","); StringBuffer regex = new StringBuffer(); int count = 0; for (String somefilter : filters) { regex.append(somefilter); if (!somefilter.startsWith("/")) { regex.append("|"); regex.append("/").append(somefilter); } if (count < (filters.length - 1)) regex.append("|"); count++; } myFilterValue = regex.toString(); } public boolean matches(String name) { return name.matches(myFilterValue); } } }