Skip to content

Commit 84aa250

Browse files
committed
Gets rid of a few warnings from error-prone and others
1 parent 4fdccbc commit 84aa250

File tree

3 files changed

+37
-20
lines changed

3 files changed

+37
-20
lines changed

src/main/java/tech/stackable/hadoop/OpaException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
public abstract class OpaException extends RuntimeException {
99

10-
public OpaException(String message, Throwable cause) {
10+
protected OpaException(String message, Throwable cause) {
1111
super(message, cause);
1212
}
1313

src/main/java/tech/stackable/hadoop/OpaQuery.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package tech.stackable.hadoop;
22

3+
import java.util.StringJoiner;
4+
35
public class OpaQuery {
46
public final OpaQueryInput input;
57

@@ -13,5 +15,19 @@ public static class OpaQueryInput {
1315
public OpaQueryInput(String user) {
1416
this.username = user;
1517
}
18+
19+
@Override
20+
public String toString() {
21+
return new StringJoiner(", ", OpaQueryInput.class.getSimpleName() + "[", "]")
22+
.add("username='" + username + "'")
23+
.toString();
24+
}
25+
}
26+
27+
@Override
28+
public String toString() {
29+
return new StringJoiner(", ", OpaQuery.class.getSimpleName() + "[", "]")
30+
.add("input=" + input)
31+
.toString();
1632
}
1733
}

src/main/java/tech/stackable/hadoop/StackableGroupMapper.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,30 @@
1212
import java.util.List;
1313
import java.util.Map;
1414
import java.util.Objects;
15-
import java.util.function.UnaryOperator;
1615
import org.apache.hadoop.conf.Configuration;
1716
import org.apache.hadoop.security.GroupMappingServiceProvider;
1817
import org.apache.hadoop.util.Lists;
1918
import org.slf4j.Logger;
2019
import org.slf4j.LoggerFactory;
2120

2221
public class StackableGroupMapper implements GroupMappingServiceProvider {
22+
23+
private static final Logger LOG = LoggerFactory.getLogger(StackableGroupMapper.class);
2324
public static final String OPA_MAPPING_URL_PROP = "hadoop.security.group.mapping.opa.url";
24-
public static final String OPA_MAPPING_GROUP_NAME_PROP =
25+
private static final String OPA_MAPPING_GROUP_NAME_PROP =
2526
"hadoop.security.group.mapping.opa.list.name";
2627
// response base field: see https://www.openpolicyagent.org/docs/latest/rest-api/#response-message
27-
public static final String OPA_RESULT_FIELD = "result";
28-
public final String mappingGroupName;
29-
private final Logger LOG = LoggerFactory.getLogger(StackableGroupMapper.class);
28+
private static final String OPA_RESULT_FIELD = "result";
29+
private final String mappingGroupName;
30+
3031
private final HttpClient httpClient = HttpClient.newHttpClient();
3132
private final ObjectMapper json;
32-
private URI opaUri = null;
33+
private URI opaUri;
3334

3435
public enum HadoopConfig {
3536
INSTANCE;
36-
private Configuration configuration = new Configuration();
37+
private final Configuration configuration = new Configuration();
38+
3739
public Configuration getConfiguration() {
3840
return this.configuration;
3941
}
@@ -83,11 +85,11 @@ public StackableGroupMapper() {
8385
public List<String> getGroups(String user) throws IOException {
8486
LOG.info("Calling StackableGroupMapper.getGroups for user [{}]", user);
8587

86-
HttpResponse<String> response = null;
8788
OpaQuery query = new OpaQuery(new OpaQuery.OpaQueryInput(user));
8889
String body = json.writeValueAsString(query);
8990

9091
LOG.debug("Request body [{}]", body);
92+
HttpResponse<String> response = null;
9193
try {
9294
response =
9395
httpClient.send(
@@ -120,24 +122,23 @@ public List<String> getGroups(String user) throws IOException {
120122
List<String> rawGroups = (List<String>) result.get(this.mappingGroupName);
121123

122124
for (String rawGroup : rawGroups) {
123-
groups.add(stripSlashes.apply(rawGroup));
125+
groups.add(stripSlashes(rawGroup));
124126
}
125127

126128
LOG.info("Groups for [{}]: [{}]", user, groups);
127129

128130
return groups;
129131
}
130132

131-
private static final UnaryOperator<String> stripSlashes =
132-
s -> {
133-
if (s.startsWith("/")) {
134-
s = s.substring(1);
135-
}
136-
if (s.endsWith("/")) {
137-
s = s.substring(0, s.length() - 1);
138-
}
139-
return s;
140-
};
133+
private static String stripSlashes(String s) {
134+
if (s.startsWith("/")) {
135+
s = s.substring(1);
136+
}
137+
if (s.endsWith("/")) {
138+
s = s.substring(0, s.length() - 1);
139+
}
140+
return s;
141+
}
141142

142143
/** Caches groups, no need to do that for this provider */
143144
@Override

0 commit comments

Comments
 (0)