Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Spring interceptor that gets called before UsernamePasswordAuthenticationFilter?

I want to call a method before UsernamePasswordAuthenticationFilter.attemptAuthentication() is called (and before any other requests are handled in the app).

I tried calling the method in HandlerInterceptorAdapter.preHandle() but this is not triggered prior to attemptAuthentication() although it takes care of other types of requests.

Is there a Spring interceptor that gets called before UsernamePasswordAuthenticationFilter?

like image 941
Corrugate Avatar asked Sep 19 '11 11:09

Corrugate


People also ask

What is the difference between Spring interceptor and filter?

Filters can modify inbound and outbound requests and responses including modification of headers, entity and other request/response parameters. Interceptors are used primarily for modification of entity input and output streams. You can use interceptors for example to zip and unzip output and input entity streams.

Is WebSecurityConfigurerAdapter deprecated?

The type WebSecurityConfigurerAdapter is deprecatedWell, it's because the developers of Spring framework encourage users to move towards a component-based security configuration.

What are the levels of security in Spring?

Apart from authentication, spring security also check authorization of the logged in user. After login which user is authorize to access the resource is done on the bases of user's ROLE. At the time of creating user in WebSecurityConfig class, we can specify user?


1 Answers

I guess you are talking about the spring security filter chain.

Filters with this names should be invoked before UsernamePasswordAuthenticationFilter

  • FIRST
  • CHANNEL_FILTER,
  • CONCURRENT_SESSION_FILTER,
  • SECURITY_CONTEXT_FILTER,
  • LOGOUT_FILTER,
  • X509_FILTER,
  • PRE_AUTH_FILTER,
  • CAS_FILTER,

See source code of org.springframework.security.config.http.SecurityFilters for more details.


But you can also use before:

<security:custom-filter ref="myFiler" before="FORM_LOGIN_FILTER" />
like image 197
Ralph Avatar answered Nov 10 '22 00:11

Ralph