File tree Expand file tree Collapse file tree 2 files changed +24
-4
lines changed
fluss-common/src/main/java/org/apache/fluss/security/auth/sasl/jaas Expand file tree Collapse file tree 2 files changed +24
-4
lines changed Original file line number Diff line number Diff line change 2525import javax .annotation .Nullable ;
2626import javax .security .auth .Subject ;
2727import javax .security .auth .callback .UnsupportedCallbackException ;
28+ import javax .security .auth .kerberos .KerberosPrincipal ;
2829import javax .security .auth .login .LoginContext ;
2930import javax .security .auth .login .LoginException ;
3031
32+ import java .util .Set ;
33+
3134/* This file is based on source code of Apache Kafka Project (https://kafka.apache.org/), licensed by the Apache
3235 * Software Foundation (ASF) under the Apache License, Version 2.0. See the NOTICE file distributed with this work for
3336 * additional information regarding copyright ownership. */
@@ -73,9 +76,26 @@ public Subject subject() {
7376
7477 @ Override
7578 public String serviceName () {
79+ if (loginContext != null && loginContext .getSubject () != null ) {
80+ Set <KerberosPrincipal > principals =
81+ loginContext .getSubject ().getPrincipals (KerberosPrincipal .class );
82+ if (!principals .isEmpty ()) {
83+ KerberosPrincipal principal = principals .iterator ().next ();
84+ String name = principal .getName ();
85+ int slash = name .indexOf ('/' );
86+ if (slash > 0 ) {
87+ return name .substring (0 , slash );
88+ }
89+ int at = name .indexOf ('@' );
90+ if (at > 0 ) {
91+ return name .substring (0 , at );
92+ }
93+ return name ;
94+ }
95+ }
7696 return contextName ;
7797 }
7898
7999 @ Override
80100 public void close () {}
81- }
101+ }
Original file line number Diff line number Diff line change 1919
2020import org .apache .fluss .security .auth .sasl .gssapi .GssapiServerCallbackHandler ;
2121import org .apache .fluss .security .auth .sasl .plain .PlainServerCallbackHandler ;
22-
2322import org .slf4j .Logger ;
2423import org .slf4j .LoggerFactory ;
2524
2928import javax .security .sasl .SaslClient ;
3029import javax .security .sasl .SaslException ;
3130import javax .security .sasl .SaslServer ;
32-
3331import java .security .PrivilegedActionException ;
3432import java .security .PrivilegedExceptionAction ;
3533import java .util .Arrays ;
@@ -71,7 +69,7 @@ public static SaslServer createSaslServer(
7169 () ->
7270 Sasl .createSaslServer (
7371 mechanism ,
74- "fluss" ,
72+ loginManager . serviceName () ,
7573 hostName ,
7674 props ,
7775 callbackHandler ));
@@ -99,6 +97,8 @@ public static SaslClient createSaslClient(
9997 (PrivilegedExceptionAction <SaslClient >)
10098 () -> {
10199 String [] mechs = {mechanism };
100+ // The serviceName here is the name of the service we are connecting to.
101+ // It is NOT the name of the client principal.
102102 String serviceName = "fluss" ;
103103 LOG .debug (
104104 "Creating SaslClient: service={};mechs={}" ,
You can’t perform that action at this time.
0 commit comments