/* 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. */ using System; using System.Collections.Generic; namespace com.pcbsys.nirvana.nAdminAPI.apps { using com.pcbsys.nirvana.nAdminAPI; using nSessionAttributes = com.pcbsys.nirvana.client.nSessionAttributes; /// /// This application can be used to remove the ACL from a service /// public class removeServiceACL { /// /// Private variables used in this application /// private string realm = null; private nSessionAttributes attr = null; private string serviceName = null; private nRealmNode node = null; /// /// Construct and instance of this class using the command line arguments passed /// when it is executed. /// public removeServiceACL(string[] args) { //Process command line arguments getOptions(args); try { Console.WriteLine("Connecting to " + realm); // construct the session attributes from the realm attr = new nSessionAttributes(realm); // get the root realm node from the realm admin node = new nRealmNode(attr); if (!node.isAuthorised()) { Console.WriteLine("User not authorised on this node " + realm); return; } // wait for the entire node namespace to be constructed if // the operation is recursive Console.Write("waiting for namepsace construction..... "); node.waitForEntireNameSpace(); Console.WriteLine("finished"); searchNode(node); node.close(); } catch (Exception e) { Console.WriteLine(e.Message); } } /// /// recursively search through the realm node looking for service nodes /// public virtual void removeService(nRealmNode p_node, nServiceNode p_svc) { try { // remove the acl p_svc.removeACLEntries(p_svc.getACLs()); Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); Console.WriteLine("Remove ACL for " + p_svc.Name + " in realm " + p_node.Name); Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); } catch (Exception e) { Console.WriteLine(e.Message); } } /// /// search the enumeration of chil nodes for other realms and channels /// private void searchNodes(nRealmNode p_node, System.Collections.IEnumerator enum1) { while (enum1.MoveNext()) { object obj = enum1.Current; if (obj is nServiceNode) { nServiceNode svc = (nServiceNode)obj; string service = svc.Name; Console.WriteLine("Found service " + service); if (service.Equals(serviceName)) { removeService(p_node, svc); return; } } else if (obj is nRealmNode) { searchNode((nRealmNode)obj); } else if (obj is nContainer) { nContainer cont = (nContainer)obj; searchNodes(p_node, cont.getNodes()); } } } /// /// Search the children of the realm passed as a paremeter /// private void searchNode(nRealmNode p_node) { try { searchNodes(p_node, p_node.getNodes()); } catch (Exception ex) { Console.WriteLine(ex.Message); } } /// /// Set the program variables and permissions flags based on command line args /// public virtual void getOptions(string[] args) { if (args == null || args.Length == 0) { Usage(); System.Environment.Exit(1); } realm = args[0]; if (realm == null) { Usage(); System.Environment.Exit(1); } serviceName = args[1]; if (serviceName == null) { Usage(); System.Environment.Exit(1); } } /// /// Run this as a command line program passing the command line args. /// /// Or construct one of these classes from another class ensuring you have added : /// /// RNAME /// NAME /// HOST /// CHANNEL /// /// as system properties, and pass in a list of permissions in the constructor /// /// static void Main(string[] args) { removeServiceACL setAcl = new removeServiceACL(args); System.Environment.Exit(0); } /// /// Prints the usage message for this class /// private static void Usage() { Console.WriteLine("Usage ...\n"); Console.WriteLine("nremoveserviceacl \n"); Console.WriteLine(" \n"); Console.WriteLine(" - the rname of the server to connect to"); Console.WriteLine(" - Service name parameter for the service to remove the ACL from"); Console.WriteLine("\n[Optional Arguments] \n"); } } }