Kra*_*786 4 java authentication tomcat
我需要在我的最新项目中使用Container Managed Security and Authentication.我有一些关于如何配置凭据处理程序的疑问.
MessageDigestCredentialHandler和
SecretKeyCredentialHandler哪一个更安全?SecretKeyCredentialHandler指定只有一个算法中
的文档是PBKDF2WithHmacSHA1.还有哪些其他算法?bon*_*ldi 10
回答第一点,这里<Realm>是切换到Tomcat 8之前和之后的context.xml 的比较:
之前:
<Realm className="org.apache.catalina.realm.DataSourceRealm"
dataSourceName="jdbc/myDataSource"
roleNameCol="role" userCredCol="password" userNameCol="loginid"
digest="md5"
userRoleTable="userroles" userTable="users"
localDataSource="true" />
Run Code Online (Sandbox Code Playgroud)
后:
<Realm className="org.apache.catalina.realm.DataSourceRealm"
dataSourceName="jdbc/myDataSource"
roleNameCol="role" userCredCol="password" userNameCol="loginid"
userRoleTable="userroles" userTable="users" localDataSource="true">
<CredentialHandler
className="org.apache.catalina.realm.MessageDigestCredentialHandler"
algorithm="md5" />
</Realm>
Run Code Online (Sandbox Code Playgroud)
NestedCredentialHandler 适用于您有多个摘要方法的情况,例如您过去使用过 MessageDigest 但现在您想切换更安全的 PBKDF2-SHA512 配置,并且不想使已配置的密码无效。
例如:
<CredentialHandler className="org.apache.catalina.realm.NestedCredentialHandler">
<CredentialHandler className="org.apache.catalina.realm.SecretKeyCredentialHandler"
algorithm="PBKDF2WithHmacSHA512"
iterations="100000"
keyLength="256"
saltLength="16"
/>
<CredentialHandler className="org.apache.catalina.realm.MessageDigestCredentialHandler"
algorithm="SHA-256"
iterations="1000"
keyLength="256"
saltLength="8"
/>
</CredentialHandler>
<!-- NOTE: keyLength is in bits, saltLength is in bytes. 16 bytes = 128 bits -->
Run Code Online (Sandbox Code Playgroud)
这将进入您的 Realm 元素。
SecretKeyCredentialHandler 是在 Tomcat 8.0.15 中引入的,它使用 javax.crypto API 中的 SecretKeyFactory 而不是旧方法 (MessageDigest) 来改变密码。SecretKeyFactory 允许使用更好的算法,例如带有 HMAC-SHA-512 的 PBKDF2,而不是简单的哈希算法,例如 SHA-512。旧方法可通过 MessageDigestCredentialHandler 使用,这相当于直接在 Realm 元素上设置摘要属性。
请注意,直接设置摘要属性或使用没有可选迭代属性的 MessageDigestCredentialHandler(仅限 8.0.15+)只会进行一次迭代。这是不安全的。
至于什么算法可用于 SecretKeyFactory,JDK 8的Java Cryptography Architecture Standard Algorithm Name Documentation是我能找到的最好的参考,但它没有明确列出所有组合。这些是我在我的平台(Linux 3.13.0、Oracle JDK 1.8.0_111)上发现的,但你的可能支持其他组合。
MessageDigestCredentialHandler 的算法字段是一个字符串,可以采用此处描述的任何值:http://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#MessageDigest
MessageDigestCredentialHandler 和 SecretKeyHandler 之间的区别在于使用的算法,我认为 SecretKeyHandler 更安全,因为 javax.crypto.SecretKeyFactory 。
我无法提供任何配置示例,但是当我使用 TomcatRealms 实现自定义 AuthorizationProviders 时,我总是在 META-INF/context.xml 中配置它
最后,我想告诉你,多年来我一直在使用自定义 AuthorizationProvider,但现在我将它们全部迁移到 Spring Security。
| 归档时间: |
|
| 查看次数: |
4741 次 |
| 最近记录: |