/*
Copyright 1999-2011 (c) My-Channels
Copyright (c) 2012-2014 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.client.nBaseClientException;
import com.pcbsys.nirvana.client.nChannelAlreadyExistsException;
import com.pcbsys.nirvana.client.nChannelAttributes;
import com.pcbsys.nirvana.client.nChannelPublishKeys;
import com.pcbsys.nirvana.client.nConflationAttributes;
import com.pcbsys.nirvana.client.nDataGroup;
import com.pcbsys.nirvana.client.nIllegalArgumentException;
import com.pcbsys.nirvana.client.nRealm;
import com.pcbsys.nirvana.client.nRequestTimedOutException;
import com.pcbsys.nirvana.client.nSecurityException;
import com.pcbsys.nirvana.client.nSession;
import com.pcbsys.nirvana.client.nSessionAttributes;
import com.pcbsys.nirvana.client.nSessionFactory;
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.nACLEntry;
import com.pcbsys.nirvana.nAdminAPI.nAdminIllegalArgumentException;
import com.pcbsys.nirvana.nAdminAPI.nAdminSecurityException;
import com.pcbsys.nirvana.nAdminAPI.nBaseAdminException;
import com.pcbsys.nirvana.nAdminAPI.nChannelACLEntry;
import com.pcbsys.nirvana.nAdminAPI.nClusterMemberConfiguration;
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.nConfigurationException;
import com.pcbsys.nirvana.nAdminAPI.nCustomHeader;
import com.pcbsys.nirvana.nAdminAPI.nDuplicateACLEntryException;
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.nLeafNode;
import com.pcbsys.nirvana.nAdminAPI.nMulticastConfiguration;
import com.pcbsys.nirvana.nAdminAPI.nMulticastManager;
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.nSchedulerManager;
import com.pcbsys.nirvana.nAdminAPI.nSchedulerParseException;
import com.pcbsys.nirvana.nAdminAPI.nSecurityGroup;
import com.pcbsys.nirvana.nAdminAPI.nSecurityGroupManager;
import com.pcbsys.nirvana.nAdminAPI.nSharedMemoryInterface;
import com.pcbsys.nirvana.nAdminAPI.nSocketInterface;
import com.pcbsys.nirvana.nAdminAPI.xml.ChannelACLEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.ChannelAttributesEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.ChannelEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.ChannelGroupACLEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.ChannelJoinEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.ChannelJoinSet;
import com.pcbsys.nirvana.nAdminAPI.xml.ChannelKeyEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.ChannelKeySet;
import com.pcbsys.nirvana.nAdminAPI.xml.ChannelPermissionSet;
import com.pcbsys.nirvana.nAdminAPI.xml.ChannelSet;
import com.pcbsys.nirvana.nAdminAPI.xml.ClusterEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.ClusterMember;
import com.pcbsys.nirvana.nAdminAPI.xml.ClusterSet;
import com.pcbsys.nirvana.nAdminAPI.xml.ClusterSite;
import com.pcbsys.nirvana.nAdminAPI.xml.ConfigGroup;
import com.pcbsys.nirvana.nAdminAPI.xml.ConfigItem;
import com.pcbsys.nirvana.nAdminAPI.xml.ConflationAttributesEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.CustomHeadersConfigEntryType;
import com.pcbsys.nirvana.nAdminAPI.xml.DataGroupAttributesEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.DataGroupEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.DataGroupPublisherEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.DataGroupSet;
import com.pcbsys.nirvana.nAdminAPI.xml.InterfaceACLEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.InterfaceGroupACLEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.InterfacePermissionSet;
import com.pcbsys.nirvana.nAdminAPI.xml.JavascriptConfigEntryType;
import com.pcbsys.nirvana.nAdminAPI.xml.NestedGroupEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.NirvanaFilePluginEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.NirvanaProxyPassThroughPluginEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.NirvanaRESTPluginEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.NirvanaRealm;
import com.pcbsys.nirvana.nAdminAPI.xml.NirvanaSOAPPluginEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.NirvanaXMLPluginEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.ObjectFactory;
import com.pcbsys.nirvana.nAdminAPI.xml.PluginConfigEntryType;
import com.pcbsys.nirvana.nAdminAPI.xml.QueueACLEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.QueueEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.QueueGroupACLEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.QueuePermissionSet;
import com.pcbsys.nirvana.nAdminAPI.xml.QueueSet;
import com.pcbsys.nirvana.nAdminAPI.xml.RealmACLEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.RealmConfiguration;
import com.pcbsys.nirvana.nAdminAPI.xml.RealmEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.RealmGroupACLEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.RealmInterfacePluginEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.RealmInterfaceSet;
import com.pcbsys.nirvana.nAdminAPI.xml.RealmInterfaceSupportedCipher;
import com.pcbsys.nirvana.nAdminAPI.xml.RealmInterfaceSupportedCipherSet;
import com.pcbsys.nirvana.nAdminAPI.xml.RealmMulticastAdvancedConfigurationEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.RealmMulticastBasicConfigurationEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.RealmMulticastConfigurationEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.RealmMulticastSecurityConfigurationEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.RealmNHPInterfaceEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.RealmNHPSInterfaceEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.RealmNSPInterfaceEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.RealmNSPSInterfaceEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.RealmPermissionSet;
import com.pcbsys.nirvana.nAdminAPI.xml.RealmSHMConfigurationEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.RealmSchedulerSet;
import com.pcbsys.nirvana.nAdminAPI.xml.RealmSecurityGroup;
import com.pcbsys.nirvana.nAdminAPI.xml.RealmSet;
import com.pcbsys.nirvana.nAdminAPI.xml.Scheduler;
import com.pcbsys.nirvana.nAdminAPI.xml.SecurityGroupReferenceEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.SecurityGroupSubjectEntry;
import com.pcbsys.nirvana.nAdminAPI.xml.SiteMember;
import com.pcbsys.nirvana.nAdminAPI.xml.StorePropertiesEntry;
import org.w3c.dom.Document;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
/**
* 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 nImportRealmXML {
private String realmUrl = null;
private nRealmNode node = null;
private String fileName = null;
private boolean realms = false;
private boolean cluster = false;
private boolean realmAcl = false;
private boolean realmCfg = false;
private boolean channels = false;
private boolean channelAcls = false;
private boolean datagroups = false;
private boolean joins = false;
private boolean queues = false;
private boolean queueAcls = false;
private boolean interfaces = false;
private boolean iplugins = false;
private boolean via = false;
private boolean scheduler = false;
private Filter channelfilter;
private Filter queuefilter;
private Filter datagroupfilter;
/**
* Constructor for the class, takes the string realm url
*/
private nImportRealmXML(String[] args) {
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(5000);
// 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.
ObjectFactory objFactory = new ObjectFactory();
NirvanaRealm realm;
// create a Marshaller and marshal to System.out
Unmarshaller m = jc.createUnmarshaller();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new File(fileName));
realm = (NirvanaRealm) m.unmarshal(doc);
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) {
RealmPermissionSet realmPerms = realm.getRealmPermissionSet();
if (realmPerms != null) {
report("Importing Realm ACLs");
importRealmACL(realmPerms);
report("Imported Realm ACLs");
} else {
report("No realm permissins to load");
}
}
// if specified, import the cluster information
if (cluster) {
ClusterSet clusterset = realm.getClusterSet();
if (clusterset != null) {
report("Importing Cluster configuration");
importClusters(clusterset);
report("Imported Cluster configuration");
} else {
report("No cluster configuration to load");
}
}
// if specified, import the realm entries
if (realms) {
RealmSet realmSet = realm.getRealmSet();
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) {
RealmConfiguration cfg = realm.getRealmConfiguration();
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.getRealmInterfaces();
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) {
ChannelSet chanSet = realm.getChannelSet();
report("Importing topic configuration");
if (chanSet == null) {
chanSet = objFactory.createChannelSet();
}
importChannels(chanSet);
report("Imported topic configuration");
}
// if specified, import the queues and their acls
if (queues) {
report("Importing Queue configuration");
QueueSet qSet = realm.getQueueSet();
if (qSet == null) {
qSet = objFactory.createQueueSet();
}
importQueues(qSet);
report("Imported Queue configuration");
}
// if specified, import the channels and their acls
if (joins) {
ChannelSet chanSet = realm.getChannelSet();
report("Importing Join configuration");
if (chanSet == null) {
chanSet = objFactory.createChannelSet();
}
importChannelJoins(chanSet);
report("Imported Join configuration");
}
// if specified, import the queues and their acls
if (datagroups) {
report("Importing DataGroup configuration");
DataGroupSet dgSet = realm.getDataGroupSet();
if (dgSet == null) {
dgSet = objFactory.createDataGroupSet();
}
importDataGroups(dgSet);
report("Imported DataGroup configuration");
}
if (via) {
report("Importing Interface VIA configuration");
RealmInterfaceSet iSet = realm.getRealmInterfaces();
if (iSet != null) {
importInterfaceViaList(iSet);
}
report("Imported Interface VIA configuration");
}
if (scheduler) {
RealmSchedulerSet sSet = realm.getRealmSchedulerSet();
if (sSet != null) {
report("Importing Scheduler configuration");
importSchedulers(sSet);
report("Imported Scheduler configuration");
} else {
report("No Scheduler configuration to load");
}
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (node != null) {
node.close();
nSessionFactory.shutdown();
}
}
}
private void importDataGroups(DataGroupSet dgSet) throws Exception {
List dataGroupList = dgSet.getDataGroupEntry();
LinkedHashMap dgnamemap = new LinkedHashMap();
LinkedHashMap> dgnestedmap = new LinkedHashMap>();
for (Object aDataGroupList : dataGroupList) {
DataGroupEntry groupEntry = (DataGroupEntry) aDataGroupList;
if (datagroupfilter != null && !datagroupfilter.matches(groupEntry.getDataGroupAttributesEntry().getName())) {
report("Datagroup " + groupEntry.getDataGroupAttributesEntry().getName() + " ignored as it does not match datagroup filter");
continue; //skip
}
DataGroupAttributesEntry dgattrib = groupEntry.getDataGroupAttributesEntry();
nConflationAttributes cattrib = getConflationAttributes(groupEntry.getConflationAttributesEntry());
nDataGroup newgroup = node.getSession().createDataGroup(dgattrib.getName(), null, cattrib, dgattrib.isMulticastenabled(), false, dgattrib.getPriority()); //create data group
List publishers = groupEntry.getDataGroupPublisherEntry();
for (DataGroupPublisherEntry publisherEntry : publishers) { //add group publishers
String spubentry = publisherEntry.getName() + "@" + publisherEntry.getHost();
newgroup.addPublisher(spubentry);
}
dgnamemap.put(dgattrib.getName(), newgroup);
List nestedgroups = groupEntry.getNestedGroupEntry();
if (nestedgroups != null && nestedgroups.size() > 0)
dgnestedmap.put(dgattrib.getName(), nestedgroups); //Store newsted group list in map
}
for (Map.Entry> groupwithchildrenname : dgnestedmap.entrySet()) {
nDataGroup parent = dgnamemap.get(groupwithchildrenname.getKey());
for (NestedGroupEntry ngentry : groupwithchildrenname.getValue()) {
nDataGroup child = dgnamemap.get(ngentry.getName());
parent.add(child);
}
}
}
private nConflationAttributes getConflationAttributes(ConflationAttributesEntry caentry) throws nIllegalArgumentException {
if (caentry == null) return null;
int catype = caentry.getType().equals("DROP_EVENTS_TYPE") ? nConflationAttributes.sDropEvents : nConflationAttributes.sMergeEvents;
return new nConflationAttributes(catype, caentry.getInterval());
}
/**
* 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();
new nImportRealmXML(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
*/
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 imported based on command line arguments
boolean foundNoCluster = false;
for (String arg : args) {
if (arg.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 (arg.equalsIgnoreCase("-nocluster")) {
foundNoCluster = true;
}
if (arg.equals("-realms")) {
realms = true;
}
if (arg.equals("-cluster")) {
cluster = true;
}
if (arg.equals("-realmacl")) {
realmAcl = true;
}
if (arg.equals("-realmcfg")) {
realmCfg = true;
}
if (arg.equals("-channels")) {
channels = true;
}
if (arg.startsWith("-channelfilter")) {
this.channelfilter = new Filter(arg.split("=")[1]);
}
if (arg.equals("-channelacls")) {
channelAcls = true;
}
if (arg.equals("-joins")) {
joins = true;
}
if (arg.equals("-queues")) {
queues = true;
}
if (arg.startsWith("-queuefilter")) {
this.queuefilter = new Filter(arg.split("=")[1]);
}
if (arg.equals("-queueacls")) {
queueAcls = true;
}
if (arg.equals("-interfaces")) {
interfaces = true;
}
if (arg.equals("-plugins")) {
iplugins = true;
}
if (arg.equals("-via")) {
via = true;
}
if (arg.equals("-datagroups")) {
datagroups = true;
}
if (arg.startsWith("-datagroupfilter")) {
this.datagroupfilter = new Filter(arg.split("=")[1]);
}
}
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(ClusterSet clusterSet) throws Exception {
List entries = clusterSet.getClusterEntry();
for (Object entry1 : entries) {
ClusterEntry entry = (ClusterEntry) entry1;
String clusterName = entry.getName();
report("Creating cluster " + clusterName);
List members = entry.getClusterMember();
nSessionAttributes[] sessionAttribs = new nSessionAttributes[members.size()];
nClusterMemberConfiguration[] memCfgs = new nClusterMemberConfiguration[members.size()];
for (int y = 0; y < members.size(); y++) {
ClusterMember member = (ClusterMember) members.get(y);
String name = member.getName();
String rname = member.getRname();
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);
List sites = entry.getClusterSite();
for (Object site1 : sites) {
ClusterSite site = (ClusterSite) site1;
String name = site.getName();
report("Adding new cluster site" + name);
List smembers = site.getSiteMember();
SiteMember firstmember = (SiteMember) smembers.get(0);
nClusterSite cSite = cluster.createSite(name, firstmember.getName());
for (int z = 1; z < smembers.size(); z++) {
SiteMember smember = (SiteMember) smembers.get(z);
cSite.addMember(smember.getName());
}
}
report("Established cluster " + clusterName);
}
}
/**
* Method to import additional realms to the namespace
*/
private void importRealms(RealmSet realmSet, nRealmNode rnode) {
List entries = realmSet.getRealmEntry();
for (Object entry1 : entries) {
RealmEntry entry = (RealmEntry) entry1;
try {
String name = entry.getName();
String rname = entry.getRname();
String mount = entry.getMountpoint();
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 nirvRealm = new nRealm(name, conns);
if (mount != null && !mount.equals("")) {
nirvRealm.setMountPoint(mount);
}
session.addRealm(nirvRealm);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
private void importSecurityGroups(NirvanaRealm realm, nRealmNode rnode) {
List realmSecurityGroups = realm.getRealmSecurityGroupSet() != null ? realm.getRealmSecurityGroupSet().getRealmSecurityGroup() : new ArrayList();
nSecurityGroupManager securityGroupManager = rnode.getSecurityGroupManager();
for (RealmSecurityGroup realmSecurityGroup : realmSecurityGroups) {
String groupName = realmSecurityGroup.getRealmSecurityGroupEntry().getGroupname();
try {
securityGroupManager.registerSecurityGroup(groupName);
} catch (Exception ex) {
}
nSecurityGroup group = securityGroupManager.getGroup(groupName);
List securityGroupSubjectEntries = realmSecurityGroup.getSecurityGroupSubjectEntry();
for (SecurityGroupSubjectEntry securityGroupSubjectEntry : securityGroupSubjectEntries) {
try {
securityGroupManager.registerGroupMember(group, new nSubject(securityGroupSubjectEntry.getName() + "@" + securityGroupSubjectEntry.getHost()));
} catch (Exception ex) {
}
}
List securityGroupReferenceEntries = realmSecurityGroup.getSecurityGroupReferenceEntry();
for (SecurityGroupReferenceEntry securityGroupReferenceEntry : securityGroupReferenceEntries) {
try {
nSecurityGroup grp = securityGroupManager.getGroup(securityGroupReferenceEntry.getGroupname());
if (grp == null) {
securityGroupManager.registerSecurityGroup(securityGroupReferenceEntry.getGroupname());
grp = securityGroupManager.getGroup(securityGroupReferenceEntry.getGroupname());
}
securityGroupManager.registerGroupMember(group, grp);
} catch (Exception ex) {
}
}
}
}
/**
* Method to import contents of a realm acl
*/
private void importRealmACL(RealmPermissionSet realmPerms) throws nBaseAdminException {
{
nACL realmAcl = node.getACLs();
List entries = realmPerms.getRealmACLEntry();
for (Object entry1 : entries) {
RealmACLEntry entry = (RealmACLEntry) entry1;
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.getName() + "@" + entry.getHost());
modify = modifyRealmACLEntry(entry, modify);
realmAcl.replace(modify);
realmAcl.notifyObservers(modify);
} catch (nAdminIllegalArgumentException ignore) {
}
}
List groupEntries = realmPerms.getRealmGroupACLEntry();
for (Object entry1 : groupEntries) {
RealmGroupACLEntry entry = (RealmGroupACLEntry) entry1;
try {
nRealmACLEntry newentry = createRealmGroupACLEntry(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.getGroupname());
modify = modifyRealmACLEntry(entry, modify);
realmAcl.replace(modify);
realmAcl.notifyObservers(modify);
} catch (nAdminIllegalArgumentException ignore) {
}
}
node.setACLs(realmAcl);
}
}
/**
* Construct a new realm acl entry based on the imported xml
*/
private nRealmACLEntry createRealmACLEntry(RealmACLEntry entry) throws nAdminIllegalArgumentException {
nRealmACLEntry newAcl;
newAcl = new nRealmACLEntry(entry.getName(), entry.getHost());
newAcl.setAccessTheRealm(entry.isConnectToRealm());
newAcl.setConfigureRealm(entry.isChangeRealmConfig());
newAcl.setFullPrivileges(entry.isFullControl());
newAcl.setList(entry.isListACLEntries());
newAcl.setModify(entry.isModifyACLEntries());
newAcl.setManageChannels(entry.isAddremoveChannels());
newAcl.setManageJoins(entry.isAddremoveJoins());
newAcl.setManageP2PServices(entry.isCreateP2PService());
newAcl.setManageRealm(entry.isAddremoveRealms());
newAcl.setOverrideConnectionCount(entry.isOverrideConnectionCount());
newAcl.setUseAdminAPI(entry.isUseAdminAPI());
newAcl.setManageDataGroups(entry.isManageDatagroups());
newAcl.setTakeOwnershipOfDataGroup(entry.isOwnDatagroups());
newAcl.setPublishToGlobalDataGroup(entry.isPublishDatagroups());
return newAcl;
}
/**
* Construct a new realm acl entry based on the imported xml
*/
private nRealmACLEntry createRealmGroupACLEntry(RealmGroupACLEntry entry) throws nAdminIllegalArgumentException {
nRealmACLEntry newAcl;
newAcl = new nRealmACLEntry(new nSecurityGroup(entry.getGroupname()));
newAcl.setAccessTheRealm(entry.isConnectToRealm());
newAcl.setConfigureRealm(entry.isChangeRealmConfig());
newAcl.setFullPrivileges(entry.isFullControl());
newAcl.setList(entry.isListACLEntries());
newAcl.setModify(entry.isModifyACLEntries());
newAcl.setManageChannels(entry.isAddremoveChannels());
newAcl.setManageJoins(entry.isAddremoveJoins());
newAcl.setManageP2PServices(entry.isCreateP2PService());
newAcl.setManageRealm(entry.isAddremoveRealms());
newAcl.setOverrideConnectionCount(entry.isOverrideConnectionCount());
newAcl.setUseAdminAPI(entry.isUseAdminAPI());
newAcl.setManageDataGroups(entry.isManageDatagroups());
newAcl.setTakeOwnershipOfDataGroup(entry.isOwnDatagroups());
newAcl.setPublishToGlobalDataGroup(entry.isPublishDatagroups());
return newAcl;
}
/**
* Modify an existing realm acl entry based on the imported xml
*/
private nRealmACLEntry modifyRealmACLEntry(RealmACLEntry entry, nRealmACLEntry mod) {
mod.setAccessTheRealm(entry.isConnectToRealm());
mod.setConfigureRealm(entry.isChangeRealmConfig());
mod.setFullPrivileges(entry.isFullControl());
mod.setList(entry.isListACLEntries());
mod.setModify(entry.isModifyACLEntries());
mod.setManageChannels(entry.isAddremoveChannels());
mod.setManageJoins(entry.isAddremoveJoins());
mod.setManageP2PServices(entry.isCreateP2PService());
mod.setManageRealm(entry.isAddremoveRealms());
mod.setOverrideConnectionCount(entry.isOverrideConnectionCount());
mod.setUseAdminAPI(entry.isUseAdminAPI());
mod.setManageDataGroups(entry.isManageDatagroups());
mod.setTakeOwnershipOfDataGroup(entry.isOwnDatagroups());
mod.setPublishToGlobalDataGroup(entry.isPublishDatagroups());
return mod;
}
/**
* Modify an existing realm acl entry based on the imported xml
*/
private nRealmACLEntry modifyRealmACLEntry(RealmGroupACLEntry entry, nRealmACLEntry mod) {
mod.setAccessTheRealm(entry.isConnectToRealm());
mod.setConfigureRealm(entry.isChangeRealmConfig());
mod.setFullPrivileges(entry.isFullControl());
mod.setList(entry.isListACLEntries());
mod.setModify(entry.isModifyACLEntries());
mod.setManageChannels(entry.isAddremoveChannels());
mod.setManageJoins(entry.isAddremoveJoins());
mod.setManageP2PServices(entry.isCreateP2PService());
mod.setManageRealm(entry.isAddremoveRealms());
mod.setOverrideConnectionCount(entry.isOverrideConnectionCount());
mod.setUseAdminAPI(entry.isUseAdminAPI());
mod.setManageDataGroups(entry.isManageDatagroups());
mod.setTakeOwnershipOfDataGroup(entry.isOwnDatagroups());
mod.setPublishToGlobalDataGroup(entry.isPublishDatagroups());
return mod;
}
/**
* Construct a new realm acl entry based on the imported xml
*/
private nACLEntry createInterfaceACLEntry(InterfaceACLEntry entry) throws nAdminIllegalArgumentException {
nInterfaceViaEntry newAcl;
newAcl = new nInterfaceViaEntry(entry.getName(), entry.getHost());
return newAcl;
}
/**
* Construct a new realm acl entry based on the imported xml
*/
private nACLEntry createInterfaceGroupACLEntry(InterfaceGroupACLEntry entry) throws nAdminIllegalArgumentException {
nInterfaceViaEntry newAcl;
//newAcl = new nInterfaceViaEntry(entry.getName(), entry.getHost());
//return newAcl;
return null;
}
/**
* Import the realm configuration groups and their item values
*/
private void importRealmConfig(RealmConfiguration cfg) throws nConfigurationException, nAdminIllegalArgumentException {
List cfgGrps = cfg.getConfigGroup();
for (Object cfgGrp : cfgGrps) {
ConfigGroup grp = (ConfigGroup) cfgGrp;
String grpName = grp.getName();
nConfigGroup nGrp = node.findConfigGroup(grpName);
if (!nGrp.isReadOnly()) {
List cfgItems = grp.getConfigItem();
for (Object cfgItem : cfgItems) {
ConfigItem item = (ConfigItem) cfgItem;
nConfigEntry nItem = nGrp.find(item.getName());
if (nItem != null) {
nItem.setValue(item.getValue());
} else {
System.err.println("Could not find config item > " + grpName + "." + item.getName());
}
}
node.commitConfig(nGrp);
} else {
report("\tConfiguration group " + nGrp.getName() + " is read only and will not be imported");
}
}
}
/**
* Import the channels and their acls if specified
*/
private void importChannels(ChannelSet chanSet) throws nBaseAdminException, nBaseClientException {
List chanList = chanSet.getChannelEntry();
for (Object aChanList : chanList) {
ChannelEntry chan = (ChannelEntry) aChanList;
if (chan.getChannelAttributesEntry() == null) {
throw new nSecurityException("Illegal channel definition, could not import.");
}
if (channelfilter != null && !channelfilter.matches(chan.getChannelAttributesEntry().getName())) {
report("Channel " + chan.getChannelAttributesEntry().getName() + " ignored as it does not match filter");
continue; //skip
}
nChannelAttributes nAttr = createChanAttributes(chan.getChannelAttributesEntry());
createStoreProperties(nAttr, chan.getStorePropertiesEntry());
nChannelPublishKeys[] keys = createChannelPublishKeys(chan);
if (keys != null) nAttr.setPublishKeys(keys);
nLeafNode nChan = null;
nACL chanAcl = null;
if (channelAcls) {
ChannelPermissionSet perms = chan.getChannelPermissionSet();
nChan = (nLeafNode) node.findNode(nAttr.getName(), false);
if (nChan != null) {
chanAcl = nChan.getACLs();
} else {
chanAcl = nLeafNode.createACL();
}
List chanPerms = perms.getChannelACLEntry();
for (Object chanPerm : chanPerms) {
ChannelACLEntry entry = (ChannelACLEntry) chanPerm;
nChannelACLEntry nEntry = createChannelACLEntry(entry);
try {
chanAcl.add(nEntry);
} catch (nDuplicateACLEntryException dup) {
chanAcl.replace(nEntry);
} catch (Exception ex) {
ex.printStackTrace();
}
}
List chanGroupPerms = perms.getChannelGroupACLEntry();
for (Object chanPerm : chanGroupPerms) {
ChannelGroupACLEntry entry = (ChannelGroupACLEntry) chanPerm;
nChannelACLEntry nEntry = createChannelGroupACLEntry(entry);
try {
chanAcl.add(nEntry);
} catch (nDuplicateACLEntryException dup) {
chanAcl.replace(nEntry);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
if (nChan == null) {
try {
if (channelAcls && channels) {
node.createChannel(nAttr, chan.getChannelAttributesEntry().getEID(), chanAcl);
} else if (channels) {
node.createChannel(nAttr, chan.getChannelAttributesEntry().getEID());
}
} catch (nChannelAlreadyExistsException e) {
System.out.println("Channel " + nAttr.getFullName() + " not imported as it already exists");
}
} else if (channelAcls) {
nChan.setACLs(chanAcl);
}
}
report("Imported " + chanList.size() + " topics");
}
/**
* Import the channel joins
*/
private void importChannelJoins(ChannelSet chanSet) throws nIllegalArgumentException, nAdminIllegalArgumentException {
List chanList = chanSet.getChannelEntry();
for (Object aChanList : chanList) {
ChannelEntry chan = (ChannelEntry) aChanList;
nChannelAttributes nAttr = createChanAttributes(chan.getChannelAttributesEntry());
nLeafNode from;
nLeafNode to;
if (joins) {
ChannelJoinSet joinSet = chan.getChannelJoinSet();
if (joinSet == null) continue;
from = (nLeafNode) node.findNode(nAttr.getName());
List joinList = joinSet.getChannelJoinEntry();
for (Object aJoinList : joinList) {
ChannelJoinEntry join = (ChannelJoinEntry) aJoinList;
if (from != null) {
to = (nLeafNode) node.findNode(join.getTo());
if (to != null) {
try {
if (join.isArchival() != null && !join.isArchival()) {
from.join(to, true, join.getHopcount(), join.getFilter(), join.isAllowPurge());
} else if (join.isArchival() == null) { //support for older XML exports without archival join support
from.join(to, true, join.getHopcount(), join.getFilter(), join.isAllowPurge());
} else {
from.archiveJoin(to, join.getFilter());
}
} catch (Exception e) {
//if it is already there removed it and then recreate it so we pick up any changed attributes
if (e.getMessage() != null && e.getMessage().indexOf("is already joined") > 0) {
//System.out.println("duplicate join for [" +from.getAbsolutePath() +"] > [" +to.getAbsolutePath() +"]");
try {
from.deleteJoin(to);
from.join(to, true, join.getHopcount(), join.getFilter(), join.isAllowPurge());
//System.out.println("recreated join for [" +from.getAbsolutePath() +"] > [" +to.getAbsolutePath() +"]");
} catch (Exception cb) {
System.out.println("join error for [" + from.getAbsolutePath() + "] > [" + to.getAbsolutePath() + "]");
e.printStackTrace();
}
} else {
System.out.println("join error for [" + from.getAbsolutePath() + "] > [" + to.getAbsolutePath() + "]");
e.printStackTrace();
}
}
}
}
}
}
}
}
private nChannelAttributes createChanAttributes(ChannelAttributesEntry attribs) throws nIllegalArgumentException {
nChannelAttributes nAttr = new nChannelAttributes();
nAttr.setName(attribs.getName());
nAttr.setTTL(attribs.getTTL());
nAttr.setMaxEvents(attribs.getCapacity());
if (attribs.getType().equals("SIMPLE_TYPE")) {
nAttr.setType(nChannelAttributes.SIMPLE_TYPE);
} else if (attribs.getType().equals("TRANSIENT_TYPE")) {
nAttr.setType(nChannelAttributes.TRANSIENT_TYPE);
} else if (attribs.getType().equals("RELIABLE_TYPE")) {
nAttr.setType(nChannelAttributes.RELIABLE_TYPE);
} else if (attribs.getType().equals("PERSISTENT_TYPE")) {
nAttr.setType(nChannelAttributes.PERSISTENT_TYPE);
} else if (attribs.getType().equals("MIXED_TYPE")) {
nAttr.setType(nChannelAttributes.MIXED_TYPE);
}
nAttr.setClusterWide(attribs.isClusterWide());
nAttr.useJMSEngine(attribs.isJmsEngine());
nAttr.useMergeEngine(attribs.isMergeEngine());
//nAttr.setMulticastEnabled(attribs.isMulticastenabled());
return nAttr;
}
private void createStoreProperties(nChannelAttributes nAttr, StorePropertiesEntry attribs) throws nIllegalArgumentException {
if (attribs != null) {
nChannelAttributes tmp = new nChannelAttributes();
nStoreProperties test = tmp.getProperties();
//
// If flow control will slow down / stop publishes if we exceed capacity
//
if (attribs.isHonorCapacityWhenFull() != null && test.getHonorCapacityWhenFull() != attribs.isHonorCapacityWhenFull()) {
nStoreProperties props = nAttr.getProperties();
props.setHonorCapacityWhenFull(attribs.isHonorCapacityWhenFull());
}
//
// Multicast enable flag
//
if (attribs.isEnableMulticast() && test.enableMulticast() != attribs.isEnableMulticast()) {
nStoreProperties props = nAttr.getProperties();
props.enableMulticast(attribs.isEnableMulticast());
}
//
// I/O Sync flags
//
if (attribs.isSyncOnEachWrite() != null) {
nStoreProperties props = nAttr.getProperties();
props.setSyncOnEachWrite(attribs.isSyncOnEachWrite());
}
if (attribs.getSyncBatchTime() != null) {
nStoreProperties props = nAttr.getProperties();
props.setSyncBatchTime(attribs.getSyncBatchTime());
}
if (attribs.getSyncMaxBatchSize() != null) {
nStoreProperties props = nAttr.getProperties();
props.setSyncMaxBatchSize(attribs.getSyncMaxBatchSize());
}
//
// Client class name to use to merge events
//
if (attribs.getClientMergeEngineClassname() != null) {
nStoreProperties props = nAttr.getProperties();
props.setClientMergeEngineClassname(attribs.getClientMergeEngineClassname());
}
//
// Fanout archive target store name
//
if (attribs.getFanoutArchiveTarget() != null) {
nStoreProperties props = nAttr.getProperties();
props.setFanoutArchiveTarget(attribs.getFanoutArchiveTarget());
}
//
// Enable / disable event caching for the store
//
if (attribs.isCacheOnReload() != null) {
nStoreProperties props = nAttr.getProperties();
props.setCacheOnReload(attribs.isCacheOnReload());
}
if (attribs.isEnableCaching() != null) {
nStoreProperties props = nAttr.getProperties();
props.setEnableCaching(attribs.isEnableCaching());
}
//
// Indicate if read buffering is allowed, this, by default is true since it is faster
//
if (attribs.isEnableReadBuffering() != null) {
nStoreProperties props = nAttr.getProperties();
props.setEnableReadBuffering(attribs.isEnableReadBuffering());
}
if (attribs.getReadBufferSize() != null) {
nStoreProperties props = nAttr.getProperties();
props.setReadBufferSize(attribs.getReadBufferSize());
}
if (attribs.isPerformAutomaticMaintenance() != null) {
nStoreProperties props = nAttr.getProperties();
props.setPerformAutomaticMaintenance(attribs.isPerformAutomaticMaintenance());
}
if (attribs.getPriority() != null) {
nStoreProperties props = nAttr.getProperties();
props.setPriority(attribs.getPriority());
}
}
}
private nChannelPublishKeys[] createChannelPublishKeys(ChannelEntry chan) throws nIllegalArgumentException {
if (!channels) {
return null;
}
nChannelPublishKeys keys[] = null;
ChannelKeySet chankeyset = chan.getChannelKeySet();
if (chankeyset == null) return null;
List chankeylist = chankeyset.getChannelKeyEntry();
if (channels) {
if ((chankeylist != null) && (chankeylist.size() > 0)) {
keys = new nChannelPublishKeys[chankeylist.size()];
for (int x = 0; x < chankeylist.size(); x++) {
ChannelKeyEntry chankeyentry = (ChannelKeyEntry) chankeylist.get(x);
keys[x] = new nChannelPublishKeys(chankeyentry.getKeyName(), chankeyentry.getKeyDepth());
}
}
} else {
return null;
}
return keys;
}
private nChannelACLEntry createChannelACLEntry(ChannelACLEntry entry) throws nAdminIllegalArgumentException {
nChannelACLEntry newAcl;
newAcl = new nChannelACLEntry(entry.getName(), entry.getHost());
newAcl.setFullPrivileges(entry.isFullControl());
newAcl.setGetLastEID(entry.isGetLastEID());
newAcl.setList(entry.isListACLEntries());
newAcl.setModify(entry.isModifyACLEntries());
newAcl.setPurge(entry.isPurgeEvents());
newAcl.setRead(entry.isSubscribe());
newAcl.setUseNamedSubscription(entry.isUseNamedSubcription());
newAcl.setWrite(entry.isPublish());
return newAcl;
}
private nChannelACLEntry createChannelGroupACLEntry(ChannelGroupACLEntry entry) throws nAdminIllegalArgumentException {
nChannelACLEntry newAcl;
newAcl = new nChannelACLEntry(new nSecurityGroup(entry.getGroupname()));
newAcl.setFullPrivileges(entry.isFullControl());
newAcl.setGetLastEID(entry.isGetLastEID());
newAcl.setList(entry.isListACLEntries());
newAcl.setModify(entry.isModifyACLEntries());
newAcl.setPurge(entry.isPurgeEvents());
newAcl.setRead(entry.isSubscribe());
newAcl.setUseNamedSubscription(entry.isUseNamedSubcription());
newAcl.setWrite(entry.isPublish());
return newAcl;
}
private nChannelACLEntry createQueueACLEntry(QueueACLEntry entry) throws nAdminIllegalArgumentException {
nChannelACLEntry newAcl;
newAcl = new nChannelACLEntry(entry.getName(), entry.getHost());
newAcl.setFullPrivileges(entry.isFullControl());
newAcl.setList(entry.isListACLEntries());
newAcl.setModify(entry.isModifyACLEntries());
newAcl.setPop(entry.isPop());
newAcl.setRead(entry.isPeek());
newAcl.setWrite(entry.isPush());
newAcl.setPurge(entry.isPurge());
return newAcl;
}
private nChannelACLEntry createQueueGroupACLEntry(QueueGroupACLEntry entry) throws nAdminIllegalArgumentException {
nChannelACLEntry newAcl;
newAcl = new nChannelACLEntry(new nSecurityGroup(entry.getGroupname()));
newAcl.setFullPrivileges(entry.isFullControl());
newAcl.setList(entry.isListACLEntries());
newAcl.setModify(entry.isModifyACLEntries());
newAcl.setPop(entry.isPop());
newAcl.setRead(entry.isPeek());
newAcl.setWrite(entry.isPush());
newAcl.setPurge(entry.isPurge());
return newAcl;
}
private void importQueues(QueueSet qSet) throws nBaseClientException, nBaseAdminException {
List qList = qSet.getQueueEntry();
for (Object aQList : qList) {
QueueEntry q = (QueueEntry) aQList;
if (queuefilter != null && !queuefilter.matches(q.getChannelAttributesEntry().getName())) {
report("Queue " + q.getChannelAttributesEntry().getName() + " ignored as it does not match filter");
continue; //skip
}
nChannelAttributes nAttr = createChanAttributes(q.getChannelAttributesEntry());
createStoreProperties(nAttr, q.getStorePropertiesEntry());
nLeafNode nqueue = null;
nACL qAcl = null;
if (queueAcls) {
QueuePermissionSet perms = q.getQueuePermissionSet();
nqueue = (nLeafNode) node.findNode(nAttr.getName(), false);
if (nqueue != null) {
qAcl = nqueue.getACLs();
} else {
qAcl = nLeafNode.createACL();
}
List qPerms = perms.getQueueACLEntry();
for (Object qPerm : qPerms) {
QueueACLEntry entry = (QueueACLEntry) qPerm;
nChannelACLEntry nEntry = createQueueACLEntry(entry);
try {
qAcl.add(nEntry);
qAcl.notifyObservers(nEntry);
} catch (nDuplicateACLEntryException dup) {
qAcl.replace(nEntry);
qAcl.notifyObservers(nEntry);
} catch (Exception ex) {
ex.printStackTrace();
}
}
List qGroupPerms = perms.getQueueGroupACLEntry();
for (Object qPerm : qGroupPerms) {
QueueGroupACLEntry entry = (QueueGroupACLEntry) qPerm;
nChannelACLEntry nEntry = createQueueGroupACLEntry(entry);
try {
qAcl.add(nEntry);
qAcl.notifyObservers(nEntry);
} catch (nDuplicateACLEntryException dup) {
qAcl.replace(nEntry);
qAcl.notifyObservers(nEntry);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
if (nqueue == null) {
try {
if (queueAcls) {
node.createQueue(nAttr, qAcl);
} else {
node.createQueue(nAttr);
}
} catch (nChannelAlreadyExistsException e) {
System.out.println("Queue " + nAttr.getFullName() + " not imported as it already exists");
}
} else {
if (queueAcls) {
nqueue.setACLs(qAcl);
}
}
}
}
private nSharedMemoryInterface createSHMInterface(RealmSHMConfigurationEntry iface) throws nAdminIllegalArgumentException {
nSharedMemoryInterface shmif;
shmif = new nSharedMemoryInterface(iface.getTimeout());
shmif.setBufferSize((int) iface.getBuffersize());
shmif.setDirectoryPath(iface.getDirectory());
shmif.setAutostart(true);
return shmif;
}
private nMulticastConfiguration createMulticastConfiguration(RealmMulticastConfigurationEntry entry) throws nAdminIllegalArgumentException {
//basic configuration
RealmMulticastBasicConfigurationEntry basicentry = entry.getRealmMulticastBasicConfigurationEntry();
nMulticastConfiguration mconfig = new nMulticastConfiguration(basicentry.getMulticastAddress(), basicentry.getAdapterAddress(), true);
mconfig.setAdapterBufferSize((int) basicentry.getAdapterBufferSize());
mconfig.setClientEstablishmentTimeout(basicentry.getClientestablishmenttimeout());
mconfig.setUseForCluster(basicentry.isUseforClusters());
mconfig.setUseForDataGroups(basicentry.isUseforDatagroups());
mconfig.setUseForStatusUpdates(basicentry.isUseforStatusUpdates());
mconfig.setUseForChannel(basicentry.isUseforChannels());
mconfig.setAllowLoopback(basicentry.isAllowLoopback());
//Security
RealmMulticastSecurityConfigurationEntry secentry = entry.getRealmMulticastSecurityConfigurationEntry();
String sCRCTYPE = secentry.getCRCtype();
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);
String sEncryptionLevel = secentry.getEncryptionlevel();
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.getRotateEncryptionKeyTime());
mconfig.setRotateEncryptionKeyCount((int) secentry.getRotateEnryptionKeyWait());
mconfig.setUniqueSessionIDSize((int) secentry.getSessionIDSize());
//advanced configuration
RealmMulticastAdvancedConfigurationEntry aentry = entry.getRealmMulticastAdvancedConfigurationEntry();
String sMode = aentry.getACKmode();
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.getKeepAliveInterval());
mconfig.setTTL((short) aentry.getPacketTTL());
mconfig.setTrafficClass((byte) aentry.getTrafficClass());
mconfig.setFlusherInterval((int) aentry.getFlusherInterval());
mconfig.setAckWindowSize((int) aentry.getAckWindowsize());
mconfig.setUnAckedWindowSize((int) aentry.getUnackedWindowsize());
mconfig.setPacketSize((int) aentry.getPacketSize());
mconfig.setMaxOutstandingPackets((int) aentry.getReceiverOutstandingPacketSize());
mconfig.setOutstandingPacketsQueueSize((int) aentry.getSenderOutstandingPacketSize());
mconfig.setPeakRate((int) aentry.getPeakDetectionRate());
return mconfig;
}
private void importInterfaces(RealmInterfaceSet iSet) throws nRequestTimedOutException, nSessionPausedException, nSessionNotConnectedException, nAdminSecurityException, nAdminIllegalArgumentException, nUnexpectedResponseException, IOException, nIllegalArgumentException {
nMulticastManager multimgr = node.getMulticastManager();
List multiList = iSet.getRealmMulticastConfiguration();
for (RealmMulticastConfigurationEntry mentry : multiList) {
nMulticastConfiguration multiconfig = createMulticastConfiguration(mentry);
multimgr.addMulticastConfiguration(multiconfig);
}
nInterfaceManager mgr = node.getInterfaceManager();
List shmList = iSet.getRealmSHMConfiguration();
for (RealmSHMConfigurationEntry shmentry : shmList) {
nSharedMemoryInterface shmif = createSHMInterface(shmentry);
mgr.addInterface(shmif);
}
List nspList = iSet.getRealmNSPInterface();
for (Object aNspList : nspList) {
RealmNSPInterfaceEntry iface = (RealmNSPInterfaceEntry) aNspList;
nSocketInterface socks = createSocketInterface(iface);
mgr.addInterface(socks);
}
List nhpList = iSet.getRealmNHPInterface();
for (Object aNhpList : nhpList) {
RealmNHPInterfaceEntry iface = (RealmNHPInterfaceEntry) aNhpList;
nHTTPInterface http = createHTTPInterface(iface);
if (mgr.findInterface(iface.getRealmInterface().getName()) != null) {
http = (nHTTPInterface) mgr.findInterface(iface.getRealmInterface().getName()).getInterface();
if (iplugins) {
createPlugin(http, iface);
}
mgr.modInterface(http);
} else {
if (iplugins) {
createPlugin(http, iface);
}
mgr.addInterface(http);
}
}
List nspsList = iSet.getRealmNSPSInterface();
for (Object aNspsList : nspsList) {
RealmNSPSInterfaceEntry iface = (RealmNSPSInterfaceEntry) aNspsList;
nSSLInterface nsps = createSSLInterface(iface);
mgr.addInterface(nsps);
}
List nhpsList = iSet.getRealmNHPSInterface();
for (Object aNhpsList : nhpsList) {
RealmNHPSInterfaceEntry iface = (RealmNHPSInterfaceEntry) aNhpsList;
nHTTPSInterface nhps = createHTTPSInterface(iface);
if (mgr.findInterface(iface.getRealmInterface().getName()) != null) {
nhps = (nHTTPSInterface) mgr.findInterface(iface.getRealmInterface().getName()).getInterface();
if (iplugins) {
createPlugin(nhps, iface);
}
mgr.modInterface(nhps);
} else {
if (iplugins) {
createPlugin(nhps, iface);
}
mgr.addInterface(nhps);
}
}
}
private void importSchedulers(RealmSchedulerSet sSet) throws nSchedulerParseException, nBaseClientException {
nSchedulerManager mgr = node.getSchedulerManager();
if (mgr == null) {
throw new nSecurityException("Scheduler not enabled");
} else {
List schedulerList = sSet.getScheduler();
for (Object aSchedulerList : schedulerList) {
Scheduler scheduler = (Scheduler) aSchedulerList;
byte[] bSource = decode(scheduler.getSource());
mgr.add(new String(bSource), scheduler.getSubject(), scheduler.isClusterWide());
}
}
}
private static byte[] decode(String base64) {
int pad = 0;
for (int i = base64.length() - 1; base64.charAt(i) == '='; i--) {
pad++;
}
int length = base64.length() * 6 / 8 - pad;
byte[] raw = new byte[length];
int rawIndex = 0;
for (int i = 0; i < base64.length(); i += 4) {
int block = (getValue(base64.charAt(i)) << 18) + (getValue(base64.charAt
(i + 1)) << 12) + (getValue(base64.charAt(i + 2)) << 6) + (getValue
(base64.charAt(i + 3)));
for (int j = 0; j < 3 && rawIndex + j < raw.length; j++) {
raw[rawIndex + j] = (byte) ((block >> (8 * (2 - j))) & 0xff);
}
rawIndex += 3;
}
return (raw);
}
private static int getValue(char c) {
if (c >= 'A' && c <= 'Z') {
return (c - 'A');
}
if (c >= 'a' && c <= 'z') {
return (c - 'a' + 26);
}
if (c >= '0' && c <= '9') {
return (c - '0' + 52);
}
if (c == '+') {
return (62);
}
if (c == '/') {
return (63);
}
if (c == '=') {
return (0);
}
return (-1);
}
/**
* Method to import contents of a realm acl
*/
private void importInterfaceViaList(RealmInterfaceSet iSet) throws nBaseAdminException {
nInterfaceManager mgr = node.getInterfaceManager();
List nspList = iSet.getRealmNSPInterface();
for (Object aNspList : nspList) {
RealmNSPInterfaceEntry iface = (RealmNSPInterfaceEntry) aNspList;
nInterfaceStatus status = mgr.findInterface(iface.getRealmInterface().getName());
nSocketInterface socks;
if (status != null) {
socks = (nSocketInterface) status.getInterface();
importViaList(iface.getInterfacePermissionSet(), socks);
}
}
List nhpList = iSet.getRealmNHPInterface();
for (Object aNhpList : nhpList) {
RealmNHPInterfaceEntry iface = (RealmNHPInterfaceEntry) aNhpList;
nInterfaceStatus status = mgr.findInterface(iface.getRealmInterface().getName());
nHTTPInterface http;
if (status != null) {
http = (nHTTPInterface) status.getInterface();
importViaList(iface.getInterfacePermissionSet(), http);
}
}
List nspsList = iSet.getRealmNSPSInterface();
for (Object aNspsList : nspsList) {
RealmNSPSInterfaceEntry iface = (RealmNSPSInterfaceEntry) aNspsList;
nInterfaceStatus status = mgr.findInterface(iface.getRealmInterface().getName());
nSSLInterface nsps;
if (status != null) {
nsps = (nSSLInterface) status.getInterface();
importViaList(iface.getInterfacePermissionSet(), nsps);
}
}
List nhpsList = iSet.getRealmNHPSInterface();
for (Object aNhpsList : nhpsList) {
RealmNHPSInterfaceEntry iface = (RealmNHPSInterfaceEntry) aNhpsList;
nInterfaceStatus status = mgr.findInterface(iface.getRealmInterface().getName());
nHTTPSInterface nhps;
if (status != null) {
nhps = (nHTTPSInterface) status.getInterface();
importViaList(iface.getInterfacePermissionSet(), nhps);
}
}
}
/**
* Method to import contents of a realm acl
*/
private void importViaList(InterfacePermissionSet interfacePerms, nInterface iface) throws nBaseAdminException {
if (interfacePerms == null) return;
nACL ifaceAcl = iface.getViaList();
List entries = interfacePerms.getInterfaceACLEntry();
if (ifaceAcl == null) {
if (entries.size() == 0) {
return;
} else {
ifaceAcl = nRealmNode.createACL();
}
}
for (Object entry1 : entries) {
if (entry1 instanceof InterfaceACLEntry) {
InterfaceACLEntry entry = (InterfaceACLEntry) entry1;
try {
nACLEntry newentry = createInterfaceACLEntry(entry);
ifaceAcl.add(newentry);
ifaceAcl.notifyObservers(newentry);
} catch (nDuplicateACLEntryException dup) {
// if entry exists, do nothing
} catch (nAdminIllegalArgumentException ignore) {
}
iface.setViaList(ifaceAcl);
}
//else{
/*InterfaceGroupACLEntry entry = (InterfaceGroupACLEntry) entry1;
try {
nACLEntry newentry = createInterfaceGroupACLEntry(entry);
ifaceAcl.add(newentry);
ifaceAcl.notifyObservers(newentry);
} catch (nDuplicateACLEntryException dup) {
// if entry exists, do nothing
} catch (nAdminIllegalArgumentException ignore) {
}
iface.setViaList(ifaceAcl);
}
}*/
}
}
private nSocketInterface createSocketInterface(RealmNSPInterfaceEntry iface) throws nAdminIllegalArgumentException {
nSocketInterface socks;
socks = new nSocketInterface(iface.getRealmInterface().getAdapter(), iface.getRealmInterface().getPort(), iface.getRealmInterface().isAutostart());
socks.setAdvertise(iface.getRealmInterface().isAdvertise());
socks.setAuthTimeOut((int) iface.getRealmInterface().getAuthtime());
socks.setBacklog(iface.getRealmInterface().getBacklog());
socks.setThreadCount(iface.getRealmInterface().getAcceptThreads());
socks.setAdvertise(iface.getRealmInterface().isAdvertise());
socks.setAutostart(iface.getRealmInterface().isAutostart());
socks.setRecvBufferSize((int) iface.getRealmInterface().getReceivebuffersize());
socks.setSendBufferSize((int) iface.getRealmInterface().getSendbuffersize());
socks.setInterRealmAllow(iface.getRealmInterface().isAllowforinterrealm());
socks.setAllowClientConnections(iface.getRealmInterface().isAllowclientconnections());
socks.setAdapterAlias(iface.getRealmInterface().getAlias());
socks.setAllowNIO(iface.getRealmInterface().getEnableNIO());
report("Creating socket interface on " + iface.getRealmInterface().getAdapter() + " port " + iface.getRealmInterface().getPort());
return socks;
}
private nHTTPInterface createHTTPInterface(RealmNHPInterfaceEntry iface) throws nAdminIllegalArgumentException, nIllegalArgumentException {
nHTTPInterface http;
http = new nHTTPInterface(iface.getRealmInterface().getAdapter(), iface.getRealmInterface().getPort(), iface.getRealmInterface().isAutostart());
http.setAdvertise(iface.getRealmInterface().isAdvertise());
http.setAuthTimeOut((int) iface.getRealmInterface().getAuthtime());
http.setBacklog(iface.getRealmInterface().getBacklog());
http.setThreadCount(iface.getRealmInterface().getAcceptThreads());
http.setAdvertise(iface.getRealmInterface().isAdvertise());
http.setAutostart(iface.getRealmInterface().isAutostart());
http.setRecvBufferSize((int) iface.getRealmInterface().getReceivebuffersize());
http.setSendBufferSize((int) iface.getRealmInterface().getSendbuffersize());
http.setInterRealmAllow(iface.getRealmInterface().isAllowforinterrealm());
http.setAllowClientConnections(iface.getRealmInterface().isAllowclientconnections());
http.setAllowNIO(iface.getRealmInterface().getEnableNIO());
JavascriptConfigEntryType jsconfig = iface.getJavascriptConfigEntry();
if (jsconfig != null) {
http.enabledWebSockets(jsconfig.isEnableWebSockets());
http.setNativeCometAllowed(jsconfig.isEnableJavaScript());
http.setAjaxLPActiveDelay(jsconfig.getAjaxLPActiveDelay());
http.setAjaxLPIdleDelay(jsconfig.getAjaxLPIdleDelay());
http.setAllowedOrigins(jsconfig.getCORSAllowedOrigins());
List customheaderlist = jsconfig.getCustomHeadersConfig();
if (customheaderlist != null && customheaderlist.size() > 0) {
ArrayList httpcustomheaderlist = new ArrayList();
for (CustomHeadersConfigEntryType customHeadersConfigEntryType : customheaderlist) {
nCustomHeader headerconfigentry = new nCustomHeader(customHeadersConfigEntryType.getKey(), customHeadersConfigEntryType.getValue(), customHeadersConfigEntryType.getUserAgents());
httpcustomheaderlist.add(headerconfigentry);
}
http.setCustomHeaders(httpcustomheaderlist);
}
}
http.setAdapterAlias(iface.getRealmInterface().getAlias());
report("Creating HTTP interface on " + iface.getRealmInterface().getAdapter() + " port " + iface.getRealmInterface().getPort());
return http;
}
private nSSLInterface createSSLInterface(RealmNSPSInterfaceEntry iface) throws nAdminIllegalArgumentException, IOException {
nSSLInterface nsps;
nsps = new nSSLInterface(iface.getRealmInterface().getAdapter(), iface.getRealmInterface().getPort(), iface.getRealmInterface().isAutostart());
nsps.setAdvertise(iface.getRealmInterface().isAdvertise());
nsps.setAuthTimeOut((int) iface.getRealmInterface().getAuthtime());
nsps.setBacklog(iface.getRealmInterface().getBacklog());
nsps.setThreadCount(iface.getRealmInterface().getAcceptThreads());
nsps.setAdvertise(iface.getRealmInterface().isAdvertise());
nsps.setAutostart(iface.getRealmInterface().isAutostart());
nsps.setRecvBufferSize((int) iface.getRealmInterface().getReceivebuffersize());
nsps.setSendBufferSize((int) iface.getRealmInterface().getSendbuffersize());
nsps.setInterRealmAllow(iface.getRealmInterface().isAllowforinterrealm());
nsps.setAllowClientConnections(iface.getRealmInterface().isAllowclientconnections());
nsps.setAdapterAlias(iface.getRealmInterface().getAlias());
nsps.setAllowNIO(iface.getRealmInterface().getEnableNIO());
if (iface.getRealmInterfaceSSLConfig().getCRLFile() != null && iface.getRealmInterfaceSSLConfig().getCRLFile().trim().length() > 0) {
nsps.setCRLFile(iface.getRealmInterfaceSSLConfig().getCRLFile());
}
if (iface.getRealmInterfaceSSLConfig().getCertificateAlias() != null) {
if (iface.getRealmInterfaceSSLConfig().getCertificateAlias().trim().length() > 0) {
nsps.setAlias(iface.getRealmInterfaceSSLConfig().getCertificateAlias());
}
}
nsps.setCertRequired(iface.getRealmInterfaceSSLConfig().isEnableClientValidation());
if (iface.getRealmInterfaceSSLConfig().getKeyStorePath().trim().length() > 0) {
nsps.setKeyStore(iface.getRealmInterfaceSSLConfig().getKeyStorePath());
}
if (iface.getRealmInterfaceSSLConfig().getTrustStorePath().trim().length() > 0) {
nsps.setTrustStore(iface.getRealmInterfaceSSLConfig().getTrustStorePath());
}
RealmInterfaceSupportedCipherSet cSet = iface.getRealmInterfaceSupportedCipherSet();
List cipherList = cSet.getRealmInterfaceSupportedCipher();
String supported[] = new String[cipherList.size()];
for (int x = 0; x < cipherList.size(); x++) {
RealmInterfaceSupportedCipher cipher = (RealmInterfaceSupportedCipher) cipherList.get(x);
supported[x] = cipher.getName();
report("\tSupporting : " + supported[x]);
}
nsps.setEnabledCiphers(supported, false);
report("Please enter the password for the keystore on interface " + nsps.getProtocol() + "://" + nsps.getAdapter() + ":" + nsps.getPort());
System.out.print("Store " + nsps.getKeyStore() + " : ");
System.out.flush();
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
String password = stdIn.readLine();
nsps.setKeyStorePassword(password);
report("Please enter the password for the trust store on interface " + nsps.getProtocol() + "://" + nsps.getAdapter() + ":" + nsps.getPort());
System.out.print("Trust Store " + nsps.getTrustStore() + " : ");
System.out.flush();
password = stdIn.readLine();
nsps.setTrustStorePassword(password);
report("Please enter the password for the private key on interface " + nsps.getProtocol() + "://" + nsps.getAdapter() + ":" + nsps.getPort());
System.out.print("Password : ");
System.out.flush();
password = stdIn.readLine();
nsps.setPrivateKeyPassword(password);
report("Creating SSL interface on " + iface.getRealmInterface().getAdapter() + " port " + iface.getRealmInterface().getPort());
return nsps;
}
private nHTTPSInterface createHTTPSInterface(RealmNHPSInterfaceEntry iface) throws nAdminIllegalArgumentException, IOException {
nHTTPSInterface nhps;
nhps = new nHTTPSInterface(iface.getRealmInterface().getAdapter(), iface.getRealmInterface().getPort(), iface.getRealmInterface().isAutostart());
nhps.setAdvertise(iface.getRealmInterface().isAdvertise());
nhps.setAuthTimeOut((int) iface.getRealmInterface().getAuthtime());
nhps.setBacklog(iface.getRealmInterface().getBacklog());
nhps.setThreadCount(iface.getRealmInterface().getAcceptThreads());
nhps.setAdvertise(iface.getRealmInterface().isAdvertise());
nhps.setAutostart(iface.getRealmInterface().isAutostart());
nhps.setRecvBufferSize((int) iface.getRealmInterface().getReceivebuffersize());
nhps.setSendBufferSize((int) iface.getRealmInterface().getSendbuffersize());
nhps.setInterRealmAllow(iface.getRealmInterface().isAllowforinterrealm());
nhps.setAllowClientConnections(iface.getRealmInterface().isAllowclientconnections());
nhps.setAdapterAlias(iface.getRealmInterface().getAlias());
nhps.enabledWebSockets(iface.isEnableWebSockets());
nhps.setNativeCometAllowed(iface.isEnableNativeComet());
nhps.setAjaxLPActiveDelay(iface.getAjaxLPActiveDelay());
nhps.setAjaxLPIdleDelay(iface.getAjaxLPIdleDelay());
nhps.setAllowNIO(iface.getRealmInterface().getEnableNIO());
if (iface.getRealmInterfaceSSLConfig().getCRLFile() != null && iface.getRealmInterfaceSSLConfig().getCRLFile().trim().length() > 0) {
nhps.setCRLFile(iface.getRealmInterfaceSSLConfig().getCRLFile());
}
if (iface.getRealmInterfaceSSLConfig().getCertificateAlias() != null) {
if (iface.getRealmInterfaceSSLConfig().getCertificateAlias().trim().length() > 0) {
nhps.setAlias(iface.getRealmInterfaceSSLConfig().getCertificateAlias());
}
}
nhps.setCertRequired(iface.getRealmInterfaceSSLConfig().isEnableClientValidation());
if (iface.getRealmInterfaceSSLConfig().getKeyStorePath().trim().length() > 0) {
nhps.setKeyStore(iface.getRealmInterfaceSSLConfig().getKeyStorePath());
}
if (iface.getRealmInterfaceSSLConfig().getTrustStorePath().trim().length() > 0) {
nhps.setTrustStore(iface.getRealmInterfaceSSLConfig().getTrustStorePath());
}
RealmInterfaceSupportedCipherSet cSet = iface.getRealmInterfaceSupportedCipherSet();
List cipherList = cSet.getRealmInterfaceSupportedCipher();
String supported[] = new String[cipherList.size()];
for (int x = 0; x < cipherList.size(); x++) {
RealmInterfaceSupportedCipher cipher = (RealmInterfaceSupportedCipher) cipherList.get(x);
supported[x] = cipher.getName();
report("\tSupporting : " + supported[x]);
}
nhps.setEnabledCiphers(supported, false);
report("Please enter the password for the keystore on interface " + nhps.getProtocol() + "://" + nhps.getAdapter() + ":" + nhps.getPort());
System.out.print("Store " + nhps.getKeyStore() + " : ");
System.out.flush();
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
String password = stdIn.readLine();
nhps.setKeyStorePassword(password);
report("Please enter the password for the trust store on interface " + nhps.getProtocol() + "://" + nhps.getAdapter() + ":" + nhps.getPort());
System.out.print("Trust Store " + nhps.getTrustStore() + " : ");
System.out.flush();
password = stdIn.readLine();
nhps.setTrustStorePassword(password);
report("Please enter the password for the private key on interface " + nhps.getProtocol() + "://" + nhps.getAdapter() + ":" + nhps.getPort());
System.out.print("Password : ");
System.out.flush();
password = stdIn.readLine();
nhps.setPrivateKeyPassword(password);
report("Creating HTTPS interface on " + iface.getRealmInterface().getAdapter() + " port " + iface.getRealmInterface().getPort());
return nhps;
}
private void createPlugin(nHTTPInterface niface, RealmNHPInterfaceEntry iface) {
List plugins = iface.getRealmInterfacePlugin();
if (plugins.size() == 0) {
return;
}
Vector pluginCfg = new Vector();
NirvanaFilePluginEntry file;
NirvanaProxyPassThroughPluginEntry proxy;
NirvanaSOAPPluginEntry soap;
NirvanaXMLPluginEntry xml;
NirvanaRESTPluginEntry restPluginEntry;
for (Object plugin1 : plugins) {
RealmInterfacePluginEntry plugin = (RealmInterfacePluginEntry) plugin1;
file = plugin.getNirvanaFilePlugin();
proxy = plugin.getNirvanaProxyPassThroughPlugin();
soap = plugin.getNirvanaSOAPPlugin();
xml = plugin.getNirvanaXMLPlugin();
restPluginEntry = plugin.getNirvanaRESTPlugin();
if (file != null) {
nPluginConfig filePlugin = new nPluginConfig(plugin.getName(), plugin.getMountPoint());
List configEntries = file.getPluginConfigEntry();
for (Object configEntry : configEntries) {
PluginConfigEntryType entry = (PluginConfigEntryType) configEntry;
nPluginConfigEntry nEntry = new nPluginEntry(entry.getName(), entry.getDescription(), entry.getValue());
filePlugin.add(nEntry);
}
pluginCfg.add(filePlugin);
} else if (proxy != null) {
nPluginConfig proxyPlugin = new nPluginConfig(plugin.getName(), plugin.getMountPoint());
List configEntries = proxy.getPluginConfigEntry();
for (Object configEntry : configEntries) {
PluginConfigEntryType entry = (PluginConfigEntryType) configEntry;
nPluginConfigEntry nEntry = new nPluginEntry(entry.getName(), entry.getDescription(), entry.getValue());
proxyPlugin.add(nEntry);
}
pluginCfg.add(proxyPlugin);
} else if (xml != null) {
nPluginConfig xmlPlugin = new nPluginConfig(plugin.getName(), plugin.getMountPoint());
List configEntries = xml.getPluginConfigEntry();
for (Object configEntry : configEntries) {
PluginConfigEntryType entry = (PluginConfigEntryType) configEntry;
nPluginConfigEntry nEntry = new nPluginEntry(entry.getName(), entry.getDescription(), entry.getValue());
xmlPlugin.add(nEntry);
}
pluginCfg.add(xmlPlugin);
} else if (soap != null) {
nPluginConfig soapPlugin = new nPluginConfig(plugin.getName(), plugin.getMountPoint());
List configEntries = soap.getPluginConfigEntry();
for (Object configEntry : configEntries) {
PluginConfigEntryType entry = (PluginConfigEntryType) configEntry;
nPluginConfigEntry nEntry = new nPluginEntry(entry.getName(), entry.getDescription(), entry.getValue());
soapPlugin.add(nEntry);
}
pluginCfg.add(soapPlugin);
} else if (restPluginEntry != null) {
nPluginConfig webPlugin = new nPluginConfig(plugin.getName(), plugin.getMountPoint());
List configEntries = restPluginEntry.getPluginConfigEntry();
for (Object configEntry : configEntries) {
PluginConfigEntryType entry = (PluginConfigEntryType) configEntry;
nPluginConfigEntry nEntry = new nPluginEntry(entry.getName(), entry.getDescription(), entry.getValue());
webPlugin.add(nEntry);
}
pluginCfg.add(webPlugin);
}
}
niface.setPlugin(pluginCfg);
}
private void createPlugin(nHTTPSInterface niface, RealmNHPSInterfaceEntry iface) {
List plugins = iface.getRealmInterfacePlugin();
if (plugins.size() == 0) {
return;
}
Vector pluginCfg = new Vector();
NirvanaFilePluginEntry file;
NirvanaProxyPassThroughPluginEntry proxy;
NirvanaSOAPPluginEntry soap;
NirvanaXMLPluginEntry xml;
for (Object plugin1 : plugins) {
RealmInterfacePluginEntry plugin = (RealmInterfacePluginEntry) plugin1;
file = plugin.getNirvanaFilePlugin();
proxy = plugin.getNirvanaProxyPassThroughPlugin();
soap = plugin.getNirvanaSOAPPlugin();
xml = plugin.getNirvanaXMLPlugin();
if (file != null) {
nPluginConfig filePlugin = new nPluginConfig(plugin.getName(), plugin.getMountPoint());
List configEntries = file.getPluginConfigEntry();
for (Object configEntry : configEntries) {
PluginConfigEntryType entry = (PluginConfigEntryType) configEntry;
nPluginConfigEntry nEntry = new nPluginEntry(entry.getName(), entry.getDescription(), entry.getValue());
filePlugin.add(nEntry);
}
pluginCfg.add(filePlugin);
} else if (proxy != null) {
nPluginConfig proxyPlugin = new nPluginConfig(plugin.getName(), plugin.getMountPoint());
List configEntries = proxy.getPluginConfigEntry();
for (Object configEntry : configEntries) {
PluginConfigEntryType entry = (PluginConfigEntryType) configEntry;
nPluginConfigEntry nEntry = new nPluginEntry(entry.getName(), entry.getDescription(), entry.getValue());
proxyPlugin.add(nEntry);
}
pluginCfg.add(proxyPlugin);
} else if (xml != null) {
nPluginConfig xmlPlugin = new nPluginConfig(plugin.getName(), plugin.getMountPoint());
List configEntries = xml.getPluginConfigEntry();
for (Object configEntry : configEntries) {
PluginConfigEntryType entry = (PluginConfigEntryType) configEntry;
nPluginConfigEntry nEntry = new nPluginEntry(entry.getName(), entry.getDescription(), entry.getValue());
xmlPlugin.add(nEntry);
}
pluginCfg.add(xmlPlugin);
} else if (soap != null) {
nPluginConfig soapPlugin = new nPluginConfig(plugin.getName(), plugin.getMountPoint());
List configEntries = soap.getPluginConfigEntry();
for (Object configEntry : configEntries) {
PluginConfigEntryType entry = (PluginConfigEntryType) configEntry;
nPluginConfigEntry nEntry = new nPluginEntry(entry.getName(), entry.getDescription(), entry.getValue());
soapPlugin.add(nEntry);
}
pluginCfg.add(soapPlugin);
}
}
niface.setPlugin(pluginCfg);
}
/**
* Prints the usage message for this class
*/
private static void Usage() {
System.out.println("Usage ...\n");
System.out.println("nimportrealmxml file_name\n");
System.out.println(" -all -realmacl -realmcfg -channels -channelfilter= -channelacls -queues -queuefilter= -queueacls -interfaces -datagroups -datagroupfilter=\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: nimportrealmxml test.xml -channels -channelfilter=/perf.+ \n will import only channels whose absolute path starts with /perf");
System.out.println("\nExample 2: nimportrealmxml test.xml -channels -channelfilter=.+test \n will import only channels whose absolute path ends in test");
System.out.println("\nExample 3: nimportrealmxml test.xml -channels -channelfilter=.*test.* \n will import only channels whose absolute path contains test");
System.out.println("\nExample 4: nimportrealmxml test.xml -all -channelfilter=.*test.*,/perf.* \n will import 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);
}
private static class nPluginEntry extends nPluginConfigEntry {
nPluginEntry(String name, String desc, String value) {
super(name, desc, value);
}
}
private static class nPluginConfig extends nPluginConfiguration {
nPluginConfig(String name, String mount) {
super(name, mount);
}
protected void add(nPluginConfigEntry entry) {
super.add(entry);
}
}
private static void report(String line) {
Date dt = new Date();
System.out.println(dt.toString() + " > " + line);
}
private static class Filter {
private final String myFilterValue;
Filter(String filter) {
String[] filters = filter.split(",");
StringBuilder regex = new StringBuilder();
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);
}
}
}