Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8513933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:43:20+00:00 2026-06-11T04:43:20+00:00

Spring security (2.0.x) http namespace, form-login definition automatically uses AuthenticationProcessingFilter. <form-login login-page=’/logon.jsp’ default-target-url=’/home.jsp’ always-use-default-target=’true’

  • 0

Spring security (2.0.x) http namespace, form-login definition automatically uses AuthenticationProcessingFilter.

<form-login login-page='/logon.jsp' 
default-target-url='/home.jsp' 
always-use-default-target='true' />

I also know that If I set auto-config="false" I can customise authentication by providing custom bean definition.

I have CustomAuthenticationProcessingFilter that extends AuthenticationProcessingFilter overrides obtainUsername and uses custom logic to get username than the one passed.

protected String obtainUsername(HttpServletRequest request) {
   // custom logic to return username from parameter/cookies/header etc ... 
}

Is it possible to use CustomAuthenticationProcessingFilter while still using auto-config="true" <form-login> without needing to define customAuthFilter and all dependent beans ?

  <beans:bean id="customAuthFilter" class="x.y.z.CustomAuthenticationProcessingFilter">
    <custom-filter  position="AUTHENTICATION_PROCESSING_FILTER" />
    <beans:property name="defaultTargetUrl" value="/home.jsp"></beans:property>
    ...
    ...
  </beans:bean>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T04:43:22+00:00Added an answer on June 11, 2026 at 4:43 am

    The fact is that spring’s namespace handler internally defines bean with the name _formLoginFilter for AuthenticationProcessingFilter (See for BeanIds complete list). There are coulpe of ways to workaround with this issue (i.e to authenticate using something other than j_username from DaoAuthenticationProvider , like say take username from header etc… )

    Use Spring AOP bean() syntax to intercept doFilter()

    Define a pointcut that looks for bean with name _formLoginFilter and intercepts doFiltermethod. ( AuthenticationProcessingFilter.doFilter() method) and conditionally delegate to something else

    public class AuthenticationProcessingFilterAspect {
      private static final Logger LOGGER = LoggerFactory.getLogger(AuthenticationProcessingFilterAspect.class);
      public Object intercept(ProceedingJoinPoint pjp) throws Throwable {
        LOGGER.info("intercept------------------{}",pjp.toLongString());
        //Delegate to customised method instead of default  pjp.proceed()
        return pjp.proceed();
      }
    }
    

    Config

    <beans:bean id="authFilterAspect" class="x.y.z.AuthenticationProcessingFilterAspect" />
    <aop:config>
      <aop:aspect ref="authFilterAspect">
        <aop:around pointcut="bean(_formLoginFilter) &amp;&amp; execution(* doFilter(..))" method="intercept"/>
      </aop:aspect>
    </aop:config>
    

    Use CustomWebAuthenticationDetails to do authentication

    Define a bean postprocessor for AuthenticationProcessingFilter bean that injects CustomWebAuthenticationDetails which populates custom fields

    public class AuthenticationProcessingFilterBeanPostProcessor implements
        BeanPostProcessor {
    
      private static final Logger LOGGER = LoggerFactory.getLogger(AuthenticationProcessingFilterBeanPostProcessor.class);
    
      public Object postProcessAfterInitialization(Object bean, String beanName)
          throws BeansException {
        if ("_formLoginFilter".equals(beanName) && bean instanceof AuthenticationProcessingFilter) {
          AuthenticationProcessingFilter filter = (AuthenticationProcessingFilter) bean;
          WebAuthenticationDetailsSource source = (WebAuthenticationDetailsSource) filter.getAuthenticationDetailsSource();
          source.setClazz(CustomWebAuthenticationDetails.class);
        }
        return bean;
      }
    
      public Object postProcessBeforeInitialization(Object bean, String beanName)
          throws BeansException {
        return bean;
      }
    
      @SuppressWarnings("serial")
      public static class CustomWebAuthenticationDetails extends
          WebAuthenticationDetails {
        private String customAttribute;//customfield
        public CustomWebAuthenticationDetails(HttpServletRequest request) {
          super(request);
          //Build custom attributes that could be used elsewhere (say in DaoAuthenticationProvider ) 
          //with (CustomWebAuthenticationDetails)authentication.getDetails()
          customAttribute = request.getHeader("username");
        }
        public boolean getCustomAttribute() {
          return customAttribute;
        }
      }
    }
    

    Config

    <beans:bean id="authFilterProcessor" class="x.y.z.AuthenticationProcessingFilterBeanPostProcessor" />
    

    Use thread bound request to do actual authentication (within DaoAuthenticationProvider)

    Use getHttpServletRequest() to access threadbound request object and use request.getHeader(“username”) to do custom authentication.

    public static HttpServletRequest getHttpServletRequest(){
      return((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
    }
    

    Also need to Define this in web.xml if request is not through DispatcherServlet

    <filter>
      <filter-name>requestContextFilter</filter-name>
      <filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
    </filter>
    <filter-mapping>
      <filter-name>requestContextFilter</filter-name>
      <url-pattern>/j_spring_security_check</url-pattern>
      <dispatcher>FORWARD</dispatcher>
      <dispatcher>REQUEST</dispatcher>
    </filter-mapping>
    <filter-mapping>
      <filter-name>requestContextFilter</filter-name>
      <url-pattern>/j_spring_security_logout</url-pattern>
      <dispatcher>FORWARD</dispatcher>
      <dispatcher>REQUEST</dispatcher>
    </filter-mapping>
    

    If its faces application use FacesContext.getCurrentInstance()

    public static HttpServletRequest getHttpServletRequest(){
        FacesContext context = FacesContext.getCurrentInstance();
        return (HttpServletRequest) context.getExternalContext().getRequest();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Spring Security 3 and my ApplicationContext-Security.xml specifies <form-login login-page=/genesis default-target-url=/diagnostics/start-diagnostics authentication-failure-url=/genesis?authfailed=true authentication-success-handler-ref=customTargetUrlResolver/>
At my project I use Spring Security and GWT with url-like internationalization (http://....html?locale=en). Login
I’m trying to convert Spring Security configuration from HTTP namespace into direct configuration using
Following the spring-security documentation: http://static.springsource.org/spring-security/site/docs/3.0.x/reference/ldap.html I am trying to set up ldap authentication (very
I've implemented authentication through WS-Security on my webservice as described at http://static.springframework.org/spring-ws/sites/1.5/reference/html/security.html , like
Does the Spring Security plugin for Grails support automatically locking an account after X
I'm trying to add <session-management> in my Spring Security namespace configuration so that I
I am trying to use PreAuthFilter (for Siteminder) with Spring Security 3.0. <http use-expressions=true>
I am new to spring security I have web.xml <?xml version=1.0 encoding=UTF-8?> <web-app xmlns=http://java.sun.com/xml/ns/javaee
I have the following spring security configuration: <security:http> ...... <security:intercept-url pattern=/auth/** access=ROLE_ADMIN/> ......... </security:http>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.