[2023-07-13]
- Token 생성시 필요 Data( 고유ID, 조직명등..) 추가. - @AuthenticationPrincipal LoginVo NullpointException 처리 - CustomAuthenticationPrincipalResolver - 컨트롤러 불필요 권한체크 코드 제거main
parent
940be3e28a
commit
e29717c84b
@ -0,0 +1,45 @@
|
||||
package egovframework.com.security;
|
||||
|
||||
import egovframework.com.cmm.LoginVO;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.web.bind.support.WebDataBinderFactory;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
import org.springframework.web.method.support.ModelAndViewContainer;
|
||||
|
||||
/**
|
||||
* fileName : CustomAuthenticationPrincipalResolver
|
||||
* author : crlee
|
||||
* date : 2023/07/13
|
||||
* description :
|
||||
* ===========================================================
|
||||
* DATE AUTHOR NOTE
|
||||
* -----------------------------------------------------------
|
||||
* 2023/07/13 crlee 최초 생성
|
||||
*/
|
||||
public class CustomAuthenticationPrincipalResolver implements HandlerMethodArgumentResolver {
|
||||
|
||||
@Override
|
||||
public boolean supportsParameter(MethodParameter parameter) {
|
||||
return parameter.hasParameterAnnotation(AuthenticationPrincipal.class) &&
|
||||
parameter.getParameterType().equals(LoginVO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
|
||||
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (authentication == null ||
|
||||
authentication.getPrincipal() == null ||
|
||||
"anonymousUser".equals(authentication.getPrincipal())
|
||||
) {
|
||||
return new LoginVO();
|
||||
}
|
||||
|
||||
return authentication.getPrincipal();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
package egovframework.com.security;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* fileName : WebMvcConfig
|
||||
* author : crlee
|
||||
* date : 2023/07/13
|
||||
* description :
|
||||
* ===========================================================
|
||||
* DATE AUTHOR NOTE
|
||||
* -----------------------------------------------------------
|
||||
* 2023/07/13 crlee 최초 생성
|
||||
*/
|
||||
@Configuration
|
||||
public class WebMvcConfig implements WebMvcConfigurer {
|
||||
@Override
|
||||
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
|
||||
argumentResolvers.add(new CustomAuthenticationPrincipalResolver());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue