SpringSecurity : Configure In Memory Authentication

Configure Spring Security to Authenticate user using In-Memory Authentication.

To implement inMemory authentication, all you need to do is

  1. extend WebSecurityConfigurerAdapter.
  2. override configure(AuthenticationManagerBuilder) method
  3. add username, password and roles/authorities for authentication.

After adding the following class to your application, you will be able to login using these username password pairs.

package com.ekiras.ss.config;

import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

 * @author ekiras
public class SpringSecurityConfigurer extends WebSecurityConfigurerAdapter{

    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
                .roles("USER", "ROLE");


As shown in the code above, we have configured two user-password pairs,

  1. username : user , password : user and role/authorities : USER.
  2. username : admin , password : admin and role/authorities : ADMIN.


You can use any of the above pairs to login and authenticate user. First, can be used for requests that can be accessed by USER role and Second can be used to access the requests with ADMIN role.

Also Read

    Download project from Github

No comments :

Post a Comment