首页 \ 问答 \ 在SaaS环境中使用客户端密钥的最佳做法(Best practice to make use of Client Secret Key in SaaS environment)

在SaaS环境中使用客户端密钥的最佳做法(Best practice to make use of Client Secret Key in SaaS environment)

当全新客户端获得注册并存储在数据库列(对其有唯一约束 )时, Asp.NET Web API会生成一个秘密密钥使用32个字符长的对称算法 )。 在整个过程中,客户端必须在授权标头中提供密钥才能访问自己的资源( 多租户SaaS环境 )。 目前不需要访问令牌。 期望客户端密钥的主要原因是从数据库中过滤并提供适当的数据!

我认为在WHERE子句中使用ClientSecretKey从SQL表中获取客户端数据不会对性能友好,例如:

SELECT Multiple_Columns from ClientTable WHERE ClientSecretKey='X3i1aBer'

理想情况下,我宁愿使用在表中定义为IDENTITY列的ClientId来获取客户端记录。

问题:

  1. 如何最好地设计一个唯一的客户端密钥,在对数据库执行查询以获取特定的客户端记录时,该密钥应该绝对性能友好?
  2. 我的想法或设计中是否有缺陷?

任何想法都会非常感谢。

谢谢!


The Asp.NET Web API generates a Secret Key (using Symmetric Algorithm 32 characters long) when a brand new client gets registered which is stored in a database column (has unique constraint on it). Throughout, the API usage a client must provide the Secret Key in an Authorization header in order to access the it's own resources (Multi-Tenant SaaS environment). There is no requirement for Access Token at the moment. The main reason of expecting Client Secret Key is to filter and deliver an appropriate data from the database!

I think fetching Client Data from SQL Table using the ClientSecretKey in a WHERE clause is not going to be performance friendly, for an example:

SELECT Multiple_Columns from ClientTable WHERE ClientSecretKey='X3i1aBer'

Ideally, I would prefer to fetch the client records using ClientId which is defined as an IDENTITY column in a table.

Questions:

  1. How best to design a Unique Client Key that should be absolutely performance friendly when executing the query against database to fetch that specific client records?
  2. Is there any flaw in my thinking or the design?

Any ideas would be REALLY appreciated.

Thanks!


原文:https://stackoverflow.com/questions/34417742
更新时间:2023-10-03 20:10

最满意答案

你的delta有这个值: -64E9*1E-8 ,实际上是-64 。那就是:它是一个负值。 由于delta预计是实际值和期望值之间差异的上限,因此您需要将其设为正数。

看一下Assert类的源代码 。 比较双打的地方是doubleIsDifferent方法:

static private boolean doubleIsDifferent(double d1, double d2, double delta) {
    if (Double.compare(d1, d2) == 0) {
        return false;
    }
    if ((Math.abs(d1 - d2) <= delta)) {    
        return false;
    }

    return true;
}

如您所见,相关表达式为Math.abs(d1 - d2) <= delta 。 由于它使用Math.abs因此左侧始终为0或正数。 因此它永远不会小于负值,因此此方法始终返回true从而向调用者( assertEquals )指示您的值不同。

换句话说:将delta的定义更改为:

double delta = Math.abs(n * 1E-8);

Your delta has this value: -64E9*1E-8 which is actually -64.That is: it is a negative value. As delta is expected to be the upper limit on the difference between the actual and expected value you need to make it a positive number.

Take a look at the source code of the Assert class. The place where doubles are compared is the doubleIsDifferent method:

static private boolean doubleIsDifferent(double d1, double d2, double delta) {
    if (Double.compare(d1, d2) == 0) {
        return false;
    }
    if ((Math.abs(d1 - d2) <= delta)) {    
        return false;
    }

    return true;
}

As you can see the relevant expression is Math.abs(d1 - d2) <= delta. As it uses Math.abs the left-hand side is always 0 or positive. Thus it can never be less than a negative value so this method always returns true thus indicating to the caller (assertEquals) that your values are different.

In other words: change the definition of delta to:

double delta = Math.abs(n * 1E-8);

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)