4

私は Maximo 7.5 REST API を使用しており、Java で REST クライアントを作成して、この RESTful サービスを利用したいと考えています。Maximo ユーザーが独自の REST サービスにアクセスできるように、Maximo 7.5 側で Maximo セキュリティーを有効にしました。以下は、Maximo RESTful サービスの web.xml のようです。

<security-constraint>
        <web-resource-collection>
            <web-resource-name>REST Servlet for Web App</web-resource-name>
            <description>Object Structure Service Servlet (HTTP POST) accessible by authorized users</description>
            <url-pattern>/rest/*</url-pattern>
            <http-method>GET</http-method>
            <http-method>POST</http-method>
        </web-resource-collection>
        <auth-constraint>
            <description>Roles that have access to Object Structure Service Servlet (HTTP POST)</description>
            <role-name>maximouser</role-name>
        </auth-constraint>
        <user-data-constraint>
            <description>data transmission gaurantee</description>
            <transport-guarantee>NONE</transport-guarantee>
        </user-data-constraint>
    </security-constraint>


    <login-config>
        <auth-method>BASIC</auth-method>
        <realm-name>REST Web Application Realm</realm-name>        
    </login-config>

Chrome の Postman プラグインを使用して Maximo REST サービスを正常に照会できます。以下の 2 つは、私の Postman (REST クライアント) のヘッダーです。1. MAXAUTH - bWF4YWRtaW46bWF4YWRtaW4= 2. 承認 - Application/xml

ヘッダーで許可 (MAXAUTH) を指定しましたが、以前は、Maximo REST サービスを照会するためにユーザー名とパスワードを入力するためのポップアップ ウィンドウが表示されていました。資格情報を提供すると、応答が返されます (以下を参照)。 ここに画像の説明を入力

以下は、上記の同じ RESTful サービスを使用するための私の Java コードです。継続的に 401 エラーが発生し、資格情報をプロパティとして提供していますが、認証されていません。

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class RESTConsume {

    // http://localhost:8080/RESTfulExample/json/product/get
    public static void main(String[] args) {

        try {

            URL url = new URL("HOSTNAME/maxrest/rest/os/mxperson?personid=maxadmin");
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET");
            connection.setRequestProperty("Accept", "Application/xml");
            connection.setRequestProperty("MAXAUTH", "bWF4YWRtaW46bWF4YWRtaW4=");
            System.out.println("Output from Server ....1 \n");

            /*
             * if (conn.getResponseCode() != 200) {
             * System.out.println("Output from Server ....2 \n");
             * 
             * throw new RuntimeException("Failed : HTTP error code : "+
             * conn.getResponseCode()); }
             */
            System.out.println("Output from Server ....3 \n");

            BufferedReader br = new BufferedReader(new InputStreamReader(
                    (connection.getInputStream())));
            System.out.println("Output from Server ....4 \n");

            String output;
            System.out.println("Output from Server .... \n");
            while ((output = br.readLine()) != null) {
                System.out.println(output);
            }

        } catch (MalformedURLException e) {

            e.printStackTrace();

        } catch (IOException e) {

            e.printStackTrace();

        }

    }

}

以下は私の出力です:

Output from Server ....1 

Output from Server ....3 

java.io.IOException: Server returned HTTP response code: 401 for URL: http://vhost0043.dc1.co.us.compute.ihost.com/maxrest/rest/os/mxperson?personid=maxadmin
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    at RESTConsume.main(RESTConsume.java:35)

別の RESTful サービス (Maximo RESTful サービスではない) で機能しており、セキュリティが有効になっていない期待どおりの応答を取得しています。Maximo RESTful サービスを利用するために何か特別なことをする必要があるかどうか教えてください。

4

4 に答える 4

1

user:password がユーザー名とパスワードの場合は、encode64 "user:password" (このツールを使用する場合など: https://www.base64encode.org/ )。次に、"imimastrangestring" が encode64 の出力である場合、それを要求プロパティ "MAXAUTH" として設定します。

于 2015-01-22T22:19:10.870 に答える
0

サービスがユーザー名とパスワードを予期しているか、maxauth が無効であるため、ブラウザーの場合は明示的に入力するように求められますが、maximo の場合は 401 が返されます。要求にユーザー名とパスワードのヘッダーも指定してみてください。

于 2014-01-06T08:16:49.700 に答える