11package tech .stackable .hadoop ;
22
3+ import com .fasterxml .jackson .annotation .JsonInclude ;
4+ import com .fasterxml .jackson .databind .DeserializationFeature ;
5+ import com .fasterxml .jackson .databind .ObjectMapper ;
36import org .apache .hadoop .conf .Configuration ;
47import org .apache .hadoop .security .GroupMappingServiceProvider ;
58import org .apache .hadoop .util .Lists ;
@@ -18,9 +21,32 @@ public class StackableGroupMapper implements GroupMappingServiceProvider {
1821 private final Logger LOG = LoggerFactory .getLogger (StackableGroupMapper .class );
1922 private final Configuration configuration ;
2023 private final HttpClient httpClient = HttpClient .newHttpClient ();
24+ private final ObjectMapper json ;
2125
2226 public StackableGroupMapper () {
2327 this .configuration = new Configuration ();
28+ this .json = new ObjectMapper ()
29+ // https://github.com/stackabletech/trino-opa-authorizer/issues/24
30+ // OPA server can send other fields, such as `decision_id`` when enabling decision logs
31+ // We could add all the fields we *currently* know, but it's more future-proof to ignore any unknown fields.
32+ .configure (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES , false )
33+ // do not include null values
34+ .setSerializationInclusion (JsonInclude .Include .NON_NULL );
35+ }
36+
37+ private static class OpaQuery {
38+ public OpaQueryInput input ;
39+
40+ public OpaQuery (OpaQueryInput input ) {
41+ this .input = input ;
42+ }
43+ }
44+
45+ public class OpaQueryInput {
46+ public final String username ;
47+ public OpaQueryInput (String user ) {
48+ this .username = user ;
49+ }
2450 }
2551
2652 /**
@@ -42,7 +68,9 @@ public List<String> getGroups(String user) throws IOException {
4268 URI opaUri = URI .create (opaMappingUrl );
4369 HttpResponse <String > response = null ;
4470
45- String body = String .format ("{\" input\" :{\" username\" : \" %s\" }}" , user );
71+ OpaQuery query = new OpaQuery (new OpaQueryInput (user ));
72+ String body = json .writeValueAsString (query );
73+
4674 LOG .info ("Request body [{}]" , body );
4775 try {
4876 response = httpClient .send (
0 commit comments