/* * The Security QuickStart Example. * * This example takes the following steps: * * 1. Sets the client security properties. * 2. Connect to a GemFire Distributed System. * 3. Put an Entry ( for which it has valid credentials ). * 4. Fail to Get an Entry ( for which user doesn't have permission ). * 5. Close the Cache. * 6. Disconnect from the Distributed System. * */ // Include the GemFire library. #include // Use the "gemfire" namespace. using namespace gemfire; // The Security QuickStart example. int main(int argc, char ** argv) { try { // Create client's Authentication Intializer and Credentials using api ( Same can be set to gfcpp.properties & comment following code ). PropertiesPtr secProp = Properties::create(); secProp->insert("security-client-auth-factory", "createPKCSAuthInitInstance"); secProp->insert("security-client-auth-library", "securityImpl"); secProp->insert("security-keystorepath", "keystore/gemfire6.keystore"); secProp->insert("security-alias", "gemfire6"); secProp->insert("security-keystorepass", "gemfire"); // Connect to the GemFire Distributed System using the settings from the gfcpp.properties file by default, programatically // overriding secProp properties. DistributedSystemPtr dSysPtr = DistributedSystem::connect("ExampleDistributedSystem", secProp); LOGINFO("Connected to the GemFire Distributed System"); // Create a GemFire Cache with the "clientSecurity.xml" Cache XML file. CachePtr cachePtr = CacheFactory::create("ExampleCache", dSysPtr, "XMLs/clientSecurity.xml"); LOGINFO("Created the GemFire Cache"); // Get the example Region from the Cache which is declared in the Cache XML file. RegionPtr regionPtr = cachePtr->getRegion("/root/exampleRegion"); LOGINFO("Obtained the Region from the Cache"); // Put an Entry (Key and Value pair) into the Region using the direct/shortcut method. regionPtr->put("Key1", "Value1"); LOGINFO("Entry created in the Region"); try { // Get Entries back out of the Region. CacheablePtr result1Ptr = regionPtr->get("Key1"); //collect NotAuthorized exception } catch (const gemfire::NotAuthorizedException& expected) { LOGINFO("Got expected authorization failure while obtaining the Entry: %s", expected.getMessage()); } // Close the GemFire Cache. cachePtr->close(); LOGINFO("Closed the GemFire Cache"); // Disconnect from the GemFire Distributed System. dSysPtr->disconnect(); LOGINFO("Disconnected from the GemFire Distributed System"); } // An exception should not occur catch(const Exception & gemfireExcp) { LOGERROR("Security GemFire Exception: %s", gemfireExcp.getMessage()); } }