第8章

ユーザ属性へのアクセス

この章では、ユーザ属性によるプロファイル作成について説明します。この章は、次の節で構成されています。

For more information    基礎的な情報については、を参照してください。

 
Top of page

属性について

属性」は、ユーザプロファイル内の個々のデータアイテムです。各属性は、(データベース用語では)カラムまたはフィールドに対応します。

属性は、ユーザに関連付ける任意のデータです。Userサブシステムには組み込み属性のセットがあり、ユーザプロファイルに対して独自のユーザ属性を作成および使用できます。

 
Top of section

組み込み属性

次の組み込み文字列属性は、レルム設定に関係なく、各ユーザプロファイルで提供されています。

User IDおよびUserUUID属性の値は、多くのexteNd Director APIパッケージでユーザの識別に使用されます。

新規ユーザポートレット   新規ユーザポートレットは、exteNd DirectorプロジェクトのカスタムWebアプリケーションで使用されるコアポートレットです。このコンポーネントを使用すると、ユーザを書き込み可能レルムに追加して、新しい各ユーザのプロファイルを自動的に作成できます。このプロファイルには、組み込み属性が含まれています。

For more information    詳細については、新規ユーザポートレットについてを参照してください。

 
Top of section

属性および非LDAPレルム

書き込み可能な非LDAPレルムを使用するアプリケーションは、アプリケーションデータベースを使用してプロファイル情報を保存します。デフォルトでは、データベース内のプロファイルには、組み込み属性のみが含まれます。これらのアプリケーションは、必要に応じてカスタム属性を作成できます。

For more information    例については、属性の作成(非LDAP)を参照してください。

 
Top of section

属性およびLDAPレルム

LDAPレルムを使用するアプリケーションは、LDAPディレクトリを使用してプロファイル情報を保存します。LDAPは、ほとんどのWebアプリケーションの要件を満たす豊富な属性セットを提供します。新しい(カスタム)属性をディレクトリに追加するには、LDAP管理コンソールを使用します。

注記:   exteNd DirectorアプリケーションからLDAPディレクトリにカスタム属性を追加することはできません。

User APIは、使用できるすべてのLDAP属性のリストをアプリケーションで取得するための方法を備えています。EARウィザードの[ユーザLDAPオプション]パネルでは、ユーザAPIに対して、特定の属性を有効にし、他の属性を無効にすることができます。また、特定の構文定義を無効にすることもできます。

For more information    詳細については、exteNd Directorアプリケーションの開発のLDAPユーザオプションに関する節を参照してください。

 
Top of page

属性プロパティ

各属性には、名前、説明、表示プロパティ、およびデータタイプがあります。

 
Top of section

表示プロパティ

各属性には、次の2つのうちいずれかの値を指定できる表示プロパティがあります。

属性の使用

説明

表示可能

個人データや環境設定など、ユーザから直接収集する情報。通常、ユーザは、この情報を登録フォームで指定します。

非表示

購入パターンやクリックストリームカウントなど、ユーザにより明示的には提供されていないが、保存されている情報。

 
Top of section

データタイプ

属性データ値には、次の2種類があります。

BLOB属性は、大きなドキュメントやイメージなど、バイト配列形式のバイナリデータの保存に使用されます。BLOB属性を使用するために、独立したAPIメソッドが提供されています。

注記:   User APIは、LDAPレルムを使用するアプリケーションの複数値属性をサポートしています。DAC (Director Administration Console)でも、これらの属性の既存値を表示および変更できます。

 
Top of page

APIを使用した属性へのアクセス

必要な任意の属性を定義し、これらをコードで使用してコンテンツをパーソナライズできます。この節では、コンポーネントから属性にアクセスする方法、およびカスタム属性の作成と設定の方法について説明します。

For more information    User APIの概要については、APIを使用したプロファイルへのアクセスを参照してください。

DACを使用した属性へのアクセス   DAC (Director Administration Console)を使用してユーザ属性にアクセスすることもできます。

For more information    詳細については、を参照してください。

 
Top of section

属性のリストの取得(非LDAP)

