2013-12-10 40 views
2

我想配置一個cxf soap webservice,授權和身份驗證部署在Servicemix上。卡拉夫cxf-rs-ws授權

我配置了LDAP身份驗證模塊如下:

<!-- Bean to allow the $[karaf.base] property to be correctly resolved --> 
<ext:property-placeholder placeholder-prefix="$[" placeholder-suffix="]"/> 

<jaas:config name="myRealm"> 
    <jaas:module className="org.apache.karaf.jaas.modules.ldap.LDAPLoginModule" flags="required"> 
     connection.url = ldap://srv-ldap:389 
     user.base.dn = ou=people,dc=intranet,dc=company,dc=com 
     user.filter = (uid=%u) 
     user.search.subtree = false 
     role.base.dn = ou=groups,dc=intranet,dc=company,dc=com 
     role.filter = (member:=uid=%u,ou=people,dc=intranet,dc=company,dc=com) 
     role.name.attribute = cn 
     role.search.subtree = true 
     authentication = simple 
    </jaas:module> 
</jaas:config> 

<service interface="org.apache.karaf.jaas.modules.BackingEngineFactory"> 
    <bean class="org.apache.karaf.jaas.modules.properties.PropertiesBackingEngineFactory"/> 
</service> 

這裏是beans.xml的文件

<jaxws:endpoint id="myService" 
     implementor="com.myorg.services.impl.MyServiceWSImpl" 
     address="/myService"> 
     <jaxws:inInterceptors> 
      <bean class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor"> 
       <constructor-arg> 
        <map> 
         <entry key="action" value="UsernameToken" /> 
         <entry key="passwordType" value="PasswordText" /> 
        </map> 
       </constructor-arg> 
      </bean> 
      <ref bean="authenticationInterceptor" /> 
      <ref bean="authorizationInterceptor" /> 
     </jaxws:inInterceptors> 
     <jaxws:properties> 
      <entry key="ws-security.validate.token" value="false" /> 
     </jaxws:properties> 
    </jaxws:endpoint> 

    <bean id="authenticationInterceptor" 
     class="org.apache.cxf.interceptor.security.JAASLoginInterceptor"> 
     <property name="contextName" value="myRealm" /> 
    </bean> 

    <bean id="authorizationInterceptor" 
     class="org.apache.cxf.interceptor.security.SecureAnnotationsInterceptor"> 
     <property name="securedObject" ref="securedBean"/> 
    </bean> 

最後,在我的WebService實現我註釋的方法與@RolesAllowed。

@RolesAllowed("Role1") 
    public Department get(String name) throws IdMException { 
     return service.get(name); 
    } 

身份驗證攔截器正在檢索用戶,對其進行身份驗證並將組檢索爲RolePrincipal實例。 然後,在授權攔截器(SecureAnnotationsInterceptor)中讀取方法配置,expectedRoles爲「Role1」,但SimpleAuthorizingInterceptor.isUserInRole方法返回false。

我還沒有發現任何例如試圖做更多或更少相同,我發現了從CXF文檔頁面http://cxf.apache.org/docs/security.html#Security-Authorization

我必須失去了一些東西重要的幾個信息,希望有人能幫助我。 在此先感謝和親切的問候。

回答

1

你的問題是因爲Karaf的角色,Pricipal沒有按照預期的CXF實現組。代替它,它實現了Pricipal,因此CXF認爲第一個角色名稱是一個用戶名。這就是爲什麼「SimpleAuthorizingInterceptor.isUserInRole方法返回false」。

解決方案是等待CXF(2.7.11和3.0.0)的固定版本。 如果不能更新到新版本,那麼奇怪的臨時解決方案(簡單的解決方法)是向LDAP中的用戶和方法添加多個角色。

你可以找到更多關於這裏的錯誤:CXF-5603

+0

非常感謝您! –

+0

沒問題。請注意,有一個ServiceMix的商業克隆提供全面支持。現在,JBoss Fuse中也出現了相同的問題,但是JBoss Fuse很快就會解決這個問題。問題鏈接:https://issues.jboss.org/browse/ENTESB-1672 –