/* * * Copyright (c) 1999 - 2011 my-Channels Ltd * Copyright (c) 2012 - 2017 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors. * * Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG. * */ #include "nSampleApp.h" #include "nRealmNode.h" #include "nLeafNode.h" #include "nChannelACLEntry.h" #include "nSessionAttributes.h" #include "nAdminIllegalArgumentException.h" #include #include namespace com { namespace pcbsys { namespace nirvana { namespace nAdminAPI { namespace apps { using namespace com::pcbsys::nirvana::client; using namespace com::pcbsys::nirvana::nAdminAPI; class delnodeacl { /// /// This application can be used to remove subject from a channel or a queue /// private: std::string m_realm; std::string m_name; std::string m_host; nSessionAttributes *m_pAttr; std::string m_channelName; nRealmNode *m_pNode; public: /// /// * Consruct an instance of this class using the command line arguments passed /// * when it is executed. /// delnodeacl(int argc, char** argv) : m_pAttr(NULL), m_pNode(NULL) { try { getOptions(argc, argv); printf("Connecting to %s\n", m_realm.c_str()); // construct the session attributes from the realm m_pAttr = new nSessionAttributes(m_realm); // get the root realm node from the realm admin m_pNode = new nRealmNode(m_pAttr); if (!m_pNode->isAuthorised()) { printf("User not authorised on this node %s\n", m_realm.c_str()); return; } printf("waiting for namepsace construction....."); m_pNode->waitForEntireNameSpace(); printf("finished\n"); nLeafNode *node = (nLeafNode*) m_pNode->findNode(m_channelName); if (node != NULL) { node->removeACLEntry(createNewACLEntry(m_name, m_host)); printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); printf("Removed ACL for %s in realm %s\n", m_name.c_str(), node->getName().c_str()); printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); } else { printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); printf("Failed to find node %s in realm %s\n", m_name.c_str(), node->getName().c_str()); printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); } m_pNode->close(); } catch (Exception e) { printf("%s\n", e.message().c_str()); } } /// /// * Create a new acl entry and set the permissions based on the permissions flags /// virtual nChannelACLEntry* createNewACLEntry(const std::string& name, const std::string& host) { nChannelACLEntry *pAclEntry = NULL; try { pAclEntry = new nChannelACLEntry(name, host); } catch (nAdminIllegalArgumentException e) { printf("%s\n", e.message().c_str()); } return pAclEntry; } /// /// * If you construct an instance of this class from another class, you can set the name /// * and host for the subject. /// virtual void setSubject(const std::string& name, const std::string& host) { m_name = name; m_host = host; } virtual void getOptions(int argc, char** argv) { if (argv == NULL || argc <5) { Usage(); exit(1); } m_realm = argv[1]; m_name = argv[2]; m_host = argv[3]; m_channelName = argv[4]; } private: /// /// * Prints the usage message for this class /// static void Usage() { printf("Usage ...\n\n"); printf("ndelnodeacl \n\n"); printf(" \n\n"); printf(" - the rname of the server to connect to\n"); printf(" - User name\n"); printf(" - Host name\n"); printf(" - Channel / Queue name to remove the entry from\n"); } }; } } } } } using namespace com::pcbsys::nirvana::nAdminAPI::apps; int main (int argc, char** argv) { delnodeacl (argc, argv); return 0; }