Java Code Examples for javax.security.sasl.RealmCallback.setText()

The following are Jave code examples for showing how to use setText() of the javax.security.sasl.RealmCallback class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: kafka-0.11.0.0-src-with-comment   File: AbstractLogin.java   Source Code and License Vote up 6 votes
@Override
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) {
            String errorMessage = "Could not login: the client is being asked for a password, but the Kafka" +
                         " client code does not currently support obtaining a password from the user.";
            throw new UnsupportedCallbackException(callback, errorMessage);
        } else if (callback instanceof RealmCallback) {
            RealmCallback rc = (RealmCallback) callback;
            rc.setText(rc.getDefaultText());
        } else {
            throw new UnsupportedCallbackException(callback, "Unrecognized SASL Login callback");
        }
    }
}
 
Example 2
Project: kafka-0.11.0.0-src-with-comment   File: TestDigestLoginModule.java   Source Code and License Vote up 6 votes
@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());
            }
        }
    }
}
 
Example 3
Project: kafka   File: AbstractLogin.java   Source Code and License Vote up 6 votes
@Override
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) {
            String errorMessage = "Could not login: the client is being asked for a password, but the Kafka" +
                         " client code does not currently support obtaining a password from the user.";
            throw new UnsupportedCallbackException(callback, errorMessage);
        } else if (callback instanceof RealmCallback) {
            RealmCallback rc = (RealmCallback) callback;
            rc.setText(rc.getDefaultText());
        } else {
            throw new UnsupportedCallbackException(callback, "Unrecognized SASL Login callback");
        }
    }
}
 
Example 4
Project: kafka   File: TestDigestLoginModule.java   Source Code and License Vote up 6 votes
@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());
            }
        }
    }
}
 
Example 5
Project: registry   File: AbstractLogin.java   Source Code and License Vote up 6 votes
@Override
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) {
            String errorMessage = "Could not login: the client is being asked for a password, but this " +
                    " module does not currently support obtaining a password from the user.";
            throw new UnsupportedCallbackException(callback, errorMessage);
        } else if (callback instanceof RealmCallback) {
            RealmCallback rc = (RealmCallback) callback;
            rc.setText(rc.getDefaultText());
        } else {
            throw new UnsupportedCallbackException(callback, "Unrecognized Login callback");
        }
    }
}
 
Example 6
Project: apex-core   File: DefaultCallbackHandler.java   Source Code and License Vote up 6 votes
protected void processCallback(Callback callback) throws IOException, UnsupportedCallbackException
{
  if (callback instanceof NameCallback) {
    NameCallback namecb = (NameCallback)callback;
    namecb.setName(context.getValue(SecurityContext.USER_NAME));
  } else if (callback instanceof PasswordCallback) {
    PasswordCallback passcb = (PasswordCallback)callback;
    passcb.setPassword(context.getValue(SecurityContext.PASSWORD));
  } else if (callback instanceof RealmCallback) {
    RealmCallback realmcb = (RealmCallback)callback;
    realmcb.setText(context.getValue(SecurityContext.REALM));
  } else if (callback instanceof TextOutputCallback) {
    TextOutputCallback textcb = (TextOutputCallback)callback;
    if (textcb.getMessageType() == TextOutputCallback.INFORMATION) {
      logger.info(textcb.getMessage());
    } else if (textcb.getMessageType() == TextOutputCallback.WARNING) {
      logger.warn(textcb.getMessage());
    } else if (textcb.getMessageType() == TextOutputCallback.ERROR) {
      logger.error(textcb.getMessage());
    } else {
      logger.debug("Auth message type {}, message {}", textcb.getMessageType(), textcb.getMessage());
    }
  } else {
    throw new UnsupportedCallbackException(callback);
  }
}
 
Example 7
Project: jgroups-3.6.4-fixed   File: SASLTest.java   Source Code and License Vote up 6 votes
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for(Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            NameCallback nameCallback = (NameCallback)callback;
            nameCallback.setName("user");
        } else if (callback instanceof PasswordCallback) {
            PasswordCallback passwordCallback = (PasswordCallback)callback;
            passwordCallback.setPassword(password.toCharArray());
        } else if (callback instanceof AuthorizeCallback) {
            AuthorizeCallback authorizeCallback = (AuthorizeCallback)callback;
            authorizeCallback.setAuthorized(authorizeCallback.getAuthenticationID().equals(authorizeCallback.getAuthorizationID()));
        } else if (callback instanceof RealmCallback) {
            RealmCallback realmCallback = (RealmCallback) callback;
            realmCallback.setText(REALM);
        } else {
            throw new UnsupportedCallbackException(callback);
        }
    }
}
 
Example 8
Project: wildfly-config-api   File: AuthCallback.java   Source Code and License Vote up 6 votes
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback current : callbacks) {
        if (current instanceof NameCallback) {
            NameCallback ncb = (NameCallback) current;
            ncb.setName(args[0]);
        } else if (current instanceof PasswordCallback) {
            PasswordCallback pcb = (PasswordCallback) current;
            pcb.setPassword(args[1].toCharArray());
        } else if (current instanceof RealmCallback) {
            RealmCallback rcb = (RealmCallback) current;
            rcb.setText(rcb.getDefaultText());
        } else {
            throw new UnsupportedCallbackException(current);
        }
    }
}
 
Example 9
Project: ARCHIVE-wildfly-swarm   File: AuthCallbackHandler.java   Source Code and License Vote up 6 votes
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback current : callbacks) {
        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.toCharArray());
        } else if (current instanceof RealmCallback) {
            RealmCallback rcb = (RealmCallback) current;
            rcb.setText(rcb.getDefaultText());
        } else {
            throw new UnsupportedCallbackException(current);
        }
    }

}
 
Example 10
Project: RecordServiceClient   File: ThriftUtils.java   Source Code and License Vote up 6 votes
@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");
    }
  }
}
 
Example 11
Project: jube   File: SimpleCallbackHandler.java   Source Code and License Vote up 6 votes
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback current : callbacks) {
        if (current instanceof NameCallback) {
            NameCallback ncb = (NameCallback) current;
            ncb.setName(username);
        } else if (current instanceof PasswordCallback) {
            PasswordCallback pcb = (PasswordCallback) current;
            pcb.setPassword(password.toCharArray());
        } else if (current instanceof RealmCallback) {
            RealmCallback rcb = (RealmCallback) current;
            rcb.setText(rcb.getDefaultText());
        } else {
            throw new UnsupportedCallbackException(current);
        }
    }
}
 
Example 12
Project: wildfly-core   File: Authentication.java   Source Code and License Vote up 6 votes
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback current : callbacks) {
        if (current instanceof NameCallback) {
            NameCallback ncb = (NameCallback) current;
            ncb.setName(username);
        } else if (current instanceof PasswordCallback) {
            PasswordCallback pcb = (PasswordCallback) current;
            pcb.setPassword(password.toCharArray());
        } else if (current instanceof RealmCallback) {
            RealmCallback rcb = (RealmCallback) current;
            rcb.setText(rcb.getDefaultText());
        } else {
            throw new UnsupportedCallbackException(current);
        }
    }
}
 
