인터넷에서 spring security를 검색하면 한글 자료는 대부분 xml 설정으로 되어있다.
먼저 web.xml에 DelegateFilterProxy를 설정하는 것부터 나온다.
그리고 나머지 설정을 외우거나 복붙해서 만든다.
반면 java 설정은 자동완성과 클래스를 들여다 보기때문에 공부하는데 더 좋다.
설정도 web.xml에 필터를 등록할 필요 없다.
<dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-web</artifactId> <version>5.0.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-config</artifactId> <version>5.0.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-taglibs</artifactId> <version>5.0.0.RELEASE</version> </dependency>자바 설정은 다음 클래스로 시작한다.
@Configuration
@EnableWebSecurity
public class CustomSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter
클래스로 시작하면 된다.
클래스 멤버는 다음과 같다.
@Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication() .withUser("user1").password("user1Pass") .authorities("ROLE_USER"); }
}
경로에 권한 설정과 로그인 페이지 설정을 한다. 로그인 페이지 설정을 안하면 브라우저 prompt로 인증을 요구한다. 로그인 페이지 url을 설정안하면 디폴트 로그인 페이지가 나온다.@Override protected void configure(HttpSecurity http) throws Exception { logger.info("http: "+http); http.httpBasic(); http.authorizeRequests().antMatchers("/main/**").hasRole("USER"); http.formLogin().loginPage("/login") .usernameParameter("username").passwordParameter("password") .permitAll() .and(); }spring-security 시작은 단순하다.
'스프링(Spring)' 카테고리의 다른 글
AspectJ @annotaion 표현식 (0) | 2018.01.28 |
---|---|
spring security#2 DB를 통한 인증 (0) | 2018.01.17 |
Invalid character found in method name. HTTP method names must be tokens (0) | 2018.01.15 |
Spring + Mysql + MyBatis (0) | 2017.10.29 |
스프링 설정#4 예외처리 하기 (0) | 2017.10.06 |