SpringMVC Ldap身份验证@annotated

时间:2014-03-24 18:11:15

标签: spring-mvc spring-security

我正在尝试在我的应用中使用springMVC ldap身份验证。我收到来自服务器的回复,说用户成功验证后,我目前陷入困境。

    11:56:16,289 DEBUG HttpSessionSecurityContextRepository:90 - No SecurityContext was available from the HttpSession: org.apache.catalina.session.StandardSessionFacade@7e18ddb9. A new one will be created.
11:56:16,290 DEBUG FilterChainProxy:337 - /login at position 3 of 14 in additional filter chain; firing Filter: 'HeaderWriterFilter'
11:56:16,290 DEBUG HstsHeaderWriter:129 - Not injecting HSTS header since it did not match the requestMatcher org.springframework.security.web.header.writers.HstsHeaderWriter$SecureRequestMatcher@32326
11:56:16,290 DEBUG FilterChainProxy:337 - /login at position 4 of 14 in additional filter chain; firing Filter: 'CsrfFilter'
11:56:16,291 DEBUG FilterChainProxy:337 - /login at position 5 of 14 in additional filter chain; firing Filter: 'LogoutFilter'
11:56:16,291 DEBUG AntPathRequestMatcher:116 - Checking match of request : '/login'; against '/logout'
11:56:16,292 DEBUG FilterChainProxy:337 - /login at position 6 of 14 in additional filter chain; firing Filter: 'UsernamePasswordAuthenticationFilter'
11:56:16,292 DEBUG AntPathRequestMatcher:116 - Checking match of request : '/login'; against '/login'
11:56:16,292 DEBUG UsernamePasswordAuthenticationFilter:205 - Request is to process authentication
11:56:16,297 DEBUG ProviderManager:152 - Authentication attempt using org.springframework.security.ldap.authentication.LdapAuthenticationProvider
11:56:16,297 DEBUG LdapAuthenticationProvider:51 - Processing authentication request for user: username
11:56:16,299 DEBUG BindAuthenticator:108 - Attempting to bind as cn=username,cn=users,dc=myorgnet,dc=global,dc=myorg,dc=com
11:56:16,300 DEBUG DefaultSpringSecurityContextSource:76 - Removing pooling flag for user cn=username,cn=users,dc=myorgnet,dc=global,dc=myorg,dc=com
11:56:16,350 DEBUG AbstractContextSource:259 - Got Ldap context on server 'ldap://myorgNET.GLOBAL.myorg.COM'
11:56:16,357 DEBUG BindAuthenticator:116 - Retrieving attributes...
11:56:16,463 DEBUG DefaultLdapAuthoritiesPopulator:182 - Getting authorities for user cn=username,cn=users,dc=myorgnet,dc=global,dc=myorg,dc=com
11:56:16,464 DEBUG DefaultLdapAuthoritiesPopulator:211 - Searching for roles for user 'username', DN = 'cn=username,cn=users,dc=myorgnet,dc=global,dc=myorg,dc=com', with filter (uniqueMember={0}) in search base ''
11:56:16,464 DEBUG SpringSecurityLdapTemplate:152 - Using filter: (uniqueMember=cn=username,cn=users,dc=myorgnet,dc=global,dc=myorg,dc=com)
11:56:16,468  INFO LdapTemplate:1262 - The returnObjFlag of supplied SearchControls is not set but a ContextMapper is used - setting flag to true
11:56:16,517 DEBUG AbstractContextSource:259 - Got Ldap context on server 'ldap://myorgNET.GLOBAL.myorg.COM'
11:56:16,542 DEBUG HttpSessionSecurityContextRepository:300 - SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession.
11:56:16,542 DEBUG SecurityContextPersistenceFilter:97 - SecurityContextHolder now cleared, as request processing completed
11:56:16,542 DEBUG SecurityContextPersistenceFilter:97 - SecurityContextHolder now cleared, as request processing completed
Mar 24, 2014 11:56:16 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/Results] threw exception
org.springframework.ldap.UncategorizedLdapException: Uncategorized exception occured during LDAP processing; nested exception is javax.naming.NamingException: [LDAP: error code 1 - 00000000: LdapErr: DSID-0C090627, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, vece ]; remaining name ''
at org.springframework.ldap.support.LdapUtils.convertLdapException(LdapUtils.java:217)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:319)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:259)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:606)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:524)

这就是我在初始化程序中的含义:     public class Initializer实现WebApplicationInitializer {     private static final String DISPATCHER_SERVLET_NAME =“dispatcher”;

@Override
public void onStartup(ServletContext servletContext)
        throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(WebAppConfig.class);
    servletContext.addListener(new ContextLoaderListener(ctx));

    ctx.setServletContext(servletContext);

    Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx));

    FilterRegistration.Dynamic springFilter = servletContext.addFilter("springSecurityFilterChain", DelegatingFilterProxy.class);
    springFilter.addMappingForUrlPatterns(null, true, "/*");

我的SecurityContext看起来像这样:

 @Configuration
 @EnableWebSecurity
 public class SecurityContext extends WebSecurityConfigurerAdapter {
   @Autowired
   protected void configureGlobal(AuthenticationManagerBuilder authManagerBuilder) {        
    try{            
        ContextSourceBuilder ctx = authManagerBuilder.ldapAuthentication()
                                .userDnPatterns("cn={0},cn=users,DC=myorgnet,DC=global,DC=myorg,DC=com")            
                                .contextSource().url("ldap://myorgnet.GLOBAL.myorg.COM");           
    }catch(Exception e){

    }finally{

    }

0 个答案:

没有答案