Example 13
Project: wildfly-arquillian   File: Authentication.java   Source Code and License Vote up 6 votes
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback current : callbacks) {
        if (current instanceof NameCallback) {
            NameCallback ncb = (NameCallback) current;
            ncb.setName(username);
        } else if (current instanceof PasswordCallback) {
            PasswordCallback pcb = (PasswordCallback) current;
            pcb.setPassword(password.toCharArray());
        } else if (current instanceof RealmCallback) {
            RealmCallback rcb = (RealmCallback) current;
            rcb.setText(rcb.getDefaultText());
        } else {
            throw new UnsupportedCallbackException(current);
        }
    }
}
 
Example 14
Project: java-bells   File: SASLMechanism.java   Source Code and License Vote up 6 votes
/**
 * 
 */
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]);
        }
     }
}
 
Example 15
Project: jboss-controller-operation-executor   File: AuthenticationCallbackHandler.java   Source Code and License Vote up 6 votes
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback current : callbacks) {
        if (current instanceof RealmCallback) {
            RealmCallback realmCallback = (RealmCallback) current;
            if (realm == null || realm.trim().length() == 0) {
                String defaultRealm = realmCallback.getDefaultText();
                realmCallback.setText(defaultRealm);
            } else {
                realmCallback.setText(realm);
            }
        } else if (current instanceof NameCallback) {
            NameCallback nameCallback = (NameCallback) current;
            nameCallback.setName(username);
        } else if (current instanceof PasswordCallback) {
            PasswordCallback passwordCallback = (PasswordCallback) current;
            passwordCallback.setPassword(password);
        } else {
            throw new UnsupportedCallbackException(current);
        }
    }
}
 
Example 16
Project: river-metrics   File: WildlfyRiver.java   Source Code and License Vote up 6 votes
static ModelControllerClient createClient(
        final InetAddress host, final int port,
        final String username, final String password) {

    final CallbackHandler callbackHandler = new CallbackHandler() {

        public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
            for (Callback current : callbacks) {
                if (current instanceof NameCallback) {
                    NameCallback ncb = (NameCallback) current;
                    ncb.setName(username);
                } else if (current instanceof PasswordCallback) {
                    PasswordCallback pcb = (PasswordCallback) current;
                    pcb.setPassword(password.toCharArray());
                } else if (current instanceof RealmCallback) {
                    RealmCallback rcb = (RealmCallback) current;
                    rcb.setText(rcb.getDefaultText());
                } else {
                    throw new UnsupportedCallbackException(current);
                }
            }
        }
    };

    return ModelControllerClient.Factory.create(host, port, callbackHandler);
}
 
Example 17
Project: kafka-0.11.0.0-src-with-comment   File: SaslClientCallbackHandler.java   Source Code and License Vote up 5 votes
@Override
public void handle(Callback[] callbacks) throws UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            NameCallback nc = (NameCallback) callback;
            if (!isKerberos && subject != null && !subject.getPublicCredentials(String.class).isEmpty()) {
                nc.setName(subject.getPublicCredentials(String.class).iterator().next());
            } else
                nc.setName(nc.getDefaultName());
        } else if (callback instanceof PasswordCallback) {
            if (!isKerberos && subject != null && !subject.getPrivateCredentials(String.class).isEmpty()) {
                char[] password = subject.getPrivateCredentials(String.class).iterator().next().toCharArray();
                ((PasswordCallback) callback).setPassword(password);
            } else {
                String errorMessage = "Could not login: the client is being asked for a password, but the Kafka" +
                         " client code does not currently support obtaining a password from the user.";
                if (isKerberos) {
                    errorMessage += " Make sure -Djava.security.auth.login.config property passed to JVM and" +
                         " the client is configured to use a ticket cache (using" +
                         " the JAAS configuration setting 'useTicketCache=true)'. Make sure you are using" +
                         " FQDN of the Kafka broker you are trying to connect to.";
                }
                throw new UnsupportedCallbackException(callback, errorMessage);
            }
        } 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();
            ac.setAuthorized(authId.equals(authzId));
            if (ac.isAuthorized())
                ac.setAuthorizedID(authzId);
        } else {
            throw new UnsupportedCallbackException(callback, "Unrecognized SASL ClientCallback");
        }
    }
}
 
Example 18
Project: kafka   File: SaslClientCallbackHandler.java   Source Code and License Vote up 5 votes
@Override
public void handle(Callback[] callbacks) throws UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            NameCallback nc = (NameCallback) callback;
            if (!isKerberos && subject != null && !subject.getPublicCredentials(String.class).isEmpty()) {
                nc.setName(subject.getPublicCredentials(String.class).iterator().next());
            } else
                nc.setName(nc.getDefaultName());
        } else if (callback instanceof PasswordCallback) {
            if (!isKerberos && subject != null && !subject.getPrivateCredentials(String.class).isEmpty()) {
                char [] password = subject.getPrivateCredentials(String.class).iterator().next().toCharArray();
                ((PasswordCallback) callback).setPassword(password);
            } else {
                String errorMessage = "Could not login: the client is being asked for a password, but the Kafka" +
                         " client code does not currently support obtaining a password from the user.";
                if (isKerberos) {
                    errorMessage += " Make sure -Djava.security.auth.login.config property passed to JVM and" +
                         " the client is configured to use a ticket cache (using" +
                         " the JAAS configuration setting 'useTicketCache=true)'. Make sure you are using" +
                         " FQDN of the Kafka broker you are trying to connect to.";
                }
                throw new UnsupportedCallbackException(callback, errorMessage);
            }
        } 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();
            ac.setAuthorized(authId.equals(authzId));
            if (ac.isAuthorized())
                ac.setAuthorizedID(authzId);
        } else {
            throw new UnsupportedCallbackException(callback, "Unrecognized SASL ClientCallback");
        }
    }
}
 
Example 19
Project: herddb   File: SaslNettyServer.java   Source Code and License Vote up 5 votes
@Override
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 {
                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");
                    }
                }
            }
        }
    }
}
 
Example 20
Project: herddb   File: SaslNettyClient.java   Source Code and License Vote up 5 votes
@Override
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 {
                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");
                    }
                }
            }
        }
    }
}
 
Example 21
Project: hawkular-agent   File: ModelControllerClientFactory.java   Source Code and License Vote up 5 votes
protected ModelControllerClient createClient(final MonitoredEndpoint endpoint) {
    final ConnectionData cnData = endpoint.getConnectionData();
    final CallbackHandler callbackHandler = new CallbackHandler() {
        public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
            for (Callback current : callbacks) {
                if (current instanceof NameCallback) {
                    NameCallback ncb = (NameCallback) current;
                    ncb.setName(cnData.getUsername());
                } else if (current instanceof PasswordCallback) {
                    PasswordCallback pcb = (PasswordCallback) current;
                    pcb.setPassword(cnData.getPassword().toCharArray());
                } else if (current instanceof RealmCallback) {
                    RealmCallback rcb = (RealmCallback) current;
                    rcb.setText(rcb.getDefaultText());
                } else {
                    throw new UnsupportedCallbackException(current);
                }
            }
        }
    };
    final URI uri = cnData.getUri();
    try {
        ModelControllerClientConfiguration config = new ModelControllerClientConfiguration.Builder()
                .setProtocol(uri.getScheme())
                .setHostName(uri.getHost())
                .setPort(uri.getPort())
                .setSslContext(endpoint.getSSLContext())
                .setHandler(callbackHandler)
                .build();

        return ModelControllerClient.Factory.create(config);
    } catch (Exception e) {
        throw new RuntimeException("Failed to create management client", e);
    }
}
 
