Junior — Middle
Have you used filters within Spring Security to configure application protection?
sobes.tech AI
Answer from AI
In Spring Security, filters are used to intercept HTTP requests and perform various security tasks such as authentication, authorization, logging, etc.
Experience with filters includes:
- Configuring the filter chain, where each filter is responsible for a specific security aspect.
- Creating custom filters, for example, for handling JWT tokens or custom authentication.
- Using standard Spring Security filters like UsernamePasswordAuthenticationFilter, BasicAuthenticationFilter.
An example of creating a simple logging filter:
public class LoggingFilter extends GenericFilterBean {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
System.out.println("Request to: " + req.getRequestURI());
chain.doFilter(request, response);
}
}
This filter can be registered in the security configuration to handle all incoming requests.