27
27
import java .io .File ;
28
28
import java .io .IOException ;
29
29
import java .io .OutputStreamWriter ;
30
- import java .io .PrintWriter ;
31
- import java .io .StringWriter ;
32
30
import java .nio .charset .StandardCharsets ;
33
31
import java .security .PrivilegedExceptionAction ;
34
32
import java .util .ArrayList ;
67
65
import org .apache .hadoop .hbase .util .Bytes ;
68
66
import org .apache .hadoop .hbase .util .CommonFSUtils ;
69
67
import org .apache .hadoop .hbase .util .Pair ;
70
- import org .apache .hadoop .ipc .RemoteException ;
71
68
import org .apache .hadoop .minikdc .MiniKdc ;
72
69
import org .apache .hadoop .security .UserGroupInformation ;
73
- import org .apache .hadoop .security .token .SecretManager .InvalidToken ;
74
70
import org .junit .AfterClass ;
75
71
import org .junit .Before ;
76
72
import org .junit .BeforeClass ;
82
78
import org .slf4j .Logger ;
83
79
import org .slf4j .LoggerFactory ;
84
80
85
- import org .apache .hbase .thirdparty .com .google .common .base .Throwables ;
86
-
87
81
@ Category ({ MediumTests .class , SecurityTests .class })
88
82
public class TestShadeSaslAuthenticationProvider {
89
83
private static final Logger LOG =
@@ -210,21 +204,23 @@ public String run() throws Exception {
210
204
@ Test
211
205
public void testPositiveAuthentication () throws Exception {
212
206
final Configuration clientConf = new Configuration (CONF );
213
- try (Connection conn = ConnectionFactory .createConnection (clientConf )) {
207
+ try (Connection conn1 = ConnectionFactory .createConnection (clientConf )) {
214
208
UserGroupInformation user1 =
215
209
UserGroupInformation .createUserForTesting ("user1" , new String [0 ]);
216
- user1 .addToken (ShadeClientTokenUtil .obtainToken (conn , "user1" , USER1_PASSWORD ));
210
+ user1 .addToken (ShadeClientTokenUtil .obtainToken (conn1 , "user1" , USER1_PASSWORD ));
217
211
user1 .doAs (new PrivilegedExceptionAction <Void >() {
218
212
@ Override
219
213
public Void run () throws Exception {
220
- try (Table t = conn .getTable (tableName )) {
221
- Result r = t .get (new Get (Bytes .toBytes ("r1" )));
222
- assertNotNull (r );
223
- assertFalse ("Should have read a non-empty Result" , r .isEmpty ());
224
- final Cell cell = r .getColumnLatestCell (Bytes .toBytes ("f1" ), Bytes .toBytes ("q1" ));
225
- assertTrue ("Unexpected value" , CellUtil .matchingValue (cell , Bytes .toBytes ("1" )));
214
+ try (Connection conn = ConnectionFactory .createConnection (clientConf )) {
215
+ try (Table t = conn .getTable (tableName )) {
216
+ Result r = t .get (new Get (Bytes .toBytes ("r1" )));
217
+ assertNotNull (r );
218
+ assertFalse ("Should have read a non-empty Result" , r .isEmpty ());
219
+ final Cell cell = r .getColumnLatestCell (Bytes .toBytes ("f1" ), Bytes .toBytes ("q1" ));
220
+ assertTrue ("Unexpected value" , CellUtil .matchingValue (cell , Bytes .toBytes ("1" )));
226
221
227
- return null ;
222
+ return null ;
223
+ }
228
224
}
229
225
}
230
226
});
@@ -262,7 +258,6 @@ public Void run() throws Exception {
262
258
} catch (Exception e ) {
263
259
LOG .info ("Caught exception in negative Master connectivity test" , e );
264
260
assertEquals ("Found unexpected exception" , pair .getSecond (), e .getClass ());
265
- validateRootCause (Throwables .getRootCause (e ));
266
261
}
267
262
return null ;
268
263
}
@@ -279,7 +274,6 @@ public Void run() throws Exception {
279
274
} catch (Exception e ) {
280
275
LOG .info ("Caught exception in negative RegionServer connectivity test" , e );
281
276
assertEquals ("Found unexpected exception" , pair .getSecond (), e .getClass ());
282
- validateRootCause (Throwables .getRootCause (e ));
283
277
}
284
278
return null ;
285
279
}
@@ -293,19 +287,4 @@ public Void run() throws Exception {
293
287
}
294
288
});
295
289
}
296
-
297
- void validateRootCause (Throwable rootCause ) {
298
- LOG .info ("Root cause was" , rootCause );
299
- if (rootCause instanceof RemoteException ) {
300
- RemoteException re = (RemoteException ) rootCause ;
301
- IOException actualException = re .unwrapRemoteException ();
302
- assertEquals (InvalidToken .class , actualException .getClass ());
303
- } else {
304
- StringWriter writer = new StringWriter ();
305
- rootCause .printStackTrace (new PrintWriter (writer ));
306
- String text = writer .toString ();
307
- assertTrue ("Message did not contain expected text" ,
308
- text .contains (InvalidToken .class .getName ()));
309
- }
310
- }
311
290
}
0 commit comments