Universal Messaging 10.3 | Developer Guide | Enterprise APIs | Enterprise Developer's Guide for C# | Examples | Administration API | Set Container ACL
 
Set Container ACL
Set the ACL of a container to that currently applied to a specified channel.
Usage
nsetcontaineracl <channel name> <container name>

<Required Arguments>

<rname> - name of the realm to connect to.
<channel name> - channel name parameter used to obtaine the ACL to set the container
nodes to" );
<container name> - Container name parameter for the container to set the ACL to" );


Note: -? provides help on environment variables
Application Source Code
/**
*
* ----------------------------------------------------------------------------------
*
* PCB Systems Limited License Version 1.1
* Copyright PCB Systems Limited. All rights reserved
*
* In the event that you should download or otherwise use this software
* ( the "Software" ) you hereby acknowledge and agree that:
*
* 1. The Software is the property of PCB Systems Limited: Title, Copyright and all
* other proprietary rights, interest and benefit in and to the Software is and
* shall be owned by PCB Systems Limited;
*
* 2. You will not make copies of the Software whatsoever other than, if you should
* so wish, a single copy for archival purposes only;
*
* 3. You will not modify, reverse assemble, decompile, reverse engineer or otherwise
* translate the Software;
*
* 4. You will not redistribute, copy, forward electronically or circulate the Software
* to any person for any purpose whatsoever without the prior written consent of
* PCB Systems Limited;
*
* 5. You will not charge for, market or provide any managed service or product that
* is based upon or includes the Software or any variant of it; and
*
* 6. You will not use the Software for any purpose apart from your own personal,
* noncommercial and lawful use;
*
* You hereby agree that the software is used by you on an "as is" basis, without
* warranty of any kind. PCB Systems Limited hereby expressly disclaim all warranties
* and conditions, either expressed or implied, including but not limited to any
* implied warranties or conditions or merchantability and fitness for a particular
* purpose.
*
* You agree that you are solely responsible for determining the appropriateness of
* using the Software and assume all risks associated with it including but not
* limited to the risks of program errors, damage to or loss of of data, programs or
* equipment and unavailability or interruption of operations.
*
* PCB Systems Limited will not be liable for any direct damages or for any, special,
* incidental or indirect damages or for any economic consequential damages ( including
* lost profits or savings ), or any damage howsoever arising.
*/

