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


Java PasswordCallback.setPassword方法代碼示例

本文整理匯總了Java中javax.security.auth.callback.PasswordCallback.setPassword方法的典型用法代碼示例。如果您正苦於以下問題:Java PasswordCallback.setPassword方法的具體用法?Java PasswordCallback.setPassword怎麽用?Java PasswordCallback.setPassword使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.security.auth.callback.PasswordCallback的用法示例。


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

示例1: handle

import javax.security.auth.callback.PasswordCallback; //導入方法依賴的package包/類
public void handle(Callback[] callbacks)
        throws IOException, UnsupportedCallbackException {
    System.out.println("Callback Handler - handle called");
    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof NameCallback) {
            NameCallback nameCallback = (NameCallback) callbacks[i];
            nameCallback.setName(name);
        } else if (callbacks[i] instanceof PasswordCallback) {
            PasswordCallback passwordCallback = (PasswordCallback) callbacks[i];
            passwordCallback.setPassword(password.toCharArray());
        } else {
            throw new UnsupportedCallbackException(callbacks[i],
                    "The submitted Callback is unsupported");
        }
    }
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:17,代碼來源:WSCallbackHandler.java

示例2: handle

import javax.security.auth.callback.PasswordCallback; //導入方法依賴的package包/類
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            NameCallback ncb = (NameCallback) callback;
            ncb.setName(username);
        } else if (callback instanceof PasswordCallback) {
            PasswordCallback pwcb = (PasswordCallback) callback;
            pwcb.setPassword(password.toCharArray());
        } else {
            throw new UnsupportedCallbackException(
                    callback,
                    "We got a "
                            + callback.getClass().getCanonicalName()
                            + ", but only NameCallback and PasswordCallback is supported");
        }
    }
}
 
開發者ID:Transwarp-DE,項目名稱:Transwarp-Sample-Code,代碼行數:19,代碼來源:KerberosAuthenticator2.java

示例3: handle

import javax.security.auth.callback.PasswordCallback; //導入方法依賴的package包/類
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            NameCallback nameCallback = (NameCallback) callback;
            nameCallback.setName(nameCallback.getDefaultName());
        } else if (callback instanceof PasswordCallback) {
            PasswordCallback passwordCallback = (PasswordCallback) callback;
            passwordCallback.setPassword(TestJaasConfig.PASSWORD.toCharArray());
        } else if (callback instanceof RealmCallback) {
            RealmCallback realmCallback = (RealmCallback) callback;
            realmCallback.setText(realmCallback.getDefaultText());
        } else if (callback instanceof AuthorizeCallback) {
            AuthorizeCallback authCallback = (AuthorizeCallback) callback;
            if (TestJaasConfig.USERNAME.equals(authCallback.getAuthenticationID())) {
                authCallback.setAuthorized(true);
                authCallback.setAuthorizedID(authCallback.getAuthenticationID());
            }
        }
    }
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:22,代碼來源:TestDigestLoginModule.java

示例4: handle

