@Configuration
@EnableWebMvc
@EnableConfigurationProperties(ProjectProperties.class)
@EnableScheduling
@EnableTransactionManagement
public class ApiWebMvcConfigurerAdapter implements WebMvcConfigurer {
...
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
argumentResolvers.add(new HandlerMethodArgumentResolver() {
@Override
public boolean supportsParameter(MethodParameter parameter) {
return UserAuthToken.class.isAssignableFrom(parameter.getParameterType()) && parameter.hasParameterAnnotation(ModelAttributeMapping.class);
}
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
// HttpServletRequest request = (HttpServletRequest) nativeWebRequest.getNativeRequest();
String jwt = webRequest.getHeader(HttpHeaders.AUTHORIZATION);
UserAuthToken userToken = tokenService.parserJwtToUserToken(jwt);
userToken.setToken(jwt);
return userToken;
}
});
}
}
@Slf4j
@RestController
@RequestMapping(UsersController.URI_PREFIX)
@Api(tags = "회원")
@Validated
public class UsersController {
public static final String URI_PREFIX = ApisController.URI_PREFIX + "/users";
...
@ApiOperation(value = "비밀번호변경")
@PutMapping(value = "/{no}/password")
public void putPassword(@PathVariable("no") Long no, @RequestBody RequestChangeId requestChangeId, HttpServletResponse response, @ModelAttributeMapping UserAuthToken userAuthToken) {
...
}
}