Deveel.Data.Protocol.ServerConnector.Authenticate C# (CSharp) Method

Authenticate() protected method

protected Authenticate ( string defaultSchema, string username, string password ) : bool
defaultSchema string
username string
password string
return bool
        protected virtual bool Authenticate(string defaultSchema, string username, string password)
        {
            if (CurrentState == ConnectorState.Authenticated)
                throw new InvalidOperationException("Already authenticated.");

            // TODO: get the default schema from server configuration
            if (String.IsNullOrEmpty(defaultSchema))
                defaultSchema = "SA";

            // TODO: Log a debug information

            // TODO: Log an information about the logging user...

            try {
                if (!Database.Authenticate(username, password))
                    return false;

                if (!OnAuthenticated(username))
                    return false;

                User = username;

                // TODO: Accept more connection settings and store them here...
                Metadata = new Dictionary<string, object> {
                    { "IgnoreIdentifiersCase", ignoreIdentifiersCase },
                    { "ParameterStyle", parameterStyle },
                    { "DefaultSchema", defaultSchema }
                };

                ChangeState(ConnectorState.Authenticated);

                return true;
            } catch (Exception) {
                // TODO: throw server error
                throw;
            }
        }

Usage Example

Example #1
0
            private IMessageEnvelope ProcessAuthenticate(IDictionary <string, object> metadata, AuthenticateRequest request)
            {
                try {
                    if (!connector.Authenticate(request.DefaultSchema, request.UserName, request.Password))
                    {
                        var response = connector.CreateEnvelope(metadata, new AuthenticateResponse(false, -1));
                        // TODO: make the specialized exception ...
                        response.SetError(new Exception("Unable to authenticate."));
                        return(response);
                    }

                    connector.ChangeState(ConnectorState.Authenticated);

                    // TODO: Get the UNIX epoch here?
                    return(connector.CreateEnvelope(metadata, new AuthenticateResponse(true, DateTime.UtcNow.Ticks)));
                } catch (Exception ex) {
                    return(CreateErrorResponse(metadata, ex));
                }
            }