Skip to content

Enable to Add Spring DelegatingFilterProxy Filter to Handler #68

Closed
@navalgandhi1989

Description

@navalgandhi1989

Hi,

I am trying to Run a Spring Code on Lambda. Everything works except Spring's URL Based Security. I Tried adding the springSecurityFilterChain filter my self but it gives the following exception.

	 java.lang.IllegalArgumentException: FilterConfig must not be null
		at org.springframework.util.Assert.notNull(Assert.java:134)
		at org.springframework.web.filter.GenericFilterBean.init(GenericFilterBean.java:175)
		at com.amazonaws.serverless.proxy.internal.servlet.FilterHolder.init(FilterHolder.java:84)
		at com.amazonaws.serverless.proxy.internal.servlet.FilterChainHolder.doFilter(FilterChainHolder.java:83)
		at com.amazonaws.serverless.proxy.internal.servlet.AwsLambdaServletContainerHandler.doFilter(AwsLambdaServletContainerHandler.java:184)
		at com.amazonaws.serverless.proxy.spring.SpringLambdaContainerHandler.handleRequest(SpringLambdaContainerHandler.java:139)
		at com.amazonaws.serverless.proxy.spring.SpringLambdaContainerHandler.handleRequest(SpringLambdaContainerHandler.java:35)
		at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxy(LambdaContainerHandler.java:126)

Below is my Code

App Config

	 @Configuration
	 @EnableWebMvc
	 @EnableAspectJAutoProxy
	 @ComponentScan(basePackages = "com.sample")
	 @PropertySource(value = { "classpath:config.properties" })
	 public class AppConfiguration {

	 }

WebSecurity Config

	 @Configuration
	 @EnableWebSecurity
	 @EnableGlobalMethodSecurity(prePostEnabled = true)
	 public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
	 
	 @Override
		 protected void configure(HttpSecurity http) throws Exception {
			 
			 http.csrf().disable();
			 http.exceptionHandling().authenticationEntryPoint(restAuthenticationEntryPoint);
			 http.authorizeRequests().antMatchers(HttpMethod.OPTIONS).permitAll();
			 http.formLogin().loginPage("/login").permitAll();
			 http.logout().logoutUrl("/logout").logoutSuccessHandler(restLogoutSuccessHandler);
			 http.authorizeRequests().antMatchers("/**").authenticated();
			 http.addFilterBefore(authenticationFilter(),UsernamePasswordAuthenticationFilter.class);
		 }
	 
	 }

Request Handler Method

	 @Override
	 public AwsProxyResponse handleRequest(AwsProxyRequest awsProxyRequest, Context context) {
	 
	 if(handler == null)
	 {
		 try {
			 handler = SpringLambdaContainerHandler.getAwsProxyHandler(AppConfiguration.class);
			 
			 handler.onStartup(servletContext -> {
				 
				 Dynamic securityFilter = servletContext.addFilter(AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME, DelegatingFilterProxy.class);
				 securityFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*");
				 
			 });
			 
		 } catch (ContainerInitializationException e) {
			 e.printStackTrace();
		 }
	 }
	 
	 return handler.proxy(awsProxyRequest, context);
	 } 

I am not able to find any way to initialize the filterConfig variable of FilterHolder class.

Please a look into the issue.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions