我创建了一个BasicAuthFilter,它有这个签名:
@Override
public void doFilter(ServletRequest request,
ServletResponse response,
FilterChain chain) throws IOException, ServletException
Run Code Online (Sandbox Code Playgroud)
如果有人使用正确设置的授权标头调用过滤器,则此方法有效。但是,如果有人在 chrome 或 firefox 上访问如下网址:
http://username:password@localhost:8888
Run Code Online (Sandbox Code Playgroud)
浏览器没有使用该信息填充授权标头(这让我感到惊讶)。我查看了 chrome 发送的信息,用户名和密码位于请求 URL 中,但其他地方都没有。
我不知道如何从 URL 中提取该信息。我在 上尝试了很多吸气剂HttpServletRequest,但没有找到任何可以给我用户名和密码的东西。
注意:是的,我知道这是不安全的,但当您尝试测试系统时使用起来确实很方便。
Vagrant up可以通过 访问并下载我的 Vagrant box(我打包并放置在我的主机上)http://devops.example.com/vagrant.box。
但我不希望我的盒子被公开,并且希望通过使用 HTTP 基本身份验证来进行保护。当我打开基本身份验证并执行“vagrant up”时,Vagrant 返回带有 401 错误的消息。
我如何配置 Vagrant,以便它可以通过基本身份验证访问该框?
预先感谢,干杯!
当前支持的获取图像的方式是将 {uri:link} 对象插入到 Image 的 source props 中,但是,这没有启用身份验证。有没有办法将身份验证令牌插入到 url 调用中或以其他方式进行身份验证以检索图像?多谢!
< Image
style={styles.logo}
source={{uri: 'http://facebook.github.io/react/img/logo_og.png'}}
/>
Run Code Online (Sandbox Code Playgroud) javascript authentication android basic-authentication react-native
Nginx(docker image,1.17.2)需要对子路径进行基本身份验证。尽管我的配置另有说明https://example.org/subpath:
// /etc/nginx/conf.d/mysetup.conf
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
server {
listen 443 ssl;
server_name example.org;
server_tokens off;
ssl_certificate /etc/letsencrypt/live/example.org/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.org/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
access_log /var/logs/nginx/example.org.access.log;
error_log /var/logs/nginx/example.org.error.log info;
root /var/www/domains/example.org/stage_root/;
location / {
auth_basic "example.org server";
auth_basic_user_file /var/htaccess/htaccess_example.org;
}
location /subpath {
auth_basic off;
root /var/www/domains/example.org/;
}
}
Run Code Online (Sandbox Code Playgroud)
一些事实:
server指令中)和上游丛。docker-compose其自己网络设置的一部分(nginx 是网关)/var/www/domains/example.org/subpath/auth_basic会禁用身份验证请求到目前为止我尝试过的:
location /块移至该server …我正在尝试使用基本身份验证对经过身份验证的服务使用 Java 11 HTTP 客户端。身份验证成功进行,但它会与服务器进行额外的往返,以了解它应该发送身份验证数据。
已搜索文档和代码,在内部某个时刻它使用某种缓存,但我无法设置缓存值。
这是我的客户端代码:
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("http://someurl.com"))
.build();
HttpClient client = HttpClient.newBuilder()
.authenticator(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("user", "pass".toCharArray());
}
})
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
Run Code Online (Sandbox Code Playgroud)
我期望的是,我可以以某种方式告诉客户端抢先发送身份验证数据,而不仅仅是在服务器请求时发送。
我开始制作一个应用程序,并首先将其连接到模拟 API。现在我想将其连接到在我的 PC 上运行的 API。
首先,我正在尝试实现登录访问。由于我的 API 的基本 URL 是http://localhost:5000/energy/api/我将其更改为 http://<< MyIPAddress >>:5000/energy/api/ (还不知道这是否正确)。我正在我的实际手机上进行测试。但在我的代码中,用户名和密码作为参数传递,而我想使用基本身份验证登录(这就是我在 Postman 中执行此操作的方式)。例如,这就是我希望完成身份验证的方式:

