簡體   English   中英

通用Java API,用於密碼更改/哈希/摘要

[英]General Java API for password mutate / hash / digest

我的Web應用程序使用容器管理的身份驗證使用固定的摘要式密碼進行保護。 我想通過在JNDI中提供一個處理密碼更改/驗證的服務來減少與當前容器的耦合。 我在追求這樣的事情:

/**
 * A service for mutating passwords with salt.
 * Note that the same password should yield different mutations every time.
 */
public interface PasswordMutationService {
    /**
     * Mutates the given password for storage purposes.
     * The 'salt' must be coded into the result so that it can be extracted later.
     */
    String mutatePassword(String password);

    /**
     * Confirm the given password was used to create the given stored mutation.
     *
     * @param candidatePassword     The password supplied by a user that wants to be authenticated.
     * @param storedMutatedPassword A mutation of the users password retrieved from storage.
     */
    boolean verifyMutatedPassword(String candidatePassword, String storedMutatedPassword);
}

您是否知道提供此接口的API,所以我不必自己編寫和管理? 我很難相信它不在Java EE中。

注意:我不需要Tomcat Realm,它已經完成了 我也不需要實現,也已經完成了

要將我的應用程序與密碼摘要實現分離開,我實際上只需要一種方法:

String mutatePassword(String password)

容器插件可以與摘要實現耦合,而不會造成太大損害,因此它不需要在接口上使用“ verifyMutatedPassword()”。

瀏覽了一些JDK7 API之后,我發現可以完成此工作 (如果您不容易受到冒犯):

public interface Provider<T> {
  public T invoke(T request);
}

這意味着我的應用程序可以通過以下方式利用密碼突變

InitialContext ctx = new InitialContext();
passwordMutator = (Provider<String>) ctx.lookup("java:comp/env/bean/appPasswordMutator");

用於密碼突變和安全領域的tomcat容器配置為:

<Resource name="bean/appPasswordMutator" auth="Container"
          factory="org.apache.naming.factory.BeanFactory"
          type="pkg.PasswordMutator"
          seedNumBytes="8"
          keyNumBits="160"
          digestIterationCount="10000"
          singleton="true"/>

<Realm className="pkg.PasswordMutationRealm" 
       userCredCol="usercred"
       passwordMutatorName="bean/appPasswordMutator" 
       localPasswordMutator="true"
       localDataSource="true"
       dataSourceName="jdbc/appDb"
       userTable="usercred"
       userNameCol="username"
       userRoleTable="userrole"
       roleNameCol="userrole"/>

可以從我的SVN存儲庫中找到有效的演示, 網址為: https ://subversion.assembla.com/svn/freshcode_public/learn/tomcat-maven-plugin(請參閱READ_ME.txt文件)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM