Spring Security using HTTP headers

前端 未结 4 920
青春惊慌失措
青春惊慌失措 2021-02-14 12:05

I am trying to add security to my Spring Boot application. My current application is using REST controllers and every time I get a GET or POST request

4条回答
  •  遥遥无期
    2021-02-14 13:01

    In memory authentication would serve your purpose

    @Configuration
    @EnableWebMvc
    public class SecurityConfig extends WebSecurityConfigurerAdapter {
    
        @Override
        protected void configure(AuthenticationManagerBuilder auth) throws Exception {
            auth.inMemoryAuthentication()
            .withUser("user1").password("password1").roles("USER")
            .and()
            .withUser("user2").password("password2").roles("ADMIN");
        }
    
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.authorizeRequests().anyRequest().fullyAuthenticated();
            http.httpBasic();   
        }
    
    }
    

提交回复
热议问题