[AX2012]Claims user

AX2012可以创建一种account type为claims user的账号,这种账号不需要在AD中事先已创建用户,但是claims账号是无法通过rich client登陆到AX,它的主要应用场景是在enterprise protal或者AIF中,这里具体来看看如何在AIF中使用Claims user。首先在AX中创建一个Claims user:

User Id是必须输入的,根据自己的命名规则可以任意编写,network domain也是可以根据自己的用途任意输入,alias可以使用邮件地址。

接下来我们创建一个名为ItemsPort的inbound ports,service operations中只选择InventItemService.find操作。需要注意的是我们要勾选“Allow trusted intermediary to impersonate”,在Trusted intermediary users中我们添加一个用户,比如Administrator账号。这是一个AD域用户的账号,后续我们的程序要用这个账号来执行。

创建一个c#的控制台程序,在service reference中添加从http://AOS_HOST:8101/DynamicsAx/Services/ItemsPort导入的服务,命名空间我们取为ItemReference。完整的程序如下:

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,重新运行就能得到正确的结果。

注意我们运行这个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.”。

回过头来看看AX没有要求CU001用户输入密码,只用它的用户名就可以登陆,这是因为AX信任当前程序的运行账号,相信这个Trusted intermediary users已经代为对CU001进行了认证。这是AIF的例子,EP也是同样如此,我们不需要对vendor和customer在AD中创建账号,而是直接在AX中创建对应的claims用户,而对这些用户的认证交由EP站点,AX信任EP站点连接时所有的BCP 代理账号。

 

posted @ 2015-02-17 09:37  断水流  阅读(1179)  评论(0编辑  收藏  举报