Sanjay
Sanjay

Reputation: 315

username and password retrieval in spring security

As per Spring Security version 4, j_username and j_password are deprecated, and username and password should be used in JSP.

I see these variables are defined in UsernamePasswordAuthenticationFilter.

Can we override the properties through some external configuration so that it looks for j_username?

Upvotes: 1

Views: 504

Answers (1)

Marcus Hert da Coregio
Marcus Hert da Coregio

Reputation: 6258

You can override the default parameter names this way:

@Bean
public SecurityFilterChain formLoginFilterChain(HttpSecurity http) throws Exception {
    http
            ...
            .formLogin((form) -> form
                    .usernameParameter("j_username")
                    .passwordParameter("j_password")
            );
    return http.build();
}

This way Spring Security will look for these parameters in the HTTP request when performing authentication.

Upvotes: 1

Related Questions