我正在尝试使用urllib2下载受基本身份验证保护的页面.我正在使用python 2.7,但我也在另一台使用python 2.5的计算机上尝试过它,并遇到了完全相同的行为.我尽可能地遵循本指南中给出的示例,这是我生成的代码:
import urllib2
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, "http://authenticationsite.com/', "protected", "password")
authhandler = urllib2.HTTPBasicAuthHandler(passman)
opener = urllib2.build_opener(authhandler)
f = opener.open("http://authenticationsite.com/content.html")
print f.read()
f.close()
Run Code Online (Sandbox Code Playgroud)
不幸的是服务器不是我的,所以我不能分享细节; 我把它们从上面和下面换了出来.当我运行它时,我得到以下Traceback:
File
"/usr/lib/python2.7/urllib2.py", line
397, in open
response = meth(req, response) File "/usr/lib/python2.7/urllib2.py",
line 510, in http_response
'http', request, response, code, msg, hdrs) File
"/usr/lib/python2.7/urllib2.py", line
435, in error
return self._call_chain(*args) File "/usr/lib/python2.7/urllib2.py",
line 369, in _call_chain
result = func(*args) File "/usr/lib/python2.7/urllib2.py", line
518, in http_error_default
raise HTTPError(req.get_full_url(), code,
msg, hdrs, …Run Code Online (Sandbox Code Playgroud) 我用Java编写了13周的时间,正在开发一个RESTful Web服务.后端已完成,现在我正在创建一个UI.其中一个要求是用户使用http basic登录.我已将此配置为当用户导航到页面时弹出对话框出现的位置,您可以输入我所拥有的一个硬编码用户并将其登录.但我真正需要它做的是验证用户是否在一个数据库.我已经广泛搜索,试图找到一种方法来配置它来验证数据库,但无济于事.这是我的假用户的spring-security.xml文件.
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<!-- <http auto-config="true"> <intercept-url pattern="/welcome*" access="ROLE_USER"
/> <form-login login-page="/login" default-target-url="/welcome" authentication-failure-url="/loginfailed"
/> <logout logout-success-url="/logout" /> </http> -->
<http>
<intercept-url pattern="/*" access="ROLE_USER" />
<http-basic />
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="tmain" password="123456" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
Run Code Online (Sandbox Code Playgroud)
这里(我相信)只有我的web.xml文件中的设置相关信息.
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Run Code Online (Sandbox Code Playgroud)
任何人都可以给我一些关于配置spring security以对数据库进行身份验证的方向,而不是我的虚拟用户吗?我在数据库中有一个User实体,其中包含firstname,lastname,email,password,activeStatus和timezone.电子邮件是用户的用户名.任何和所有的帮助将不胜感激.
嗨,我想从我的android webview 打开这个网址http://3864.cloud-matic.net/,我尝试了很多方法,但应用程序甚至没有打开mainActivity.我试过的是下面的内容.
public void onCreate(Bundle state) {
super.onCreate(state);
setContentView(R.layout.main);
WebView webView = (WebView) findViewById(R.id.webView1);
webView.setHttpAuthUsernamePassword("cloud-matic.net/", "realm", username, password);
webView.loadUrl("http://3864.cloud-matic.net/");
}
Run Code Online (Sandbox Code Playgroud)
请告诉我哪里错了.阿里
我有一个现有的angularjs代码,它可以生成HTTP GET.下面提取的是控制器内部的一些相关代码.
.controller('imptViewCtrl', ['$scope', '$http',
function ($scope, $http, ) {
var url = $configuration.webroot + '/impt/list?list=testlist';
$http.get(url).then(function (response) {
tableData = response.data;
});
}]);
Run Code Online (Sandbox Code Playgroud)
我想将HTTP基本身份验证添加到HTTP GET.用户名是foo,密码是bar.如何才能做到这一点?
我有一个作为服务运行的Jetty 7的嵌入式实现,并且想要为servlet添加没有web.xml文件的基本身份验证.
我使用此处描述的步骤创建了我的凭据
我以为我可以创建服务器,使用基本身份验证创建安全处理程序并将HashLoginService附加到安全管理器.但我显然遗漏了几件事,因为我从来没有得到凭证的提示.
下面是代码.任何帮助将不胜感激.
server = new Server(port);
server.addConnector(getSslChannelConnector(securePort));
server.setGracefulShutdown(1000);
server.setStopAtShutdown(true);
// create the context handler for the server
ServletContextHandler sch = new ServletContextHandler(server, WEBAPP_CONTEXT);
// attach the security handler to it that has basic authentication
sch.setSecurityHandler(getSecurityHandler());
// define the processing servlet.
sch.addServlet(new ServletHolder(new ProcessingServlet()), "/process");
.
.
private SecurityHandler getSecurityHandler() {
// add authentication
Constraint constraint = new Constraint(Constraint.__BASIC_AUTH,"user");
constraint.setAuthenticate(true);
constraint.setRoles(new String[]{"user","admin"});
// map the security constraint to the root path.
ConstraintMapping cm = new ConstraintMapping(); …Run Code Online (Sandbox Code Playgroud) 我们聘请了一位为我们编写iPhone应用程序的承包商,我开始用ServiceStack为它编写后端服务.
我一般都在努力获得授权:使用何种授权以及如何实施授权.
我对ServiceStack,HTTP和授权(我)了解不多.我读过这篇文章,但我可能还是做错了.
我将使用现有遗留数据库中的用户名和密码进行身份验证(但没有别的 - 没有注册新用户,没有不同的权限.只是进行身份验证).
所以我需要编写自己的提供者.
我已经设法在本教程CredentialsAuthProvider的帮助下实现了一个工作.
它在我在浏览器中测试时有效:
auth/credentials但是,我注意到当我在Fiddler中尝试时,相同的工作流程不起作用.
POST auth/credentials工作.我发布这个:
POST http://localhost:52690/auth/credentials?format=json HTTP/1.1
User-Agent: Fiddler
Host: localhost:52690
Content-Length: 74
Content-Type: application/json; charset=utf-8
{
"UserName": "chspe",
"Password": "xyz",
"RememberMe": true
}
Run Code Online (Sandbox Code Playgroud)
......得到这个:
HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
Date: Fri, 14 Jun 2013 13:07:35 GMT
X-AspNet-Version: 4.0.30319
X-Powered-By: ServiceStack/3,949 Win32NT/.NET
Set-Cookie: ss-id=3YUUgfwIeJd7PedFK5Th; path=/; HttpOnly
Set-Cookie: ss-pid=zQJ5Z4Vq7AY+BpVwbttj; expires=Tue, 14-Jun-2033 13:07:35 GMT; path=/; HttpOnly
Set-Cookie: ss-opt=perm; expires=Tue, 14-Jun-2033 13:07:35 GMT; …Run Code Online (Sandbox Code Playgroud) c# authentication web-services basic-authentication servicestack
我可以使用HTTP标头中的HTTP基本身份验证凭据从Sonatype Nexus下载该文件.
但是我无法通过将凭据作为URL的一部分来实现这一点 - 这样的事情:
http://admin:admin123@nexus.example.com/nexus/service/local/artifact/maven/content?g=com.test&a=project&v=1.0&r=test_repo_1_release
Run Code Online (Sandbox Code Playgroud)
有没有人知道为什么或如何在标题中不使用auth来实现相同的目的?
PS:这是一个测试环境 - 因此没有SSL.
REST API无需身份验证方法即可运行.现在,我想通过移动应用程序对API请求进行HTTP基本身份验证来验证REST API.我试过yii2指南,但它对我不起作用.
基本上移动用户需要使用用户名和密码登录,如果用户名和密码正确,则用户需要登录,并且需要使用令牌进一步验证API请求.
当我调试findIdentityByAccessToken()函数时,$ token等于用户名.Postman扩展用于检查HTTP Basic请求.用户表中的access_token字段为空.我需要手动保存吗?如何将access_token作为响应返回?
这三种方法(HttpBasicAuth,HttpBearerAuth,QueryParamAuth)是否有任何原因,为什么?怎么样?
我的应用程序文件夹结构如下所示.
api
-config
-modules
--v1
---controllers
---models
-runtime
-tests
-web
backend
common
console
environments
frontend
Run Code Online (Sandbox Code Playgroud)
API \模块\ V1\Module.php
namespace api\modules\v1;
class Module extends \yii\base\Module
{
public $controllerNamespace = 'api\modules\v1\controllers';
public function init()
{
parent::init();
\Yii::$app->user->enableSession = false;
}
}
Run Code Online (Sandbox Code Playgroud)
API \模块\ V1 \控制器\ CountryController.php
namespace api\modules\v1\controllers;
use Yii;
use yii\rest\ActiveController;
use common\models\LoginForm;
use common\models\User;
use yii\filters\auth\CompositeAuth;
use yii\filters\auth\HttpBasicAuth;
use yii\filters\auth\HttpBearerAuth;
use yii\filters\auth\QueryParamAuth;
class CountryController extends ActiveController
{
public $modelClass = 'api\modules\v1\models\Country';
public …Run Code Online (Sandbox Code Playgroud) 我有WD MyBookLive 2TB,并做了以下事情:
.htaccess文件是:
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
Run Code Online (Sandbox Code Playgroud)
问题是没有启用基本身份验证,我仍然可以访问HTML文件而无需任何身份验证.
而且即使我在apache2.conf中设置了以下内容,似乎也忽略了.htaccess文件:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Run Code Online (Sandbox Code Playgroud)
404时会抛出404内部服务器错误 AllowOverride All
Apache版本:2.2.9
如何激活基本身份验证?
这两个应用程序是用 PHP Laravel 开发的 Web 应用程序。在应用程序中,应用程序1和应用程序2是两个不同的应用程序,由两个不同的团队管理。应用程序 1 用于修剪视频,而应用程序 2 用于展示其视频。
目前两个应用的登录方式都是邮箱密码登录。
POST结果发送给应用程序 2(例如 Instagram)。我关心的是应用程序 2 的身份验证部分。由于用户登录方法不同,我们如何在将视频发送到应用程序 2 之前对应用程序 1 中的用户进行身份验证?
不太确定用于此类身份验证的术语。请随时在评论部分告诉我。非常感谢。