Skip to content

Commit e8e41d9

Browse files
committed
HBASE-26553. Address taklwu's comments
1 parent 4beb113 commit e8e41d9

File tree

15 files changed

+40
-44
lines changed

15 files changed

+40
-44
lines changed

hbase-client/src/test/java/org/apache/hadoop/hbase/security/provider/OAuthBearerSaslClientCallbackHandlerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void testWithZeroTokens() {
6868
assertEquals(IOException.class, e.getCause().getClass());
6969
}
7070

71-
@Test()
71+
@Test
7272
public void testWithPotentiallyMultipleTokens() throws Exception {
7373
OAuthBearerSaslClientAuthenticationProvider.OAuthBearerSaslClientCallbackHandler handler =
7474
createCallbackHandler();

hbase-common/src/main/java/org/apache/hadoop/hbase/exceptions/IllegalSaslStateException.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,4 @@ public IllegalSaslStateException(String message) {
3636
public IllegalSaslStateException(String message, Throwable cause) {
3737
super(message, cause);
3838
}
39-
4039
}

hbase-common/src/main/java/org/apache/hadoop/hbase/security/auth/AuthenticateCallbackHandler.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,4 @@ public interface AuthenticateCallbackHandler extends CallbackHandler {
4545
*/
4646
default void configure(
4747
Configuration configs, String saslMechanism, Map<String, String> saslProps) {}
48-
49-
/**
50-
* Closes this instance.
51-
*/
52-
default void close() {}
5348
}

hbase-common/src/main/java/org/apache/hadoop/hbase/security/oauthbearer/OAuthBearerExtensionsValidatorCallback.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818
package org.apache.hadoop.hbase.security.oauthbearer;
1919

20-
import static org.apache.hadoop.hbase.security.oauthbearer.Utils.subtractMap;
20+
import static org.apache.hadoop.hbase.security.oauthbearer.OAuthBearerStringUtils.subtractMap;
2121
import java.util.Collections;
2222
import java.util.HashMap;
2323
import java.util.Map;

hbase-common/src/main/java/org/apache/hadoop/hbase/security/oauthbearer/Utils.java renamed to hbase-common/src/main/java/org/apache/hadoop/hbase/security/oauthbearer/OAuthBearerStringUtils.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import org.apache.yetus.audience.InterfaceAudience;
2424

2525
@InterfaceAudience.Public
26-
public final class Utils {
26+
public final class OAuthBearerStringUtils {
2727
/**
2828
* Converts a {@code Map} class into a string, concatenating keys and values
2929
* Example:
@@ -76,16 +76,7 @@ public static <K, V> Map<K, V> subtractMap(Map<? extends K, ? extends V> minuend
7676
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
7777
}
7878

79-
/**
80-
* Checks if a string is null, empty or whitespace only.
81-
* @param str a string to be checked
82-
* @return true if the string is null, empty or whitespace only; otherwise, return false.
83-
*/
84-
public static boolean isBlank(String str) {
85-
return str == null || str.trim().isEmpty();
86-
}
87-
88-
private Utils() {
79+
private OAuthBearerStringUtils() {
8980
// empty
9081
}
9182
}

hbase-common/src/main/java/org/apache/hadoop/hbase/security/oauthbearer/OAuthBearerTokenCallback.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* 2.0 Authorization Framework</a>. Callback handlers should communicate other
3131
* problems by raising an {@code IOException}.
3232
* <p>
33-
* This class was introduced in 2.0.0 and, while it feels stable, it could
33+
* This class was introduced in 3.0.0 and, while it feels stable, it could
3434
* evolve. We will try to evolve the API in a compatible manner, but we reserve
3535
* the right to make breaking changes in minor releases, if necessary. We will
3636
* update the {@code InterfaceStability} annotation and this notice once the API

hbase-common/src/main/java/org/apache/hadoop/hbase/security/oauthbearer/internals/OAuthBearerClientInitialResponse.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import java.util.regex.Pattern;
2525
import javax.security.sasl.SaslException;
2626
import org.apache.hadoop.hbase.security.auth.SaslExtensions;
27-
import org.apache.hadoop.hbase.security.oauthbearer.Utils;
27+
import org.apache.hadoop.hbase.security.oauthbearer.OAuthBearerStringUtils;
2828
import org.apache.yetus.audience.InterfaceAudience;
2929

3030
/**
@@ -64,7 +64,7 @@ public OAuthBearerClientInitialResponse(byte[] response) throws SaslException {
6464
String authzid = matcher.group("authzid");
6565
this.authorizationId = authzid == null ? "" : authzid;
6666
String kvPairs = matcher.group("kvpairs");
67-
Map<String, String> properties = Utils.parseMap(kvPairs, "=", SEPARATOR);
67+
Map<String, String> properties = OAuthBearerStringUtils.parseMap(kvPairs, "=", SEPARATOR);
6868
String auth = properties.get(AUTH_KEY);
6969
if (auth == null) {
7070
throw new SaslException("Invalid OAUTHBEARER client first message: 'auth' not specified");
@@ -207,6 +207,6 @@ public static void validateExtensions(SaslExtensions extensions) throws SaslExce
207207
* Converts the SASLExtensions to an OAuth protocol-friendly string
208208
*/
209209
private String extensionsMessage() {
210-
return Utils.mkString(saslExtensions.map(), "", "", "=", SEPARATOR);
210+
return OAuthBearerStringUtils.mkString(saslExtensions.map(), "", "", "=", SEPARATOR);
211211
}
212212
}

hbase-common/src/main/java/org/apache/hadoop/hbase/security/oauthbearer/internals/OAuthBearerSaslServer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import org.apache.hadoop.hbase.security.oauthbearer.OAuthBearerExtensionsValidatorCallback;
3737
import org.apache.hadoop.hbase.security.oauthbearer.OAuthBearerToken;
3838
import org.apache.hadoop.hbase.security.oauthbearer.OAuthBearerValidatorCallback;
39-
import org.apache.hadoop.hbase.security.oauthbearer.Utils;
39+
import org.apache.hadoop.hbase.security.oauthbearer.OAuthBearerStringUtils;
4040
import org.apache.yetus.audience.InterfaceAudience;
4141
import org.slf4j.Logger;
4242
import org.slf4j.LoggerFactory;
@@ -103,7 +103,7 @@ public byte[] evaluateResponse(byte[] response)
103103
return process(clientResponse.tokenValue(), clientResponse.authorizationId(),
104104
clientResponse.extensions());
105105
} catch (SaslAuthenticationException e) {
106-
LOG.error("SASL authentication error: {}", e.getMessage());
106+
LOG.error("SASL authentication error", e);
107107
throw e;
108108
} catch (Exception e) {
109109
LOG.error("SASL server problem", e);
@@ -215,7 +215,7 @@ private Map<String, String> processExtensions(OAuthBearerToken token, SaslExtens
215215
if (!extensionsCallback.invalidExtensions().isEmpty()) {
216216
String errorMessage = String.format("Authentication failed: %d extensions are invalid! "
217217
+ "They are: %s", extensionsCallback.invalidExtensions().size(),
218-
Utils.mkString(extensionsCallback.invalidExtensions(), "", "", ": ", "; "));
218+
OAuthBearerStringUtils.mkString(extensionsCallback.invalidExtensions(), "", "", ": ", "; "));
219219
LOG.debug(errorMessage);
220220
throw new SaslAuthenticationException(errorMessage);
221221
}

hbase-common/src/main/java/org/apache/hadoop/hbase/security/oauthbearer/internals/knox/OAuthBearerSignedJwt.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
import java.util.Map;
3838
import java.util.Objects;
3939
import java.util.Set;
40+
import org.apache.commons.lang3.StringUtils;
4041
import org.apache.hadoop.hbase.security.oauthbearer.OAuthBearerToken;
41-
import org.apache.hadoop.hbase.security.oauthbearer.Utils;
4242
import org.apache.yetus.audience.InterfaceAudience;
4343

4444
/**
@@ -145,7 +145,7 @@ public OAuthBearerSignedJwt validate(){
145145
}
146146
lifetime = expirationTimeSeconds.toInstant().toEpochMilli();
147147
String principalName = claims.getSubject();
148-
if (Utils.isBlank(principalName)) {
148+
if (StringUtils.isBlank(principalName)) {
149149
throw new OAuthBearerIllegalTokenException(OAuthBearerValidationResult
150150
.newFailure("No principal name in JWT claim"));
151151
}
@@ -165,13 +165,13 @@ private JWTClaimsSet validateToken(String jwtToken)
165165
JWTClaimsSet.Builder jwtClaimsSetBuilder = new JWTClaimsSet.Builder();
166166

167167
// Audience
168-
if (!Utils.isBlank(requiredAudience)) {
168+
if (!StringUtils.isBlank(requiredAudience)) {
169169
requiredClaims.add("aud");
170170
jwtClaimsSetBuilder.audience(requiredAudience);
171171
}
172172

173173
// Issuer
174-
if (!Utils.isBlank(requiredIssuer)) {
174+
if (!StringUtils.isBlank(requiredIssuer)) {
175175
requiredClaims.add("iss");
176176
jwtClaimsSetBuilder.issuer(requiredIssuer);
177177
}

hbase-common/src/main/java/org/apache/hadoop/hbase/security/oauthbearer/internals/knox/OAuthBearerSignedJwtValidatorCallbackHandler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
import java.util.Objects;
2828
import javax.security.auth.callback.Callback;
2929
import javax.security.auth.callback.UnsupportedCallbackException;
30+
import org.apache.commons.lang3.StringUtils;
3031
import org.apache.hadoop.conf.Configuration;
3132
import org.apache.hadoop.hbase.security.auth.AuthenticateCallbackHandler;
3233
import org.apache.hadoop.hbase.security.oauthbearer.OAuthBearerExtensionsValidatorCallback;
3334
import org.apache.hadoop.hbase.security.oauthbearer.OAuthBearerValidatorCallback;
34-
import org.apache.hadoop.hbase.security.oauthbearer.Utils;
3535
import org.apache.yetus.audience.InterfaceAudience;
3636
import org.slf4j.Logger;
3737
import org.slf4j.LoggerFactory;
@@ -91,7 +91,7 @@ public class OAuthBearerSignedJwtValidatorCallbackHandler implements Authenticat
9191
public void handle(Callback[] callbacks) throws UnsupportedCallbackException {
9292
if (!configured) {
9393
throw new RuntimeException(
94-
"OAuthBearerSignedJwtValidatorCallbackHandler handler be configured first.");
94+
"OAuthBearerSignedJwtValidatorCallbackHandler must be configured first.");
9595
}
9696

9797
for (Callback callback : callbacks) {
@@ -171,7 +171,7 @@ private int allowableClockSkewSeconds() {
171171
ALLOWABLE_CLOCK_SKEW_SECONDS_OPTION);
172172
int allowableClockSkewSeconds = 0;
173173
try {
174-
allowableClockSkewSeconds = Utils.isBlank(allowableClockSkewSecondsValue)
174+
allowableClockSkewSeconds = StringUtils.isBlank(allowableClockSkewSecondsValue)
175175
? 0 : Integer.parseInt(allowableClockSkewSecondsValue.trim());
176176
} catch (NumberFormatException e) {
177177
throw new OAuthBearerConfigException(e.getMessage(), e);
@@ -188,12 +188,12 @@ private void loadJwkSet() throws IOException, ParseException {
188188
String jwksFile = hBaseConfiguration.get(JWKS_FILE);
189189
String jwksUrl = hBaseConfiguration.get(JWKS_URL);
190190

191-
if (Utils.isBlank(jwksFile) && Utils.isBlank(jwksUrl)) {
191+
if (StringUtils.isBlank(jwksFile) && StringUtils.isBlank(jwksUrl)) {
192192
throw new RuntimeException("Failed to initialize JWKS db. "
193193
+ JWKS_FILE + " or " + JWKS_URL + " must be specified in the config.");
194194
}
195195

196-
if (!Utils.isBlank(jwksFile)) {
196+
if (!StringUtils.isBlank(jwksFile)) {
197197
this.jwkSet = JWKSet.load(new File(jwksFile));
198198
LOG.debug("JWKS db initialized from file: {}", jwksFile);
199199
return;

0 commit comments

Comments
 (0)