这是我的请求管理器:
object RequestManager {
val interceptor = HttpLoggingInterceptor()
val client = OkHttpClient.Builder().addInterceptor(interceptor).build()
init {
interceptor.level = HttpLoggingInterceptor.Level.BODY
}
val retrofit = Retrofit.Builder()
.baseUrl("http://<<MYIP>>:5000/energy/api/")
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build()
val service = retrofit.create(Api::class.java)
Run Code Online (Sandbox Code Playgroud)
我的 MainActivity.kt:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
login_button.setOnClickListener {
buttonClicked()
}
if (getTokenFromPrefs()?.length!! > 0) {
openSearchActivity()
}
}
private fun buttonClicked() {
val …Run Code Online (Sandbox Code Playgroud) 我想实现什么目标?有一项负责 HTTP 基本身份验证(访问)的服务和两项服务(a、b),其中某些端点受到访问服务的保护。
为什么?在存在更多具有受保护端点的服务的情况下,每个服务中都不会重复授权功能。还要在一处进行修改,以防更改为 OAuth2(也许将来)。
我做了什么? 我按照官方网站上的指南创建了示例服务,该服务运行得很好。
当我尝试将授权移至单独的服务,然后在具有受保护端点的少数其他服务中使用它时,就会出现问题。我不知道该怎么做。你能帮我一下吗?
我尝试过不同的功能设置。没有任何帮助,到目前为止我的代码如下所示:
访问服务
import os
import secrets
from fastapi import FastAPI, Depends, HTTPException, status
from fastapi.security import HTTPBasic, HTTPBasicCredentials
security = HTTPBasic()
def authorize(credentials: HTTPBasicCredentials = Depends(security)):
is_user_ok = secrets.compare_digest(credentials.username, os.getenv('LOGIN'))
is_pass_ok = secrets.compare_digest(credentials.password, os.getenv('PASSWORD'))
if not (is_user_ok and is_pass_ok):
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail='Incorrect email or password.',
headers={'WWW-Authenticate': 'Basic'},
)
app = FastAPI(openapi_url="/api/access/openapi.json", docs_url="/api/access/docs")
@app.get('/api/access/auth', dependencies=[Depends(authorize)])
def auth():
return {"Granted": True} …Run Code Online (Sandbox Code Playgroud) python authentication basic-authentication microservices fastapi
我的问题是我无法通过 traefik 设置前端应用程序的基本身份验证
这就是我配置 traefik 的方式
traefik.yml
global:
checkNewVersion: true
sendAnonymousUsage: false
entryPoints:
https:
address: :443
http:
address: :80
traefik:
address: :8080
tls:
options:
foo:
minVersion: VersionTLS12
cipherSuites:
- "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"
- "TLS_RSA_WITH_AES_256_GCM_SHA384"
providers:
providersThrottleDuration: 2s
docker:
watch: true
endpoint: unix:///var/run/docker.sock
exposedByDefault: false
network: web
api:
insecure: true
dashboard: true
log:
level: INFO
certificatesResolvers:
default:
acme:
storage: /acme.json
httpChallenge:
entryPoint: http
Run Code Online (Sandbox Code Playgroud)
docker-compose.yml
version: '3'
services:
traefik:
image: traefik:v2.0
restart: always
ports:
- "80:80"
- "443:443"
- "8080:8080"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock" …Run Code Online (Sandbox Code Playgroud) 我正在为ActiveX HTTP控件制作测试装备,我需要创建一个安全POST的网站.为了简单起见,我正在使用VS调试服务器运行Web应用程序; Web应用程序项目是测试应用程序解决方案的一部分.AX控件不支持NTLM身份验证.有没有简单的方法可以在没有NTLM或重定向到页面表单的情况下要求非常基本的http身份验证?我只需要在帖子中要求用户名和密码.用户名和密码内容无关紧要,因此所有内容都将以明文形式存储.
我在Web.Config中尝试过身份验证模式; Windows看起来与NTLM相同(可能是错误的),Forms需要一个表单来连接并设置一个cookie,Passport超出了这个项目的范围,我不知道我是如何实现None的.有任何想法吗?
我在Web.Config中尝试了"authentication mode ="Windows"",并在Web应用程序的"Web"选项卡中选中了NTLM复选框.
c# asp.net authentication basic-authentication visual-studio
我找到了这篇文章,但它的目标是Play 2.0.
有没有人为Play 1做过这个(我使用的是1.2.4-mbknor-3)?