liujie
2026-09-09 39f6fca28e3f78abe48f08e474ec011abb990b36
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package com.tourguide.security;
 
import com.tourguide.common.exception.BusinessException;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
 
/** 统一解析 Authorization 请求头,避免三个客户端重复实现 Bearer Token 截取逻辑。 */
@Component
public class BearerTokenResolver {
    public String resolve(String authorization) {
        if (!StringUtils.hasText(authorization) || !authorization.startsWith("Bearer ")) {
            throw new BusinessException(401, "缺少有效Token");
        }
        return authorization.substring(7);
    }
}