Example 22
Project: majordodo   File: SaslNettyClient.java   Source Code and License Vote up 5 votes
@Override
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 {
                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");
                    }
                }
            }
        }
    }
}
 
Example 23
Project: blazingcache   File: SaslNettyServer.java   Source Code and License Vote up 5 votes
@Override
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 {
                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");
                    }
                }
            }
        }
    }
}
 
Example 24
Project: hawkular-agent   File: AbstractITest.java   Source Code and License Vote up 5 votes
protected static ModelControllerClient newModelControllerClient(final String host, final int managementPort) {
    final CallbackHandler callbackHandler = new CallbackHandler() {
        @Override
        public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
            for (Callback current : callbacks) {
                if (current instanceof NameCallback) {
                    NameCallback ncb = (NameCallback) current;
                    log.fine("ModelControllerClient is sending a username [" + managementUser + "]");
                    ncb.setName(managementUser);
                } else if (current instanceof PasswordCallback) {
                    PasswordCallback pcb = (PasswordCallback) current;
                    log.fine("ModelControllerClient is sending a password [" + managementPasword + "]");
                    pcb.setPassword(managementPasword.toCharArray());
                } else if (current instanceof RealmCallback) {
                    RealmCallback rcb = (RealmCallback) current;
                    log.fine("ModelControllerClient is sending a realm [" + rcb.getDefaultText() + "]");
                    rcb.setText(rcb.getDefaultText());
                } else {
                    throw new UnsupportedCallbackException(current);
                }
            }
        }
    };

    try {
        InetAddress inetAddr = InetAddress.getByName(host);
        log.fine("Connecting a ModelControllerClient to [" + host + ":" + managementPort + "]");
        return ModelControllerClient.Factory.create(inetAddr, managementPort, callbackHandler);
    } catch (Exception e) {
        throw new RuntimeException("Failed to create management client", e);
    }
}
 
Example 25
Project: Krackle   File: Login.java   Source Code and License Vote up 5 votes
@Override
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) {
				LOG.warn("Could not login: the client is being asked for a password");
			} 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");
					}
				}
			}
		}
	}
}
 
Example 26
Project: Krackle   File: SaslPlainTextAuthenticator.java   Source Code and License Vote up 5 votes
@Override
public void handle(Callback[] callbacks) throws UnsupportedCallbackException {
	for (Callback callback : callbacks) {
		LOG.info("callback {} received", callback.toString());
		if (callback instanceof NameCallback) {
			NameCallback nc = (NameCallback) callback;
			nc.setName(nc.getDefaultName());
		} else {
			if (callback instanceof PasswordCallback) {
				// Call `setPassword` once we support obtaining a password from the user and update message below
				throw new UnsupportedCallbackException(callback, "Could not login: the client is being asked for a password, but the Kafka"
					 + " client code does not currently support obtaining a password from the user."
					 + " Make sure -Djava.security.auth.login.config property passed to JVM and"
					 + " the client is configured to use a ticket cache (using"
					 + " the JAAS configuration setting 'useTicketCache=true)'. Make sure you are using"
					 + " FQDN of the Kafka broker you are trying to connect to.");
			} 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();
						ac.setAuthorized(authId.equals(authzId));
						if (ac.isAuthorized()) {
							ac.setAuthorizedID(authzId);
						}
					} else {
						throw new UnsupportedCallbackException(callback, "Unrecognized SASL ClientCallback");
					}
				}
			}
		}
	}
}
 
Example 27
Project: cn1   File: DefaultCallbackHandler.java   Source Code and License Vote up 5 votes
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]);
        }
    }
}
 
Example 28
Project: jamppa   File: SASLMechanism.java   Source Code and License Vote up 5 votes
/**
 * 
 */
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]);
        }
    }
}
 
Example 29
Project: nextop-client   File: DefaultCallbackHandler.java   Source Code and License Vote up 5 votes
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]);
        }
    }
}
 
Example 30
Project: tigase-server   File: AuthRepoPlainCallbackHandler.java   Source Code and License Vote up 5 votes
protected void handleRealmCallback(RealmCallback rc) throws IOException {
	String realm = domain;

	if (realm != null) {
		rc.setText(realm);
	} // end of if (realm == null)
	if (log.isLoggable(Level.FINEST)) {
		log.log(Level.FINEST, "RealmCallback: {0}", realm);
	}
}
 
Example 31
Project: tigase-server   File: PlainSPCallbackHandler.java   Source Code and License Vote up 5 votes
protected void handleRealmCallback(RealmCallback rc) throws IOException {
	String realm = domain;

	if (realm != null) {
		rc.setText(realm);
	} // end of if (realm == null)
	if (log.isLoggable(Level.FINEST)) {
		log.log(Level.FINEST, "RealmCallback: {0}", realm);
	}
}
 
Example 32
Project: wildfly-monitor   File: ClientFactoryImpl.java   Source Code and License Vote up 5 votes
@Override
public ModelControllerClient createClient() {

    final CallbackHandler callbackHandler = new CallbackHandler() {

        public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
            for (Callback current : callbacks) {
                if (current instanceof NameCallback) {
                    NameCallback ncb = (NameCallback) current;
                    ncb.setName(username);
                } else if (current instanceof PasswordCallback) {
                    PasswordCallback pcb = (PasswordCallback) current;
                    pcb.setPassword(password.toCharArray());
                } else if (current instanceof RealmCallback) {
                    RealmCallback rcb = (RealmCallback) current;
                    rcb.setText(rcb.getDefaultText());
                } else {
                    throw new UnsupportedCallbackException(current);
                }
            }
        }
    };

    try {
        return ModelControllerClient.Factory.create(InetAddress.getByName(host), port, callbackHandler);
    } catch (UnknownHostException e) {
        throw new RuntimeException("Failed ot create controller client", e);
    }
}
 
Example 33
Project: freeVM   File: DefaultCallbackHandler.java   Source Code and License Vote up 5 votes
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]);
        }
    }
}
 
Example 34
Project: wildfly-maven-plugin   File: ClientCallbackHandler.java   Source Code and License Vote up 5 votes
@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);
        }
    }
}
 
Example 35
Project: jboss-as-quickstart   File: SecurityContextCallbackHandler.java   Source Code and License Vote up 5 votes
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    Principal principal = SecurityActions.securityContextGetPrincipal();
    Object credential = SecurityActions.securityContextGetCredential();
    if (principal == null) {
        throw new IllegalStateException("No Principal set.");
    }
    if (credential == null) {
        throw new IllegalStateException("No credential set.");
    }
    if (credential instanceof PasswordPlusCredential == false) {
        throw new IllegalStateException("Invalid credential type.");
    }
    PasswordPlusCredential ppCredential = (PasswordPlusCredential) credential;

    for (Callback current : callbacks) {
        if (current instanceof NameCallback) {
            NameCallback ncb = (NameCallback) current;
            ncb.setName(principal.getName());
        } else if (current instanceof PasswordCallback) {
            PasswordCallback pcb = (PasswordCallback) current;
            pcb.setPassword(ppCredential.getPassword());
        } else if (current instanceof RealmCallback) {
            RealmCallback rcb = (RealmCallback) current;
            rcb.setText(rcb.getDefaultText());
        } else {
            UnsupportedCallbackException e = new UnsupportedCallbackException(current);
            e.printStackTrace();
            throw e;
        }
    }
}
 
