118.3. Camel ルートへのアクセスの制御
このコンポーネントを使用するには、Spring Security AuthenticationManager および AccessDecisionManager が必要です。Spring Security 名前空間を使用して Spring XML でこれらのオブジェクトを設定する方法の例を次に示します。
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:spring-security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">
<bean id="accessDecisionManager" class="org.springframework.security.access.vote.AffirmativeBased">
<property name="allowIfAllAbstainDecisions" value="true"/>
<property name="decisionVoters">
<list>
<bean class="org.springframework.security.access.vote.RoleVoter"/>
</list>
</property>
</bean>
<spring-security:authentication-manager alias="authenticationManager">
<spring-security:authentication-provider user-service-ref="userDetailsService"/>
</spring-security:authentication-manager>
<spring-security:user-service id="userDetailsService">
<spring-security:user name="jim" password="jimspassword" authorities="ROLE_USER, ROLE_ADMIN"/>
<spring-security:user name="bob" password="bobspassword" authorities="ROLE_USER"/>
</spring-security:user-service>
</beans>
基盤となるセキュリティーオブジェクトが設定されたので、それらを使用して認可ポリシーを設定し、そのポリシーを使用してルートへのアクセスを制御できます。
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:spring-security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://camel.apache.org/schema/spring-security http://camel.apache.org/schema/spring-security/camel-spring-security.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">
<!-- import the Spring security configuration -->
<import resource= "classpath:org/apache/camel/component/spring/security/commonSecurity.xml"/>
<authorizationPolicy id="admin" access="ROLE_ADMIN"
authenticationManager="authenticationManager"
accessDecisionManager="accessDecisionManager"
xmlns="http://camel.apache.org/schema/spring-security"/>
<camelContext id="myCamelContext" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start"/>
<!-- The exchange should be authenticated with the role -->
<!-- of ADMIN before it is send to mock:endpoint -->
<policy ref="admin">
<to uri="mock:end"/>
</policy>
</route>
</camelContext>
</beans>
この例では、エンドポイント mock:end は次の場合にのみ実行されます。
admin
SpringSecurityAuthorizationPolicyは、次のような Spring SecurityAuthenticationオブジェクトを見つけることができます。- 認証できる、または認証できる
-
ROLE_ADMIN権限が含まれている