private void doBindOperation(Control[] connCtsl) throws NamingException {
if (client.getReferCount() > 1) {
changeConnection();
}
SaslBind saslBind = new SaslBind();
LdapResult result = null;
SaslBind.AuthMech authMech = saslBind.valueAuthMech(env);
try {
if (authMech == SaslBind.AuthMech.None) {
BindOp bind = new BindOp("", "", null, null);
client.doOperation(bind, connCtsl);
result = bind.getResult();
} else if (authMech == SaslBind.AuthMech.Simple) {
String principal = (String) env.get(Context.SECURITY_PRINCIPAL);
String credential = Utils.getString(env
.get(Context.SECURITY_CREDENTIALS));
BindOp bind = new BindOp(principal, credential, null, null);
client.doOperation(bind, connCtsl);
result = bind.getResult();
} else if (authMech == SaslBind.AuthMech.SASL) {
result = saslBind.doSaslBindOperation(env, client, connCtsl);
}
} catch (IOException e) {
CommunicationException ex = new CommunicationException();
ex.setRootCause(e);
throw ex;