본문 바로가기

Programming!

Spring Boot 1.5 Security 적용

신규 플젝에서 Spring Security 를 적용하면서 몇가지 트러블.


@EnableWebSecurity

@Configuration

public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override

    protected void configure(HttpSecurity httpSecurity) throws Exception {

        httpSecurity.authorizeRequests()

            .antMatchers("/", "/index", "/health").permitAll()

            .antMatchers("/{serviceRoleType}/**").access("@guard.validServiceRoleType(authentication,#serviceRoleType)")

            .antMatchers("/stay/**").authenticated()

            .antMatchers("/gormet/**").authenticated()

            .anyRequest().authenticated()

            .and()

            .formLogin()

            .usernameParameter("username")

            .passwordParameter("password")

            .loginPage("/login")

            .successHandler(successHandler)

            .failureHandler(failureHandler)

            .permitAll()

            .and()

            .logout()

            .permitAll();

        httpSecurity.csrf().disable().exceptionHandling().accessDeniedPage("/403");

...


1.

레퍼런스를 보고 위와 같이 configure 를 Override 해서 돌려보니 Login이 해제되는 현상이 있었다. 아오 뭐가 문제지...하면서 소스를 파고 들어가보니 httpSecurity 의 체인 형태가 좀... 즉 httpSecurity. 를 두번 지정하니 위의 것이 초기화된 문제였다. 아.. 해서 .and() 로 묶어서 해결.

(시파! 어느 사이트의 레퍼런스...)




    @Override

    public void configure(WebSecurity webSecurity) throws Exception {

        webSecurity.ignoring().antMatchers("/static/**", "/resources/**");

    }


2.

이 주소와 thymeleaf 와 <img src=" ... 주소처리. 아씨... 이것도 햇갈려서 죽는줄 알았네..




    @Override

    protected void configure(AuthenticationManagerBuilder auth) throws Exception {

        auth.userDetailsService(userDetailsService).passwordEncoder(pelicanPasswordEncoder);

    }


3.

별도의 password 정책이 있다면 passwordEncoder 추가.