예제 #1
0
        private static bool IsUserInScopeAaa(string userUuid, string searchUuid)
        {
            try
            {
                using (var uisCilent = new UserInfoServiceClient(RouterBindings.Local, RouterAddresses.Local.RequestReply))
                {
                    var response = uisCilent.GetUserScope(new CheckUserScopeRequest
                    {
                        LoginUUID = userUuid,
                        CheckLocationUUID = new List<string> { searchUuid },
                        LocationID = null,
                        AAAServiceCode = "CPAP_SNAPIN_MANAGE_ST_IRS"
                    });

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

                    var isUserInScope = false;
                    foreach (var scope in response.UserScope)
                    {
                        isUserInScope |= scope.isInScopeField;
                    }

                    _Logger.LogDebug("STOpsConsole-IsUserInScopeAaa: {0} - {1}", userUuid, isUserInScope);

                    return isUserInScope;
                }
            }
            catch (Exception ex)
            {
                _Logger.LogError("STOpsConsole-Error get user scope from AAA service: {0}", ex.Message);
                return false;
            }
        }
예제 #2
0
        public static string GetUserInScopeAaaDetails(string userUuid, string searchUuid)
        {
            try
            {
                using (var uisCilent = new UserInfoServiceClient(RouterBindings.Local, RouterAddresses.Local.RequestReply))
                {
                    var response = uisCilent.GetUserScope(new CheckUserScopeRequest
                    {
                        LoginUUID = userUuid,
                        CheckLocationUUID = new List<string> { searchUuid },
                        LocationID = null,
                        AAAServiceCode = "CPAP_SNAPIN_MANAGE_ST_IRS"
                    });

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

                    var isUserInScope = "user:"******" search:"+searchUuid;
                    var scopeList = new List<string>();

                    foreach (var scope in response.UserScope)
                    {
                        isUserInScope += "("+scope.locationAccountIdField+"_"+scope.isInScopeField+")";
                        scopeList.Add(String.Format("{{\"location\":\"{0}\",\"isInScope\":\"{1}\"}}",
                        scope.locationAccountIdField,
                        scope.isInScopeField
                        )); 
                    }
                    _Logger.LogDebug("STOpsConsole-IsUserInScopeAaa: {0} - {1}", userUuid, isUserInScope);

                    var jsonresp = String.Format("{{\"user\":\"{0}\",\"search\":\"{1}\",\"scope\":[{2}]}}",
                                userUuid,
                                searchUuid,
                                string.Join(",", scopeList)
                                );
                    return jsonresp;
                }
            }
            catch (Exception ex)
            {
                _Logger.LogError("STOpsConsole-Error get user scope from AAA service: {0}", ex.Message);
                return "{}";
            }
        }
예제 #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;
            }

        }