- See Also:
- Top Examples, Source Code
void handle(Callback[] callbacks)
throws IOException,
UnsupportedCallbackException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[509]Implements a security service CallbackHandler
By Anonymous on 2003/11/13 16:06:11 Rate
private static class CBH implements CallbackHandler {
public void handle ( Callback [ ] callbacks )
throws UnsupportedCallbackException, IOException {
for ( int i = 0; i < callbacks.length; i++ ) {
if ( callbacks [ i ] instanceof TextOutputCallback ) {
// display the message according to the specified type
TextOutputCallback toc = ( TextOutputCallback ) callbacks [ i ] ;
switch ( toc.getMessageType ( ) ) {
case TextOutputCallback.INFORMATION:
System.err.println ( toc.getMessage ( ) ) ;
break;
case TextOutputCallback.ERROR:
System.err.println ( "ERROR: " + toc.getMessage ( ) ) ;
break;
case TextOutputCallback.WARNING:
System.err.println ( "WARNING: " + toc.getMessage ( ) ) ;
break;
default:
throw new IOException ( "Unsupported message type: " +
toc.getMessageType ( ) ) ;
}
} else if ( callbacks [ i ] instanceof NameCallback ) {
// prompt the user for a username
NameCallback nc = ( NameCallback ) callbacks [ i ] ;
nc.setName ( "junit" ) ;
} else if ( callbacks [ i ] instanceof PasswordCallback ) {
// prompt the user for sensitive information
PasswordCallback pc = ( PasswordCallback ) callbacks [ i ] ;
pc.setPassword ( "junit".toCharArray ( ) ) ;
} else {
throw new UnsupportedCallbackException
( callbacks [ i ] , "Unrecognized Callback" ) ;
}
}
}
}