Search in sources :

Example 1 with SaslClientCallbackHandler

use of org.apache.hadoop.hbase.security.AbstractHBaseSaslRpcClient.SaslClientCallbackHandler in project hbase by apache.

the class TestHBaseSaslRpcClient method testSaslClientCallbackHandlerWithException.

@Test
public void testSaslClientCallbackHandlerWithException() {
    final Token<? extends TokenIdentifier> token = createTokenMock();
    when(token.getIdentifier()).thenReturn(DEFAULT_USER_NAME.getBytes());
    when(token.getPassword()).thenReturn(DEFAULT_USER_PASSWORD.getBytes());
    final SaslClientCallbackHandler saslClCallbackHandler = new SaslClientCallbackHandler(token);
    try {
        saslClCallbackHandler.handle(new Callback[] { mock(TextOutputCallback.class) });
    } catch (UnsupportedCallbackException expEx) {
    //expected
    } catch (Exception ex) {
        fail("testSaslClientCallbackHandlerWithException error : " + ex.getMessage());
    }
}
Also used : TextOutputCallback(javax.security.auth.callback.TextOutputCallback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) SaslClientCallbackHandler(org.apache.hadoop.hbase.security.AbstractHBaseSaslRpcClient.SaslClientCallbackHandler) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with SaslClientCallbackHandler

use of org.apache.hadoop.hbase.security.AbstractHBaseSaslRpcClient.SaslClientCallbackHandler in project hbase by apache.

the class TestHBaseSaslRpcClient method testSaslClientCallbackHandler.

@Test
public void testSaslClientCallbackHandler() throws UnsupportedCallbackException {
    final Token<? extends TokenIdentifier> token = createTokenMock();
    when(token.getIdentifier()).thenReturn(DEFAULT_USER_NAME.getBytes());
    when(token.getPassword()).thenReturn(DEFAULT_USER_PASSWORD.getBytes());
    final NameCallback nameCallback = mock(NameCallback.class);
    final PasswordCallback passwordCallback = mock(PasswordCallback.class);
    final RealmCallback realmCallback = mock(RealmCallback.class);
    final RealmChoiceCallback realmChoiceCallback = mock(RealmChoiceCallback.class);
    Callback[] callbackArray = { nameCallback, passwordCallback, realmCallback, realmChoiceCallback };
    final SaslClientCallbackHandler saslClCallbackHandler = new SaslClientCallbackHandler(token);
    saslClCallbackHandler.handle(callbackArray);
    verify(nameCallback).setName(anyString());
    verify(realmCallback).setText(anyString());
    verify(passwordCallback).setPassword(any(char[].class));
}
Also used : NameCallback(javax.security.auth.callback.NameCallback) TextOutputCallback(javax.security.auth.callback.TextOutputCallback) RealmCallback(javax.security.sasl.RealmCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) NameCallback(javax.security.auth.callback.NameCallback) RealmChoiceCallback(javax.security.sasl.RealmChoiceCallback) Callback(javax.security.auth.callback.Callback) PasswordCallback(javax.security.auth.callback.PasswordCallback) SaslClientCallbackHandler(org.apache.hadoop.hbase.security.AbstractHBaseSaslRpcClient.SaslClientCallbackHandler) RealmChoiceCallback(javax.security.sasl.RealmChoiceCallback) RealmCallback(javax.security.sasl.RealmCallback) Test(org.junit.Test)

Aggregations

TextOutputCallback (javax.security.auth.callback.TextOutputCallback)2 SaslClientCallbackHandler (org.apache.hadoop.hbase.security.AbstractHBaseSaslRpcClient.SaslClientCallbackHandler)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 Callback (javax.security.auth.callback.Callback)1 NameCallback (javax.security.auth.callback.NameCallback)1 PasswordCallback (javax.security.auth.callback.PasswordCallback)1 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)1 RealmCallback (javax.security.sasl.RealmCallback)1 RealmChoiceCallback (javax.security.sasl.RealmChoiceCallback)1 ExpectedException (org.junit.rules.ExpectedException)1