當前位置: 首頁>>代碼示例>>Java>>正文


Java RealmChoiceCallback類代碼示例

本文整理匯總了Java中javax.security.sasl.RealmChoiceCallback的典型用法代碼示例。如果您正苦於以下問題:Java RealmChoiceCallback類的具體用法?Java RealmChoiceCallback怎麽用?Java RealmChoiceCallback使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


RealmChoiceCallback類屬於javax.security.sasl包,在下文中一共展示了RealmChoiceCallback類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testSaslClientCallbackHandler

import javax.security.sasl.RealmChoiceCallback; //導入依賴的package包/類
@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));
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:20,代碼來源:TestHBaseSaslRpcClient.java

示例2: handle

import javax.security.sasl.RealmChoiceCallback; //導入依賴的package包/類
/**
 * 
 */
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof NameCallback) {
            NameCallback ncb = (NameCallback)callbacks[i];
            ncb.setName(authenticationId);
        } else if(callbacks[i] instanceof PasswordCallback) {
            PasswordCallback pcb = (PasswordCallback)callbacks[i];
            pcb.setPassword(password.toCharArray());
        } else if(callbacks[i] instanceof RealmCallback) {
            RealmCallback rcb = (RealmCallback)callbacks[i];
            rcb.setText(hostname);
        } else if(callbacks[i] instanceof RealmChoiceCallback){
            //unused
            //RealmChoiceCallback rccb = (RealmChoiceCallback)callbacks[i];
        } else {
           throw new UnsupportedCallbackException(callbacks[i]);
        }
     }
}
 
開發者ID:ice-coffee,項目名稱:EIM,代碼行數:23,代碼來源:SASLMechanism.java

示例3: handle

import javax.security.sasl.RealmChoiceCallback; //導入依賴的package包/類
@Override
public void handle(Callback[] callbacks)
    throws IOException, UnsupportedCallbackException {
  for (Callback cb : callbacks) {
    if (cb instanceof RealmChoiceCallback) {
      continue; // Ignore.
    } else if (cb instanceof NameCallback) {
      ((NameCallback)cb).setName(token_.identifier);
    } else if (cb instanceof PasswordCallback) {
      PasswordCallback pcb = ((PasswordCallback)cb);
      if (token_.password == null) {
        pcb.setPassword(null);
      } else {
        pcb.setPassword(token_.password.toCharArray());
      }
    } else if (cb instanceof RealmCallback) {
      RealmCallback rcb = (RealmCallback)cb;
      rcb.setText(rcb.getDefaultText());
    } else {
      throw new UnsupportedCallbackException(cb, "Unexpected DIGEST-MD5 callback");
    }
  }
}
 
開發者ID:cloudera,項目名稱:RecordServiceClient,代碼行數:24,代碼來源:ThriftUtils.java

示例4: testSaslClientCallbackHandler

import javax.security.sasl.RealmChoiceCallback; //導入依賴的package包/類
@Test
public void testSaslClientCallbackHandler() throws UnsupportedCallbackException {
  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 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(any());
  verify(passwordCallback).setPassword(any());
}
 
開發者ID:apache,項目名稱:hbase,代碼行數:19,代碼來源:TestHBaseSaslRpcClient.java

示例5: 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;
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:20,代碼來源:RealmChoiceCallbackTest.java

示例6: handle

import javax.security.sasl.RealmChoiceCallback; //導入依賴的package包/類
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback current : callbacks) {
        if (current instanceof RealmCallback) {
            RealmCallback rcb = (RealmCallback) current;
            String defaultText = rcb.getDefaultText();
            rcb.setText(defaultText); // For now just use the realm suggested.
        } else if (current instanceof RealmChoiceCallback) {
            throw DomainManagementLogger.ROOT_LOGGER.realmNotSupported(current);
        } else if (current instanceof OptionalNameCallback) {
            // Do nothing as we don't want to set a name for local authentication.
        } else if (current instanceof NameCallback) {
            NameCallback ncb = (NameCallback) current;
            ncb.setName(userName);
        } else if (current instanceof PasswordCallback) {
            PasswordCallback pcb = (PasswordCallback) current;
            pcb.setPassword(password);
        } else {
            throw new UnsupportedCallbackException(current);
        }
    }
}
 
開發者ID:wildfly,項目名稱:wildfly-core,代碼行數:22,代碼來源:SecretIdentityService.java

示例7: handle