次のコードは、ユーザプロファイルを取得して、すべてのカスタム属性を表示する方法を示します。EbiUserInfoオブジェクトに、各組み込み属性用の特定のメソッドがあります。

  import com.sssw.fw.usermgr.api.*;
  import com.sssw.fw.usermgr.client.*;
  
  try {
      //
      // Get the user identifier.
      //
      String userUUID = EboUserHelper.getUserUUID(context);
      //
      // Get a user delegate object from the factory.
      //
      EbiUserDelegate userDelegate = EboFactory.getUserDelegate();
      //
      // Get a user info object.
      //
      EbiUserInfo userInfo =
          (EbiUserInfo)userDelegate.
              getUserInfoByUserUUID(context,userUUID);
      //
      // Get the registration info and add to output buffer.
      //
      sb.append("UserID:" + userInfo.getUserID() + "<br>");
      sb.append("UserUUID:" + userInfo.getUserUUID() + "<br>");
      sb.append("UserFirstName: " + 
          userInfo.getUserFirstName() + "<br>");
      sb.append("UserLastName: " + 
          userInfo.getUserLastName() + "<br>");
      sb.append("UserEmailAddress: " + 
          userInfo.getUserEmailAddress() + "<br>");
      //
      // Get a user metadelegate object from the factory.
      //
      EbiUserMetaDelegate userMetaDelegate =                 EboFactory.getUserMetaDelegate();
      //
      // Get the current user\qs metadata.
      //
      EbiUserMeta userMeta = userMetaDelegate.getUserMeta(context);
      if (userMeta == null) {
          userMeta = userMetaDelegate.createUserMeta();
          userMetaDelegate.addUserMeta(context, userMeta);
      }
      else {
          //
          // Get all custom attribute names and values. 
          // Add to output buffer.
          //
          String[] attributes = userMeta.getUserAttributes();
          if (attributes == null) {
              sb.append("No attributes - string array is null");
          }
          else {
              for (int i=0;i<attributes.length;i++) {
                  String attributeValue =
                   userInfo.getAttributeValue(context,attributes[i]);
                  sb.append(attributes[i] + ": " + 
                      attributeValue + "<br>");
              }
          }
      }
  }
  catch (EboFactoryException e) { sb.append( e.getMessage() ); }
  catch (EboSecurityException e) { sb.append( e.getMessage() ); }

注記:   カスタム属性を持たないプロファイルに対してこのコードを実行した場合、EbiUserMetaオブジェクトはNULLになります。

 
Top of section

属性のリストの取得(LDAP)

特定の属性値をLDAPディレクトリから直接取得するには、次のメソッドを使用します。

  EboUserHelper.getDirectoryUserAttributes(context, userdn, String[] names)

このメソッドは、値が返される属性の名前を指定する文字列のコンテキスト、ユーザDN文字列、および配列を入力します。戻り値は、要求した各ユーザ属性の値が含まれるMap(オブジェクト配列)です。

注記:   このメソッドは、複数値属性の最初の値だけを返します。

複数値属性の識別

LDAPディレクトリを使用する場合、属性には複数の値が含まれる可能性があります。このような属性を確認するには、次のメソッドを使用します。

  EbiUserMeta.isUserAttributeSingleValued(attrname)

このメソッドは、指定した属性が単一値に制限されているかどうかを示すブール値を返します。

 
Top of section

属性の作成(非LDAP)

次のコードは、カスタム属性をユーザプロファイルに追加します。

  import com.sssw.fw.usermgr.api.*;
  
  try {
      //
      // Get a user metadelegate object from the factory.
      //
      EbiUserMetaDelegate userMetaDelegate =         com.sssw.fw.usermgr.client.
              EboFactory.getUserMetaDelegate();
      //
      // Get a writable copy of the user metadata.
      //
      EbiUserMeta userMeta =         userMetaDelegate.getClonedUserMeta(context);
      //
      // Add a custom attribute
      //
      String attrib_name = "Employer";
      userMeta.addUserAttribute(attrib_name,"Name of employer",true);
      //
      // Save the modified metadata including the new attribute.
      //
      userMetaDelegate.modifyUserMeta(context,userMeta);
      //
      // Return the attribute name and value.
      //
      sb.append("Added attribute:" + attrib_name);
  } 
  catch (EboFactoryException e) { sb.append( e.getMessage() ); }
  catch (EboSecurityException e) { sb.append( e.getMessage() ); }

 
Top of section

属性値の設定

次のコードは、カスタム属性の値を設定します。

  import com.sssw.fw.usermgr.api.*;
  
  try {
      //
      // Get a user delegate object from the factory.
      //
      EbiUserDelegate userDelegate =  
          com.sssw.fw.usermgr.client.EboFactory.getUserDelegate();
      //
      // Get a user info object from the factory.
      //
      EbiUserInfo userInfo =         com.sssw.fw.usermgr.client.EboUserHelper.
              getUserInfo(context);
      //
      // Set the value of the attribute to Novell.
      //
      String attrib_name = "Employer";
      userInfo.setAttributeValue(context, attrib_name, "Novell");
      //
      // Write the new value into the user info object.
      //
      userDelegate.modifyUser(context,userInfo);
      //
      // Get the new attribute value and append to output buffer.
      //
      sb.append(attrib_name + ": " + 
          userInfo.getAttributeValue(context, attrib_name));        
  } 
  catch (EboFactoryException e) { sb.append( e.getMessage() ); }
  catch (EboSecurityException e) { sb.append( e.getMessage() ); }


Copyright © 2004 Novell, Inc. All rights reserved. Copyright © 1997, 1998, 1999, 2000, 2001, 2002, 2003 SilverStream Software, LLC. All rights reserved.  more ...