ヘッダーをスキップ
Oracle Workspaces Web Servicesアプリケーション開発者ガイド
10gリリース1(10.1.2.2)
B31241-01
  目次
目次
索引
索引

戻る
戻る
次へ
次へ
 

4 サービス間認証サービス

サービス間(S2S)認証フレームワークでは、ユーザーにかわって信頼できるパートナ・アプリケーションにより、信頼するプロバイダ・アプリケーションとのユーザー・セッションが確立されます。この結果、パートナ・アプリケーションでは、アプリケーションを使用するエンドユーザーの資格証明が要求されません。かわりに、パートナ・アプリケーション自身が資格証明を提供して、プロバイダ・アプリケーションとのユーザー・セッションが確立されます。

S2S認証サービスでは、Oracle Workspaces Webサービスを使用して開発されたアプリケーション(パートナ・アプリケーション)により、Oracle Workspaces(プロバイダ・アプリケーション)とのユーザー・セッションが確立されます。パートナ・アプリケーションでは、アプリケーションを使用するエンドユーザーの資格証明が要求されません。

S2S認証フレームワークをパートナ・アプリケーションと統合するには、次の手順を実行します。

  1. Oracle Workspacesの環境変数を設定する

  2. Oracle Internet Directoryにパートナ・アプリケーションを登録する

  3. Oracle固有のHTTPヘッダーおよびダイジェスト認証のHTTPヘッダーを設定し、S2S認証サービスを呼び出す

場合によっては、S2S認証Webサービスが使用できないこともあります。詳細は、「S2S認証サービスを使用せずに認証Cookieを取得する」を参照してください。

Oracle Workspacesの環境変数を設定する

環境プロパティoracle.workspaces.ws.s2sEnabledをtrueに設定する必要があります。デフォルトでは、このプロパティはtrueに設定されています。このプロパティは、Oracle Enterprise ManagerのApplication Server Controlで設定できます。アプリケーション層、OC4J_OCSClientシステム・コンポーネント、workspacesアプリケーション、workspaces_ws Webモジュールの順に移動し、「環境」へのリンクから、Oracle Workspacesの環境エントリにアクセスします。

Oracle Internet Directoryにパートナ・アプリケーションを登録する

パートナ・アプリケーションをS2S認証フレームワークに登録するには、次の手順を実行します。

  1. Oracle Internet Directoryに次のエントリを作成します。

    dn: cn=MyApplicationProductName,cn=Products, cn=OracleContext
    objectClass: orclContainer
    objectClass: top
    
    

    MyApplicationProductNameは、アプリケーションの製品名(またはカテゴリ)です。

  2. Oracle Internet Directoryに次のエントリを作成します。

    dn: orclApplicationCommonName=MyAppName,
    cn=MyApplicationProductName,cn=Products,
    cn=OracleContext
    objectClass: orclApplicationEntity
    objectClass: top
    orclApplicationCommonName: MyAppName
    userpassword: ApplicationPassword
    
    

    MyAppNameは、アプリケーション名です。ApplicationPasswordは、アプリケーションにアクセスするためのパスワードです。

  3. 追加したMyAppNameエントリで、プロパティorcltrustedapplicationgroupを検索します。このプロパティの値に信頼できるアプリケーション・グループの名前を設定します。次に例を示します。

    cn=trusted applications,cn=groups,cn=oraclecontext
    
    
  4. Oracle Internet Directoryで次のエントリを検索します。

    dn: cn=Trusted Applications,cn=Groups,cn=OracleContext
    
    

    検出したエントリに対して、次の行をuniquememberに追加します(すべて小文字で入力し、明確にするために改行を入れます)。

    orclapplicationcommonname=myappname,
    cn=myapplicationproductname,cn=products,cn=oraclecontext
    
    

Oracle Directory Manager、またはOracle Internet Directoryで提供されるコマンドライン・ツールを使用して、Oracle Internet Directoryのエントリを追加または変更します。これらのツールの詳細は、『Oracle Internet Directory管理者ガイド』の第4章「ディレクトリ管理ツール」を参照してください。