import javax.security.sasl.RealmChoiceCallback; //導入依賴的package包/類
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback current : callbacks) {
        if (current instanceof RealmCallback) {
            RealmCallback rcb = (RealmCallback) current;
            String defaultText = rcb.getDefaultText();
            rcb.setText(defaultText); // For now just use the realm suggested.
        } else if (current instanceof RealmChoiceCallback) {
            throw new UnsupportedCallbackException(current, "Realm choice not currently supported.");
        } else if (current instanceof NameCallback) {
            NameCallback ncb = (NameCallback) current;
            ncb.setName(userName);
        } else if (current instanceof PasswordCallback) {
            PasswordCallback pcb = (PasswordCallback) current;
            pcb.setPassword(authKey.toCharArray());
        } else {
            throw new UnsupportedCallbackException(current);
        }
    }
}
 
開發者ID:wildfly,項目名稱:wildfly-core,代碼行數:20,代碼來源:HostControllerConnection.java

示例8: handle

import javax.security.sasl.RealmChoiceCallback; //導入依賴的package包/類
/**
 * 
 */
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof NameCallback) {
            NameCallback ncb = (NameCallback)callbacks[i];
            ncb.setName(authenticationId);
        } else if(callbacks[i] instanceof PasswordCallback) {
            PasswordCallback pcb = (PasswordCallback)callbacks[i];
            pcb.setPassword(password.toCharArray());
        } else if(callbacks[i] instanceof RealmCallback) {
            RealmCallback rcb = (RealmCallback)callbacks[i];
            //Retrieve the REALM from the challenge response that the server returned when the client initiated the authentication 
            //exchange. If this value is not null or empty, *this value* has to be sent back to the server in the client's response 
            //to the server's challenge
            String text = rcb.getDefaultText();
            //The SASL client (sc) created in smack  uses rcb.getText when creating the negotiatedRealm to send it back to the server
            //Make sure that this value matches the server's realm
            rcb.setText(text);
        } else if(callbacks[i] instanceof RealmChoiceCallback){
            //unused
            //RealmChoiceCallback rccb = (RealmChoiceCallback)callbacks[i];
        } else {
           throw new UnsupportedCallbackException(callbacks[i]);
        }
     }
}
 
開發者ID:bejayoharen,項目名稱:java-bells,代碼行數:29,代碼來源:SASLMechanism.java

示例9: 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);
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:40,代碼來源:ClientServerTest.java

示例10: handle

import javax.security.sasl.RealmChoiceCallback; //導入依賴的package包/類
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    // Special case for anonymous authentication to avoid prompting user for their name.
    if (callbacks.length == 1 && callbacks[0] instanceof NameCallback) {
        ((NameCallback)callbacks[0]).setName("anonymous CLI user"); //$NON-NLS-1$
        return;
    }

    for (Callback current : callbacks) {
        if (current instanceof RealmCallback) {
            RealmCallback rcb = (RealmCallback) current;
            String defaultText = rcb.getDefaultText();
            rcb.setText(defaultText); // For now just use the realm suggested.
            if (this.realmShown == false) {
                this.realmShown = true;
            }
        } else if (current instanceof RealmChoiceCallback) {
            throw new UnsupportedCallbackException(current, "Realm choice not currently supported."); //$NON-NLS-1$
        } else if (current instanceof NameCallback) {
            NameCallback ncb = (NameCallback) current;
            ncb.setName(this.userName);
        } else if (current instanceof PasswordCallback) {
            PasswordCallback pcb = (PasswordCallback) current;
            pcb.setPassword(this.password);
        } else {
            throw new UnsupportedCallbackException(current);
        }
    }
}
 
開發者ID:kenweezy,項目名稱:teiid,代碼行數:29,代碼來源:AdminFactory.java

示例11: handle

import javax.security.sasl.RealmChoiceCallback; //導入依賴的package包/類
public void handle(Callback[] callbacks) throws java.io.IOException,
        UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof RealmChoiceCallback) {
            // TODO what to do here?
            // RealmChoiceCallback rcc = (RealmChoiceCallback) callbacks[i];

        } else if (callbacks[i] instanceof RealmCallback) {
            RealmCallback rc = (RealmCallback) callbacks[i];
            if (env.get(JAVA_NAMING_SECURITY_SASL_REALM) != null) {
                realm = (String) env.get(JAVA_NAMING_SECURITY_SASL_REALM);
                rc.setText(realm);
            } else {
                rc.setText(realm);
            }
        } else if (callbacks[i] instanceof PasswordCallback) {
            PasswordCallback pc = (PasswordCallback) callbacks[i];
            pc.setPassword(Utils.getCharArray(env
                    .get(Context.SECURITY_CREDENTIALS)));
        } else if (callbacks[i] instanceof NameCallback) {
            //authentication Id
            NameCallback nc = (NameCallback) callbacks[i];
            nc.setName((String) env.get(Context.SECURITY_PRINCIPAL));
        } else {
            throw new UnsupportedCallbackException(callbacks[i]);
        }
    }
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:29,代碼來源:DefaultCallbackHandler.java

