1212import org .elasticsearch .action .support .DestructiveOperations ;
1313import org .elasticsearch .cluster .service .ClusterService ;
1414import org .elasticsearch .common .CheckedConsumer ;
15- import org .elasticsearch .common .settings .Setting ;
1615import org .elasticsearch .common .settings .Settings ;
1716import org .elasticsearch .common .util .concurrent .AbstractRunnable ;
1817import org .elasticsearch .common .util .concurrent .ThreadContext ;
4544import java .util .HashMap ;
4645import java .util .Map ;
4746import java .util .concurrent .Executor ;
48- import java .util .function .Function ;
4947
5048import static org .elasticsearch .xpack .core .security .SecurityField .setting ;
5149
5250public class SecurityServerTransportInterceptor implements TransportInterceptor {
5351
54- private static final Function <String , Setting <String >> TRANSPORT_TYPE_SETTING_TEMPLATE = key -> new Setting <>(key , "node" , v -> {
55- if (v .equals ("node" ) || v .equals ("client" )) {
56- return v ;
57- }
58- throw new IllegalArgumentException ("type must be one of [client, node]" );
59- }, Setting .Property .NodeScope );
60- private static final String TRANSPORT_TYPE_SETTING_KEY = "xpack.security.type" ;
6152 private static final Logger logger = LogManager .getLogger (SecurityServerTransportInterceptor .class );
6253
63- public static final Setting .AffixSetting <String > TRANSPORT_TYPE_PROFILE_SETTING = Setting .affixKeySetting ("transport.profiles." ,
64- TRANSPORT_TYPE_SETTING_KEY , TRANSPORT_TYPE_SETTING_TEMPLATE );
65-
6654 private final AuthenticationService authcService ;
6755 private final AuthorizationService authzService ;
6856 private final SSLService sslService ;
@@ -71,7 +59,6 @@ public class SecurityServerTransportInterceptor implements TransportInterceptor
7159 private final ThreadPool threadPool ;
7260 private final Settings settings ;
7361 private final SecurityContext securityContext ;
74- private final boolean reservedRealmEnabled ;
7562
7663 private volatile boolean isStateNotRecovered = true ;
7764
@@ -92,7 +79,6 @@ public SecurityServerTransportInterceptor(Settings settings,
9279 this .sslService = sslService ;
9380 this .securityContext = securityContext ;
9481 this .profileFilters = initializeProfileFilters (destructiveOperations );
95- this .reservedRealmEnabled = XPackSettings .RESERVED_REALM_ENABLED_SETTING .get (settings );
9682 clusterService .addListener (e -> isStateNotRecovered = e .state ().blocks ().hasGlobalBlock (GatewayService .STATE_NOT_RECOVERED_BLOCK ));
9783 }
9884
@@ -187,21 +173,8 @@ private Map<String, ServerTransportFilter> initializeProfileFilters(DestructiveO
187173 for (Map .Entry <String , SSLConfiguration > entry : profileConfigurations .entrySet ()) {
188174 final SSLConfiguration profileConfiguration = entry .getValue ();
189175 final boolean extractClientCert = transportSSLEnabled && sslService .isSSLClientAuthEnabled (profileConfiguration );
190- final String type = TRANSPORT_TYPE_PROFILE_SETTING .getConcreteSettingForNamespace (entry .getKey ()).get (settings );
191- switch (type ) {
192- case "client" :
193- profileFilters .put (entry .getKey (), new ServerTransportFilter .ClientProfile (authcService , authzService ,
194- threadPool .getThreadContext (), extractClientCert , destructiveOperations , reservedRealmEnabled ,
195- securityContext , licenseState ));
196- break ;
197- case "node" :
198- profileFilters .put (entry .getKey (), new ServerTransportFilter .NodeProfile (authcService , authzService ,
199- threadPool .getThreadContext (), extractClientCert , destructiveOperations , reservedRealmEnabled ,
200- securityContext , licenseState ));
201- break ;
202- default :
203- throw new IllegalStateException ("unknown profile type: " + type );
204- }
176+ profileFilters .put (entry .getKey (), new ServerTransportFilter (authcService , authzService , threadPool .getThreadContext (),
177+ extractClientCert , destructiveOperations , securityContext , licenseState ));
205178 }
206179
207180 return Collections .unmodifiableMap (profileFilters );
0 commit comments