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); } }
/// <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); } }
/// <summary> /// NAASAccountAuthenticationProvider /// </summary> /// <param name="endpointUrl"></param> /// <param name="runtimeCredentials"></param> public NAASManager(string testUrl, string prodUrl, bool isProduction, string defaultRequestIp, AuthenticationCredentials naasRuntimeCredentials, AuthenticationCredentials usermgrRuntimeCredentials) { if (string.IsNullOrEmpty(testUrl)) { throw new ArgumentNullException("testUrl"); } if (string.IsNullOrEmpty(prodUrl)) { throw new ArgumentNullException("prodUrl"); } if (string.IsNullOrEmpty(defaultRequestIp)) { throw new ArgumentNullException("defaultRequestIp"); } if (!testUrl.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase)) { throw new ArgumentException("Invalid protocol. Must be HTTPS: " + testUrl); } if (!prodUrl.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase)) { throw new ArgumentException("Invalid protocol. Must be HTTPS: " + prodUrl); } if (naasRuntimeCredentials == null || string.IsNullOrEmpty(naasRuntimeCredentials.UserName) || string.IsNullOrEmpty(naasRuntimeCredentials.Password)) { throw new ArgumentException("Null naasRuntimeCredentials. Username and Password are required"); } if (string.IsNullOrEmpty(naasRuntimeCredentials.Domain)) { _naasRuntimeCredentialDomain = NAAS_CLIENT.DomainTypeCode.@default; } else { _naasRuntimeCredentialDomain = (NAAS_CLIENT.DomainTypeCode) Enum.Parse(typeof(NAAS_CLIENT.DomainTypeCode), naasRuntimeCredentials.Domain, true); } if (usermgrRuntimeCredentials == null || string.IsNullOrEmpty(usermgrRuntimeCredentials.UserName) || string.IsNullOrEmpty(usermgrRuntimeCredentials.Password)) { throw new ArgumentException("Null usermgrRuntimeCredentials. Username and Password are required"); } if (string.IsNullOrEmpty(usermgrRuntimeCredentials.Domain)) { _usermgrRuntimeCredentialDomain = NAAS_USRMGR.DomainTypeCode.@default; } else { _usermgrRuntimeCredentialDomain = (NAAS_USRMGR.DomainTypeCode) Enum.Parse(typeof(NAAS_USRMGR.DomainTypeCode), usermgrRuntimeCredentials.Domain, true); } _testNaasClient = new Windsor.Commons.NAASClient.NAASClient(testUrl); _prodNaasClient = new Windsor.Commons.NAASClient.NAASClient(prodUrl); _naasClient = isProduction ? _prodNaasClient : _testNaasClient; _naasRuntimeCredential = naasRuntimeCredentials; _usermgrRuntimeCredential = usermgrRuntimeCredentials; _defaultRequestIp = defaultRequestIp; }