コード例 #1
0
        public override void Authenticate(IWampSessionClient client, string signature, AuthenticateExtraData extra)
        {
            IWampClientProxy <TMessage> wampClient = client as IWampClientProxy <TMessage>;

            IWampSessionAuthenticator authenticator = wampClient.Authenticator;

            try
            {
                authenticator.Authenticate(signature, extra);

                if (authenticator.IsAuthenticated)
                {
                    OnClientAuthenticated(wampClient, wampClient.HelloDetails);
                }
                else
                {
                    SendAbort(client,
                              new WampAuthenticationException(new AbortDetails(),
                                                              WampErrors.AuthorizationFailed));
                }
            }
            catch (WampAuthenticationException ex)
            {
                SendAbort(client, ex);
            }
        }
コード例 #2
0
        public IWampSessionAuthenticator GetSessionAuthenticator(WampPendingClientDetails details,
                                                                 IWampSessionAuthenticator transportAuthenticator)
        {
            if (!transportAuthenticator.IsAuthenticated)
            {
                throw new WampAuthenticationException("Cookie wasn't present");
            }

            return(transportAuthenticator);
        }
コード例 #3
0
        public AsyncWebSocketWampConnection
            (ICookieProvider cookieProvider,
            ICookieAuthenticatorFactory cookieAuthenticatorFactory = null)
        {
            if (cookieAuthenticatorFactory != null)
            {
                IWampSessionAuthenticator authenticator =
                    cookieAuthenticatorFactory.CreateAuthenticator(cookieProvider);

                mAuthenticator = authenticator;
            }
        }
コード例 #4
0
        protected override WelcomeDetails GetWelcomeDetails(IWampClientProxy <TMessage> wampClient)
        {
            WelcomeDetails welcomeDetails =
                base.GetWelcomeDetails(wampClient);

            IWampSessionAuthenticator authenticator = wampClient.Authenticator;

            WelcomeDetails result =
                authenticator.WelcomeDetails ?? welcomeDetails;

            result.Roles = welcomeDetails.Roles;
            result.AuthenticationMethod = authenticator.AuthenticationMethod;
            result.AuthenticationId     = authenticator.AuthenticationId;

            return(result);
        }
コード例 #5
0
        public IWampSessionAuthenticator GetSessionAuthenticator
            (WampPendingClientDetails details,
            IWampSessionAuthenticator transportAuthenticator)
        {
            IWampSessionAuthenticator result =
                mSessionAuthenticationFactory.GetSessionAuthenticator
                    (details,
                    transportAuthenticator);

            if (result == null)
            {
                return(null);
            }

            return(new RestrictedSessionAuthenticator(result));
        }
コード例 #6
0
        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));
        }
コード例 #7
0
        public IWampSessionAuthenticator GetSessionAuthenticator(
            WampPendingClientDetails details,
            IWampSessionAuthenticator transportAuthenticator)
        {
            if (details.Realm != _realm)
            {
                throw new WampAuthenticationException(new AbortDetails {
                    Message = "unknown realm"
                });
            }

            if (details.HelloDetails.AuthenticationMethods != null && details.HelloDetails.AuthenticationMethods.Contains(AuthMethods.Ticket))
            {
                return(new TicketSessionAuthenticator(details, _tokenValidator, _sessionCache));
            }

            return(new AnonymousWampSessionAuthenticator());
        }
        public IWampSessionAuthenticator GetSessionAuthenticator(
            WampPendingClientDetails details,
            IWampSessionAuthenticator transportAuthenticator)
        {
            // todo: change hardcoded realm name into realm collection resolving
            if (details.Realm != "prices")
            {
                throw new WampAuthenticationException(new AbortDetails {
                    Message = "unknown realm"
                });
            }

            if (details.HelloDetails.AuthenticationMethods != null && details.HelloDetails.AuthenticationMethods.Contains(AuthMethods.Ticket))
            {
                return(new TicketSessionAuthenticator(details, _tokenValidator, _sessionCache));
            }

            return(new AnonymousWampSessionAuthenticator());
        }
コード例 #9
0
        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);
            }
        }
コード例 #10
0
 public IWampSessionAuthenticator GetSessionAuthenticator(WampPendingClientDetails details,
                                                          IWampSessionAuthenticator transportAuthenticator)
 {
     return(mGetSessionAuthenticator(details, transportAuthenticator));
 }
コード例 #11
0
 public IWampSessionAuthenticator GetSessionAuthenticator(WampPendingClientDetails details, IWampSessionAuthenticator transportAuthenticator)
 {
     if (details.HelloDetails.AuthenticationMethods.Contains(AuthMethods.Ticket))
     {
         return(new TicketSessionAuthenticator(details, _apiKeyValidator, _sessionRepository));
     }
     return(new AnonymousWampSessionAuthenticator());
 }
コード例 #12
0
 public RestrictedAuthorizer(IWampSessionAuthenticator authenticator)
 {
     mAuthenticator = authenticator;
 }
コード例 #13
0
        public IWampSessionAuthenticator GetSessionAuthenticator(WampPendingClientDetails details, IWampSessionAuthenticator transportAuthenticator)
        {
            HelloDetails helloDetails = details.HelloDetails;

            if (helloDetails.AuthenticationMethods?.Contains("ticket") != true)
            {
                throw new WampAuthenticationException("supports only 'ticket' authentication");
            }

            string user = helloDetails.AuthenticationId;

            if (user == null ||
                !_mUserToTicket.TryGetValue(user, out string ticket))
            {
                throw new WampAuthenticationException($"no user with authid '{user}' in user database");
            }

            return(new TicketSessionAuthenticator(user, ticket, new BackendStaticAuthorizer(new string[0])));
        }
コード例 #14
0
 public IWampSessionAuthenticator GetSessionAuthenticator
     (WampPendingClientDetails details,
     IWampSessionAuthenticator transportAuthenticator)
 {
     return(new AnonymousWampSessionAuthenticator());
 }
コード例 #15
0
 public RestrictedSessionAuthenticator(IWampSessionAuthenticator authenticator)
 {
     mAuthenticator = authenticator;
     mAuthorizer    = new RestrictedAuthorizer(mAuthenticator);
 }