2

ファイルを取得しようとするときに、クライアント側で HTTP 基本認証を使用するように強制する方法を探していWSDLます。JAX-WSI created the following web service を使用して、GlassFish 3 を使用します。

@WebService(serviceName = "Hello")
@Stateless
public class HelloService {
    @WebMethod(operationName = "sayHello")
    @RolesAllowed("myrole")
    public String sayHello(@WebParam(name = "name") @XmlElement(required=true) String name){
        return "Hello "+name;
    }
}

グーグルで調べた後、web.xml記述子にセキュリティ制約を追加することでこれを処理する必要があるようです。

<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>
<security-constraint>
    <display-name>HelloSC</display-name>
    <web-resource-collection>
        <web-resource-name>HelloRC</web-resource-name>
        <url-pattern>/*</url-pattern>
        <http-method>GET</http-method>
        <http-method>POST</http-method>
        <http-method>HEAD</http-method>
    </web-resource-collection>
    <auth-constraint>
        <role-name>myrole</role-name>
    </auth-constraint>
    <user-data-constraint>
        <transport-guarantee>NONE</transport-guarantee>
    </user-data-constraint>
</security-constraint>
<login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>file</realm-name>
</login-config>

ここで、デプロイしてブラウザーを http:// myserver/Hello に向けると、ブラウザーは資格情報を要求します。また、sayHelloメソッドは正しい資格情報でのみ使用できます。

質問: ここまでは順調ですが、ブラウザーで WSDL (http:// myserver/Hello/HelloService?wsdl) を参照すると、資格情報は要求されず、読み込まれるだけで、パスワードで保護する必要があります。

url-pattern が WSDL にも適用されるべきであることは、私の理解です。やっぱりGETリクエストですね…

ポインタはありますか?

編集: .war を JBoss インスタンスにデプロイしたところ、意図したとおりに動作しました。GlassFish の構成が不足しているようです。

4

2 に答える 2