0. Quartz Quartz는 스케줄러를 위한 라이브러리이다. 일정한 시간이나 날짜마다 작업을 수행하기 위해 사용한다. 1. 의존 라이브러리 추가 pom.xml에 다음과 같이 라이브러리를 추가한다. org.quartz-scheduler quartz 2.3.2 org.springframework spring-context-support 5.2.5.RELEASE 2. Quartz 스케줄러 설정 root-context.xml에서 Quartz 스케줄러를 설정한다.
0. AuthenticationSuccessHandler 스프링 시큐리티에서는 authentication-success-hander-ref 를 통해 로그인에 성공했을 경우 작업을 수행할 클래스를 설정할 수 있다. 이 경우 로그인 했을 때 필요한 작업을 수행할 수 있지만 onAuthenticationSuccess()의 파라미터로 받는 HttpServletRequest 또는 HttpServletResponse를 사용해 다음으로 진행할 경로를 지정해주어야 한다. 1. SavedRequestAwareAuthenticationSuccessHandler AuthenticationSuccessHandler를 사용하지 않았을 경우, 스프링 시큐리티에서는 기본적으로 SavedRequestAwareAuthenticatio..
0. 다중 로그인 화면 여러 개의 로그인 화면에 대해 시큐리티 처리를 하고자 한다. 고객 테이블과 직원 테이블이 각자 분리되어 있고 각 테이블에 대해 서로 다른 로그인 폼을 사용하게 된다. 1. security-context.xml 로그인에 대한 처리를 설정하는 security-context.xml에서 이를 설정하면 된다. 와 를 고객과 직원 각각에게 만들어주면 된다. 핵심은 의 pattern과 authentication-manager-ref 라는 속성이다. pattern은 이 보안 설정을 어느 경로에서 적용할지 지정한다. 경로가 다음과 같이 '/customer/**'일 경우, URI가 '/customer'로 시작하는 모든 경로에 대해 이 보안 설정을 적용하게 된다. 그리고 authentication-m..
0. 스프링 시큐리티의 설정 XML 파일에서 안에서 태그를 사용할 수 있다. 이름 그대로 세션 관리 설정을 위한 영역이다. 태그 안에는 태그를 사용할 수 있다. 세션의 동시성(Concurrency) 과 관련된 설정을 할 수 있는데 여기서 max-session을 "1"로 주면 서버에서 계정 당 한 명만 로그인할 수 있도록 설정할 수 있다. error-if-maximum-exceeded 설정에는 최대 로그인 가능 수를 넘으면 에러를 발생시킬지 여부를 설정한다. 이렇게 설정한 뒤, 최대 접속자 수를 넘으면 에러가 발생하는데 session-management의 session-authentication-error-url 로 에러 페이지 경로를 설정할 수 있다.
0. 컨트롤러의 메서드에서 Authentication 객체 받기 요청을 받아 처리하는 컨트로러 메서드들은 Authentication 객체를 파라미터로 받을 수 있다. 이 Authentication 객체를 사용하여 사용자의 간단한 정보를 확인하거나 getPrincipal() 메서드를 통해 로그인 처리에 사용했던 UserDetails의 구현 클래스를 반환받을 수 있다. @GetMapping("/test") public String test(Authentication auth) { // 사용자 아이디 String memId = auth.getName(); // 로그인에 사용했던 UserDetails의 구현 클래스로 변환 AuthUser user = (AuthUser) auth.getPrincipal(); Me..
0. Servlet-Context.xml 1. 시큐리티 스키마 추가 xmlns:security="http://www.springframework.org/schema/security" http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd 2. 어노테이션 활성화 1. 어노테이션 적용 // 요청 URI : /board/register ~ 로그인한 회원만 접근 가능 @PreAuthorize("hasRole('ROLE_MEMBER')") @GetMapping("/register") public String register() { return "board/regist..
0. 의존 라이브러리 추가 org.springframework.security spring-security-core 5.2.5.RELEASE org.springframework.security spring-security-web 5.2.5.RELEASE org.springframework.security spring-security-config 5.2.5.RELEASE org.springframework.security spring-security-taglibs 5.2.5.RELEASE 1. web.xml 작성 1. 수정 의 에 시큐리티에 관련한 설정을 작성할 security-context.xml 에 대한 경로를 추가한다. contextConfigLocation /WEB-INF/spring/root-co..