com.github.yingzhuo.spring.security.jwt.RawToken Maven / Gradle / Ivy
/* _ _ _ _ _
* ___ _ __ _ __(_)_ __ __ _ ___ ___ ___ _ _ _ __(_) |_ _ _ _ __ __ _| |_ ___| |__
* / __| '_ \| '__| | '_ \ / _` |_____/ __|/ _ \/ __| | | | '__| | __| | | |_____| '_ \ / _` | __/ __| '_ \
* \__ \ |_) | | | | | | | (_| |_____\__ \ __/ (__| |_| | | | | |_| |_| |_____| |_) | (_| | || (__| | | |
* |___/ .__/|_| |_|_| |_|\__, | |___/\___|\___|\__,_|_| |_|\__|\__, | | .__/ \__,_|\__\___|_| |_|
* |_| |___/ |___/ |_|
*
* https://github.com/yingzhuo/spring-security-patch
*/
package com.github.yingzhuo.spring.security.jwt;
import com.github.yingzhuo.spring.security.jwt.parser.JwtTokenParser;
import org.springframework.core.MethodParameter;
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;
import java.lang.annotation.*;
/**
* @author 应卓
* @since 1.0.0
*/
@Documented
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
public @interface RawToken {
public static class RawTokenHandlerMethodArgumentResolver implements HandlerMethodArgumentResolver {
private final JwtTokenParser jwtTokenParser;
public RawTokenHandlerMethodArgumentResolver(JwtTokenParser jwtTokenParser) {
this.jwtTokenParser = jwtTokenParser;
}
@Override
public boolean supportsParameter(MethodParameter parameter) {
return parameter.hasParameterAnnotation(RawToken.class) &&
parameter.getParameterType() == String.class;
}
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) {
return jwtTokenParser.parseAsString(webRequest);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy