搜索

97.9. 使用 HTTP 基本身份验证

download PDF

Netty HTTP 使用者通过指定要使用的安全域名称来支持 HTTP 基本身份验证,如下所示

<route>
   <from uri="netty-http:http://0.0.0.0:{{port}}/foo?securityConfiguration.realm=karaf"/>
   ...
</route>

域名称是启用基本身份验证所必需的。默认情况下,使用基于 JAAS 的验证器,它使用指定的 realm 名称(上例中的karaf),并使用 JAAS 域和这个域的 JAAS \\{{LoginModule}}s 进行身份验证。

Apache Karaf / ServiceMix 最终用户开箱即用有一个 karaf realm,因此上例将从这些容器开箱即用的原因。

97.9.1. 在 web 资源中指定 ACL

org.apache.camel.component.netty.http.SecurityConstraint 允许定义 web 资源的约束。org.apache.camel.component.netty.http.SecurityConstraintMapping 开箱即用,可轻松定义带有角色的包含和排除项。

例如,在 XML DSL 中,我们定义约束 bean:

  <bean id="constraint" class="org.apache.camel.component.netty.http.SecurityConstraintMapping">
    <!-- inclusions defines url -> roles restrictions -->
    <!-- a * should be used for any role accepted (or even no roles) -->
    <property name="inclusions">
      <map>
        <entry key="/*" value="*"/>
        <entry key="/admin/*" value="admin"/>
        <entry key="/guest/*" value="admin,guest"/>
      </map>
    </property>
    <!-- exclusions is used to define public urls, which requires no authentication -->
    <property name="exclusions">
      <set>
        <value>/public/*</value>
      </set>
    </property>
  </bean>

以上约束被定义,以便

  • 对 Attr 的访问会被限制,并接受任何角色(如果用户没有角色)
  • 访问 /adminAttr 需要 admin 角色
  • 访问 /guestAttr 需要 admin 或 guest 角色
  • 访问 /publicAttr 是一个排除的,这意味着不需要身份验证,因此任何人都没有登录

要使用此约束,我们只需要引用 bean id,如下所示:

<route>
   <from uri="netty-http:http://0.0.0.0:{{port}}/foo?matchOnUriPrefix=true&amp;securityConfiguration.realm=karaf&amp;securityConfiguration.securityConstraint=#constraint"/>
   ...
</route>
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.