public void AuthenticateClient(ICustomAuthPeer peer, IAuthenticateRequest authRequest, AuthSettings authSettings, SendParameters sendParameters, object state) { //TBD: why are we enqueuing could be done on the peers fiber this.fiber.Enqueue(() => this.OnAuthenticateClient(peer, authRequest, authSettings, sendParameters, state) ); }
public AuthQueueState(ICustomAuthPeer peer, IAuthenticateRequest authenticateRequest, SendParameters sendParameters, object state) { this.Peer = peer; this.AuthenticateRequest = authenticateRequest; this.State = state; this.SendParameters = sendParameters; }
protected override void OnAuthenticateClient( ICustomAuthPeer peer, IAuthenticateRequest authRequest, AuthSettings authSettings, SendParameters sendParameters, object state) { base.OnAuthenticateClient(peer, authRequest, authSettings, sendParameters, state); }
protected virtual void OnAuthenticateClient(ICustomAuthPeer peer, IAuthenticateRequest authRequest, AuthSettings authSettings, SendParameters sendParameters, object state) { try { if (log.IsDebugEnabled) { log.DebugFormat("Authenticating client {0} - custom authentication type: {1}", peer.ConnectionId, authRequest.ClientAuthenticationType); } // when authentication data is provided check if // it is either a byte array or string and convert to byte array // if it's a string value byte[] authData = null; if (authRequest.ClientAuthenticationData != null) { authData = authRequest.ClientAuthenticationData as byte[]; if (authData == null) { var stringData = authRequest.ClientAuthenticationData as string; if (stringData == null) { peer.OnCustomAuthenticationError( ErrorCode.CustomAuthenticationFailed, "Authentication data type not supported", authRequest, sendParameters, state); this.IncrementFailedCustomAuth(); return; } authData = Encoding.UTF8.GetBytes(stringData); } } if (string.IsNullOrEmpty(authRequest.ClientAuthenticationParams) && authData == null && this.isAnonymousAccessAllowed) { // instant callback - treat as anonymous user: if (log.IsDebugEnabled) { log.DebugFormat("Authenticate client: grant access as anonymous user: conId={0}", peer.ConnectionId); } var customResult = new CustomAuthenticationResult { ResultCode = CustomAuthenticationResultCode.Ok }; peer.OnCustomAuthenticationResult(customResult, authRequest, sendParameters, state); return; } // take auth type from auth request (default: custom) var authenticationType = (ClientAuthenticationType)authRequest.ClientAuthenticationType; ClientAuthenticationQueue authQueue; if (this.authenticationServices.TryGetValue(authenticationType, out authQueue) == false) { if (log.IsWarnEnabled) { log.WarnFormat("Authentication type not supported: {0} for AppId={1}/{2}", authenticationType, authRequest.ApplicationId, authRequest.ApplicationVersion); } peer.OnCustomAuthenticationError( ErrorCode.CustomAuthenticationFailed, "Authentication type not supported", authRequest, sendParameters, state); this.IncrementFailedCustomAuth(); return; } var queueState = new AuthQueueState(peer, authRequest, sendParameters, state); authQueue.EnqueueRequest(authRequest.ClientAuthenticationParams, authData, this.AuthQueueResponseCallback, queueState); } catch (Exception ex) { log.Error(ex); } }
protected virtual void OnAuthenticateClient(ICustomAuthPeer peer, IAuthenticateRequest authRequest, AuthSettings authSettings, SendParameters sendParameters, object state) { try { if (log.IsDebugEnabled) { log.DebugFormat("Authenticating client {0} - custom authentication type: {1}", peer.ConnectionId, authRequest.ClientAuthenticationType); } // when authentication data is provided check if // it is either a byte array or string and convert to byte array // if it's a string value byte[] authData = null; if (authRequest.ClientAuthenticationData != null) { authData = authRequest.ClientAuthenticationData as byte[]; if (authData == null) { var stringData = authRequest.ClientAuthenticationData as string; if (stringData == null) { peer.OnCustomAuthenticationError( ErrorCode.CustomAuthenticationFailed, "Authentication data type not supported", authRequest, sendParameters, state); this.IncrementFailedCustomAuth(); return; } authData = Encoding.UTF8.GetBytes(stringData); } } //Test auth custom bool teste = true; if (teste) { string authpar = authRequest.ClientAuthenticationParams; log.Debug("Douglas teste authpar :: CustomAuthHandler.cs :: authpar :: "); object parms = sendParameters; JObject o = (JObject)JToken.FromObject(parms); foreach (var item in o) { log.Debug("Douglas teste sendParameters :: CustomAuthHandler.cs :: item.Key [" + item.Key + "] item.Value[" + item.Value + "]"); } log.Debug("Douglas teste ok :: CustomAuthHandler.cs"); var customResult = new CustomAuthenticationResult { ResultCode = CustomAuthenticationResultCode.Ok }; peer.OnCustomAuthenticationResult(customResult, authRequest, sendParameters, state); return; } else { log.Debug("Douglas teste erro :: CustomAuthHandler.cs"); peer.OnCustomAuthenticationError( ErrorCode.CustomAuthenticationFailed, "Authentication failed.", authRequest, sendParameters, state); this.IncrementFailedCustomAuth(); return; } } catch (Exception ex) { log.Error(ex); } /* Alterado para testes * try * { * if (log.IsDebugEnabled) * { * log.DebugFormat("Authenticating client {0} - custom authentication type: {1}", * peer.ConnectionId, * authRequest.ClientAuthenticationType); * } * * // when authentication data is provided check if * // it is either a byte array or string and convert to byte array * // if it's a string value * byte[] authData = null; * if (authRequest.ClientAuthenticationData != null) * { * authData = authRequest.ClientAuthenticationData as byte[]; * if (authData == null) * { * var stringData = authRequest.ClientAuthenticationData as string; * if (stringData == null) * { * peer.OnCustomAuthenticationError( * ErrorCode.CustomAuthenticationFailed, * "Authentication data type not supported", * authRequest, * sendParameters, * state); * * this.IncrementFailedCustomAuth(); * return; * } * * authData = Encoding.UTF8.GetBytes(stringData); * } * } * * if (string.IsNullOrEmpty(authRequest.ClientAuthenticationParams) && authData == null && this.isAnonymousAccessAllowed) * { * // instant callback - treat as anonymous user: * if (log.IsDebugEnabled) * { * log.DebugFormat("Authenticate client: grant access as anonymous user: conId={0}", peer.ConnectionId); * } * * var customResult = new CustomAuthenticationResult { ResultCode = CustomAuthenticationResultCode.Ok }; * peer.OnCustomAuthenticationResult(customResult, authRequest, sendParameters, state); * return; * } * * // take auth type from auth request (default: custom) * var authenticationType = (ClientAuthenticationType)authRequest.ClientAuthenticationType; * * ClientAuthenticationQueue authQueue; * if (this.authenticationServices.TryGetValue(authenticationType, out authQueue) == false) * { * if (log.IsWarnEnabled) * { * log.WarnFormat("Authentication type not supported: {0} for AppId={1}/{2}", authenticationType, * authRequest.ApplicationId, authRequest.ApplicationVersion); * } * * peer.OnCustomAuthenticationError( * ErrorCode.CustomAuthenticationFailed, * "Authentication type not supported", * authRequest, * sendParameters, * state); * this.IncrementFailedCustomAuth(); * return; * } * * var queueState = new AuthQueueState(peer, authRequest, sendParameters, state); * authQueue.EnqueueRequest(authRequest.ClientAuthenticationParams, authData, this.AuthQueueResponseCallback, queueState); * } * catch (Exception ex) * { * log.Error(ex); * } */ }