2015-05-28 165 views
0

我的应用程序初始化程序春季安全错误

public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer{ 

@Override 
protected Class<?>[] getRootConfigClasses() { 
    // TODO Auto-generated method stub 
    return new Class[]{ApplicationConfiguration.class}; 
} 

@Override 
protected Class<?>[] getServletConfigClasses() { 
    // TODO Auto-generated method stub 
    return null; 
} 

@Override 
protected String[] getServletMappings() { 
    // TODO Auto-generated method stub 
    return new String[]{"/"}; 
} 

}

ApplicationConfiguration.java

@Configuration 
@EnableWebMvc 
@ComponentScan(basePackages = "base package name") 
public class ApplicationConfiguration extends WebMvcConfigurerAdapter { 

private static final Logger LOGGER = LoggerFactory 
     .getLogger(ApplicationConfiguration.class); 

@Override 
public void addResourceHandlers(ResourceHandlerRegistry registry) { 
    registry.addResourceHandler("/secured/resources/**").addResourceLocations(
      "/secured/resources/"); 
} 

@Override 
public void addInterceptors(InterceptorRegistry intRegistry) { 
    UserInfoInterceptor interceptor = new UserInfoInterceptor(); 
    intRegistry.addInterceptor(interceptor); 
} 


@Override 
public void configureDefaultServletHandling(
     DefaultServletHandlerConfigurer configurer) { 
    configurer.enable(); 
} 

@Bean 
public InternalResourceViewResolver jspViewResolver() { 
    InternalResourceViewResolver bean = new InternalResourceViewResolver(); 
    bean.setPrefix("/secured/resources/html/"); 
    bean.setSuffix(".html"); 
    bean.setOrder(1); 
    return bean; 
} 


@Bean(name = "messageSource") 
public ReloadableResourceBundleMessageSource getMessageSource() { 
    ReloadableResourceBundleMessageSource resource = new ReloadableResourceBundleMessageSource(); 
    resource.setBasename("classpath:messages"); 
    resource.setDefaultEncoding("UTF-8"); 
    return resource; 
} 

@Bean 
public PropertyPlaceholderConfigurer getPropertyPlaceHolder() { 
    PropertyPlaceholderConfigurer prop = new PropertyPlaceholderConfigurer(); 
    Resource[] resource = new ClassPathResource[] { new ClassPathResource(
      "application.properties") }; 
    prop.setLocations(resource); 
    return prop; 
} 

}

SecurityConfiguration.java

@Configuration 
    @EnableWebSecurity 
    //@Order(Ordered.HIGHEST_PRECEDENCE) 
    public class SecurityConfiguration extends WebSecurityConfigurerAdapter{ 

     @Bean 
     @Override 
    public AuthenticationManager authenticationManager() throws Exception{ 
    return super.authenticationManager(); 
     } 

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

@Override 
protected void configure(HttpSecurity http) throws Exception { 
    http.addFilterBefore(getopenIdConnectAuthenticationFilter(), 
      AbstractPreAuthenticatedProcessingFilter.class); 
    http.exceptionHandling().authenticationEntryPoint(
      openIdAuthenticationEntryPoint()); 
    http.authorizeRequests().antMatchers("/**"); 
    http.logout(); 
    //  http.authenticationProvider(getAuthenticationProvider()); 
} 


@Bean 
public void setObjectPostProcessor(ObjectPostProcessor<Object> objectPostProcessor) { 
    super.setObjectPostProcessor(objectPostProcessor); 
} 

}

MethodSecurityConfiguration.java

@Configuration 
@EnableGlobalMethodSecurity(securedEnabled=true,prePostEnabled = true,  proxyTargetClass = true) 
public class MethodSecurityConfiguration { 

@Autowired 
SecurityConfiguration secConfig; 

@Autowired 
public void configureGlobal(AuthenticationManagerBuilder auth) 
     throws Exception { 
     auth.authenticationProvider(secConfig.getAuthenticationProvider()); 
    } 
    } 

