2016-07-06 6 views
0

私は、さまざまな操作を含むSOAP Webサービスを持っています。私はそれらのすべてがすべてのユーザーにアクセスできないようにしようとしています。 web.xmlファイルのセキュリティ制約を編集してこれを達成しようとしました。ユーザーがすべてのwsdl要素にアクセスするのを防ぎます

私のサービスには、操作1,2および3があります。私はuser1とuser2を持っています。私はuser1が1,2,3にアクセスできるようにします。user2は3にしかアクセスできません。別の役割を持つ2つのセキュリティ制約を設定しました。

 <security-constraint> 
     <web-resource-collection> 
     <web-resource-name>SOAP Service</web-resource-name> 
      <url-pattern>/*</url-pattern> 
      <http-method>DELETE</http-method> 
      <http-method>POST</http-method> 
      <http-method>PUT</http-method> 
     </web-resource-collection> 
     <auth-constraint> 
      <role-name>user1</role-name> 
     </auth-constraint> 
    </security-constraint> 

    <security-constraint> 
     <web-resource-collection> 
     <web-resource-name>SOAP Service</web-resource-name> 
      <url-pattern>/*</url-pattern> 
      <http-method>DELETE</http-method> 
      <http-method>POST</http-method> 
      <http-method>PUT</http-method> 
     </web-resource-collection> 
     <auth-constraint> 
      <role-name>user2</role-name> 
     </auth-constraint> 
    </security-constraint> 

これは正常に動作しますので、私はさらにUser2がURLパターンを変更することで何ができるかを制限しようとしたWSDLによって公開されたすべてのものにアクセスするためにuser1とuser2の両方ができます。

<security-constraint> 
    <web-resource-collection> 
     <web-resource-name>SOAP Service</web-resource-name> 
     <url-pattern>/3/*</url-pattern> 
     <http-method>DELETE</http-method> 
     <http-method>POST</http-method> 
     <http-method>PUT</http-method> 
    </web-resource-collection> 
    <auth-constraint> 
     <role-name>user2</role-name> 
    </auth-constraint> 
</security-constraint> 

残念ながら、これは機能しません。私はそれが石鹸の要求であり、すべての要求が同じURLに来るのでこれが言われた???だから私は今こだわっている。特定のユーザーのみがwsdlの一部にアクセスできるようにする最善の方法は何ですか?

答えて

0

ウェブサービスについて十分に理解していなかったので、たくさんの研究をする必要がありました。私が持っているものは、tomcatコンテナに常駐するWebサービスです。tomcat-users.xmlのユーザとweb.xmlで設定された基本認証を使用します。これは、彼らが役割serviceUsersまたはotherUsersを持っていない限り、全体としてサービスにアクセスされることを防ぎ

<security-constraint> 
    <web-resource-collection> 
     <web-resource-name>SOAP Service</web-resource-name> 
     <url-pattern>/*</url-pattern> 
     <http-method>DELETE</http-method> 
     <http-method>POST</http-method> 
     <http-method>PUT</http-method> 
    </web-resource-collection> 
    <auth-constraint> 
     <role-name>serviceUsers</role-name> 
    </auth-constraint> 
</security-constraint> 

<security-constraint> 
    <web-resource-collection> 
     <web-resource-name>SOAP Service</web-resource-name> 
     <url-pattern>/*</url-pattern> 
     <http-method>DELETE</http-method> 
     <http-method>POST</http-method> 
     <http-method>PUT</http-method> 
    </web-resource-collection> 
    <auth-constraint> 
     <role-name>otherUsers</role-name> 
    </auth-constraint> 
</security-constraint> 

<security-role> 
    <role-name>serviceUsers</role-name> 
</security-role> 

<security-role> 
    <role-name>otherUsers</role-name> 
</security-role> 

のようにweb.xmlが見えます。私は何をしたいのか、それぞれの操作をブロックします。これを行うには、serviceEndpointImplを編集する必要がありました。どのような私は、これは何

@Resource 
private WebServiceContext context; 

if (context.isUserInRole("webServiceUsers")) { 
    //do whatever that user should be able to do or block them. 
} 

を追加することは、彼らが使用のtomcat-user.xmlのユーザー名とパスワードに基づいて、あなたのサービスに接続しているユーザーの役割を取得することです。これを使用して、私はコンテナレベルで認証を維持することができましたが、ユーザが使用したくないメソッドへのユーザのアクセスを依然として拒否しました。

関連する問題