11package tech .stackable .hadoop ;
22
3- import io .fabric8 .kubernetes .client .DefaultKubernetesClient ;
4- import io .fabric8 .kubernetes .client .KubernetesClient ;
53import org .apache .hadoop .conf .Configuration ;
64import org .apache .hadoop .security .GroupMappingServiceProvider ;
75import org .apache .hadoop .util .Lists ;
1816public class StackableGroupMapper implements GroupMappingServiceProvider {
1917 private static final String OPA_MAPPING_URL_PROP = "hadoop.security.group.mapping.opa.url" ;
2018 private final Logger LOG = LoggerFactory .getLogger (StackableGroupMapper .class );
21- private final KubernetesClient client ;
2219 private final Configuration configuration ;
2320 private final HttpClient httpClient = HttpClient .newHttpClient ();
2421
2522 public StackableGroupMapper () {
26- this .client = new DefaultKubernetesClient ();
2723 this .configuration = new Configuration ();
2824 }
2925
@@ -35,7 +31,7 @@ public StackableGroupMapper() {
3531 */
3632 @ Override
3733 public List <String > getGroups (String user ) throws IOException {
38- LOG .info ("Calling StackableGroupMapper.getGroups..." );
34+ LOG .info ("Calling StackableGroupMapper.getGroups for user [{}]" , user );
3935
4036 String opaMappingUrl = configuration .get (OPA_MAPPING_URL_PROP );
4137
@@ -45,12 +41,15 @@ public List<String> getGroups(String user) throws IOException {
4541
4642 URI opaUri = URI .create (opaMappingUrl );
4743 HttpResponse <String > response = null ;
44+
45+ String body = String .format ("{\" input\" :{\" username\" : \" %s\" }}" , user );
46+ LOG .info ("Request body [{}]" , body );
4847 try {
4948 response = httpClient .send (
50- HttpRequest .newBuilder (opaUri ).header ("Content-Type" , "application/json" ). GET (). build (),
51- // .POST(HttpRequest.BodyPublishers.ofByteArray(user.getBytes() )).build(),
49+ HttpRequest .newBuilder (opaUri ).header ("Content-Type" , "application/json" )
50+ .POST (HttpRequest .BodyPublishers .ofString ( body )).build (),
5251 HttpResponse .BodyHandlers .ofString ());
53- LOG .info ("Opa response [{}]" , response );
52+ LOG .info ("Opa response [{}]" , response . body () );
5453 } catch (InterruptedException e ) {
5554 LOG .error (e .getMessage ());
5655 }
@@ -73,7 +72,7 @@ public List<String> getGroups(String user) throws IOException {
7372 @ Override
7473 public void cacheGroupsRefresh () {
7574 // does nothing in this provider of user to groups mapping
76- LOG .info ("cacheGroupsRefresh: caching should be provided by the policy provider" );
75+ LOG .info ("ignoring cacheGroupsRefresh: caching should be provided by the policy provider" );
7776 }
7877
7978 /**
@@ -84,6 +83,6 @@ public void cacheGroupsRefresh() {
8483 @ Override
8584 public void cacheGroupsAdd (List <String > groups ) {
8685 // does nothing in this provider of user to groups mapping
87- LOG .info ("cacheGroupsAdd: caching should be provided by the policy provider" );
86+ LOG .info ("ignoring cacheGroupsAdd: caching should be provided by the policy provider" );
8887 }
8988}
0 commit comments