2013-03-12 2 views
0

웹 어플리케이션을위한 스프링 보안을 소개합니다. 먼저 인증 관리자가 있습니다.스프링 encodePassword와 소금

<authentication-manager> 
    <authentication-provider> 
     <password-encoder hash='md5'> 
     </password-encoder> 
     <jdbc-user-service data-source-ref="dataSource"/> 
    </authentication-provider> 
</authentication-manager> 

나는 '1'을 사용자 이름과 암호로 사용하려고합니다. 나는 온라인 md5 해시 생성기를 사용하고 md5 (1)에 대해 'c4ca4238a0b923820dcc509a6f75849b'를 얻었다. 이 구성으로 로그인이 올바르게 작동합니다. 소금을 시험해보고 싶었고 다음과 같이 인증 관리자를 수정합니다.

<authentication-manager> 
    <authentication-provider> 
     <password-encoder hash='md5'> 
      <salt-source user-property="username"/> 
     </password-encoder> 
     <jdbc-user-service data-source-ref="dataSource"/> 
    </authentication-provider> 
</authentication-manager> 

그래서 내가 사용하는 소금은 해시 (소금 + 비밀번호)와 같은 방법 웹에서 읽을 수있다. 따라서 동일한 도구를 사용하여 '11'을 해시 한 다음 해시 값 '6512bd43d9caa6e02c990b0a82652dca'를 얻었습니다. 그 값으로 데이터베이스를 업데이트합니다. 하지만 이제 로그인이 실패하여 'Caused : Bad credentials'오류가 발생하여 실패합니다. 즉, 암호가 데이터베이스와 일치하지 않습니다. 그래서 제 질문은 스프링이 소금을 칠하기 위해 다른 방법을 사용한다는 것입니까?

+2

[BCrypt] (http://stackoverflow.com/a/8528804/241990)를 사용하십시오. 그것은 더 안전하고 염분 자체가 처리됩니다. MD5는 암호 해싱에 실제로 좋은 선택이 아닙니다. –

+0

시도해야합니다. 감사합니다 루크 –

답변

0

어쨌든 스프링 염법이 다릅니다. 사용자가 자바 코드를 따라 해시로 해시를 계산합니다.

public static void main(String[] args) { 
    Md5PasswordEncoder md5 = new Md5PasswordEncoder(); 
    String hash = md5.encodePassword("1", "1"); 
    System.out.println(hash); 
} 

나는 암호화 된 암호로 '6a8a1f634e38d30e87b450899b31f810'(다른 권리?) 있어요. 그런 다음 데이터베이스에 삽입하고 응용 프로그램 로그인을 시도합니다. Vola !!! 로그인 성공.

2

스프링 보안을 사용하고 있으므로 PasswordEncoder 콩을 사용하는 것이 좋습니다.

<authentication-manager> 
    <authentication-provider> 
     <password-encoder ref="passwordEncoder"> 
      <salt-source user-property="username"/> 
     <password-encoder/> 
     <jdbc-user-service data-source-ref="dataSource"/> 
    </authentication-provider> 
</authentication-manager> 

방문 Spring Security Custom Authentication and Password Encoding & Spring Security:password encoding in DB and in applicationContext 더 알고 :

<beans:bean id="passwordEncoder" class="org.springframework.security.authentication.encoding.ShaPasswordEncoder"> 
</beans:bean> 

그리고 당신의 인증 관리자 (변경 코드) 같은 것이다.

+0

속성 "해시"를 사용하여 동일하지 않습니다? 나는 명시 적으로 빈을 만드는 것과 동일하다고 생각한다. PasswordEncoder로서 org.springframework.security.authentication.encoding.ShaPasswordEncoder를 삽입하는 것은 다음과 같이 쉽게 할 수 있습니까? <인증 관리자> <인증 공급자> <암호 엔코더 해시 = "SHA"> <염 소스 사용자 속성 = "이름"/> <암호 인코더 />

+0

바로 알겠습니다. –