Camel cxf pax-web Обрабатывать токен имени пользователя WS-Security

Я внедряю веб-сервис с использованием Camel CXF для развертывания в Karaf. Я использую пакс паутину, которая идет с карафом. Я использую плагин cxf codegen в pom, чтобы сделать wsdl для java.

Я определяю cxf uri и маршруты в Java DSL RouteBuilder. В файле blueprint.xml есть только несколько компонентов и ссылка на RouteBuilder.

final String cxfUri =
            String.format("cxf:%s?serviceClass=%s&wsdlURL=wsdl/Event.wsdl",
                    "/Event.jws", com.example.EventPortType.class.getCanonicalName());

У меня есть настройка ssl с pax-web(jetty.xml). Если я отправляю заголовки безопасности WSSE с именем пользователя и паролем, он генерирует ошибку мыла MustUnderstand.

<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" S:mustUnderstand="1">
  <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Id-LdZa8aaGdy7mWQWXLp_zpbfg">
    <wsse:Username>xxx</wsse:Username>
    <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">xxx</wsse:Password>
  </wsse:UsernameToken>
</wsse:Security>

Запрос ввода не может быть изменен. Я получаю это исключение.

<soap:Fault>
     <faultcode>soap:MustUnderstand</faultcode>
     <faultstring>MustUnderstand headers: [{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}Security] are not understood.</faultstring>
  </soap:Fault>

Как я могу защитить конечную точку cxf для аутентификации запроса?

Спасибо.

1 ответ

Решение

Вам нужно добавить перехватчики WSS4J к открытой службе CXF. Вы можете предоставить свой собственный PasswordCallback для проверки пользователя, но я предпочитаю использовать собственный JAAS. Это пример проекта, требующий использования UsernameToken с любым пользователем Karaf (это предназначено для предоставления маршрутов camel-cxf, однако тот же принцип применяется к чистой реализации CXF). Если вы предпочитаете построители маршрутов на основе Java на основе Java, вы можете добавить компоненты-перехватчики в реестр контекста, чтобы использовать их. Но - план (или конфигурация пружины) позволяет вам более детально управлять, чем простые параметры конечной точки.

<?xml version="1.0" encoding="UTF-8"?>
    <blueprint 
        xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns:cxf="http://cxf.apache.org/blueprint/core" 
        xmlns:camelcxf="http://camel.apache.org/schema/blueprint/cxf" 
        xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0" 
        xmlns:jaxws="http://cxf.apache.org/blueprint/jaxws"
        xsi:schemaLocation="
            http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
            http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd http://camel.apache.org/schema/blueprint 
            http://camel.apache.org/schema/blueprint/camel-blueprint.xsd http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0
            http://svn.apache.org/repos/asf/aries/trunk/blueprint/blueprint-cm/src/main/resources/org/apache/aries/blueprint/compendium/cm/blueprint-cm-1.1.0.xsd 
            http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
            http://cxf.apache.org/blueprint/jaxws       http://cxf.apache.org/schemas/blueprint/jaxws.xsd
            http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/cxf/camel-cxf-2.7.5.xsd">

  <bean id="authenticationInterceptor" class="org.apache.cxf.interceptor.security.JAASLoginInterceptor">
            <property name="contextName" value="karaf"/>
            <property name="roleClassifier" value="RolePrincipal"/>
            <property name="roleClassifierType" value="classname"/>        
        </bean>

        <bean id="wsSecInterceptor" class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor">
            <argument>
                <map>
                    <entry key="action" value="UsernameToken"/>
                    <entry key="passwordType" value="PasswordText"/>
                </map>
            </argument>
        </bean>     

        <!-- ================  Apache Camel impl ======================= -->
         <camelcxf:cxfEndpoint id="testService2" 
                          address="/api/2.0/external/TestService"
                          xmlns:apogado="http://test.ws.apogado.com/v1_0/ws"
                          endpointName="apogado:AddressServicePort"
                          serviceName="apogado:AddressService"    
                          wsdlURL="classpath:/xsd/ws/TestService.wsdl"
    >

        <camelcxf:properties>
            <entry key="dataFormat" value="PAYLOAD" /> 
            <entry key="ws-security.ut.no-callbacks" value="true"/>
            <entry key="ws-security.validate.token" value="false"/>  
        </camelcxf:properties>  
        <camelcxf:inInterceptors>
            <ref component-id="wsSecInterceptor" />
            <ref component-id="authenticationInterceptor"/>  
        </camelcxf:inInterceptors>
        <camelcxf:features> 
        </camelcxf:features>
    </camelcxf:cxfEndpoint>

 <camelContext xmlns="http://camel.apache.org/schema/blueprint" id="testWsCtx" trace="true">
   <!-- your service implementation -->
   <route>
      <from uri="testService2" />
      <to uri="..." />
   <route>
</camelContext>
 </blueprint>
Другие вопросы по тегам