2013-09-02 4 views
-1

저는 Java EE, Spring 보안 프레임 워크 및 Oracle 11g 데이터베이스를 사용하는 응용 프로그램에서 작업하고 있습니다. 스프링 보안에 MD5 해시를 추가해야하며이 작업을 성공하지 못했습니다. 내가 지금까지했던 어떤봄 보안에 MD5 또는 SHA 해시를 추가하는 방법은 무엇입니까?

:

1에서 첫 주 내가 springsecuritycontext.xml하는 코드를 추가하지 않고 내 응용 프로그램에 MD5 해시를 추가하려고 내가 성공했다.

이 내가 한 일이다라는 패키지에서

두 classes.The 첫 번째가 PolicyManager라고있다 ma.dyaralmansour.zkgui.policy이 클래스는 스프링 보안 UserDetailService을 구현합니다. 두 번째는 LoginLoggingPolicyService이며이 클래스는 Spring AOP에서 애스펙트로 호출되며 로깅 용입니다. 내 모든 암호는 MD5 해시 해시

하지만 난을 사용할 때 더 이상 응용 프로그램에 액세스 할 수 없습니다

 *** I added an MD5Password class to the ma.dyaralmansour.zkgui.policy and I added some code to the PolicyManager class to activate the hash and it's working. 

내 문제는 지금 :

그래서 이것은 내가 한 일이다 일반 암호.

는 지금은 2 가지 옵션이 있습니다,하지만 난을 구현하는 방법을 전혀 생각이 없다 다음 MD5password 클래스의

1

이 testPassword이다 (문자열 clearTextTestPassword, 문자열 encodedActualPassword)라는 메서드

그것은 비교가 데이터베이스에 저장된 해시 된 암호가있는 일반 암호이지만 내 policymanager 클래스에 암호를 추가하는 방법을 이해할 수 없습니다.

2 - 내가했던 모든 것을 완전히 제거하고 정상적인 암호를 사용할 때 응용 프로그램에 암호와 해시를 해시하기 위해 스프링 보안 구성에만 초점을 맞 춥니 다.

다른 해결책이 있습니까?

http://www.mediafire.com/download/gxgda63wyhkpehn/DamPromoZK4.rar

<!-- Spring namespace-based configuration --> 

<beans:beans xmlns="http://www.springframework.org/schema/security" 
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:zksp="http://www.zkoss.org/2008/zkspring" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" 
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 
        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.1.xsd 
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> 



<!-- Enable the @Secured annotation to secure service layer methods --> 
<global-method-security secured-annotations="enabled" /> 

<http auto-config="true"> 

    <!-- ### If we have our own LoginPage. So we must ### --> 
    <!-- ###  tell Spring the name and the place.  ### --> 
    <!-- ###  In our case we take the same page  ### --> 
    <!-- ###  for a error message by a failure.  ### --> 
    <!-- ### Further the page after a successfully login. ### --> 
    <form-login login-page="/index.zul" 

     authentication-failure-url="/index.zul?login_error=1" 
     default-target-url="/AccueilIntranet.zul" /> 

    <!-- ### Tell Spring where it goes after logout. ### --> 
    <!-- ###   logout-url is a action url.   ### --> 
    <logout logout-url="/j_spring_logout" logout-success-url="/index.zul" /> 

    <!-- ### Define the pages that are to be intercepted ### --> 
    <!-- ### It is parsed from top to bottom. Means that ### --> 
    <!-- ### the most specific pattern is standing on TOP ### --> 
    <!-- ###   and the CATCH ALL is on BOTTOM!  ### --> 
    <intercept-url pattern="/pages/**" access="IS_AUTHENTICATED_REMEMBERED" filters="none" /> 
    <intercept-url pattern="/WEB-INF/pages/**" access="IS_AUTHENTICATED_REMEMBERED" filters="none"/> 

    <!-- ### The root page is accessible by everyone but ### --> 
    <!-- ### internally spring makes a login and  ### --> 
    <!-- ###  this user becames a UserDetails   ### --> 
    <!-- ### (in there are the ip-address and others) ### --> 
    <intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY" filters="none"/> 

    <!-- ###   Per user one session !!   ### --> 
    <concurrent-session-control max-sessions="1" /> 
</http> 

<!-- ### We define the kind of authentification with a ### --> 
<!-- ###   so called authentication-provider  ### --> 
<!-- ### So we have our users stored in a DB we use  ### --> 
<!-- ### our own user-service class and point to her. ### --> 
<authentication-provider user-service-ref="myUserDetailsService"> 
</authentication-provider> 




<!-- ### The Implementation of the Interface   ### --> 
<!-- ###  UserDetailService for the logged in   ### --> 
<!-- ###    user and his rights     ### --> 
<beans:bean id="myUserDetailsService" class="ma.dyaralmansour.zkgui.policy.PolicyManager"> 
    <beans:property name="userService" ref="userService" /> 