SpringSecurityInitializer.java

public class SpringSecurityInitializer extends 
    AbstractSecurityWebApplicationInitializer { 

} 

我一直在努力实施开放ID连接Mitreid客户端和上面给出的配置了安全配置。基于MITREID Client的配置

当我部署我得到下面的错误

at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1904) [jboss-msc-1.2.2.Final.jar:1.2.2.Final] 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_40] 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_40] 
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_40] 
Caused by: java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.IllegalStateException: org.springframework.security.config.annotation.ObjectPostProcessor is a required bean. Ensure you have used @EnableWebSecurity and @Configuration 
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:222) 
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:87) 
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.start(UndertowDeploymentService.java:72) 
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.2.Final.jar:1.2.2.Final] 
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.2.Final.jar:1.2.2.Final] 
... 3 more 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.IllegalStateException: org.springframework.security.config.annotation.ObjectPostProcessor is a required bean. Ensure you have used @EnableWebSecurity and @Configuration 
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) 
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293) 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755) 
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) 
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) 
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) 
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) 
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) 
at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:173) 
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:193) 
... 7 more 
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.IllegalStateException: org.springframework.security.config.annotation.ObjectPostProcessor is a required bean. Ensure you have used @EnableWebSecurity and @Configuration 
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) 
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) 
... 25 more 
Caused by: java.lang.IllegalStateException: org.springframework.security.config.annotation.ObjectPostProcessor is a required bean. Ensure you have used @EnableWebSecurity and @Configuration 
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter$1.postProcess(WebSecurityConfigurerAdapter.java:78) 
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.getHttp(WebSecurityConfigurerAdapter.java:175) 
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.init(WebSecurityConfigurerAdapter.java:283) 
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.init(WebSecurityConfigurerAdapter.java:68) 
at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.init(AbstractConfiguredSecurityBuilder.java:367) 
at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.doBuild(AbstractConfiguredSecurityBuilder.java:320) 
at org.springframework.security.config.annotation.AbstractSecurityBuilder.build(AbstractSecurityBuilder.java:39) 
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.springSecurityFilterChain(WebSecurityConfiguration.java:92) 
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration$$EnhancerBySpringCGLIB$$96834940.CGLIB$springSecurityFilterChain$3(<generated>) 
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration$$EnhancerBySpringCGLIB$$96834940$$FastClassBySpringCGLIB$$7ad1d6c4.invoke(<generated>) 
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) 
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309) 
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration$$EnhancerBySpringCGLIB$$96834940.springSecurityFilterChain(<generated>) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_40] 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_40] 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_40] 
at java.lang.reflect.Method.invoke(Method.java:497) [rt.jar:1.8.0_40] 
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) 
... 26 more 

已经包含了安全的相关部分configuration.Tried覆盖ObjectPostProcessor的建议here但我得到同样的错误。注意:不使用弹簧靴或弹簧加载。 我无法弄清楚我犯的错误。任何帮助都非常感谢。提前感谢。

Spring version : 4.1.6.RELEASE 
Spring security verison : 4.0.1.RELEASE 
+0

我试图解决这个过去的几天,但它就像我碰到了一堵砖墙。 – Ananth

回答

0

的jwtstore配置是造成与弹簧安全问题configuration.Moved相关代码到另一个类,它得到了工作。

+0

请您详细说明您的解决方案吗?几个小时后我撞到了同一堵墙。 –

+2

我解决了我的问题。我已经浏览了所有的spring初始化警告,并注意到我的'@Bean(name =“sAMLBootstrap”) public static SAMLBootstrap sAMLBootstrap() { {0128}返回新的SAMLBootstrap(); }'没有被声明为'静态',并且spring会警告我,否则依赖关系将不可用于自动装配。添加了与'ObjectPostProcessor'相关的静态异常之后。 –

+0

@JenyaG很好的建议! –