243.9. 使用 HTTP 基本身份验证


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

<route>
   <from uri="netty4-http:http://0.0.0.0:{{port}}/foo?securityConfiguration.realm=karaf"/>
   ...
</route>
Copy to Clipboard Toggle word wrap

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

Apache Karaf / ServiceMix 的最终用户开箱即用有一个 karaf 域,因此上面的示例将在这些容器中开箱即用。

243.9.1. 在 Web 资源中指定 ACL

org.apache.camel.component.netty4.http.SecurityConstraint 允许定义对 Web 资源的约束。并且提供了 org.apache.camel.component.netty.http.SecurityConstraintMapping,允许使用角色轻松定义包含和排除项。

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

  <bean id="constraint" class="org.apache.camel.component.netty4.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>
Copy to Clipboard Toggle word wrap

上面的约束已定义,以便

  • 对 Thycotic 的访问会被限制,并且接受任何角色(也如果没有角色,也接受任何角色)
  • 访问 /admin86] 需要 admin 角色
  • 访问 /guest205 需要 admin 或 guest 角色
  • 对 /public netobserv 的访问是一个排除项,这意味着不需要身份验证,因此对于没有登录的任何人都公开了身份验证

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

<route>
   <from uri="netty4-http:http://0.0.0.0:{{port}}/foo?matchOnUriPrefix=true&amp;securityConfiguration.realm=karaf&amp;securityConfiguration.securityConstraint=#constraint"/>
   ...
</route>
Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2025 Red Hat