import javax.security.auth.callback.PasswordCallback; //導入方法依賴的package包/類
@Override
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            NameCallback nc = (NameCallback) callback;
            nc.setName(userName);
        } else if (callback instanceof PasswordCallback) {
            PasswordCallback pc = (PasswordCallback) callback;
            pc.setPassword(password);
        } else {
            throw new UnsupportedCallbackException(callback,
                    "Unrecognized Callback");
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:17,代碼來源:DynamicConfigurationTest.java

示例5: handlePasswordCallback

import javax.security.auth.callback.PasswordCallback; //導入方法依賴的package包/類
private void handlePasswordCallback(PasswordCallback pc) {
    if ("super".equals(this.userName) && System.getProperty(SYSPROP_SUPER_PASSWORD) != null) {
        // superuser: use Java system property for password, if available.
        pc.setPassword(System.getProperty(SYSPROP_SUPER_PASSWORD).toCharArray());
    } else if (credentials.containsKey(userName) ) {
        pc.setPassword(credentials.get(userName).toCharArray());
    } else {
        LOG.warn("No password found for user: " + userName);
    }
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:11,代碼來源:SaslServerCallbackHandler.java

示例6: handle

import javax.security.auth.callback.PasswordCallback; //導入方法依賴的package包/類
public void handle(
                    Callback[] callbacks ) throws IOException, UnsupportedCallbackException {

    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof NameCallback) {
            NameCallback nc = (NameCallback) callbacks[i];
            nc.setName(username);
        } else if (callbacks[i] instanceof PasswordCallback) {
            PasswordCallback pc = (PasswordCallback) callbacks[i];
            pc.setPassword(password);
        }
    }
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:14,代碼來源:JaasKerberosConfiguration.java

示例7: getUsernamePasswordHandler

import javax.security.auth.callback.PasswordCallback; //導入方法依賴的package包/類
private static CallbackHandler getUsernamePasswordHandler(final String username, final String password) {
    return callbacks -> {
        for (Callback callback : callbacks) {
            if (callback instanceof NameCallback) {
                final NameCallback nameCallback = (NameCallback) callback;
                nameCallback.setName(username);
            } else if (callback instanceof PasswordCallback) {
                final PasswordCallback passCallback = (PasswordCallback) callback;
                passCallback.setPassword(password.toCharArray());
            } else {
                System.err.println("Unsupported Callback: " + callback.getClass().getName());
            }
        }
    };
}
 
開發者ID:LIBCAS,項目名稱:ARCLib,代碼行數:16,代碼來源:PasswordTicketValidator.java

示例8: handle

import javax.security.auth.callback.PasswordCallback; //導入方法依賴的package包/類
public void handle(Callback[] callbacks)
        throws IOException, UnsupportedCallbackException {
    if (!(callbacks[0] instanceof PasswordCallback)) {
        throw new UnsupportedCallbackException(callbacks[0]);
    }
    PasswordCallback pc = (PasswordCallback)callbacks[0];
    pc.setPassword(password);  // this clones the password if not null
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:9,代碼來源:P11KeyStore.java

示例9: handle

import javax.security.auth.callback.PasswordCallback; //導入方法依賴的package包/類
public void handle(Callback[] callbacks) {
    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof NameCallback) {
            NameCallback nc = (NameCallback) callbacks[i];
            nc.setName(user);
        } else if (callbacks[i] instanceof PasswordCallback) {
            PasswordCallback pc = (PasswordCallback) callbacks[i];
            pc.setPassword(pass);
        }
    }
}
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:12,代碼來源:UserPassCallbackHandler.java

示例10: bad7

import javax.security.auth.callback.PasswordCallback; //導入方法依賴的package包/類
public void bad7() throws Exception {
    byte[] bytes = new byte[2];
    char[] pwd = "secret7".toCharArray();
    new PBEKeySpec(pwd);
    new PBEKeySpec(pwd, bytes, 1);
    new PBEKeySpec(pwd, bytes, 1, 1);
    PasswordAuthentication auth = new PasswordAuthentication("user", pwd);
    PasswordCallback callback = new PasswordCallback("str", true);
    callback.setPassword(pwd);
    KeyStore.PasswordProtection protection = new KeyStore.PasswordProtection(pwd);
    KerberosKey key = new KerberosKey(null, pwd, "alg");
    KeyManagerFactory.getInstance("").init(null, pwd);
}
 
開發者ID:blackarbiter,項目名稱:Android_Code_Arbiter,代碼行數:14,代碼來源:ConstantPasswords.java

示例11: handlePasswordCallback

