Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.mycompany.springboot.config; import com.mycompany.springboot.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; /** * * @author josiamu */ @Configuration public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Autowired private UserService userService; @Override protected void configure(HttpSecurity http) throws Exception { http.csrf().disable().authorizeRequests().anyRequest().authenticated().and().httpBasic(); // http // .csrf() // .disable() // .authorizeRequests() // .anyRequest() // .authenticated() // .and() // .formLogin() // .permitAll() // .and() // .logout() // .permitAll(); // http // .csrf() // .disable() // .authorizeRequests() // .anyRequest() // .authenticated() // .and() // .formLogin() // .loginPage("/login") // .permitAll() // .and() // .logout() // .permitAll(); } @Autowired public void configGlobal(AuthenticationManagerBuilder auth) throws Exception { //AuthenticationManagerBuilder spring bean ? spring autowired auth.inMemoryAuthentication().withUser("user").password("password").roles("USER").and().withUser("admin") .password("password").roles("ADMIN"); // auth // .userDetailsService(userService); } }