2012-03-20 2 views
0

스프링 MVC 프로젝트에서 인증 된 스프링 보안 3을 사용하고 있습니다. 내 프로젝트를 다른 환경에 배포하고 JDK의 버전을 1.6에서 1.7로 변경해야 할 때까지 제대로 작동합니다. 에, 위해 welcome.jsp에 대한 URL을 리디렉션합니다스프링 보안 3이 JDK 1.7에서 작동하지 않습니다.

1) 보안 응용 프로그램의 context.xml

<?xml version="1.0" encoding="UTF-8"?> 
<beans 
    xmlns:s="http://www.springframework.org/schema/security" 
    xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation=" 
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
        http://www.springframework.org/schema/security 
        http://www.springframework.org/schema/security/spring-security-3.1.xsd"> 

    <s:http use-expressions="true">  
     <s:intercept-url pattern="/auth/**" access="permitAll" /> 
     <s:intercept-url pattern="/css/**" access="permitAll" /> 
     <s:intercept-url pattern="/image/**" access="permitAll" /> 
     <s:intercept-url pattern="/scripts/**" access="permitAll" />   

     <s:intercept-url pattern="/**" access="hasRole('GENERAL_USER')" /> 

     <s:form-login login-page="/auth/login.html" 
         default-target-url="/welcome.html" 
         authentication-failure-url="/auth/login.html?error=1" /> 

     <s:access-denied-handler error-page="/auth/denied.html"/> 

     <s:logout invalidate-session="true" logout-success-url="/auth/logoutSuccess.html"/>       
    </s:http> 

    <s:authentication-manager> 
     <s:authentication-provider ref="ldapAuthProvider" /> 
    </s:authentication-manager> 

    <bean 
     id="contextSource" 
     class="org.springframework.security.ldap.DefaultSpringSecurityContextSource" 
     scope="singleton"> 
     <constructor-arg 
      value="ldap://ldapurl:389/dc=o,dc=a" /> 
      <property name="userDn" value="cn=xxx,cn=users,dc=o,dc=a" /> 
      <property name="password" value="password" /> 
      <property name="baseEnvironmentProperties"> 
       <map> 
        <entry key="java.naming.referral"> 
         <value>follow</value> 
        </entry>      
       </map> 
      </property>   
    </bean> 

    <bean id="userSearch" 
     class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch"> 
     <!-- searchBase, searchFilter, contextSource --> 
     <constructor-arg index="0" value="" /> 
     <constructor-arg index="1" value="(sAMAccountName={0})" /> 
     <constructor-arg index="2" ref="contextSource" /> 
    </bean> 

    <bean id="ldapAuthProvider" 
     class="com.foo.auth.MyLdapAuthenticationProvider">  
     <constructor-arg>  
      <bean  
       class="com.foo.auth.MyLdapAuthenticator"> 
       <constructor-arg ref="contextSource" /> 
       <property name="userSearch"> 
        <ref bean="userSearch" /> 
       </property>    
      </bean> 
     </constructor-arg> 
     <property name="authoritiesPopulator" ref="authoritiesPopulator" /> 
     <property name="userDetailsContextMapper" ref="userDetailsMapper" /> 
    </bean> 

    <bean id="authoritiesPopulator" class="com.foo.auth.MyLdapAuthoritiesPopulator"> 
     <constructor-arg ref="userService" />  
    </bean>  

    <bean id="userService" class="com.foo.auth.MyLdapUserDetailsService"> 
     <constructor-arg ref="userSearch" /> 
     <property name="userDetailsMapper" ref="userDetailsMapper" /> 
    </bean> 
    <bean id="userDetailsMapper" class="com.foo.auth.MyUserDetailsContextMapper">      
    </bean>   
</beans> 

2) 성공 로그온 후 아래

내 봄 보안 설정 파일과 샘플 코드 welcome.jsp, 나는 봄 보안 taglib을 사용하여 로그온 사용자의 성명을 얻는다. (테스트를 위해, 나는 전체 컨텍스트 정보를 보여 주 사용) :

<security:authentication property="principal"></security:authentication>  

때 사용 JDK 1.6, 주요 프로그램 :

[email protected]:......... 

와 나는 그런 principal.fullName처럼 내 사용자 정의 UserDetail의 속성을 사용할 수 있습니다. 때 사용 JDK 1.7, 교장 쇼 :

or[email protected]86dae957:... 

내 사용자 정의 UserDetail 개체를하지 않습니다. JDKk1.7을 사용하면 Spring 컨텍스트를 올바르게 가져올 수 없습니다.

이 문제가 근본 원인을 발견 거의 일주 나를 필요는 JDK 버전의 문제 ;-(입니다

사람이 LDAP 봄 보안 JDK1.7에서 작동하지 않습니다 알고 않는 이유는 무엇입니까? 아니면 내가 뭔가를 그리워 설정?

사전에 감사합니다!

답변

0

문제가 수정되었습니다. 내 MyLdapAuthenticationProvider 잘못 제공자를 확장하기 때문입니다. 내가 LdapAuthenticationProvider, 에 MyLdapAuthenticationProvider 확장 클래스를 변경하고 봄 보안 작업 f를 JDK 1.6과 1.7에서 모두 사용되었습니다.

public class MyLdapAuthenticationProvider extends LdapAuthenticationProvider { 

private static Logger logger = Logger.getLogger(MyLdapAuthenticationProvider.class);   
private MyLdapAuthenticator authenticator; 
@Autowired 
private MyLdapAuthoritiesPopulator authoritiesPopulator; 
@Autowired 
private MyUserDetailsContextMapper userDetailsContextMapper; 

public MyLdapAuthenticationProvider(LdapAuthenticator authenticator) { 
    super(authenticator); 
    this.authenticator = (MyLdapAuthenticator) authenticator; 
} 

@Override 
protected DirContextOperations doAuthentication(UsernamePasswordAuthenticationToken userToken) { 
    try { 
     DirContextOperations dirCtx = getAuthenticator().authenticate(userToken);    
     return dirCtx; 
    } catch (PasswordPolicyException ppe) { 
     throw new LockedException(this.messages.getMessage(ppe.getStatus().getErrorCode(), ppe.getStatus() 
       .getDefaultMessage())); 
    } catch (UsernameNotFoundException notFound) {    
     throw new BadCredentialsException("User Name Error!"); 
    } catch (NamingException ldapAccessFailure) { 
     throw new AuthenticationServiceException(ldapAccessFailure.getMessage(), ldapAccessFailure); 
    } 
} 

private void setAuthenticator(MyLdapAuthenticator authenticator) { 
    Assert.notNull(authenticator, "An LdapAuthenticator must be supplied"); 
    this.authenticator = authenticator; 
} 

private MyLdapAuthenticator getAuthenticator() { 
    return authenticator; 
} 

public MyUserDetailsContextMapper getUserDetailsContextMapper() { 
    return userDetailsContextMapper; 
} 

public void setUserDetailsContextMapper(MyUserDetailsContextMapper userDetailsContextMapper) { 
    this.userDetailsContextMapper = userDetailsContextMapper; 
} 

public void setAuthoritiesPopulator(MyLdapAuthoritiesPopulator authoritiesPopulator) { 
    this.authoritiesPopulator = authoritiesPopulator; 
} 

public MyLdapAuthoritiesPopulator getAuthoritiesPopulator() { 
    return authoritiesPopulator; 
} 

}

: 여기

내 사용자 정의 LdapAuthenticationProvider입니다
관련 문제