Example 36
Project: directory-ldap-api   File: SaslCallbackHandler.java   Source Code and License Vote up 4 votes
/**
 * {@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 ) ) );
            }
        }
    }
}
 
Example 37
Project: fuck_zookeeper   File: ZooKeeperSaslClient.java   Source Code and License Vote up 4 votes
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");
                    }
                }
            }
        }
    }
}
 
Example 38
Project: fuck_zookeeper   File: SaslServerCallbackHandler.java   Source Code and License Vote up 4 votes
private void handleRealmCallback(RealmCallback rc) {
    LOG.debug("client supplied realm: " + rc.getDefaultText());
    rc.setText(rc.getDefaultText());
}
 
Example 39
Project: https-github.com-apache-zookeeper   File: ZooKeeperSaslClient.java   Source Code and License Vote up 4 votes
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");
                    }
                }
            }
        }
    }
}
 
Example 40
Project: https-github.com-apache-zookeeper   File: SaslServerCallbackHandler.java   Source Code and License Vote up 4 votes
private void handleRealmCallback(RealmCallback rc) {
    LOG.debug("client supplied realm: " + rc.getDefaultText());
    rc.setText(rc.getDefaultText());
}
 
Example 41
Project: OpenJSharp   File: DefaultCallbackHandler.java   Source Code and License Vote up 4 votes
public void handle(Callback[] callbacks)
    throws IOException, UnsupportedCallbackException {
        for (int i = 0; i < callbacks.length; i++) {
            if (callbacks[i] instanceof NameCallback) {
                ((NameCallback)callbacks[i]).setName(authenticationID);

            } else if (callbacks[i] instanceof PasswordCallback) {
                ((PasswordCallback)callbacks[i]).setPassword(passwd);

            } else if (callbacks[i] instanceof RealmChoiceCallback) {
                /* Deals with a choice of realms */
                String[] choices =
                    ((RealmChoiceCallback)callbacks[i]).getChoices();
                int selected = 0;

                if (authRealm != null && authRealm.length() > 0) {
                    selected = -1; // no realm chosen
                    for (int j = 0; j < choices.length; j++) {
                        if (choices[j].equals(authRealm)) {
                            selected = j;
                        }
                    }
                    if (selected == -1) {
                        StringBuffer allChoices = new StringBuffer();
                        for (int j = 0; j <  choices.length; j++) {
                            allChoices.append(choices[j] + ",");
                        }
                        throw new IOException("Cannot match " +
                            "'java.naming.security.sasl.realm' property value, '" +
                            authRealm + "' with choices " + allChoices +
                            "in RealmChoiceCallback");
                    }
                }

                ((RealmChoiceCallback)callbacks[i]).setSelectedIndex(selected);

            } else if (callbacks[i] instanceof RealmCallback) {
                /* 1 or 0 realms specified in challenge */
                RealmCallback rcb = (RealmCallback) callbacks[i];
                if (authRealm != null) {
                    rcb.setText(authRealm);  // Use what user supplied
                } else {
                    String defaultRealm = rcb.getDefaultText();
                    if (defaultRealm != null) {
                        rcb.setText(defaultRealm); // Use what server supplied
                    } else {
                        rcb.setText("");  // Specify no realm
                    }
                }
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        }
}
 
Example 42
Project: kafka-0.11.0.0-src-with-comment   File: SaslServerCallbackHandler.java   Source Code and License Vote up 4 votes
private void handleRealmCallback(RealmCallback rc) {
    LOG.trace("Client supplied realm: {} ", rc.getDefaultText());
    rc.setText(rc.getDefaultText());
}
 
Example 43
Project: jdk8u-jdk   File: DefaultCallbackHandler.java   Source Code and License Vote up 4 votes
public void handle(Callback[] callbacks)
    throws IOException, UnsupportedCallbackException {
        for (int i = 0; i < callbacks.length; i++) {
            if (callbacks[i] instanceof NameCallback) {
                ((NameCallback)callbacks[i]).setName(authenticationID);

            } else if (callbacks[i] instanceof PasswordCallback) {
                ((PasswordCallback)callbacks[i]).setPassword(passwd);

            } else if (callbacks[i] instanceof RealmChoiceCallback) {
                /* Deals with a choice of realms */
                String[] choices =
                    ((RealmChoiceCallback)callbacks[i]).getChoices();
                int selected = 0;

                if (authRealm != null && authRealm.length() > 0) {
                    selected = -1; // no realm chosen
                    for (int j = 0; j < choices.length; j++) {
                        if (choices[j].equals(authRealm)) {
                            selected = j;
                        }
                    }
                    if (selected == -1) {
                        StringBuffer allChoices = new StringBuffer();
                        for (int j = 0; j <  choices.length; j++) {
                            allChoices.append(choices[j] + ",");
                        }
                        throw new IOException("Cannot match " +
                            "'java.naming.security.sasl.realm' property value, '" +
                            authRealm + "' with choices " + allChoices +
                            "in RealmChoiceCallback");
                    }
                }

                ((RealmChoiceCallback)callbacks[i]).setSelectedIndex(selected);

            } else if (callbacks[i] instanceof RealmCallback) {
                /* 1 or 0 realms specified in challenge */
                RealmCallback rcb = (RealmCallback) callbacks[i];
                if (authRealm != null) {
                    rcb.setText(authRealm);  // Use what user supplied
                } else {
                    String defaultRealm = rcb.getDefaultText();
                    if (defaultRealm != null) {
                        rcb.setText(defaultRealm); // Use what server supplied
                    } else {
                        rcb.setText("");  // Specify no realm
                    }
                }
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        }
}
 
Example 44
Project: openjdk-jdk10   File: DefaultCallbackHandler.java   Source Code and License Vote up 4 votes
public void handle(Callback[] callbacks)
    throws IOException, UnsupportedCallbackException {
        for (int i = 0; i < callbacks.length; i++) {
            if (callbacks[i] instanceof NameCallback) {
                ((NameCallback)callbacks[i]).setName(authenticationID);

            } else if (callbacks[i] instanceof PasswordCallback) {
                ((PasswordCallback)callbacks[i]).setPassword(passwd);

            } else if (callbacks[i] instanceof RealmChoiceCallback) {
                /* Deals with a choice of realms */
                String[] choices =
                    ((RealmChoiceCallback)callbacks[i]).getChoices();
                int selected = 0;

                if (authRealm != null && authRealm.length() > 0) {
                    selected = -1; // no realm chosen
                    for (int j = 0; j < choices.length; j++) {
                        if (choices[j].equals(authRealm)) {
                            selected = j;
                        }
                    }
                    if (selected == -1) {
                        StringBuilder allChoices = new StringBuilder();
                        for (int j = 0; j <  choices.length; j++) {
                            allChoices.append(choices[j]).append(',');
                        }
                        throw new IOException("Cannot match " +
                            "'java.naming.security.sasl.realm' property value, '" +
                            authRealm + "' with choices " + allChoices +
                            "in RealmChoiceCallback");
                    }
                }

                ((RealmChoiceCallback)callbacks[i]).setSelectedIndex(selected);

            } else if (callbacks[i] instanceof RealmCallback) {
                /* 1 or 0 realms specified in challenge */
                RealmCallback rcb = (RealmCallback) callbacks[i];
                if (authRealm != null) {
                    rcb.setText(authRealm);  // Use what user supplied
                } else {
                    String defaultRealm = rcb.getDefaultText();
                    if (defaultRealm != null) {
                        rcb.setText(defaultRealm); // Use what server supplied
                    } else {
                        rcb.setText("");  // Specify no realm
                    }
                }
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        }
}
 
Example 45
Project: ZooKeeper   File: SaslQuorumServerCallbackHandler.java   Source Code and License Vote up 4 votes
private void handleRealmCallback(RealmCallback rc) {
    LOG.debug("QuorumLearner supplied realm: {}", rc.getDefaultText());
    rc.setText(rc.getDefaultText());
}
 
Example 46
Project: ZooKeeper   File: SaslServerCallbackHandler.java   Source Code and License Vote up 4 votes
private void handleRealmCallback(RealmCallback rc) {
    LOG.debug("client supplied realm: " + rc.getDefaultText());
    rc.setText(rc.getDefaultText());
}
 
Example 47
Project: ZooKeeper   File: SaslClientCallbackHandler.java   Source Code and License Vote up 4 votes
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");
                    }
                }
            }
        }
    }
}
 
