Spring Security CAS和具有多个HttpSecurity的Kerberos

时间:2015-06-02 15:21:42

标签: java spring spring-security kerberos cas

我正在尝试将Spring Security设置为同时使用CAS和Kerberos,以便Kerberos对/ secure / krb / **进行身份验证,而/ **将由CAS进行身份验证。

我按照Spring Security文档设置了多个HttpSecurity here

我的java配置摘录是:

@Configuration
@EnableWebSecurity
public class SecurityConfig {

    @Autowired
    public void configure(AuthenticationManagerBuilder authManagerBuilder)
            throws Exception {
        authManagerBuilder
        .authenticationProvider(kerberosAuthenticationProvider())
        .authenticationProvider(kerberosServiceAuthenticationProvider())
        .authenticationProvider(casAuthenticationProvider())
        ;
    }

    @Configuration
    @Order(1)
    public static class KerberosWebSecurityConfigurationAdapter extends
            WebSecurityConfigurerAdapter {

        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http
            .antMatcher("/secure/krb/**")
            .authorizeRequests()
                    .anyRequest().authenticated()
                    .and()
            .exceptionHandling()
                .authenticationEntryPoint(spnegoEntryPoint())
                .and()
            .addFilterBefore(
                    spnegoAuthenticationProcessingFilter(authenticationManagerBean()),
                    BasicAuthenticationFilter.class);       
        }

        // snip @Bean's
    }

    @Configuration
    public static class CasWebSecurityConfigurationAdapter extends
            WebSecurityConfigurerAdapter {

        @Override
        public void configure(WebSecurity web) throws Exception {
            web.ignoring().antMatchers("/resources/**");
        }

        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.authorizeRequests()
                    .antMatchers("/403.html")
                    .permitAll()
                    .antMatchers("/casfailed.html")
                    .permitAll()
                    .antMatchers("/cas-logout.html")
                    .permitAll()
                    .antMatchers("/**")
                    .hasRole("USER")
                    .and()
                    .addFilter(casFilter())
                    .addFilterBefore(requestSingleLogoutFilter(),
                            LogoutFilter.class)
                    .addFilterBefore(singleLogoutFilter(),
                            CasAuthenticationFilter.class).logout()
                    .logoutSuccessUrl("/cas-logout.html").and()
                    .exceptionHandling().accessDeniedPage("/403.html")
                    .authenticationEntryPoint(casEntryPoint()).and()
                    .sessionManagement().invalidSessionUrl(CAS_LOGOUT_URL)
                    .and().csrf().and().headers();
        }

// snip, snip   

然后我得到一个异常,即AuthenticationManager bean不可用。

INFO: Initializing Spring root WebApplicationContext
INFO  ContextLoader - Root WebApplicationContext: initialization started
INFO  AnnotationConfigWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Tue Jun 02 09:34:48 EDT 2015]; root of context hierarchy
INFO  AnnotationConfigWebApplicationContext - Registering annotated classes: [class sample.AppConfig]
INFO  RequestMappingHandlerAdapter - Looking for @ControllerAdvice: Root WebApplicationContext: startup date [Tue Jun 02 09:34:48 EDT 2015]; root of context hierarchy
WARN  AnnotationConfigWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'spnegoAuthenticationProcessingFilter' defined in class sample.SecurityConfig$KerberosWebSecurityConfigurationAdapter: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.security.authentication.AuthenticationManager]: : No qualifying bean of type [org.springframework.security.authentication.AuthenticationManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.security.authentication.AuthenticationManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:464) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) [spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) [spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) [spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.apache.catalina.core.StandardContext.listenerStart(Unknown Source) [catalina.jar:7.0.59]
    at org.apache.catalina.core.StandardContext.startInternal(Unknown Source) [catalina.jar:7.0.59]
    at org.apache.catalina.util.LifecycleBase.start(Unknown Source) [catalina.jar:7.0.59]
    at org.apache.catalina.core.ContainerBase$StartChild.call(Unknown Source) [catalina.jar:7.0.59]
    at org.apache.catalina.core.ContainerBase$StartChild.call(Unknown Source) [catalina.jar:7.0.59]
    at java.util.concurrent.FutureTask.run(FutureTask.java:262) [na:1.7.0_80]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_80]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_80]
    at java.lang.Thread.run(Thread.java:745) [na:1.7.0_80]
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.security.authentication.AuthenticationManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1301) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1047) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:813) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    ... 24 common frames omitted

有人可以解决这个问题吗?

我使用了Spring-4.1.6,Spring Security-3.2.7,Spring Security Cas-3.2.7,Spring Security Kerberos Web-1.0和Java 1.7。 谢谢,

0 个答案:

没有答案