我正在尝试在我的域(实际上,它是一个子域)的/admin 下设置非常基本的摘要身份验证。我在我的 bootstrap.php 中注册了身份验证程序:
protected function _initAdminArea()
{
//setup protected area
$config = array(
'accept_schemes' => 'digest',
'realm' => 'administration',
'digest_domains' => '/admin',
'nonce_timeout' => 3600
);
$authAdapter = new Zend_Auth_Adapter_Http($config);
$digestResolver = new Zend_Auth_Adapter_Http_Resolver_File(APPLICATION_PATH . '/../data/admins.txt');
$authAdapter->setDigestResolver($digestResolver);
//set storage
$storage = new Zend_Auth_Storage_NonPersistent();
Zend_Auth::getInstance()->setStorage($storage);
//dispatch auth adapter using plugin
$loader = new Zend_Loader_PluginLoader(array('Application_Plugin' => APPLICATION_PATH . '/plugins'), 'auth');
$AdminAuth = $loader->load('AdminAuth');
$auth = new $AdminAuth($authAdapter);
//register plugin
Zend_Controller_Front::getInstance()->registerPlugin($auth);
}
然后,我要求用户使用插件 AdminAuth.php 登录每个请求:
require_once 'Zend/Auth.php';
require_once 'Zend/Controller/Plugin/Abstract.php';
require_once 'Zend/Auth/Adapter/Interface.php';
class Application_Plugin_AdminAuth extends Zend_Controller_Plugin_Abstract
{
/**
* The HTTP Auth adapter
*/
protected $adapter;
/**
* Constructor
*
* @param Zend_Auth_Adapter_Interface
*/
public function __construct(Zend_Auth_Adapter_Interface $adapter)
{
$this->adapter = $adapter;
}
/**
* Dispatch Loop Startup hook
*
* Called before Zend_Controller_Front enters its dispatch loop. This uses
* the authentication adapter to check if the user submitted valid login
* credentials. If not, the request is changed to point to the
* authenticateAction, instead of the requested action.
*
* @param Zend_Controller_Request_Abstract $request
*/
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
{
$this->adapter->setRequest($this->_request);
$this->adapter->setResponse($this->_response);
$result = $this->adapter->authenticate();
if (!$result->isValid()) {
echo 'auth failure';
}
}
}
这似乎工作正常。但是,身份验证总是失败。我已经多次检查客户端和服务器 MD5 哈希值,它们都是正确的。这是 admins.txt 的样子:
peter:administration:1f7758428f7646706dbdcfe8d754427a
我还尝试将摘要更改为基本身份验证并将 MD5 哈希更改为纯文本。然而,认证仍然失败。
当我在控制台中执行以下命令时:
curl --digest -u peter:password http://sub.domain.com/admin -v
我得到以下输出:
* About to connect() to sub.domain.com port 80 (#0)
* Trying 83.96.149.65... connected
* Connected to sub.domain.com (83.96.149.65) port 80 (#0)
* Server auth using Digest with user 'peter'
> GET /admin HTTP/1.1
> User-Agent: curl/7.21.0 (x86_64-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18
> Host: sub.domain.com
> Accept: */*
>
< HTTP/1.1 401 Authorization Required
< Date: Mon, 25 Jul 2011 14:04:38 GMT
< Server: Apache/2.2.19 (Unix)
< X-Powered-By: PHP/5.2.17
< Www-Authenticate: Digest realm="administration", domain="/admin", nonce="3f624929a274a868c0fc0188a3c49c8e", opaque="d75db7b160fe72d1346d2bd1f67bfd10", algorithm="MD5", qop="auth"
< X-Powered-By: PleskLin
< Content-Length: 1630
< Connection: close
< Content-Type: text/html
<
* Closing connection #0
* Issue another request to this URL: 'http://sub.domain.com/admin'
* About to connect() to sub.domain.com port 80 (#0)
* Trying 83.96.149.65... connected
* Connected to sub.domain.com (83.96.149.65) port 80 (#0)
* Server auth using Digest with user 'peter'
> GET /admin HTTP/1.1
> Authorization: Digest username="peter", realm="administration", nonce="3f624929a274a868c0fc0188a3c49c8e", uri="/admin", cnonce="MDA5ODU4", nc=00000001, qop="auth", response="28a907e1fe4b537264695bd456512f65", opaque="d75db7b160fe72d1346d2bd1f67bfd10", algorithm="MD5"
> User-Agent: curl/7.21.0 (x86_64-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18
> Host: sub.domain.com
> Accept: */*
>
< HTTP/1.1 401 Authorization Required
< Date: Mon, 25 Jul 2011 14:04:38 GMT
< Server: Apache/2.2.19 (Unix)
< X-Powered-By: PHP/5.2.17
* Authentication problem. Ignoring this.
< Www-Authenticate: Digest realm="administration", domain="/admin", nonce="3f624929a274a868c0fc0188a3c49c8e", opaque="d75db7b160fe72d1346d2bd1f67bfd10", algorithm="MD5", qop="auth"
< X-Powered-By: PleskLin
< Content-Length: 1630
< Connection: close
< Content-Type: text/html
<
auth failure
特别注意认证问题。忽略这个。 有没有人知道可能出了什么问题?我 100% 确定提供的用户凭据是正确的(我还检查了大写字母等)。
最佳答案
我最好的猜测是您没有以 HA1 格式存储凭据。这就是Zend_Auth_Adapter_Http写道:
Digest authentication expects to receive a hash of the user's username, the realm, and their password (each separated by colons). Currently, the only supported hash algorithm is MD5.
在您的情况下,这将是:
MD5(peter:administration:password) = 1aab17d17d4ace84fcf6e2230e8775ea
关于php - Zend Digest/Basic 身份验证不断失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6817280/
给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru
我想安装一个带有一些身份验证的私有(private)Rubygem服务器。我希望能够使用公共(public)Ubuntu服务器托管内部gem。我读到了http://docs.rubygems.org/read/chapter/18.但是那个没有身份验证-如我所见。然后我读到了https://github.com/cwninja/geminabox.但是当我使用基本身份验证(他们在他们的Wiki中有)时,它会提示从我的服务器获取源。所以。如何制作带有身份验证的私有(private)Rubygem服务器?这是不可能的吗?谢谢。编辑:Geminabox问题。我尝试“捆绑”以安装新的gem..
我希望我的UserPrice模型的属性在它们为空或不验证数值时默认为0。这些属性是tax_rate、shipping_cost和price。classCreateUserPrices8,:scale=>2t.decimal:tax_rate,:precision=>8,:scale=>2t.decimal:shipping_cost,:precision=>8,:scale=>2endendend起初,我将所有3列的:default=>0放在表格中,但我不想要这样,因为它已经填充了字段,我想使用占位符。这是我的UserPrice模型:classUserPrice回答before_val
我有一个表单,其中有很多字段取自数组(而不是模型或对象)。我如何验证这些字段的存在?solve_problem_pathdo|f|%>... 最佳答案 创建一个简单的类来包装请求参数并使用ActiveModel::Validations。#definedsomewhere,atthesimplest:require'ostruct'classSolvetrue#youcouldevencheckthesolutionwithavalidatorvalidatedoerrors.add(:base,"WRONG!!!")unlesss
我有一些非常大的模型,我必须将它们迁移到最新版本的Rails。这些模型有相当多的验证(User有大约50个验证)。是否可以将所有这些验证移动到另一个文件中?说app/models/validations/user_validations.rb。如果可以,有人可以提供示例吗? 最佳答案 您可以为此使用关注点:#app/models/validations/user_validations.rbrequire'active_support/concern'moduleUserValidationsextendActiveSupport:
当我的预订模型通过rake任务在状态机上转换时,我试图找出如何跳过对ActiveRecord对象的特定实例的验证。我想在reservation.close时跳过所有验证!叫做。希望调用reservation.close!(:validate=>false)之类的东西。仅供引用,我们正在使用https://github.com/pluginaweek/state_machine用于状态机。这是我的预订模型的示例。classReservation["requested","negotiating","approved"])}state_machine:initial=>'requested
我有一个服务模型/表及其注册表。在表单中,我几乎拥有服务的所有字段,但我想在验证服务对象之前自动设置其中一些值。示例:--服务Controller#创建Action:defcreate@service=Service.new@service_form=ServiceFormObject.new(@service)@service_form.validate(params[:service_form_object])and@service_form.saverespond_with(@service_form,location:admin_services_path)end在验证@ser
我已经构建了一些serverspec代码来在多个主机上运行一组测试。问题是当任何测试失败时,测试会在当前主机停止。即使测试失败,我也希望它继续在所有主机上运行。Rakefile:namespace:specdotask:all=>hosts.map{|h|'spec:'+h.split('.')[0]}hosts.eachdo|host|begindesc"Runserverspecto#{host}"RSpec::Core::RakeTask.new(host)do|t|ENV['TARGET_HOST']=hostt.pattern="spec/cfengine3/*_spec.r
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下
我正在尝试在Rails上安装ruby,到目前为止一切都已安装,但是当我尝试使用rakedb:create创建数据库时,我收到一个奇怪的错误:dyld:lazysymbolbindingfailed:Symbolnotfound:_mysql_get_client_infoReferencedfrom:/Library/Ruby/Gems/1.8/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundleExpectedin:flatnamespacedyld:Symbolnotfound:_mysql_get_client_infoReferencedf