Example 48
Project: openjdk9   File: DefaultCallbackHandler.java   Source Code and License Vote up 4 votes
public void handle(Callback[] callbacks)
    throws IOException, UnsupportedCallbackException {
        for (int i = 0; i < callbacks.length; i++) {
            if (callbacks[i] instanceof NameCallback) {
                ((NameCallback)callbacks[i]).setName(authenticationID);

            } else if (callbacks[i] instanceof PasswordCallback) {
                ((PasswordCallback)callbacks[i]).setPassword(passwd);

            } else if (callbacks[i] instanceof RealmChoiceCallback) {
                /* Deals with a choice of realms */
                String[] choices =
                    ((RealmChoiceCallback)callbacks[i]).getChoices();
                int selected = 0;

                if (authRealm != null && authRealm.length() > 0) {
                    selected = -1; // no realm chosen
                    for (int j = 0; j < choices.length; j++) {
                        if (choices[j].equals(authRealm)) {
                            selected = j;
                        }
                    }
                    if (selected == -1) {
                        StringBuilder allChoices = new StringBuilder();
                        for (int j = 0; j <  choices.length; j++) {
                            allChoices.append(choices[j]).append(',');
                        }
                        throw new IOException("Cannot match " +
                            "'java.naming.security.sasl.realm' property value, '" +
                            authRealm + "' with choices " + allChoices +
                            "in RealmChoiceCallback");
                    }
                }

                ((RealmChoiceCallback)callbacks[i]).setSelectedIndex(selected);

            } else if (callbacks[i] instanceof RealmCallback) {
                /* 1 or 0 realms specified in challenge */
                RealmCallback rcb = (RealmCallback) callbacks[i];
                if (authRealm != null) {
                    rcb.setText(authRealm);  // Use what user supplied
                } else {
                    String defaultRealm = rcb.getDefaultText();
                    if (defaultRealm != null) {
                        rcb.setText(defaultRealm); // Use what server supplied
                    } else {
                        rcb.setText("");  // Specify no realm
                    }
                }
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        }
}
 
Example 49
Project: kafka   File: SaslServerCallbackHandler.java   Source Code and License Vote up 4 votes
private void handleRealmCallback(RealmCallback rc) {
    LOG.trace("Client supplied realm: {} ", rc.getDefaultText());
    rc.setText(rc.getDefaultText());
}
 
Example 50
Project: herddb   File: SaslNettyServer.java   Source Code and License Vote up 4 votes
private void handleRealmCallback(RealmCallback rc) {
    LOG.info("client supplied realm: " + rc.getDefaultText());
    rc.setText(rc.getDefaultText());
}
 
Example 51
Project: StreamProcessingInfrastructure   File: ZooKeeperSaslClient.java   Source Code and License Vote up 4 votes
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");
                    }
                }
            }
        }
    }
}
 
Example 52
Project: SecureKeeper   File: SaslServerCallbackHandler.java   Source Code and License Vote up 4 votes
private void handleRealmCallback(RealmCallback rc) {
    LOG.debug("client supplied realm: " + rc.getDefaultText());
    rc.setText(rc.getDefaultText());
}
 
Example 53
Project: bigstreams   File: ZooKeeperSaslClient.java   Source Code and License Vote up 4 votes
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");
                    }
                }
            }
        }
    }
}
 
Example 54
Project: bigstreams   File: SaslServerCallbackHandler.java   Source Code and License Vote up 4 votes
private void handleRealmCallback(RealmCallback rc) {
    LOG.debug("client supplied realm: " + rc.getDefaultText());
    rc.setText(rc.getDefaultText());
}
 
Example 55
Project: zookeeper-src-learning   File: ZooKeeperSaslClient.java   Source Code and License Vote up 4 votes
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");
                    }
                }
            }
        }
    }
}
 
Example 56
Project: zookeeper-src-learning   File: SaslServerCallbackHandler.java   Source Code and License Vote up 4 votes
private void handleRealmCallback(RealmCallback rc) {
    LOG.debug("client supplied realm: " + rc.getDefaultText());
    rc.setText(rc.getDefaultText());
}
 
Example 57
Project: zookeeper   File: ZooKeeperSaslClient.java   Source Code and License Vote up 4 votes
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");
                    }
                }
            }
        }
    }
}
 
Example 58
Project: zookeeper   File: SaslServerCallbackHandler.java   Source Code and License Vote up 4 votes
private void handleRealmCallback(RealmCallback rc) {
    LOG.debug("client supplied realm: " + rc.getDefaultText());
    rc.setText(rc.getDefaultText());
}
 
Example 59
Project: SecureKeeper   File: ZooKeeperSaslClient.java   Source Code and License Vote up 4 votes
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");
                    }
                }
            }
        }
    }
}
 
