javax.security.auth.callback.TextOutputCallback Java Examples

The following examples show how to use javax.security.auth.callback.TextOutputCallback. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultCallbackHandler.java    From Bats with Apache License 2.0 6 votes vote down vote up
protected void processCallback(Callback callback) throws IOException, UnsupportedCallbackException
{
  if (callback instanceof NameCallback) {
    NameCallback namecb = (NameCallback)callback;
    namecb.setName(context.getValue(SecurityContext.USER_NAME));
  } else if (callback instanceof PasswordCallback) {
    PasswordCallback passcb = (PasswordCallback)callback;
    passcb.setPassword(context.getValue(SecurityContext.PASSWORD));
  } else if (callback instanceof RealmCallback) {
    RealmCallback realmcb = (RealmCallback)callback;
    realmcb.setText(context.getValue(SecurityContext.REALM));
  } else if (callback instanceof TextOutputCallback) {
    TextOutputCallback textcb = (TextOutputCallback)callback;
    if (textcb.getMessageType() == TextOutputCallback.INFORMATION) {
      logger.info(textcb.getMessage());
    } else if (textcb.getMessageType() == TextOutputCallback.WARNING) {
      logger.warn(textcb.getMessage());
    } else if (textcb.getMessageType() == TextOutputCallback.ERROR) {
      logger.error(textcb.getMessage());
    } else {
      logger.debug("Auth message type {}, message {}", textcb.getMessageType(), textcb.getMessage());
    }
  } else {
    throw new UnsupportedCallbackException(callback);
  }
}
 
Example #2
Source File: UpnPwdCallbackHandler.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException,
		UnsupportedCallbackException {
	
	for (Callback callback : callbacks) {
		if (callback instanceof TextOutputCallback) {
			 TextOutputCallback tc = (TextOutputCallback) callback;
			 switch (tc.getMessageType()) {
			 	case TextOutputCallback.INFORMATION: logger.info(tc.getMessage()); break;
			 	case TextOutputCallback.ERROR: logger.error(tc.getMessage()); break;
			 	case TextOutputCallback.WARNING: logger.warn(tc.getMessage()); break;
			 }
		} else if (callback instanceof NameCallback) {
			NameCallback nc = (NameCallback) callback;
			nc.setName(upn);
		} else if (callback instanceof PasswordCallback) {
			PasswordCallback pc = (PasswordCallback) callback;
			pc.setPassword(this.password.toCharArray());
		}
	}

}
 
Example #3
Source File: DefaultCallbackHandler.java    From attic-apex-core with Apache License 2.0 6 votes vote down vote up
protected void processCallback(Callback callback) throws IOException, UnsupportedCallbackException
{
  if (callback instanceof NameCallback) {
    NameCallback namecb = (NameCallback)callback;
    namecb.setName(context.getValue(SecurityContext.USER_NAME));
  } else if (callback instanceof PasswordCallback) {
    PasswordCallback passcb = (PasswordCallback)callback;
    passcb.setPassword(context.getValue(SecurityContext.PASSWORD));
  } else if (callback instanceof RealmCallback) {
    RealmCallback realmcb = (RealmCallback)callback;
    realmcb.setText(context.getValue(SecurityContext.REALM));
  } else if (callback instanceof TextOutputCallback) {
    TextOutputCallback textcb = (TextOutputCallback)callback;
    if (textcb.getMessageType() == TextOutputCallback.INFORMATION) {
      logger.info(textcb.getMessage());
    } else if (textcb.getMessageType() == TextOutputCallback.WARNING) {
      logger.warn(textcb.getMessage());
    } else if (textcb.getMessageType() == TextOutputCallback.ERROR) {
      logger.error(textcb.getMessage());
    } else {
      logger.debug("Auth message type {}, message {}", textcb.getMessageType(), textcb.getMessage());
    }
  } else {
    throw new UnsupportedCallbackException(callback);
  }
}
 
Example #4
Source File: TMLoginModuleTest.java    From ontopia with Apache License 2.0 6 votes vote down vote up
@Override
   public void handle(Callback[] callbacks)
     throws IOException, UnsupportedCallbackException {
   
     for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof NameCallback) {
         // prompt the user for a username
         NameCallback nc = (NameCallback)callbacks[i];
  String username = tokens[index++];
         nc.setName(username);

       } else if (callbacks[i] instanceof PasswordCallback) {      
         // prompt the user for sensitive information
         PasswordCallback pc = (PasswordCallback)callbacks[i];
  String password = tokens[index++];
         pc.setPassword(password.toCharArray());

} else if (callbacks[i] instanceof TextOutputCallback) {
  // ignore
       
       } else {
         throw new UnsupportedCallbackException(callbacks[i], 
					 "Unrecognized Callback");
       }
     }
   }
 
Example #5
Source File: KerberosUtilities.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
private LoginContext createLoginContext(final String serviceName, final Subject subject, final Configuration config)
        throws LoginException
{
    return new LoginContext(serviceName, subject, callbacks -> {
        for (Callback callback : callbacks)
        {
            if (callback instanceof TextOutputCallback)
            {
                LOGGER.error(((TextOutputCallback) callback).getMessage());
            }
        }
    }, config);
}
 
Example #6
Source File: TestHBaseSaslRpcClient.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testDigestSaslClientCallbackHandlerWithException() {
  final Token<? extends TokenIdentifier> token = createTokenMock();
  when(token.getIdentifier()).thenReturn(Bytes.toBytes(DEFAULT_USER_NAME));
  when(token.getPassword()).thenReturn(Bytes.toBytes(DEFAULT_USER_PASSWORD));
  final DigestSaslClientCallbackHandler saslClCallbackHandler =
      new DigestSaslClientCallbackHandler(token);
  try {
    saslClCallbackHandler.handle(new Callback[] { mock(TextOutputCallback.class) });
  } catch (UnsupportedCallbackException expEx) {
    //expected
  } catch (Exception ex) {
    fail("testDigestSaslClientCallbackHandlerWithException error : " + ex.getMessage());
  }
}