Пример #1
0
            /// <exception cref="Org.Apache.Hadoop.Security.Token.SecretManager.InvalidToken"/>
            /// <exception cref="Javax.Security.Auth.Callback.UnsupportedCallbackException"/>
            /// <exception cref="Org.Apache.Hadoop.Ipc.StandbyException"/>
            /// <exception cref="Org.Apache.Hadoop.Ipc.RetriableException"/>
            /// <exception cref="System.IO.IOException"/>
            public virtual void Handle(Javax.Security.Auth.Callback.Callback[] callbacks)
            {
                NameCallback      nc = null;
                PasswordCallback  pc = null;
                AuthorizeCallback ac = null;

                foreach (Javax.Security.Auth.Callback.Callback callback in callbacks)
                {
                    if (callback is AuthorizeCallback)
                    {
                        ac = (AuthorizeCallback)callback;
                    }
                    else
                    {
                        if (callback is NameCallback)
                        {
                            nc = (NameCallback)callback;
                        }
                        else
                        {
                            if (callback is PasswordCallback)
                            {
                                pc = (PasswordCallback)callback;
                            }
                            else
                            {
                                if (callback is RealmCallback)
                                {
                                    continue;
                                }
                                else
                                {
                                    // realm is ignored
                                    throw new UnsupportedCallbackException(callback, "Unrecognized SASL DIGEST-MD5 Callback"
                                                                           );
                                }
                            }
                        }
                    }
                }
                if (pc != null)
                {
                    TokenIdentifier tokenIdentifier = GetIdentifier(nc.GetDefaultName(), secretManager
                                                                    );
                    char[] password           = GetPassword(tokenIdentifier);
                    UserGroupInformation user = null;
                    user = tokenIdentifier.GetUser();
                    // may throw exception
                    connection.attemptingUser = user;
                    if (Log.IsDebugEnabled())
                    {
                        Log.Debug("SASL server DIGEST-MD5 callback: setting password " + "for client: " +
                                  tokenIdentifier.GetUser());
                    }
                    pc.SetPassword(password);
                }
                if (ac != null)
                {
                    string authid  = ac.GetAuthenticationID();
                    string authzid = ac.GetAuthorizationID();
                    if (authid.Equals(authzid))
                    {
                        ac.SetAuthorized(true);
                    }
                    else
                    {
                        ac.SetAuthorized(false);
                    }
                    if (ac.IsAuthorized())
                    {
                        if (Log.IsDebugEnabled())
                        {
                            string username = GetIdentifier(authzid, secretManager).GetUser().GetUserName();
                            Log.Debug("SASL server DIGEST-MD5 callback: setting " + "canonicalized client ID: "
                                      + username);
                        }
                        ac.SetAuthorizedID(authzid);
                    }
                }
            }