import javax.security.auth.callback.PasswordCallback; //導入方法依賴的package包/類
private void handlePasswordCallback(PasswordCallback pc) {
    if (credentials.containsKey(userName) ) {
        pc.setPassword(credentials.get(userName).toCharArray());
    } else {
        LOG.warn("No password found for user: {}", userName);
    }
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:8,代碼來源:SaslQuorumServerCallbackHandler.java

示例12: handle

import javax.security.auth.callback.PasswordCallback; //導入方法依賴的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

示例13: handle

import javax.security.auth.callback.PasswordCallback; //導入方法依賴的package包/類
public void handle(Callback[] callbacks) throws
  UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            NameCallback nc = (NameCallback) callback;
            nc.setName(nc.getDefaultName());
        }
        else {
            if (callback instanceof PasswordCallback) {
                PasswordCallback pc = (PasswordCallback)callback;
                if (password != null) {
                    pc.setPassword(this.password.toCharArray());
                } else {
                    LOG.warn("Could not login: the client is being asked for a password, but the Zookeeper" +
                      " client code does not currently support obtaining a password from the user." +
                      " Make sure that the client is configured to use a ticket cache (using" +
                      " the JAAS configuration setting 'useTicketCache=true)' and restart the client. If" +
                      " you still get this message after that, the TGT in the ticket cache has expired and must" +
                      " be manually refreshed. To do so, first determine if you are using a password or a" +
                      " keytab. If the former, run kinit in a Unix shell in the environment of the user who" +
                      " is running this Zookeeper client using the command" +
                      " 'kinit <princ>' (where <princ> is the name of the client's Kerberos principal)." +
                      " If the latter, do" +
                      " 'kinit -k -t <keytab> <princ>' (where <princ> is the name of the Kerberos principal, and" +
                      " <keytab> is the location of the keytab file). After manually refreshing your cache," +
                      " restart this client. If you continue to see this message after manually refreshing" +
                      " your cache, ensure that your KDC host's clock is in sync with this host's clock.");
                }
            }
            else {
                if (callback instanceof RealmCallback) {
                    RealmCallback rc = (RealmCallback) callback;
                    rc.setText(rc.getDefaultText());
                }
                else {
                    if (callback instanceof AuthorizeCallback) {
                        AuthorizeCallback ac = (AuthorizeCallback) callback;
                        String authid = ac.getAuthenticationID();
                        String authzid = ac.getAuthorizationID();
                        if (authid.equals(authzid)) {
                            ac.setAuthorized(true);
                        } else {
                            ac.setAuthorized(false);
                        }
                        if (ac.isAuthorized()) {
                            ac.setAuthorizedID(authzid);
                        }
                    }
                    else {
                        throw new UnsupportedCallbackException(callback,"Unrecognized SASL ClientCallback");
                    }
                }
            }
        }
    }
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:57,代碼來源:ZooKeeperSaslClient.java

示例14: handle

import javax.security.auth.callback.PasswordCallback; //導入方法依賴的package包/類
public void handle(Callback[] callbacks) throws UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            NameCallback nc = (NameCallback) callback;
            nc.setName(nc.getDefaultName());
        }
        else {
            if (callback instanceof PasswordCallback) {
                PasswordCallback pc = (PasswordCallback)callback;
                if (password != null) {
                    pc.setPassword(this.password.toCharArray());
                } else {
                    LOG.warn("Could not login: the {} is being asked for a password, but the ZooKeeper {}" +
                      " code does not currently support obtaining a password from the user." +
                      " Make sure that the {} is configured to use a ticket cache (using" +
                      " the JAAS configuration setting 'useTicketCache=true)' and restart the {}. If" +
                      " you still get this message after that, the TGT in the ticket cache has expired and must" +
                      " be manually refreshed. To do so, first determine if you are using a password or a" +
                      " keytab. If the former, run kinit in a Unix shell in the environment of the user who" +
                      " is running this Zookeeper {} using the command" +
                      " 'kinit <princ>' (where <princ> is the name of the {}'s Kerberos principal)." +
                      " If the latter, do" +
                      " 'kinit -k -t <keytab> <princ>' (where <princ> is the name of the Kerberos principal, and" +
                      " <keytab> is the location of the keytab file). After manually refreshing your cache," +
                      " restart this {}. If you continue to see this message after manually refreshing" +
                      " your cache, ensure that your KDC host's clock is in sync with this host's clock.",
                      new Object[]{entity, entity, entity, entity, entity, entity, entity});
                }
            }
            else {
                if (callback instanceof RealmCallback) {
                    RealmCallback rc = (RealmCallback) callback;
                    rc.setText(rc.getDefaultText());
                }
                else {
                    if (callback instanceof AuthorizeCallback) {
                        AuthorizeCallback ac = (AuthorizeCallback) callback;
                        String authid = ac.getAuthenticationID();
                        String authzid = ac.getAuthorizationID();
                        if (authid.equals(authzid)) {
                            ac.setAuthorized(true);
                        } else {
                            ac.setAuthorized(false);
                        }
                        if (ac.isAuthorized()) {
                            ac.setAuthorizedID(authzid);
                        }
                    }
                    else {
                        throw new UnsupportedCallbackException(callback, "Unrecognized SASL " + entity + "Callback");
                    }
                }
            }
        }
    }
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:57,代碼來源:SaslClientCallbackHandler.java


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