Example 60
Project: lookaside_java-1.8.0-openjdk   File: DefaultCallbackHandler.java   Source Code and License Vote up 4 votes
public void handle(Callback[] callbacks)
    throws IOException, UnsupportedCallbackException {
        for (int i = 0; i < callbacks.length; i++) {
            if (callbacks[i] instanceof NameCallback) {
                ((NameCallback)callbacks[i]).setName(authenticationID);

            } else if (callbacks[i] instanceof PasswordCallback) {
                ((PasswordCallback)callbacks[i]).setPassword(passwd);

            } else if (callbacks[i] instanceof RealmChoiceCallback) {
                /* Deals with a choice of realms */
                String[] choices =
                    ((RealmChoiceCallback)callbacks[i]).getChoices();
                int selected = 0;

                if (authRealm != null && authRealm.length() > 0) {
                    selected = -1; // no realm chosen
                    for (int j = 0; j < choices.length; j++) {
                        if (choices[j].equals(authRealm)) {
                            selected = j;
                        }
                    }
                    if (selected == -1) {
                        StringBuffer allChoices = new StringBuffer();
                        for (int j = 0; j <  choices.length; j++) {
                            allChoices.append(choices[j] + ",");
                        }
                        throw new IOException("Cannot match " +
                            "'java.naming.security.sasl.realm' property value, '" +
                            authRealm + "' with choices " + allChoices +
                            "in RealmChoiceCallback");
                    }
                }

                ((RealmChoiceCallback)callbacks[i]).setSelectedIndex(selected);

            } else if (callbacks[i] instanceof RealmCallback) {
                /* 1 or 0 realms specified in challenge */
                RealmCallback rcb = (RealmCallback) callbacks[i];
                if (authRealm != null) {
                    rcb.setText(authRealm);  // Use what user supplied
                } else {
                    String defaultRealm = rcb.getDefaultText();
                    if (defaultRealm != null) {
                        rcb.setText(defaultRealm); // Use what server supplied
                    } else {
                        rcb.setText("");  // Specify no realm
                    }
                }
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        }
}
 
Example 61
Project: SecureKeeper   File: SaslServerCallbackHandler.java   Source Code and License Vote up 4 votes
private void handleRealmCallback(RealmCallback rc) {
    LOG.debug("client supplied realm: " + rc.getDefaultText());
    rc.setText(rc.getDefaultText());
}
 
Example 62
Project: blazingcache   File: SaslNettyServer.java   Source Code and License Vote up 4 votes
private void handleRealmCallback(RealmCallback rc) {
    LOG.severe("client supplied realm: " + rc.getDefaultText());
    rc.setText(rc.getDefaultText());
}
 
Example 63
Project: jstorm-0.9.6.3-   File: ServerCallbackHandler.java   Source Code and License Vote up 4 votes
private void handleRealmCallback(RealmCallback rc) {
	LOG.debug("handleRealmCallback: " + rc.getDefaultText());
	rc.setText(rc.getDefaultText());
}
 
Example 64
Project: majordodo   File: SaslNettyServer.java   Source Code and License Vote up 4 votes
private void handleRealmCallback(RealmCallback rc) {
    LOG.severe("client supplied realm: " + rc.getDefaultText());
    rc.setText(rc.getDefaultText());
}
 
Example 65
Project: learn_jstorm   File: ServerCallbackHandler.java   Source Code and License Vote up 4 votes
private void handleRealmCallback(RealmCallback rc) {
	LOG.debug("handleRealmCallback: " + rc.getDefaultText());
	rc.setText(rc.getDefaultText());
}
 
Example 66
Project: StreamBench   File: ZooKeeperSaslClient.java   Source Code and License Vote up 4 votes
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");
                    }
                }
            }
        }
    }
}
 
Example 67
Project: StreamBench   File: SaslServerCallbackHandler.java   Source Code and License Vote up 4 votes
private void handleRealmCallback(RealmCallback rc) {
    LOG.debug("client supplied realm: " + rc.getDefaultText());
    rc.setText(rc.getDefaultText());
}
 
Example 68
Project: ACaZoo   File: ZooKeeperSaslClient.java   Source Code and License Vote up 4 votes
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");
                    }
                }
            }
        }
    }
}
 
Example 69
Project: ACaZoo   File: SaslServerCallbackHandler.java   Source Code and License Vote up 4 votes
private void handleRealmCallback(RealmCallback rc) {
    LOG.debug("client supplied realm: " + rc.getDefaultText());
    rc.setText(rc.getDefaultText());
}
 
Example 70
Project: jstrom   File: ServerCallbackHandler.java   Source Code and License Vote up 4 votes
private void handleRealmCallback(RealmCallback rc) {
    LOG.debug("handleRealmCallback: " + rc.getDefaultText());
    rc.setText(rc.getDefaultText());
}
 
Example 71
Project: Tstream   File: ServerCallbackHandler.java   Source Code and License Vote up 4 votes
private void handleRealmCallback(RealmCallback rc) {
	LOG.debug("handleRealmCallback: " + rc.getDefaultText());
	rc.setText(rc.getDefaultText());
}
 
Example 72
Project: jdk8u-dev-jdk   File: DefaultCallbackHandler.java   Source Code and License Vote up 4 votes
public void handle(Callback[] callbacks)
    throws IOException, UnsupportedCallbackException {
        for (int i = 0; i < callbacks.length; i++) {
            if (callbacks[i] instanceof NameCallback) {
                ((NameCallback)callbacks[i]).setName(authenticationID);

            } else if (callbacks[i] instanceof PasswordCallback) {
                ((PasswordCallback)callbacks[i]).setPassword(passwd);

            } else if (callbacks[i] instanceof RealmChoiceCallback) {
                /* Deals with a choice of realms */
                String[] choices =
                    ((RealmChoiceCallback)callbacks[i]).getChoices();
                int selected = 0;

                if (authRealm != null && authRealm.length() > 0) {
                    selected = -1; // no realm chosen
                    for (int j = 0; j < choices.length; j++) {
                        if (choices[j].equals(authRealm)) {
                            selected = j;
                        }
                    }
                    if (selected == -1) {
                        StringBuffer allChoices = new StringBuffer();
                        for (int j = 0; j <  choices.length; j++) {
                            allChoices.append(choices[j] + ",");
                        }
                        throw new IOException("Cannot match " +
                            "'java.naming.security.sasl.realm' property value, '" +
                            authRealm + "' with choices " + allChoices +
                            "in RealmChoiceCallback");
                    }
                }

                ((RealmChoiceCallback)callbacks[i]).setSelectedIndex(selected);

            } else if (callbacks[i] instanceof RealmCallback) {
                /* 1 or 0 realms specified in challenge */
                RealmCallback rcb = (RealmCallback) callbacks[i];
                if (authRealm != null) {
                    rcb.setText(authRealm);  // Use what user supplied
                } else {
                    String defaultRealm = rcb.getDefaultText();
                    if (defaultRealm != null) {
                        rcb.setText(defaultRealm); // Use what server supplied
                    } else {
                        rcb.setText("");  // Specify no realm
                    }
                }
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        }
}
 
Example 73
Project: LoadBalanced_zk   File: ZooKeeperSaslClient.java   Source Code and License Vote up 4 votes
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");
                    }
                }
            }
        }
    }
}
 
