1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.security.token;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.apache.hadoop.io.Text;
24 import org.apache.hadoop.security.token.Token;
25 import org.apache.hadoop.security.token.TokenIdentifier;
26 import org.apache.hadoop.security.token.TokenSelector;
27
28 import java.util.Collection;
29
30 public class AuthenticationTokenSelector
31 implements TokenSelector<AuthenticationTokenIdentifier> {
32 private static Log LOG = LogFactory.getLog(AuthenticationTokenSelector.class);
33
34 public AuthenticationTokenSelector() {
35 }
36
37 @Override
38 public Token<AuthenticationTokenIdentifier> selectToken(Text serviceName,
39 Collection<Token<? extends TokenIdentifier>> tokens) {
40 if (serviceName != null) {
41 for (Token ident : tokens) {
42 if (serviceName.equals(ident.getService()) &&
43 AuthenticationTokenIdentifier.AUTH_TOKEN_TYPE.equals(ident.getKind())) {
44 if (LOG.isDebugEnabled()) {
45 LOG.debug("Returning token "+ident);
46 }
47 return (Token<AuthenticationTokenIdentifier>)ident;
48 }
49 }
50 }
51 LOG.debug("No matching token found");
52 return null;
53 }
54 }