How to move username/passwords out of spring-security-context.xml?

前端 未结 6 1425
一个人的身影
一个人的身影 2020-12-16 23:01

I am using Spring Security in one of my project. The web-app requires the user to login. Hence I have added few usernames and passwords in the spring-security-context.xml fi

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-16 23:40

    You can simply add Bean inside your Spring Security Configuration :

    @Bean
    public UserDetailsService userDetailsService() {
       Properties users = PropertiesLoaderUtils.loadAllProperties("users.properties");
       return new InMemoryUserDetailsManager(users);
    }
    

    and users.properties looks like :

    admin={noop}password,ROLE_USER,ROLE_ADMIN,enabled
    bob={noop}password,ROLE_USER,enabled
    123={noop}123,ROLE_USER,enabled
    

提交回复
热议问题