This is an automated email from the ASF dual-hosted git repository. igodwin pushed a commit to branch release/1.8 in repository https://gitbox.apache.org/repos/asf/geode-native.git
commit 5f876af4fec8ea9eec4bf8449167de2a30d8ac0b Author: Dave Barnes <dbar...@pivotal.io> AuthorDate: Mon Nov 19 17:30:02 2018 -0800 GEODE-6043: Improve User Guide Authentication example --- .../security/authentication.html.md.erb | 122 ++++----------------- 1 file changed, 20 insertions(+), 102 deletions(-) diff --git a/docs/geode-native-docs/security/authentication.html.md.erb b/docs/geode-native-docs/security/authentication.html.md.erb index faca71b..d12c4bc 100644 --- a/docs/geode-native-docs/security/authentication.html.md.erb +++ b/docs/geode-native-docs/security/authentication.html.md.erb @@ -19,13 +19,11 @@ See the License for the specific language governing permissions and limitations under the License. --> -A client is authenticated when it connects, with valid credentials, to a <%=vars.product_name%> cache server that is configured with the client `Authenticator` callback. +A client is authenticated when it connects with valid credentials to a <%=vars.product_name%> cache server that is configured with the client `Authenticator` callback. +For details on the server's role in authentication and what it expects from the client, see [Implementing Authentication](geodeman/managing/security/implementing_authentication.html) in the *<%=vars.product_name%> User Guide*. Examples of various implementations can be found in the Native Client source distribution's `../templates/security` directory. -An `AuthenticationRequiredException` is thrown when the server is configured with security and the -client does not present its credentials while attempting to connect. - In your application, authentication credentials must be set when creating the cache. In practice, this means setting the authentication credentials when you create the CacheFactory. @@ -36,66 +34,31 @@ In this C# authentication example, credentials are implemented in the GetCredent ```cs -using System; -using Apache.Geode.Client; - -namespace Apache.Geode.Examples.AuthInitialize -{ - class Program + class ExampleAuthInitialize : IAuthInitialize { - class ExampleAuthInitialize : IAuthInitialize + public ExampleAuthInitialize() { - public ExampleAuthInitialize() - { - // TODO initialize your resources here - Console.Out.WriteLine("ExampleAuthInitialize::ExampleAuthInitialize called"); - } - - public void Close() - { - // TODO close your resources here - Console.Out.WriteLine("ExampleAuthInitialize::Close called"); - } - - public Properties<string, object> GetCredentials(Properties<string, string> props, string server) - { - // TODO get your username and password - Console.Out.WriteLine("ExampleAuthInitialize::GetCredentials called"); - - var credentials = new Properties<string, object>(); - credentials.Insert("username", "john"); - credentials.Insert("password", "secret"); - return credentials; - } - } - - static void Main(string[] args) - { - var cacheFactory = new CacheFactory() - .Set("log-level", "none") - .SetAuthInitialize(new ExampleAuthInitialize()); - - var cache = cacheFactory.Create(); - var poolFactory = cache.GetPoolFactory() - .AddLocator("localhost", 10334); - poolFactory.Create("pool"); - var regionFactory = cache.CreateRegionFactory(RegionShortcut.PROXY) - .SetPoolName("pool"); - var region = regionFactory.Create<string, string>("region"); - - region["a"] = "1"; - region["b"] = "2"; + // TODO initialize your resources here + Console.Out.WriteLine("ExampleAuthInitialize::ExampleAuthInitialize called"); + } - var a = region["a"]; - var b = region["b"]; + public void Close() + { + // TODO close your resources here + Console.Out.WriteLine("ExampleAuthInitialize::Close called"); + } - Console.Out.WriteLine("a = " + a); - Console.Out.WriteLine("b = " + b); + public Properties<string, object> GetCredentials(Properties<string, string> props, string server) + { + // TODO get your username and password + Console.Out.WriteLine("ExampleAuthInitialize::GetCredentials called"); - cache.Close(); + var credentials = new Properties<string, object>(); + credentials.Insert("security-username", "root"); + credentials.Insert("security-password", "root"); + return credentials; } } -} ``` @@ -104,19 +67,6 @@ namespace Apache.Geode.Examples.AuthInitialize In this C++ authentication example, credentials are implemented in the getCredentials member function of the AuthInitialize abstract class. ```cpp -#include <iostream> - -#include <geode/CacheFactory.hpp> -#include <geode/PoolManager.hpp> -#include <geode/RegionFactory.hpp> -#include <geode/RegionShortcut.hpp> -#include <geode/AuthInitialize.hpp> - -using namespace apache::geode::client; - -constexpr auto SECURITY_USERNAME = "security-username"; -constexpr auto SECURITY_PASSWORD = "security-password"; - class UserPasswordAuthInit : public AuthInitialize { public: UserPasswordAuthInit() = default; @@ -147,36 +97,4 @@ public: void close() override { return; } }; -int main(int argc, char** argv) { - auto config = Properties::create(); - config->insert(SECURITY_USERNAME, "root"); - config->insert(SECURITY_PASSWORD, "root"); - - auto cacheFactory = CacheFactory(config); - auto authInitialize = std::make_shared<UserPasswordAuthInit>(); - cacheFactory.set("log-level", "none"); - cacheFactory.setAuthInitialize(authInitialize); - - auto cache = cacheFactory.create(); - auto poolFactory = cache.getPoolManager().createFactory(); - - poolFactory.addLocator("localhost", 10334); - auto pool = poolFactory.create("pool"); - auto regionFactory = cache.createRegionFactory(RegionShortcut::PROXY); - auto region = regionFactory.setPoolName("pool").create("example_userinfo"); - - region->put("rtimmons", "Robert Timmons"); - region->put("scharles", "Sylvia Charles"); - - auto user1 = region->get("rtimmons"); - auto user2 = region->get("scharles"); - std::cout << " rtimmons = " - << std::dynamic_pointer_cast<CacheableString>(user1)->value() - << std::endl; - std::cout << " scharles = " - << std::dynamic_pointer_cast<CacheableString>(user2)->value() - << std::endl; - - cache.close(); -} ```