예제 #1
0
        public static UserDetails GetUserDetails(string uuid)
        {
            var userDetails = new UserDetails();
            using (var uisCilent = new UserInfoServiceClient(RouterBindings.Local, RouterAddresses.Local.RequestReply))
            {
                var userResp = uisCilent.GetUserInfoReq2(new UserInfoReq
                {
                    uuid = uuid,
                    fields = new[]
                    {
                        "UserId",
                        "EmailAddress",
                        "LocationAccountId"
                    }
                });

                if (!userResp.OperationSuccessful)
                {
                    ALogger.LogWarn("STOpsConsole-GetTopLocationScope - Failed response with {0} - {1}",
                        userResp.ResponseCode,
                        userResp.ResponseMessage);
                    return null;
                }

                var userID = userResp.UserInfo.UserDetails.First(x => x.Key == "UserId").Value;
                var email = userResp.UserInfo.UserDetails.First(x => x.Key == "EmailAddress").Value;
                userDetails.UserID = userID;
                userDetails.Email = email;
                var locAccID = userResp.UserInfo.UserDetails.First(x => x.Key == "LocationAccountId").Value;

                if (string.IsNullOrEmpty(locAccID)) return userDetails;

                var locResp = uisCilent.GetLocation(new LocationInfoRequest
                {
                    LocationAccountId = locAccID
                });
                if (locResp != null)
                {
                    userDetails.Country = locResp.Country;
                }
                return userDetails;
            }
        }
예제 #2
0
        public void SetUser(string uuid)
        {
            using (var uisCilent = new UserInfoServiceClient(RouterBindings.Local,RouterAddresses.Local.RequestReply))
            {
                var locResp = uisCilent.GetUserInfoReq2(new UserInfoReq
                {
                    uuid = uuid,
                    fields = new List<string>
                    {
                        "LocationAccountId",
                        "EmailAddress",
                        "UserId",
                        "FullName",
                        "AccountName",
                        "NearestLegalEntityId",
                        "UltimateParentId"
                    }
                });

                if (!locResp.OperationSuccessful)
                {
                    Logger.LogWarn("STOpsConsole-AaaUser - Failed response with {0} - {1}", locResp.ResponseCode,
                        locResp.ResponseMessage);
                    return;
                }

                UUID = uuid;
                LocationAccountId = locResp.UserInfo.UserDetails.First(x => x.Key == "LocationAccountId").Value;
                EmailAddress = locResp.UserInfo.UserDetails.First(x => x.Key == "EmailAddress").Value;
                UserId = locResp.UserInfo.UserDetails.First(x => x.Key == "UserId").Value;
                FullName = locResp.UserInfo.UserDetails.First(x => x.Key == "FullName").Value;
                CompanyName = locResp.UserInfo.UserDetails.First(x => x.Key == "AccountName").Value;
                NearestLegalEntityId = locResp.UserInfo.UserDetails.First(x => x.Key == "NearestLegalEntityId").Value;
                UltimateParentId = locResp.UserInfo.UserDetails.First(x => x.Key == "UltimateParentId").Value;
            }
        }
예제 #3
0
        internal static KeyValuePair<FindLocationFilter, string> GetTopLocationScope(IAaaUser user)
        {
            var key = default(KeyValuePair<FindLocationFilter, string>);
            
            try
            {
                var locationScope = GetLocationScopeFromCache(user.UUID);

                if (locationScope == null)
                {
                    using (
                        var uisCilent = new UserInfoServiceClient(RouterBindings.Local,
                            RouterAddresses.Local.RequestReply))
                    {
                        var locResp = uisCilent.GetUserInfoReq2(new UserInfoReq
                        {
                            uuid = user.UUID,
                            fields = new List<string>
                            {
                                "LocationAccountId",
                                "NearestLegalEntityId",
                                "UltimateParentId"
                            }
                        });

                        if (!locResp.OperationSuccessful)
                        {
                            _Logger.LogWarn("STOpsConsole-GetTopLocationScope - Failed response with {0} - {1}", locResp.ResponseCode,
                                locResp.ResponseMessage);
                            return key;
                        }

                        var locs = new Dictionary<string, string>();

                        locs.Add("lo",locResp.UserInfo.UserDetails.First(x => x.Key == "LocationAccountId").Value);
                        locs.Add("le",locResp.UserInfo.UserDetails.First(x => x.Key == "NearestLegalEntityId").Value);
                        locs.Add("up",locResp.UserInfo.UserDetails.First(x => x.Key == "UltimateParentId").Value);

                        var response = uisCilent.GetUserScope(new CheckUserScopeRequest
                        {
                            LoginUUID = user.UUID,
                            CheckLocationUUID = null,
                            LocationID = new List<string> { locs["up"], locs["le"], locs["lo"] },
                            AAAServiceCode = "CPAP_SNAPIN_MANAGE_ST_IRS"
                        });

                        if (!response.Success)
                        {
                            _Logger.LogWarn("STOpsConsole-GetTopLocationScope - Failed response with {0}", response.Message);
                            return key;
                        }

                        foreach (var scope in response.UserScope)
                        {
                            if (locs["up"] == scope.locationAccountIdField && scope.isInScopeField)
                            {
                                key = new KeyValuePair<FindLocationFilter, string>(FindLocationFilter.ULT, locs["up"]);
                                break;
                            }
                            if (locs["le"] == scope.locationAccountIdField && scope.isInScopeField)
                            {
                                key = new KeyValuePair<FindLocationFilter, string>(FindLocationFilter.LGL, locs["le"]);
                                break;
                            }
                            if (locs["lo"] == scope.locationAccountIdField && scope.isInScopeField)
                            {
                                key = new KeyValuePair<FindLocationFilter, string>(FindLocationFilter.LOC, locs["lo"]);
                                break;
                            }
                        }

                        AddLocationScopeToCache(user.UUID, new LocationScope
                        {
                            TopLocationScope = key
                        });
                    }
                }
                else
                {
                    key = locationScope.TopLocationScope;
                }

                _Logger.LogInfo("STOpsConsole-GetTopLocationScope - User {0}, Key {1}, Value {2}", user.UUID, key.Key.ToString(), key.Value);
                return key;
            }
            catch (Exception ex)
            {
                _Logger.LogError("STOpsConsole-GetTopLocationScope: Error get user scope from AAA service: {0}", ex.Message);
                return key;
            }

        }