[AX2012]Claims user

AX2012能夠建立一種account type爲claims user的帳號,這種帳號不須要在AD中事先已建立用戶,可是claims帳號是沒法經過rich client登錄到AX,它的主要應用場景是在enterprise protal或者AIF中,這裏具體來看看如何在AIF中使用Claims user。首先在AX中建立一個Claims user:c#

User Id是必須輸入的,根據本身的命名規則能夠任意編寫,network domain也是能夠根據本身的用途任意輸入,alias可使用郵件地址。app

接下來咱們建立一個名爲ItemsPort的inbound ports,service operations中只選擇InventItemService.find操做。須要注意的是咱們要勾選「Allow trusted intermediary to impersonate」,在Trusted intermediary users中咱們添加一個用戶,好比Administrator帳號。這是一個AD域用戶的帳號,後續咱們的程序要用這個帳號來執行。dom

建立一個c#的控制檯程序,在service reference中添加從http://AOS_HOST:8101/DynamicsAx/Services/ItemsPort導入的服務,命名空間咱們取爲ItemReference。完整的程序以下:this

using ConsoleApplication1.ItemReference;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var context = new CallContext
                              {
                                  Company = "USMF",
                                  LogonAsUser = "TestApp\\cu001@testapp.local",
                                  Language = "en-gb"
                              };
            var client = new ItemServiceClient();
            var criteria = new QueryCriteria();
            var itemIdCriteria = new CriteriaElement
                                     {
                                         DataSourceName = "InventTable",
                                         FieldName = "ItemId",
                                         Operator = Operator.Range,
                                         Value1 = "A",
                                         Value2 = "B"
                                     };
            criteria.CriteriaElement = new CriteriaElement[1];
            criteria.CriteriaElement[0] = itemIdCriteria;

            try
            {
                var myItem = client.find(context, criteria);
                if (myItem != null &&
                    myItem.InventTable != null &&
                    myItem.InventTable.Length > 0)
                {
                    foreach (var item in myItem.InventTable)
                    {
                        Console.WriteLine("Item Id {0} - {1}", item.ItemId,item.NameAlias);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error {0}", e.Message);
            }

            Console.ReadKey();
        }
    }
}

程序是在inventtable查找首字母介於A和B直接的料號,運行後獲得的結果是:「Error Access denied to method find in class InventItemService.」,這是由於咱們沒有對CU001用戶授予權限,能夠添加system administrator角色到CU001,從新運行就能獲得正確的結果。spa

注意咱們運行這個C#程序時用的域管理員帳號,這個帳號也是被添加到ItemPorts的Trusted intermediary users列表,若是咱們把這個帳號從Trusted intermediary users刪除會是什麼結果?咱們會獲得異常「Error An error occurred.」,具體的信息能夠在system administration->periodic->services and application framework->exceptions查看,看到的是「The submitting user 'admin' has not been configured as a trusted intermediary for the port.」,「User is not authorised for this port.」。代理

若是不勾選「Allow trusted intermediary to impersonate」,又會是什麼結果呢?獲得的錯誤是「The submitting user 'Admin' is different from the logon user 'CU001', but a trusted intermediary has not been enabled on the port.」,一樣最後結果也是「User is not authorised for this port.」。code

回過頭來看看AX沒有要求CU001用戶輸入密碼,只用它的用戶名就能夠登錄,這是由於AX信任當前程序的運行帳號,相信這個Trusted intermediary users已經代爲對CU001進行了認證。這是AIF的例子,EP也是一樣如此,咱們不須要對vendor和customer在AD中建立帳號,而是直接在AX中建立對應的claims用戶,而對這些用戶的認證交由EP站點,AX信任EP站點鏈接時全部的BCP 代理帳號。blog

相關文章
相關標籤/搜索