public IWampSessionAuthenticator GetSessionAuthenticator
            (WampPendingClientDetails details,
            IWampSessionAuthenticator transportAuthenticator)
        {
            HelloDetails helloDetails = details.HelloDetails;

            if ((helloDetails.AuthenticationMethods == null) ||
                !helloDetails.AuthenticationMethods.Contains(WampCra))
            {
                throw new WampAuthenticationException("supports only 'wampcra' authentication");
            }

            WampCraUser user =
                mUserDb.GetUserById(helloDetails.AuthenticationId);

            if (user == null)
            {
                throw new WampAuthenticationException
                          (string.Format("no user with authid '{0}' in user database",
                                         helloDetails.AuthenticationId));
            }

            user.AuthenticationId = user.AuthenticationId ??
                                    helloDetails.AuthenticationId;

            string authenticationRole = user.AuthenticationRole;

            WampAuthenticationRole role =
                mAuthenticationProvider.GetRoleByName(details.Realm, authenticationRole);

            if (role == null)
            {
                throw new WampAuthenticationException
                          (message: string.Format("authentication failed - realm '{0}' has no role '{1}'",
                                                  details.Realm,
                                                  authenticationRole),
                          reason: WampErrors.NoSuchRole);
            }

            role.AuthenticationRole = role.AuthenticationRole ??
                                      authenticationRole;

            role.AuthenticationProvider = role.AuthenticationProvider ??
                                          mAuthenticationProvider.ProviderName;

            return(new WampCraUserDbSessionAuthenticator(user, role, details.SessionId));
        }
        public override void Hello(IWampSessionClient client, string realm, HelloDetails details)
        {
            IWampClientProxy <TMessage> wampClient = GetWampClient(client, realm, details);

            WampPendingClientDetails clientDetails = new WampPendingClientDetails()
            {
                HelloDetails = details,
                Realm        = realm,
                SessionId    = wampClient.Session
            };

            try
            {
                IWampSessionAuthenticator authenticator =
                    mSessionAuthenticatorFactory.GetSessionAuthenticator
                        (clientDetails,
                        wampClient.Authenticator);

                if (authenticator == null)
                {
                    throw new Exception("Get null authenticator.");
                }

                wampClient.Authenticator = authenticator;

                bool authenticated = authenticator.IsAuthenticated;

                if (authenticated)
                {
                    OnClientAuthenticated(wampClient, details);
                }
                else
                {
                    wampClient.Challenge(authenticator.AuthenticationMethod,
                                         authenticator.ChallengeDetails);
                }
            }
            catch (WampAuthenticationException ex)
            {
                SendAbort(client, ex);
            }
        }