Example 74
Project: OLD-OpenJDK8   File: DefaultCallbackHandler.java   Source Code and License Vote up 4 votes
public void handle(Callback[] callbacks)
    throws IOException, UnsupportedCallbackException {
        for (int i = 0; i < callbacks.length; i++) {
            if (callbacks[i] instanceof NameCallback) {
                ((NameCallback)callbacks[i]).setName(authenticationID);

            } else if (callbacks[i] instanceof PasswordCallback) {
                ((PasswordCallback)callbacks[i]).setPassword(passwd);

            } else if (callbacks[i] instanceof RealmChoiceCallback) {
                /* Deals with a choice of realms */
                String[] choices =
                    ((RealmChoiceCallback)callbacks[i]).getChoices();
                int selected = 0;

                if (authRealm != null && authRealm.length() > 0) {
                    selected = -1; // no realm chosen
                    for (int j = 0; j < choices.length; j++) {
                        if (choices[j].equals(authRealm)) {
                            selected = j;
                        }
                    }
                    if (selected == -1) {
                        StringBuffer allChoices = new StringBuffer();
                        for (int j = 0; j <  choices.length; j++) {
                            allChoices.append(choices[j] + ",");
                        }
                        throw new IOException("Cannot match " +
                            "'java.naming.security.sasl.realm' property value, '" +
                            authRealm + "' with choices " + allChoices +
                            "in RealmChoiceCallback");
                    }
                }

                ((RealmChoiceCallback)callbacks[i]).setSelectedIndex(selected);

            } else if (callbacks[i] instanceof RealmCallback) {
                /* 1 or 0 realms specified in challenge */
                RealmCallback rcb = (RealmCallback) callbacks[i];
                if (authRealm != null) {
                    rcb.setText(authRealm);  // Use what user supplied
                } else {
                    String defaultRealm = rcb.getDefaultText();
                    if (defaultRealm != null) {
                        rcb.setText(defaultRealm); // Use what server supplied
                    } else {
                        rcb.setText("");  // Specify no realm
                    }
                }
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        }
}
 
Example 75
Project: LoadBalanced_zk   File: ZooKeeperSaslClient.java   Source Code and License Vote up 4 votes
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");
                    }
                }
            }
        }
    }
}
 
Example 76
Project: LoadBalanced_zk   File: SaslServerCallbackHandler.java   Source Code and License Vote up 4 votes
private void handleRealmCallback(RealmCallback rc) {
    LOG.debug("client supplied realm: " + rc.getDefaultText());
    rc.setText(rc.getDefaultText());
}
 
