⛏️/Spring

[Spring] 로그인 성공시 권한별로 페이지 이동

defyuil 2023. 12. 29. 09:22

로그인 성공시 권한별로 페이지 이동

CustomLoginSuccessHandler 생성

  • 로그인 성공시 권한별로 페이지 이동

상속 - 오버라이딩 - 객체생성(security-context)

servlet-context

시큐리티 관련 객체 생성

로그인 시 아무 화면도 안뜸

CustomLoginSuccessHandler

사용자의 권한 정보를 저장

람다식 사용하여 함수 호출

ctrl+1 ⇒

람다식을 기존 오버라이딩 형태로 변환해줌

각 권한별로 페이지 이동

 

package com.itwillbs.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping(value = "/sample/*")
public class SampleController {
	private static final Logger logger = LoggerFactory.getLogger(SampleController.class);

	//http://localhost:8088/sample/all
	@RequestMapping(value = "/all",method = RequestMethod.GET)
	public void doALL() throws Exception{
		logger.debug("/sample/all -> doALL() 실행");
	}
	
	//http://localhost:8088/sample/member
	@RequestMapping(value = "/member",method = RequestMethod.GET)
	public void doMember() throws Exception{
		logger.debug("/sample/member -> doMember() 실행");
	}
	
	//http://localhost:8088/sample/admin
	@RequestMapping(value = "/admin",method = RequestMethod.GET)
	public void doAdmin() throws Exception{
		logger.debug("/sample/adminb -> doAdmin() 실행");
	}
}