</beans:bean> 



<authentication-provider user-service-ref="myUserDetailsService"> 
<password-encoder hash="md5"/> 
</authentication-provider> 




    <!-- ### This aspect call automatically the methode  ### --> 
    <!-- ### 'loginLogging' which is for writing a log for ### --> 
    <!-- ### all successfully and failed logins, if a  ### --> 
    <!-- ### methode is called that handles the    ### --> 
    <!-- ### Authentication.        ### --> 
    <beans:bean id="LoginLoggingPolicyService" 
     class="ma.dyaralmansour.zkgui.policy.LoginLoggingPolicyService"> 
     <beans:property name="loginLoggingService" ref="loginLoggingService" /> 
    </beans:bean> 






    <aop:config> 
     <aop:aspect id="LoginLoggingAspect" ref="LoginLoggingPolicyService"> 
      <aop:pointcut id="authPointcut" 
       expression="execution(public org.springframework.security.Authentication org.springframework.security.providers.AuthenticationProvider.authenticate(org.springframework.security.Authentication))" /> 
      <aop:around pointcut-ref="authPointcut" method="loginLogging" /> 
     </aop:aspect> 
    </aop:config> 

</beans:beans> 

답변

2

왜 바퀴를 개혁하는? 스프링 시큐리티 (Spring Security)는 패스워드 해싱을 즉시 사용할 수 있도록 지원하며 구성의 문제 일뿐입니다. UserDetailService에 대한 맞춤 구현은 사용자 이름에 대해 찾은 사용자 만 반환해야합니다 (비밀번호를 확인하지 않았거나 그 어느 때까지만). 그런 다음 Spring Security는 구성된 해시로 비밀번호를 확인합니다.

간단히 (대신에 로그인하기위한 AOP를 사용하는 것입니다

<authentication-provider user-service-ref="myUserDetailsService"> 
    <password-encoder hash="md5"/> 
</authentication-provider> 

당신은 또한 개선을위한 Spring Security documentation

또 다른 제안을 확인 할 수 있습니다 당신의 <authentication-provider .. > 요소에 암호 인코더를 추가하여 봄 보안을 적절하게 구성 그것이 유일한 일이라고 가정 할 때 ApplicationListener을 구현하고 AbstractAuthenticationEvent을 청취합니다. 간단한 작업 샘플의 기본값 인 LoggerListener을 확인하고자 할 수 있습니다.그것은 자동으로 당신을 위해 소금 암호를 것이다

http://static.springsource.org/spring-security/site/docs/3.1.x/apidocs/org/springframework/security/crypto/bcrypt/BCryptPasswordEncoder.html

:

+0

이 코드를 springsecuritycontext.xml에 추가했는데 MD5password 클래스와 코드를 policymanager 클래스에서 제거했지만 응용 프로그램을 실행할 때 일반 암호를 사용하면 해당 암호가 해시되지 않습니다. 코드의 라인은 어쩌면 내가 더 설명해 줄 수 있을까? – user2644068

+0

어떻게 응용 프로그램에 연결하려면 내 데이터베이스에서 읽고 해시 암호를 사용하도록 봄을 말할 수 있습니까? – user2644068

+0

위와 같이 구성을 추가하면됩니다. '정상적인 암호를 사용하여 해시되지 않는'것은 무엇을 의미합니까? 어느 암호를 해시해야합니까? 현재 설정 (구성 및 코드)으로 질문을 업데이트하십시오. –

3

새로운 BCryptPasswordEncoder를 사용합니다.

강력하고 느리고 약점이 없으므로 BCrypt를 사용하는 것이 좋습니다. "느려짐"은 실제로 해시 알고리즘에서 원하는 기능입니다. 누군가 암호를 도용하면 해독하는 데 시간이 오래 걸리기 때문입니다.

SHA 256이 약화되었습니다. MD5가 확실히 망가졌습니다.

+0

더 많은 것을 설명 할 수 있습니다. 이것이 봄에 처음으로 작동하는 것이고 아직 그것에 대한 명확한 생각은 없습니다. , 내게 말해 줄까? 내 질문에 게시 된 코드에서 BCryptpassword를 구현해야합니까? – user2644068

+0

"slow"에주의해야합니다. _session-less_ 코드로 작업하는 경우 모든 작업이 매우 느리게 진행됩니다. 가장 효과적인 작업 필자가 지금까지 생각해 보았던 것은 기억 된 암호에 대한 강력한 해싱을 유지하는 것입니다. 그러나 이전에는 사용했던 것과 똑같은 암호를 사용하는 것이 더 빠를 수 있으므로 더 저렴한 투명한 메모리 캐시를 앞에 두는 것이 훨씬 더 빠릅니다. 아이디어는 지속적인 공격을받지 않는 시스템의 합법적 인 사용자가 비용을 너무 많이 내지 않아도되도록하는 것입니다. –

관련 문제