Example 77
Project: openjdk-jdk7u-jdk   File: DefaultCallbackHandler.java   Source Code and License Vote up 4 votes
public void handle(Callback[] callbacks)
    throws IOException, UnsupportedCallbackException {
        for (int i = 0; i < callbacks.length; i++) {
            if (callbacks[i] instanceof NameCallback) {
                ((NameCallback)callbacks[i]).setName(authenticationID);

            } else if (callbacks[i] instanceof PasswordCallback) {
                ((PasswordCallback)callbacks[i]).setPassword(passwd);

            } else if (callbacks[i] instanceof RealmChoiceCallback) {
                /* Deals with a choice of realms */
                String[] choices =
                    ((RealmChoiceCallback)callbacks[i]).getChoices();
                int selected = 0;

                if (authRealm != null && authRealm.length() > 0) {
                    selected = -1; // no realm chosen
                    for (int j = 0; j < choices.length; j++) {
                        if (choices[j].equals(authRealm)) {
                            selected = j;
                        }
                    }
                    if (selected == -1) {
                        StringBuffer allChoices = new StringBuffer();
                        for (int j = 0; j <  choices.length; j++) {
                            allChoices.append(choices[j] + ",");
                        }
                        throw new IOException("Cannot match " +
                            "'java.naming.security.sasl.realm' property value, '" +
                            authRealm + "' with choices " + allChoices +
                            "in RealmChoiceCallback");
                    }
                }

                ((RealmChoiceCallback)callbacks[i]).setSelectedIndex(selected);

            } else if (callbacks[i] instanceof RealmCallback) {
                /* 1 or 0 realms specified in challenge */
                RealmCallback rcb = (RealmCallback) callbacks[i];
                if (authRealm != null) {
                    rcb.setText(authRealm);  // Use what user supplied
                } else {
                    String defaultRealm = rcb.getDefaultText();
                    if (defaultRealm != null) {
                        rcb.setText(defaultRealm); // Use what server supplied
                    } else {
                        rcb.setText("");  // Specify no realm
                    }
                }
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        }
}
 
Example 78
Project: storm-resa   File: ServerCallbackHandler.java   Source Code and License Vote up 4 votes
private void handleRealmCallback(RealmCallback rc) {
    LOG.debug("handleRealmCallback: "+ rc.getDefaultText());
    rc.setText(rc.getDefaultText());
}
 
Example 79
Project: tigase-server   File: AuthRepositoryImpl.java   Source Code and License Vote up 4 votes
@Override
public void handle(final Callback[] callbacks)
		throws IOException, UnsupportedCallbackException {
	BareJID jid = null;

	for (int i = 0; i < callbacks.length; i++) {
		if (log.isLoggable(Level.FINEST)) {
			log.finest("Callback: " + callbacks[i].getClass().getSimpleName());
		}
		if (callbacks[i] instanceof RealmCallback) {
			RealmCallback rc    = (RealmCallback) callbacks[i];
			String        realm = (String) options.get(REALM_KEY);

			if (realm != null) {
				rc.setText(realm);
			}        // end of if (realm == null)
			if (log.isLoggable(Level.FINEST)) {
				log.finest("RealmCallback: " + realm);
			}
		} else {
			if (callbacks[i] instanceof NameCallback) {
				NameCallback nc        = (NameCallback) callbacks[i];
				String       user_name = nc.getName();

				if (user_name == null) {
					user_name = nc.getDefaultName();
				}      // end of if (name == null)
				jid = BareJID.bareJIDInstanceNS(user_name, (String) options.get(REALM_KEY));
				options.put(USER_ID_KEY, jid);
				if (log.isLoggable(Level.FINEST)) {
					log.finest("NameCallback: " + user_name);
				}
			} else {
				if (callbacks[i] instanceof PasswordCallback) {
					PasswordCallback pc = (PasswordCallback) callbacks[i];

					try {
						String passwd = getPassword(jid);

						pc.setPassword(passwd.toCharArray());
						if (log.isLoggable(Level.FINEST)) {
							log.finest("PasswordCallback: " + passwd);
						}
					} catch (Exception e) {
						throw new IOException("Password retrieving problem.", e);
					}    // end of try-catch
				} else {
					if (callbacks[i] instanceof AuthorizeCallback) {
						AuthorizeCallback authCallback = ((AuthorizeCallback) callbacks[i]);
						String            authenId     = authCallback.getAuthenticationID();
						String            authorId     = authCallback.getAuthorizationID();

						if (log.isLoggable(Level.FINEST)) {
							log.finest("AuthorizeCallback: authenId: " + authenId);
							log.finest("AuthorizeCallback: authorId: " + authorId);
						}

						// if (authenId.equals(authorId)) {
						authCallback.setAuthorized(true);

						// } // end of if (authenId.equals(authorId))
					} else {
						throw new UnsupportedCallbackException(callbacks[i],
								"Unrecognized Callback");
					}
				}
			}
		}
	}
}
 
Example 80
Project: tigase-server   File: TigaseCustomAuth.java   Source Code and License Vote up 4 votes
@Override
public void handle(final Callback[] callbacks) throws IOException,
		UnsupportedCallbackException {
	BareJID jid = null;

	for (int i = 0; i < callbacks.length; i++) {
		if (log.isLoggable(Level.FINEST)) {
			log.log(Level.FINEST, "Callback: {0}", callbacks[i].getClass().getSimpleName());
		}

		if (callbacks[i] instanceof RealmCallback) {
			RealmCallback rc = (RealmCallback) callbacks[i];
			String realm = (String) options.get(REALM_KEY);

			if (realm != null) {
				rc.setText(realm);
			} // end of if (realm == null)

			if (log.isLoggable(Level.FINEST)) {
				log.log(Level.FINEST, "RealmCallback: {0}", realm);
			}
		} else {
			if (callbacks[i] instanceof NameCallback) {
				NameCallback nc = (NameCallback) callbacks[i];
				String user_name = nc.getName();

				if (user_name == null) {
					user_name = nc.getDefaultName();
				} // end of if (name == null)

				jid = BareJID.bareJIDInstanceNS(user_name, (String) options.get(REALM_KEY));
				options.put(USER_ID_KEY, jid);

				if (log.isLoggable(Level.FINEST)) {
					log.log(Level.FINEST, "NameCallback: {0}", user_name);
				}
			} else {
				if (callbacks[i] instanceof PasswordCallback) {
					PasswordCallback pc = (PasswordCallback) callbacks[i];

					try {
						String passwd = getPassword(jid);

						pc.setPassword(passwd.toCharArray());

						if (log.isLoggable(Level.FINEST)) {
							log.log(Level.FINEST, "PasswordCallback: {0}", passwd);
						}
					} catch (Exception e) {
						throw new IOException("Password retrieving problem.", e);
					} // end of try-catch
				} else {
					if (callbacks[i] instanceof AuthorizeCallback) {
						AuthorizeCallback authCallback = ((AuthorizeCallback) callbacks[i]);
						String authenId = authCallback.getAuthenticationID();

						if (log.isLoggable(Level.FINEST)) {
							log.log(Level.FINEST, "AuthorizeCallback: authenId: {0}", authenId);
						}

						String authorId = authCallback.getAuthorizationID();

						if (log.isLoggable(Level.FINEST)) {
							log.log(Level.FINEST, "AuthorizeCallback: authorId: {0}", authorId);
						}

						if (authenId.equals(authorId)) {
							authCallback.setAuthorized(true);
						} // end of if (authenId.equals(authorId))
					} else {
						throw new UnsupportedCallbackException(callbacks[i],
								"Unrecognized Callback");
					}
				}
			}
		}
	}
}
 
Example 81
Project: tigase-server   File: DrupalWPAuth.java   Source Code and License Vote up 4 votes
@Override
public void handle(final Callback[] callbacks)
		throws IOException, UnsupportedCallbackException {
	BareJID jid = null;

	for (int i = 0; i < callbacks.length; i++) {
		if (log.isLoggable(Level.FINEST)) {
			log.log(Level.FINEST, "Callback: {0}", callbacks[i].getClass().getSimpleName());
		}

		if (callbacks[i] instanceof RealmCallback) {
			RealmCallback rc = (RealmCallback) callbacks[i];
			String realm = (String) options.get(REALM_KEY);

			if (realm != null) {
				rc.setText(realm);
			}        // end of if (realm == null)

			if (log.isLoggable(Level.FINEST)) {
				log.log(Level.FINEST, "RealmCallback: {0}", realm);
			}
		} else {
			if (callbacks[i] instanceof NameCallback) {
				NameCallback nc = (NameCallback) callbacks[i];
				String user_name = nc.getName();

				if (user_name == null) {
					user_name = nc.getDefaultName();
				}      // end of if (name == null)

				jid = BareJID.bareJIDInstanceNS(user_name, (String) options.get(REALM_KEY));
				options.put(USER_ID_KEY, jid);

				if (log.isLoggable(Level.FINEST)) {
					log.log(Level.FINEST, "NameCallback: {0}", user_name);
				}
			} else {
				if (callbacks[i] instanceof PasswordCallback) {
					PasswordCallback pc = (PasswordCallback) callbacks[i];

					try {
						String passwd = getPassword(jid);

						pc.setPassword(passwd.toCharArray());

						if (log.isLoggable(Level.FINEST)) {
							log.log(Level.FINEST, "PasswordCallback: {0}", passwd);
						}
					} catch (Exception e) {
						throw new IOException("Password retrieving problem.", e);
					}    // end of try-catch
				} else {
					if (callbacks[i] instanceof AuthorizeCallback) {
						AuthorizeCallback authCallback = ((AuthorizeCallback) callbacks[i]);
						String authenId = authCallback.getAuthenticationID();
						String authorId = authCallback.getAuthorizationID();

						if (log.isLoggable(Level.FINEST)) {
							log.log(Level.FINEST, "AuthorizeCallback: authenId: {0}", authenId);
							log.log(Level.FINEST, "AuthorizeCallback: authorId: {0}", authorId);
						}

						// if (authenId.equals(authorId)) {
						authCallback.setAuthorized(true);

						// }    // end of if (authenId.equals(authorId))
					} else {
						throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
					}
				}
			}
		}
	}
}
 
Example 82
Project: openjdk-icedtea7   File: DefaultCallbackHandler.java   Source Code and License Vote up 4 votes
public void handle(Callback[] callbacks)
    throws IOException, UnsupportedCallbackException {
        for (int i = 0; i < callbacks.length; i++) {
            if (callbacks[i] instanceof NameCallback) {
                ((NameCallback)callbacks[i]).setName(authenticationID);

            } else if (callbacks[i] instanceof PasswordCallback) {
                ((PasswordCallback)callbacks[i]).setPassword(passwd);

            } else if (callbacks[i] instanceof RealmChoiceCallback) {
                /* Deals with a choice of realms */
                String[] choices =
                    ((RealmChoiceCallback)callbacks[i]).getChoices();
                int selected = 0;

                if (authRealm != null && authRealm.length() > 0) {
                    selected = -1; // no realm chosen
                    for (int j = 0; j < choices.length; j++) {
                        if (choices[j].equals(authRealm)) {
                            selected = j;
                        }
                    }
                    if (selected == -1) {
                        StringBuffer allChoices = new StringBuffer();
                        for (int j = 0; j <  choices.length; j++) {
                            allChoices.append(choices[j] + ",");
                        }
                        throw new IOException("Cannot match " +
                            "'java.naming.security.sasl.realm' property value, '" +
                            authRealm + "' with choices " + allChoices +
                            "in RealmChoiceCallback");
                    }
                }

                ((RealmChoiceCallback)callbacks[i]).setSelectedIndex(selected);

            } else if (callbacks[i] instanceof RealmCallback) {
                /* 1 or 0 realms specified in challenge */
                RealmCallback rcb = (RealmCallback) callbacks[i];
                if (authRealm != null) {
                    rcb.setText(authRealm);  // Use what user supplied
                } else {
                    String defaultRealm = rcb.getDefaultText();
                    if (defaultRealm != null) {
                        rcb.setText(defaultRealm); // Use what server supplied
                    } else {
                        rcb.setText("");  // Specify no realm
                    }
                }
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        }
}
 
Example 83
Project: zookeeper-pkg   File: ZooKeeperSaslClient.java   Source Code and License Vote up 4 votes
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");
                    }
                }
            }
        }
    }
}
 
Example 84
Project: zookeeper-pkg   File: SaslServerCallbackHandler.java   Source Code and License Vote up 4 votes
private void handleRealmCallback(RealmCallback rc) {
    LOG.debug("client supplied realm: " + rc.getDefaultText());
    rc.setText(rc.getDefaultText());
}
 
Example 85
Project: jstorm   File: ServerCallbackHandler.java   Source Code and License Vote up 4 votes
private void handleRealmCallback(RealmCallback rc) {
    LOG.debug("handleRealmCallback: " + rc.getDefaultText());
    rc.setText(rc.getDefaultText());
}