|
@@ -5,6 +5,7 @@ import com.its.op.webapp.handler.LoginSuccessHandler;
|
|
|
import com.its.op.webapp.security.WebPasswordEncoder;
|
|
import com.its.op.webapp.security.WebPasswordEncoder;
|
|
|
import com.its.op.webapp.service.WebLoginService;
|
|
import com.its.op.webapp.service.WebLoginService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
+import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
import org.springframework.http.HttpMethod;
|
|
import org.springframework.http.HttpMethod;
|
|
@@ -14,9 +15,11 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
|
|
import org.springframework.security.config.annotation.web.builders.WebSecurity;
|
|
import org.springframework.security.config.annotation.web.builders.WebSecurity;
|
|
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
|
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
|
|
|
+import org.springframework.security.config.http.SessionCreationPolicy;
|
|
|
import org.springframework.security.core.session.SessionRegistry;
|
|
import org.springframework.security.core.session.SessionRegistry;
|
|
|
import org.springframework.security.core.session.SessionRegistryImpl;
|
|
import org.springframework.security.core.session.SessionRegistryImpl;
|
|
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
|
|
|
+import org.springframework.security.web.session.HttpSessionEventPublisher;
|
|
|
|
|
|
|
|
@Configuration
|
|
@Configuration
|
|
|
@EnableWebSecurity
|
|
@EnableWebSecurity
|
|
@@ -56,11 +59,12 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|
|
.antMatchers("/application/facility/**", "/facility/**").permitAll()
|
|
.antMatchers("/application/facility/**", "/facility/**").permitAll()
|
|
|
.antMatchers("/application/wall/**", "/wall/**").permitAll()
|
|
.antMatchers("/application/wall/**", "/wall/**").permitAll()
|
|
|
.antMatchers("/application/login/**").permitAll()
|
|
.antMatchers("/application/login/**").permitAll()
|
|
|
|
|
+ .antMatchers("/api/auth/**").permitAll()
|
|
|
.anyRequest().authenticated()
|
|
.anyRequest().authenticated()
|
|
|
.and()
|
|
.and()
|
|
|
.formLogin()
|
|
.formLogin()
|
|
|
.loginPage("/application/login/login.html")
|
|
.loginPage("/application/login/login.html")
|
|
|
- .loginProcessingUrl("/login.do")
|
|
|
|
|
|
|
+ .loginProcessingUrl("/api/auth/login.do")
|
|
|
.defaultSuccessUrl("/application/op/00.main/main.html", true)
|
|
.defaultSuccessUrl("/application/op/00.main/main.html", true)
|
|
|
.usernameParameter("username")
|
|
.usernameParameter("username")
|
|
|
.passwordParameter("password")
|
|
.passwordParameter("password")
|
|
@@ -68,11 +72,26 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|
|
.failureHandler(this.loginFailureHandler)
|
|
.failureHandler(this.loginFailureHandler)
|
|
|
.permitAll()
|
|
.permitAll()
|
|
|
.and()
|
|
.and()
|
|
|
-// .logout()
|
|
|
|
|
-// .invalidateHttpSession(true)
|
|
|
|
|
-// .deleteCookies("JSESSIONID")
|
|
|
|
|
-// .logoutSuccessUrl("/login.do")
|
|
|
|
|
-// .permitAll()
|
|
|
|
|
|
|
+ .logout()
|
|
|
|
|
+ .invalidateHttpSession(true)
|
|
|
|
|
+ .deleteCookies("JSESSIONID")
|
|
|
|
|
+ .deleteCookies(WebConfig.USER_UUID)
|
|
|
|
|
+ .deleteCookies(WebConfig.USER_TIME)
|
|
|
|
|
+ .logoutSuccessUrl("/api/auth/login.do").permitAll()
|
|
|
|
|
+ .and()
|
|
|
|
|
+ .sessionManagement()
|
|
|
|
|
+ .sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED) // 스프링 시큐리티가 필요 시 생성 (default)
|
|
|
|
|
+ // 인증에 성공할 때 마다 세션 ID나 세션을 변경해서 발급해줌으로써
|
|
|
|
|
+ // 세션을 중간에서 가로채더라도 해당 세션이 유효하지 않게 하는 기능
|
|
|
|
|
+ .invalidSessionUrl("/api/auth/login.do") // 세션이 유효하지 않을 경우 이동 할 페이지
|
|
|
|
|
+ .sessionFixation().changeSessionId() // changeSessionId : 새로운 세션 ID를 발급해서 전달(default)
|
|
|
|
|
+ // none : 아무 동작 안함
|
|
|
|
|
+ // migrateSession : 새로운 세션을 생성해서 전달 (속성값 유지)
|
|
|
|
|
+ // newSession : 새로운 세션 전달 (속성값 유지 안됨)
|
|
|
|
|
+ .maximumSessions(20) // 최대 허용 가능 세션 수, -1인 경우 무제한 세션 허용
|
|
|
|
|
+ .maxSessionsPreventsLogin(true) // 동시 로그인 차단, false 인 경우 기존 세션 만료(default)
|
|
|
|
|
+ .expiredUrl("/api/auth/logout.do") // 세션이 만료된 경우 이동 할 페이지
|
|
|
|
|
+ .sessionRegistry(sessionRegistry())
|
|
|
// .and()
|
|
// .and()
|
|
|
// .exceptionHandling()
|
|
// .exceptionHandling()
|
|
|
// .accessDeniedPage("/login.do")
|
|
// .accessDeniedPage("/login.do")
|
|
@@ -94,16 +113,6 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|
|
// .exceptionHandling().accessDeniedPage("/login");
|
|
// .exceptionHandling().accessDeniedPage("/login");
|
|
|
;
|
|
;
|
|
|
|
|
|
|
|
-// http.sessionManagement()
|
|
|
|
|
-// .sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED)
|
|
|
|
|
-// .invalidSessionUrl("/login")
|
|
|
|
|
-// .sessionFixation()
|
|
|
|
|
-// .migrateSession()
|
|
|
|
|
-// .maximumSessions(5)
|
|
|
|
|
-// .maxSessionsPreventsLogin(true)
|
|
|
|
|
-// .expiredUrl("/login")
|
|
|
|
|
-// .sessionRegistry(sessionRegistry())
|
|
|
|
|
-// ;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public DaoAuthenticationProvider daoAuthenticationProvider() {
|
|
public DaoAuthenticationProvider daoAuthenticationProvider() {
|
|
@@ -134,4 +143,13 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|
|
return new SessionRegistryImpl();
|
|
return new SessionRegistryImpl();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 로그아웃을 했기 때문에 세션의 개수가 0이라 생각했는데 로그인이 안되었다.
|
|
|
|
|
+ * 이에 대한 해결책으로 SessionRegistry 빈을 생성 후 sessionManagement 에 DI 시킨다.
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @Bean
|
|
|
|
|
+ public static ServletListenerRegistrationBean httpSessionEventPublisher() {
|
|
|
|
|
+ return new ServletListenerRegistrationBean(new HttpSessionEventPublisher());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|