1 | package unicon.matthews.security.auth.jwt.extractor; |
||
2 | |||
3 | import org.apache.commons.lang3.StringUtils; |
||
4 | import org.springframework.security.authentication.AuthenticationServiceException; |
||
5 | import org.springframework.stereotype.Component; |
||
6 | |||
7 | /** |
||
8 | * An implementation of {@link TokenExtractor} extracts token from |
||
9 | * Authorization: Bearer scheme. |
||
10 | * |
||
11 | * @author vladimir.stankovic |
||
12 | * |
||
13 | * Aug 5, 2016 |
||
14 | */ |
||
15 | @Component |
||
16 | public class JwtHeaderTokenExtractor implements TokenExtractor { |
||
17 | public static String HEADER_PREFIX = "Bearer "; |
||
0 ignored issues
–
show
|
|||
18 | |||
19 | @Override |
||
20 | public String extract(String header) { |
||
21 | if (StringUtils.isBlank(header)) { |
||
22 | throw new AuthenticationServiceException("Authorization header cannot be blank!"); |
||
23 | } |
||
24 | |||
25 | if (header.length() < HEADER_PREFIX.length()) { |
||
26 | throw new AuthenticationServiceException("Invalid authorization header size."); |
||
27 | } |
||
28 | |||
29 | return header.substring(HEADER_PREFIX.length(), header.length()); |
||
30 | } |
||
31 | } |
||
32 |
See this CWE advisory on why this is a security issue.