Oracle固有のHTTPヘッダーおよびダイジェスト認証のHTTPヘッダーを設定し、S2S認証サービスを呼び出す

S2S認証サービスを使用するには、SOAPクライアントでHTTPダイジェスト認証がサポートされている必要があります。Apache Axisなどのダイジェスト認証がサポートされていないクライアントを使用する場合は、「S2S認証サービスを使用せずに認証Cookieを取得する」を参照してください。

SOAPクライアントでダイジェスト認証がサポートされている場合は、次の手順でS2S認証サービスを呼び出します。

  1. S2S認証サービスを取得します。

  2. setMaintainSession(true)メソッドをコールして、クライアントでセッションを管理します。

  3. パートナ・サービスを識別するダイジェスト認証のHTTPヘッダーを設定します。

  4. Oracle固有のヘッダーであるORA_S2S_PROXY_USERにOracle Collaboration Suiteユーザーのニックネームを設定します。S2S認証フレームワークで、このユーザーがパートナ・アプリケーションの認証に使用されます。

  5. login()メソッドを呼び出して、ユーザーを認証します。

S2S認証サービスを使用せずに認証Cookieを取得する

Webサービスのクライアントによっては基礎となるHTTP転送メカニズムへのアクセスがサポートされていないものがあります。この場合、HTTPヘッダーの設定ができません。したがって、これらのクライアントではS2S認証サービスは使用できません。

Oracle Workspaces Webサービスでは、S2SAuthenticationServletが提供されます。アプリケーションは、エンドユーザーの資格証明を使用せずにこのサーブレットから認証Cookieを取得できます。このCookieは、認証サービスから取得されたCookieと同様に、Oracle Workspaces Webサービスから他のサービスを呼び出す際に使用されます。

後述のコードは、S2SAuthenticationServletの使用方法を示すものです。次のパラメータを持つgetSessionCookes()メソッドをコールします。

このコードをそのまま使用する場合は、前述のように変数appNameで指定される文字列がOracle Internet Directoryに登録されていることを確認してください。

このサンプルでは、クラスパスにHTTPClientライブラリおよびJavaMail APIのmail.jarが必要です。


関連資料:

HTTPClientパッケージの詳細は、Oracle Application Serverドキュメント・ライブラリの『Oracle Application Server HTTPClient API Reference』を参照してください。

JavaMailの詳細は、http://java.sun.com/products/javamail/を参照してください。


例4-1 S2SClientSample.java

package oracle.sample.workspaces.ws;

import HTTPClient.Cookie;
import HTTPClient.CookieModule;
import HTTPClient.HTTPConnection;
import HTTPClient.HTTPResponse;
import HTTPClient.ModuleException;
import HTTPClient.NVPair;
import HTTPClient.ProtocolNotSuppException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.mail.internet.MimeUtility;
import oracle.workspaces.ws.exceptions.CwWSException;

