本文整理匯總了Java中javax.security.sasl.RealmChoiceCallback.setSelectedIndex方法的典型用法代碼示例。如果您正苦於以下問題:Java RealmChoiceCallback.setSelectedIndex方法的具體用法?Java RealmChoiceCallback.setSelectedIndex怎麽用?Java RealmChoiceCallback.setSelectedIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.security.sasl.RealmChoiceCallback
的用法示例。
在下文中一共展示了RealmChoiceCallback.setSelectedIndex方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getData
import javax.security.sasl.RealmChoiceCallback; //導入方法依賴的package包/類
@Override
protected Object[] getData() {
Object [] oo = {
new RealmChoiceCallback(msgs[0], msgs, 0, true),
new RealmChoiceCallback(msgs[1], msgs, 1, true),
new RealmChoiceCallback(msgs[1], msgs, 0, false),
new RealmChoiceCallback(msgs[2], msgs, 0, false)
};
for (Object element : oo) {
RealmChoiceCallback rc = (RealmChoiceCallback)element;
if (rc.allowMultipleSelections()) {
rc.setSelectedIndexes(idx);
} else {
rc.setSelectedIndex(msgs.length - 1);
}
}
return oo;
}
示例2: handle
import javax.security.sasl.RealmChoiceCallback; //導入方法依賴的package包/類
@Override
public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException {
for (Callback callback : callbacks) {
if (callback instanceof NameCallback) {
System.out.println("NameCallback");
((NameCallback) callback).setName(userId);
} else if (callback instanceof PasswordCallback) {
System.out.println("PasswordCallback");
((PasswordCallback) callback).setPassword(passwd);
} else if (callback instanceof RealmCallback) {
System.out.println("RealmCallback");
((RealmCallback) callback).setText(realm);
} else if (callback instanceof RealmChoiceCallback) {
System.out.println("RealmChoiceCallback");
RealmChoiceCallback choice = (RealmChoiceCallback) callback;
if (realm == null) {
choice.setSelectedIndex(choice.getDefaultChoice());
} else {
String[] choices = choice.getChoices();
for (int j = 0; j < choices.length; j++) {
if (realm.equals(choices[j])) {
choice.setSelectedIndex(j);
break;
}
}
}
} else if (callback instanceof AuthorizeCallback) {
System.out.println("AuthorizeCallback");
((AuthorizeCallback) callback).setAuthorized(true);
if (authId == null || authId.trim().length() == 0) {
authId = userId;
}
((AuthorizeCallback) callback).setAuthorizedID(authId);
} else {
throw new UnsupportedCallbackException(callback);
}
}
}
示例3: handle
import javax.security.sasl.RealmChoiceCallback; //導入方法依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
public void handle( Callback[] callbacks ) throws IOException, UnsupportedCallbackException
{
for ( Callback cb : callbacks )
{
if ( cb instanceof NameCallback )
{
NameCallback ncb = ( NameCallback ) cb;
String name = saslReq.getUsername();
LOG.debug( "sending name {} in the NameCallback", name );
ncb.setName( name );
}
else if ( cb instanceof PasswordCallback )
{
PasswordCallback pcb = ( PasswordCallback ) cb;
LOG.debug( "sending credentials in the PasswordCallback" );
pcb.setPassword( Strings.utf8ToString( saslReq.getCredentials() ).toCharArray() );
}
else if ( cb instanceof RealmCallback )
{
RealmCallback rcb = ( RealmCallback ) cb;
if ( saslReq.getRealmName() != null )
{
LOG.debug( "sending the user specified realm value {} in the RealmCallback", saslReq.getRealmName() );
rcb.setText( saslReq.getRealmName() );
}
else
{
LOG.debug(
"No user specified relam value, sending the default realm value {} in the RealmCallback",
rcb.getDefaultText() );
rcb.setText( rcb.getDefaultText() );
}
}
else if ( cb instanceof RealmChoiceCallback )
{
RealmChoiceCallback rccb = ( RealmChoiceCallback ) cb;
boolean foundRealmName = false;
String[] realmNames = rccb.getChoices();
for ( int i = 0; i < realmNames.length; i++ )
{
String realmName = realmNames[i];
if ( realmName.equals( saslReq.getRealmName() ) )
{
foundRealmName = true;
LOG.debug( "sending the user specified realm value {} in the RealmChoiceCallback", realmName );
rccb.setSelectedIndex( i );
break;
}
}
if ( !foundRealmName )
{
throw new IOException(
I18n.format(
"Cannot match ''java.naming.security.sasl.realm'' property value ''{0}'' with choices ''{1}'' in RealmChoiceCallback.",
saslReq.getRealmName(), getRealmNamesAsString( realmNames ) ) );
}
}
}
}