namespace com.pcbsys.nirvana.nAdminAPI
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Collections;
using com.pcbsys.nirvana.client;
class setContainerACL
{
/**
* Private variables used in this application
*/
private String name = null;
private String host = null;
private nSessionAttributes attr = null;
private String containerName = null;
private String channelName = null;
private nRealmNode node = null;
private nLeafNode leaf = null;
private nACL acl = null;
private String rname = null;

/**
* Consruct and instance of this class using the command line arguments passed
* when it is executed.
*/
public setContainerACL(String[] args) {

//Process command line arguments
processArgs(args);

try {
Console.WriteLine( "Connecting to " + rname );
// construct the session attributes from the realm
attr = new nSessionAttributes( rname );
// get the root realm node from the realm admin
node = new nRealmNode(attr);
if(!node.isAuthorised()){
Console.WriteLine("User not authorised on this node "+attr);
return;
}

// wait for the entire node namespace to be constructed
Console.WriteLine( "waiting for namepsace construction..... " );
node.waitForEntireNameSpace();
Console.WriteLine( "finished" );
leaf = (nLeafNode)node.findNode(channelName);
if (leaf != null) {
acl = leaf.getACLs();
searchNode(node);
} else {
Console.WriteLine("Cannot find leaf node "+channelName);
}
node.close();
} catch (Exception e) {
Console.WriteLine(e.StackTrace);
}
}

/**
* recursively search through the realm node looking for channel nodes
*/
public void setContainer(nContainer p_node) {
try {
// set the acl for the container nodes
Console.WriteLine( "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" );
Console.WriteLine( "Applying acl to container node " + p_node.getAbsolutePath() );
// set the acl on the container
p_node.setACL(acl);
Console.WriteLine( "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" );
} catch (Exception e) {
Console.WriteLine(e.StackTrace);
}
}

/**
* search the enumeration of child nodes for other realms and containers
*/
private void searchNodes( nContainer p_node, System.Collections.IEnumerator enum1 ) {
while ( enum1.MoveNext() ) {
Object obj = enum1.Current;
if ( obj is nRealmNode ) {
searchNode( (nRealmNode)obj );
} else if ( obj is nContainer ) {
nContainer cont = (nContainer)obj;
String fullyQualifiedName = cont.getAbsolutePath();
if (fullyQualifiedName.Equals(containerName)) {
Console.WriteLine("Found container "+fullyQualifiedName);
setContainer( cont );
} else {
searchNodes(cont, 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.StackTrace);
}
}

/**
* If you construct an instance of this class from another class, you can set the name
* and host for the subject.
*/
public void setSubject(String p_name, String p_host) {
name = p_name;
host = p_host;
}

/**
* Set the program variables and permissions flags based on command line args
*/

private void processArgs(String[] args){
if (args.Length != 3) {
Usage();
Environment.Exit(1);
}
switch (args.Length){
case 3:
channelName = args[2];
goto case 2;
case 2:
containerName = args[1];
goto case 1;
case 1:
rname = args[0];
break;
}
}

/**
* 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
* CHANNEL
* CONTAINER
*
* as system properties, and pass in a list of permissions in the constructor
*
*/
public static void Main( String[] args ) {

setContainerACL setAcl = new setContainerACL(args);
Environment.Exit(0);
}

/**
* Prints the usage message for this class
*/
private static void Usage() {

Console.WriteLine( "Usage ...\n" );
Console.WriteLine("nsetcontaineracl <channel name> <container name> \n");
Console.WriteLine(
"<Required Arguments> \n");
Console.WriteLine(
"<rname> - name of the realm to connect to.");
Console.WriteLine("<channel name> - channel name parameter used to obtain " );
Console.WriteLine(" the ACL to set the container nodes to" );
Console.WriteLine("<container name> - Container name parameter for the " );
Console.WriteLine(" container to set the ACL to" );
Console.WriteLine(
"\n\nNote: -? provides help on environment variables \n");
}

private static void UsageEnv() {
Console.WriteLine(
"\n\n(Environment Variables) \n");

Console.WriteLine(
"(RNAME) - One or more RNAME entries in the form protocol://host:port" );
Console.WriteLine(
" protocol - Can be one of nsp, nhp, nsps, or nhps, where:" );
Console.WriteLine(
" nsp - Specifies Universal Messaging Socket Protocol (nsp)" );
Console.WriteLine(
" nhp - Specifies Universal Messaging HTTP Protocol (nhp)" );
Console.WriteLine(" nsps - Specifies Universal Messaging Socket Protocol " );
Console.WriteLine(" Secure (nsps), i.e. using SSL/TLS" );
Console.WriteLine(" nhps - Specifies Universal Messaging HTTP Protocol " );
Console.WriteLine(" Secure (nhps), i.e. using SSL/TLS" );
Console.WriteLine(
" port - The port number of the server" );
Console.WriteLine("\nHint: - For multiple RNAME entries, use comma separated " );
Console.WriteLine(" values which will be attempted in connection " );
Console.WriteLine(" weight order\n" );

Console.WriteLine("(LOGLEVEL) - This determines how much information the nirvana " );
Console.WriteLine(" api will output 0 = verbose 7 = quiet\n" );

Console.WriteLine("(CKEYSTORE) - If using SSL, the location of the keystore ");
Console.WriteLine(" containing the client cert\n");
Console.WriteLine("(CKEYSTOREPASSWD) - If using SSL, the password for the");
Console.WriteLine(" keystore containing the client cert\n");
Console.WriteLine(
"(CAKEYSTORE) - If using SSL, the location of the ca truststore\n");
Console.WriteLine(
"(CAKEYSTOREPASSWD) - If using SSL, the password for the ca truststore\n");

Console.WriteLine(
"(HPROXY) - HTTP Proxy details in the form proxyhost:proxyport, where:" );
Console.WriteLine(
" proxyhost - The HTTP proxy host" );
Console.WriteLine(
" proxyport - The HTTP proxy port\n" );
Console.WriteLine(
"(HAUTH) - HTTP Proxy authentication details in the form user:pass, where:" );
Console.WriteLine(
" user - The HTTP proxy authentication username" );
Console.WriteLine(
" pass - The HTTP proxy authentication password\n" );
Environment.Exit(1);
}
}
}