本文整理汇总了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");
}
}
}
示例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");
}
}
}
示例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());
}
}
}
}
示例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");
}
}
}
示例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);
}
}
示例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);
}
}
}
示例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());
}
}
};
}
示例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
}
示例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);
}
}
}
示例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);
}
示例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);
}
}
示例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 ) ) );
}
}
}
}
示例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");
}
}
}
}
}
}
示例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");
}
}
}
}
}
}