104.9. 使用 HTTP 基本身份验证
Netty HTTP 使用者通过指定要使用的安全域名称来支持 HTTP 基本身份验证,如下所示
<route>
<from uri="netty-http:http://0.0.0.0:{{port}}/foo?securityConfiguration.realm=karaf"/>
...
</route>
域名称是必需的,才能启用基本身份验证。默认情况下,使用基于 JAAS 的验证器,它将使用指定的域名称(上例中的karaf),并使用此域的 JAAS 域和 JAAS \\{{LoginModule}}s 进行身份验证。
Apache Karaf / ServiceMix 的最终用户开箱即用有一个 karaf 域,因此上面的示例将在这些容器中开箱即用。
104.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>
上面的约束已定义,以便
- 对 Thycotic 的访问会被限制,并且接受任何角色(也如果没有角色,也接受任何角色)
- 访问 /admin86] 需要 admin 角色
- 访问 /guest205 需要 admin 或 guest 角色
- 对 /public netobserv 的访问是一个排除项,这意味着不需要身份验证,因此对于没有登录的任何人都公开了身份验证
要使用此约束,我们只需要引用 bean id,如下所示:
<route>
<from uri="netty-http:http://0.0.0.0:{{port}}/foo?matchOnUriPrefix=true&securityConfiguration.realm=karaf&securityConfiguration.securityConstraint=#constraint"/>
...
</route>