DropWizard Auth Realms(DropWizard 身份验证领域)
问题描述
在 DropWizard 中,我可以像这样设置基本身份验证(在 Application#run
impl 中):
BasicAuthProviderauthProvider = new BasicAuthProvider(authenticator, "SECRET_REALM");environment.jersey().register(authProvider);
我想知道String realm
("SECRET_REALM") 的意义是什么?
根据一般的安全概念,我将领域"理解为存储用户和角色/权限的地方(数据库、目录、文件、密钥库等).
在 DropWizard 中域是什么意思,在 BasicAuthProvider
中指定它的意义是什么?它是否在这个领域创造了一些东西?
从某种意义上说,领域是服务器中的一些受保护区域/空间.领域应该有一个名字.如果我们从 只是声明(关于 realm
):
领域:
要显示给用户的字符串,以便他们知道哪个用户名和使用密码.此字符串应至少包含执行身份验证的主机,并且可能另外指示可能具有访问权限的用户的集合.一个例子可能是registered_users@gotham.news.com".
In DropWizard, I can set up basic auth like so (in the Application#run
impl):
BasicAuthProvider<SimplePrincipal> authProvider = new BasicAuthProvider(authenticator, "SECRET_REALM");
environment.jersey().register(authProvider);
I am wondering what the significance of the String realm
("SECRET_REALM") is?
From general security concepts, I understand a "realm" to be a place (database, directory, file, keystore, etc.) where users and roles/permissions are stored.
What does a realm mean in DropWizard, and what's the significance of specifying it inside BasicAuthProvider
? Does it create something with this realm under the hood?
A realm is in a sense, some protected area/space in the server. The realm should have a name. If we run the example from this post, using cURL(which I recommend downloading, as it's useful in development), without any user credentials, we will see the following.
C:>curl -i http://localhost:8080/simple
HTTP/1.1 401 Unauthorized
Date: Thu, 11 Dec 2014 18:55:02 GMT
WWW-Authenticate: Basic realm="Basic Example Realm"
Content-Type: text/plain
Transfer-Encoding: chunked
Credentials are required to access this resource.
This is how the Basic Auth Protocol works. When the server want the user agent to authenticate, to access a secured resource, it will send back a "401 Unauthorized", along with the header similar to
WWW-Authenticate: Basic realm="Basic Example Realm"
The name you provide to the BasicAuthProvider
is the realm
that will be provided in the header. You can see in the source code
if (required) {
final String challenge = String.format(CHALLENGE_FORMAT, realm);
throw new WebApplicationException(
Response.status(Response.Status.UNAUTHORIZED)
.header(HttpHeaders.WWW_AUTHENTICATE, challenge)
.entity("Credentials are required to access this resource.")
.type(MediaType.TEXT_PLAIN_TYPE)
.build());
Now try to access the resource from the browser. You will see
You can also see the realm name there. The RFC 2617 just states (about the realm
):
realm:
A string to be displayed to users so they know which username and password to use. This string should contain at least the name of the host performing the authentication and might additionally indicate the collection of users who might have access. An example might be "registered_users@gotham.news.com".
这篇关于DropWizard 身份验证领域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:DropWizard 身份验证领域
基础教程推荐
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 降序排序:Java Map 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01