示例12: assertDeserialized

import javax.security.sasl.RealmChoiceCallback; //導入依賴的package包/類
public void assertDeserialized(Serializable oref, Serializable otest) {
        RealmChoiceCallback ref = (RealmChoiceCallback) oref;
        RealmChoiceCallback test = (RealmChoiceCallback) otest;
        
        boolean all = ref.allowMultipleSelections();
        assertEquals(all, test.allowMultipleSelections());
        String prompt = ref.getPrompt();
        assertEquals(prompt, test.getPrompt());
        
        String [] ch = ref.getChoices();
        String [] tCh = test.getChoices();        
        assertEquals(ch.length, tCh.length);        
        for (int i = 0; i < ch.length; i++) {
            assertEquals(ch[i], tCh[i]);
        }
        assertEquals(ref.getDefaultChoice(), test.getDefaultChoice());
        int [] in = ref.getSelectedIndexes();
        int [] tIn = test.getSelectedIndexes();
//        assertNull("in is not null", in);            
//        assertNull("tIn is not null", tIn);

        if (!all) {
            assertEquals("Incorrect length in ", in.length, 1);
            assertEquals("Incorrect length tIn ", tIn.length, 1);
            assertEquals("Incorrect index", in[0], tIn[0]);
        } else {
            assertEquals("Incorrect length", in.length, tIn.length);
            for (int i = 0; i < in.length; i++) {
                assertEquals(in[i], tIn[i]);
            }            
        }
    }
 
開發者ID:shannah,項目名稱:cn1,代碼行數:33,代碼來源:RealmChoiceCallbackTest.java

示例13: handle

import javax.security.sasl.RealmChoiceCallback; //導入依賴的package包/類
/**
 * 
 */
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof NameCallback) {
            NameCallback ncb = (NameCallback) callbacks[i];
            ncb.setName(authenticationId);
        } else if (callbacks[i] instanceof PasswordCallback) {
            PasswordCallback pcb = (PasswordCallback) callbacks[i];
            pcb.setPassword(password.toCharArray());
        } else if (callbacks[i] instanceof RealmCallback) {
            RealmCallback rcb = (RealmCallback) callbacks[i];
            // Retrieve the REALM from the challenge response that the
            // server returned when the client initiated the authentication
            // exchange. If this value is not null or empty, *this value*
            // has to be sent back to the server in the client's response
            // to the server's challenge
            String text = rcb.getDefaultText();
            // The SASL client (sc) created in smack uses rcb.getText when
            // creating the negotiatedRealm to send it back to the server
            // Make sure that this value matches the server's realm
            rcb.setText(text);
        } else if (callbacks[i] instanceof RealmChoiceCallback) {
            // unused
            // RealmChoiceCallback rccb = (RealmChoiceCallback)callbacks[i];
        } else {
            throw new UnsupportedCallbackException(callbacks[i]);
        }
    }
}
 
開發者ID:abmargb,項目名稱:jamppa,代碼行數:33,代碼來源:SASLMechanism.java

示例14: handle

import javax.security.sasl.RealmChoiceCallback; //導入依賴的package包/類
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    // Special case for anonymous authentication to avoid prompting user for their name.
    if (callbacks.length == 1 && callbacks[0] instanceof NameCallback) {
        ((NameCallback) callbacks[0]).setName("anonymous demo user");
        return;
    }

    for (Callback current : callbacks) {
        if (current instanceof RealmCallback) {
            final RealmCallback rcb = (RealmCallback) current;
            final String defaultText = rcb.getDefaultText();
            rcb.setText(defaultText); // For now just use the realm suggested.

            prompt(defaultText);
        } else if (current instanceof RealmChoiceCallback) {
            throw new UnsupportedCallbackException(current, "Realm choice not currently supported.");
        } else if (current instanceof NameCallback) {
            final NameCallback ncb = (NameCallback) current;
            final String userName = obtainUsername("Username:");

            ncb.setName(userName);
        } else if (current instanceof PasswordCallback) {
            PasswordCallback pcb = (PasswordCallback) current;
            char[] password = obtainPassword("Password:");

            pcb.setPassword(password);
        } else {
            throw new UnsupportedCallbackException(current);
        }
    }
}
 
開發者ID:wildfly,項目名稱:wildfly-maven-plugin,代碼行數:33,代碼來源:ClientCallbackHandler.java

示例15: 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 ) ) );
            }
        }
    }
}
 
開發者ID:apache,項目名稱:directory-ldap-api,代碼行數:71,代碼來源:SaslCallbackHandler.java


注:本文中的javax.security.sasl.RealmChoiceCallback類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。