14
14
**/
15
15
package com .hortonworks .registries .webservice ;
16
16
17
- import com .hortonworks .registries .common .AuthMethodConfiguration ;
17
+ import com .hortonworks .registries .common .ServiceAuthenticationConfiguration ;
18
18
import com .hortonworks .registries .common .FileStorageConfiguration ;
19
19
import com .hortonworks .registries .common .GenericExceptionMapper ;
20
20
import com .hortonworks .registries .common .HAConfiguration ;
44
44
import io .dropwizard .setup .Environment ;
45
45
import io .federecio .dropwizard .swagger .SwaggerBundle ;
46
46
import io .federecio .dropwizard .swagger .SwaggerBundleConfiguration ;
47
+ import org .apache .commons .lang .StringUtils ;
47
48
import org .apache .hadoop .security .UserGroupInformation ;
48
49
import org .eclipse .jetty .server .Server ;
49
50
import org .eclipse .jetty .servlets .CrossOriginFilter ;
@@ -94,29 +95,33 @@ public void run(RegistryConfiguration registryConfiguration, Environment environ
94
95
}
95
96
96
97
private void initializeUGI (RegistryConfiguration conf ) throws IOException {
97
- LOG .debug ("Initialization of User Group ininformation..." );
98
- if (UserGroupInformation .isSecurityEnabled ()) {
99
- LOG .debug ("UGI.isSecurityEnabled() = true." );
100
-
101
- AuthMethodConfiguration authMethodConf = conf .getAuthenticationMethod ();
102
- if (authMethodConf != null ) {
103
- String serverPrincipal = authMethodConf .getServerPrinciple ();
104
- String keyTab = authMethodConf .getServerPrincipleKeytab ();
105
-
106
- LOG .debug ("UGI is trying to login with principle = " + serverPrincipal
107
- + ", keyTab = " + keyTab );
108
-
109
- //Authenticate using keytab
110
- UserGroupInformation .loginUserFromKeytab (serverPrincipal , keyTab );
111
-
112
- LOG .debug ("UGI is login successfully with principle = " + serverPrincipal
113
- + ", keyTab = " + keyTab );
98
+ if (conf .getServiceAuthenticationConfiguration () != null ) {
99
+ String authenticationType = conf .getServiceAuthenticationConfiguration ().getType ();
100
+ if (authenticationType != null && authenticationType .equals ("kerberos" )) {
101
+ Map <String , String > serviceAuthenticationProperties = conf .getServiceAuthenticationConfiguration ().getProperties ();
102
+ if (serviceAuthenticationProperties != null ) {
103
+ String principal = serviceAuthenticationProperties .get ("principal" );
104
+ String keytab = serviceAuthenticationProperties .get ("keytab" );
105
+
106
+ if (StringUtils .isNotEmpty (principal ) && StringUtils .isNotEmpty (keytab )) {
107
+ LOG .debug ("Login with principal = '" + principal + "' and keyTab = '" + keytab + "'" );
108
+ try {
109
+ UserGroupInformation .loginUserFromKeytab (principal , keytab );
110
+ LOG .debug ("Successfully logged in" );
111
+ } catch (Exception e ) {
112
+ LOG .error ("Failed to log in" , e );
113
+ }
114
+ } else {
115
+ LOG .error ("Invalid service authentication configuration for 'kerberos' principal = '" + principal + "' and keytab = '" + keytab + "'" );
116
+ }
117
+ } else {
118
+ LOG .error ("No service authentication properties were configured for 'kerberos'" );
119
+ }
114
120
} else {
115
- LOG .warn ("UGI.isSecurityEnabled() = true, but authenticationMethod section of SR config file is empty. "
116
- + " Default UGI configuration will be used." );
121
+ LOG .error ("Invalid service authentication type : " + authenticationType );
117
122
}
118
123
} else {
119
- LOG .debug ("UGI.isSecurityEnabled() = false. Simple authentication method will be used. " );
124
+ LOG .debug ("No service authentication is configured " );
120
125
}
121
126
}
122
127
@@ -145,7 +150,7 @@ public void serverStarted(Server server) {
145
150
146
151
haServerNotificationManager .notifyDebut ();
147
152
148
- refreshHAServerManagedTask = new RefreshHAServerManagedTask (storageManager ,transactionManager , haServerNotificationManager );
153
+ refreshHAServerManagedTask = new RefreshHAServerManagedTask (storageManager , transactionManager , haServerNotificationManager );
149
154
environment .lifecycle ().manage (refreshHAServerManagedTask );
150
155
refreshHAServerManagedTask .start ();
151
156
}
@@ -154,7 +159,7 @@ public void serverStarted(Server server) {
154
159
}
155
160
156
161
private void registerHA (HAConfiguration haConfiguration , Environment environment ) throws Exception {
157
- if (haConfiguration != null ) {
162
+ if (haConfiguration != null ) {
158
163
environment .lifecycle ().addServerLifecycleListener (new ServerLifecycleListener () {
159
164
@ Override
160
165
public void serverStarted (Server server ) {
@@ -241,13 +246,13 @@ private void registerResources(Environment environment, RegistryConfiguration re
241
246
transactionManagerAware .setTransactionManager (transactionManager );
242
247
}
243
248
244
- if (moduleRegistration instanceof LeadershipAware ) {
249
+ if (moduleRegistration instanceof LeadershipAware ) {
245
250
LOG .info ("Module [{}] is registered for LeadershipParticipant registration." , moduleName );
246
251
LeadershipAware leadershipAware = (LeadershipAware ) moduleRegistration ;
247
252
leadershipAware .setLeadershipParticipant (leadershipParticipantRef );
248
253
}
249
254
250
- if (moduleRegistration instanceof HAServersAware ) {
255
+ if (moduleRegistration instanceof HAServersAware ) {
251
256
LOG .info ("Module [{}] is registered for HAServersAware registration." );
252
257
HAServersAware leadershipAware = (HAServersAware ) moduleRegistration ;
253
258
leadershipAware .setHAServerConfigManager (haServerNotificationManager );
@@ -260,7 +265,7 @@ private void registerResources(Environment environment, RegistryConfiguration re
260
265
for (Object resource : resourcesToRegister ) {
261
266
environment .jersey ().register (resource );
262
267
}
263
-
268
+
264
269
environment .jersey ().register (MultiPartFeature .class );
265
270
environment .jersey ().register (new TransactionEventListener (transactionManager , TransactionIsolation .READ_COMMITTED ));
266
271
@@ -284,7 +289,7 @@ private FileStorage getJarStorage(FileStorageConfiguration fileStorageConfigurat
284
289
if (fileStorageConfiguration .getClassName () != null )
285
290
try {
286
291
fileStorage = (FileStorage ) Class .forName (fileStorageConfiguration .getClassName (), true ,
287
- Thread .currentThread ().getContextClassLoader ()).newInstance ();
292
+ Thread .currentThread ().getContextClassLoader ()).newInstance ();
288
293
fileStorage .init (fileStorageConfiguration .getProperties ());
289
294
} catch (Exception e ) {
290
295
throw new RuntimeException (e );
@@ -307,15 +312,15 @@ private StorageManager getStorageManager(StorageProviderConfiguration storagePro
307
312
private void addServletFilters (RegistryConfiguration registryConfiguration , Environment environment ) {
308
313
List <ServletFilterConfiguration > servletFilterConfigurations = registryConfiguration .getServletFilters ();
309
314
if (servletFilterConfigurations != null && !servletFilterConfigurations .isEmpty ()) {
310
- for (ServletFilterConfiguration servletFilterConfig : servletFilterConfigurations ) {
315
+ for (ServletFilterConfiguration servletFilterConfig : servletFilterConfigurations ) {
311
316
try {
312
317
String className = servletFilterConfig .getClassName ();
313
318
Map <String , String > params = servletFilterConfig .getParams ();
314
319
String typeSuffix = params .get ("type" ) != null ? ("-" + params .get ("type" ).toString ()) : "" ;
315
320
LOG .info ("Registering servlet filter [{}]" , servletFilterConfig );
316
321
Class <? extends Filter > filterClass = (Class <? extends Filter >) Class .forName (className );
317
322
FilterRegistration .Dynamic dynamic = environment .servlets ().addFilter (className + typeSuffix , filterClass );
318
- if (params != null ) {
323
+ if (params != null ) {
319
324
dynamic .setInitParameters (params );
320
325
}
321
326
dynamic .addMappingForUrlPatterns (EnumSet .allOf (DispatcherType .class ), true , "/*" );
0 commit comments