Пример #1
0
        public static Exception AuthenticateUser(string username, string password, bool isProduction)
        {
            try
            {
                using (NAASClient client = new NAASClient(isProduction))
                {
                    client.Timeout = 30000;
                    CentralAuth req = new CentralAuth();
                    req.authenticationMethod = "password";
                    req.clientIp             = string.Empty;
                    req.credential           = password;
                    req.domain      = DomainTypeCode.@default;
                    req.resourceURI = string.Empty;
                    req.userId      = username;

                    CentralAuthResponse resp = client.CentralAuth(req);

                    string token = resp.@return;

                    if (string.IsNullOrEmpty(token))
                    {
                        throw new ArgumentException("NAAS returned an empty authentication token");
                    }

                    return(null);
                }
            }
            catch (Exception e)
            {
                return(e);
            }
        }
Пример #2
0
        /// <summary>
        /// Authenticate user NAAS credentials
        /// </summary>
        /// <param name="username">NAAS Username</param>
        /// <param name="password">NAAS Password</param>
        /// <param name="clientHostIp">IP address of the orginal requestor</param>
        /// <param name="authenticationMethod">one of the authentication methods supported by naas [password]</param>
        /// <returns></returns>
        protected string AuthenticateUser(
            string username,
            string password,
            string clientHostIP,
            string authenticationMethod,
            Windsor.Commons.NAASClient.NAASClient naasClient)
        {
            try
            {
                NAAS_CLIENT.CentralAuth req = new NAAS_CLIENT.CentralAuth();
                req.authenticationMethod = authenticationMethod;
                req.clientIp             = clientHostIP;
                req.credential           = password;
                //Once we see this being used we can refactor. For now just use the default.
                req.domain      = DEFAULT_DOMAIN_TYPE;
                req.resourceURI = string.Empty;
                req.userId      = username;

                NAAS_CLIENT.CentralAuthResponse resp = naasClient.CentralAuth(req);

                string token = resp.@return;

                if (string.IsNullOrEmpty(token))
                {
                    throw new ApplicationException("NAAS Returned an empty token");
                }

                return(token);
            }
            catch (SoapException soapException)
            {
#if DEBUG
                if (BypassNaasAuthenticateFailures)
                {
                    return(_bypassNaasUserName);
                }
#endif // DEBUG
                LOG.Error("NAAS authentication error", soapException);
                throw new InvalidCredentialException("NAAS authentication error: " + soapException.Message);
            }
            catch (Exception naasException)
            {
#if DEBUG
                if (BypassNaasAuthenticateFailures)
                {
                    return(_bypassNaasUserName);
                }
#endif // DEBUG
                LOG.Error("NAAS connection error", naasException);
                throw new AuthenticationException("NAAS connection error: " + naasException.Message);
            }
        }