public class S2SClientSample
{
  public static String getSessionCookies(
    String szUsername,
    String szApplicationName,
    String szApplicationPassword,
    String szApplicationRealm,
    URL szApplicationURL) throws CwWSException
  {

    // Clear the default CookiePolicyHandler
    // so that it accepts all cookies

    CookieModule.setCookiePolicyHandler(null);

    // The application dn should be in lower case

    szApplicationName = szApplicationName.toLowerCase();

    int status = 0;
    Cookie[] cookies = null;
    String cookieValues = "";
    Object context = new Object();

    try
    {
      try
      {
        // Get a HTTP connection for this context

        System.out.println("Connecting..");
        HTTPConnection connection =
          new HTTPConnection(szApplicationURL);
        connection.setContext(context);
        connection.setAllowUserInteraction(false);

        // Set the digest authorization information

        System.out.println("Adding Digest Auth..");

        connection.addDigestAuthorization(
          szApplicationRealm,
          szApplicationName,
          szApplicationPassword);

        // Mime encode the username

        System.out.println("Encoding username..:" + szUsername);

        String encodedUsername = MimeUtility.encodeWord(szUsername);

        // Set the ORA_S2S_PROXY_USER header

        NVPair[] headers = new NVPair[] {
          new NVPair("ORA_S2S_PROXY_USER", encodedUsername)
        };

        // Send a request to the S2S servlet

        System.out.println("Retrieving response...");

        HTTPResponse s2sResponse =
          connection.Get(
            szApplicationURL.getFile(), (NVPair[])null, headers);

        // Get the request status and cookies

        status = s2sResponse.getStatusCode();

        System.out.println("Status from response: " + status);
        System.out.println("Reason line from response: " +
          s2sResponse.getReasonLine());

        // Close out the sockets
        s2sResponse.getInputStream().close();
        connection.stop();
      }

      catch(UnsupportedEncodingException uee)
      {
        System.out.println("UnsupportedEncodingException caught: " +
          uee.toString());
        CwWSException tdex = new CwWSException();
        tdex.setErrorMessage(uee.getLocalizedMessage());
        throw tdex;
      }

      catch(ProtocolNotSuppException pnse)
      {
        System.out.println("ProtocolNotSuppException caught: " +
          pnse.toString());
        CwWSException tdex = new CwWSException();
        tdex.setErrorMessage(pnse.getLocalizedMessage());
        throw tdex;
      }

      catch(IOException ioe)
      {
        System.out.println("IOException caught: " +
          ioe.toString());
        CwWSException tdex = new CwWSException();
        tdex.setErrorMessage(ioe.getLocalizedMessage());
        throw tdex;
      }

      catch(ModuleException me)
      {
        System.out.println("ModuleException caught: " + me.toString());
        CwWSException tdex = new CwWSException();
        tdex.setErrorMessage(me.getLocalizedMessage());
        throw tdex;
      }

      // If the request succeeded then get the cookie values

      if (status == 200) {

        System.out.println("Cookies from context: " + cookies == null);

        cookies = CookieModule.listAllCookies(context);

        for(int i = 0 ; (cookies!=null) && (i<cookies.length) ; i++)
        {
          String value = cookies[i].getName() + "=" + cookies[i].getValue();
          if (i == 0)
          {
            cookieValues = value;
          }
          else
          {
            cookieValues = cookieValues + "; " + value;
          }
        }
      }
      // else throw an exception
      else
      {
        CwWSException tdex = new CwWSException();
        tdex.setErrorMessage("Response status returned was :" + status);
        throw tdex;
      }
    }
    finally
    {
      CookieModule.discardAllCookies(context) ;
    }
    return cookieValues;
  }
  public static void main(String[] args)
  {
    // Provide the application distinguished name that you
    // have registered in Oracle Internet Directory

    String appName = "orclApplicationCommonName=MyAppName," +
      "cn=MyApplicationProductName," +
      "cn=Products,cn=OracleContext";

    // Provide the application password attribute. This is the value of
    // userpassword of the application in Oracle Internet Directory.

    String appPwd = "welcome1";

    // Supply the URL where the S2SAuthenticationServlet is
    // deployed

    String appURL = "http://www.example.com:7777" +
      "/ocw/s2s/S2SAuthenticationServlet";

    // Provide the user nickname on behalf of whom the caller application
    // is proxying. The user should be a valid Oracle Collaboration
    // Suite user.

    // The user orcladmin is used in this example

    String sessionCookies = "";

    try {

      // Call the getSessionCookies method in this application

      sessionCookies = getSessionCookies("orcladmin", appName, appPwd,
        "", new URL(appURL));
    } catch (MalformedURLException mue)
    {
      System.out.println("MalformedURLException caught: " + mue.toString());
    }
    catch(CwWSException cwwse)
    {
      System.out.println("CwWSException caught: " + cwwse.getMessage());
    }

    // Use the session cookies that you have retrieved for
    // future calls to Oracle Workspaces Web serivces

    System.out.println("Session cookies:");
    System.out.println(sessionCookies);
  }
}