228.8. HTTP Basic 認証の使用
Netty HTTP コンシューマーは、使用するセキュリティーレルム名を指定して HTTP Basic 認証をサポートします。以下に例を示します。
<route> <from uri="netty-http:http://0.0.0.0:{{port}}/foo?securityConfiguration.realm=karaf"/> ... </route>
<route>
<from uri="netty-http:http://0.0.0.0:{{port}}/foo?securityConfiguration.realm=karaf"/>
...
</route>
Basic 認証を有効にするには、レルム名が必須です。デフォルトでは、JAAS ベースのオーセンティケーターが使用されます。これは指定されたレルム名(上記の例のkaraf)を使用し、認証に JAAS レルムと JAAS \{{LoginModule}}s を使用します。
Apache Karaf / ServiceMix のエンドユーザーには、そのまま使える karaf レルムがあります。そのため、上記のサンプルがこれらのコンテナーで追加設定なしで機能しなくなるからです。
228.8.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>
<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>
上記の制約は、以下のように定義されます。
- /* へのアクセスは制限され、すべてのロールが許可されます(また、ユーザーにロールがない場合も)
- /admin/* へのアクセスには admin ロールが必要です。
- /guest/* へのアクセスには admin ロールまたは guest ロールが必要です。
- /public/* へのアクセスは、認証を必要としない除外されるため、ログインせずにパブリックになります。
この制約を使用するには、以下のように Bean ID を参照する必要があります。
<route> <from uri="netty-http:http://0.0.0.0:{{port}}/foo?matchOnUriPrefix=true&securityConfiguration.realm=karaf&securityConfiguration.securityConstraint=#constraint"/> ... </route>
<route>
<from uri="netty-http:http://0.0.0.0:{{port}}/foo?matchOnUriPrefix=true&securityConfiguration.realm=karaf&securityConfiguration.securityConstraint=#constraint"/>
...
</route>