コード例 #1
0
        internal static void DeviceInfo(GenericDeviceParms parms)
        {
            if (parms.DeviceId == null)
            {
                throw new InvalidOperationException("Must specify a device");
            }

            foreach (var un in parms.DeviceId)
            {
                var device = m_client.GetDevices(o => o.Name == un).CollectionItem.FirstOrDefault() as SecurityDeviceInfo;
                if (device == null)
                {
                    throw new KeyNotFoundException($"Device {un} not found");
                }

                DisplayUtil.PrintPolicies(device,
                                          new string[] { "Name", "SID", "Invalid Auth", "Lockout", "Last Auth", "Created", "Updated", "De-Activated" },
                                          u => u.Name,
                                          u => u.Key,
                                          u => u.InvalidAuthAttempts,
                                          u => u.LockoutXml,
                                          u => u.LastAuthenticationXml,
                                          u => String.Format("{0} ({1})", u.CreationTimeXml, m_client.GetUser(m_client.GetProvenance(u.CreatedByKey.Value).UserKey.Value).Entity.UserName),
                                          u => String.Format("{0} ({1})", u.UpdatedTimeXml, m_client.GetUser(m_client.GetProvenance(u.UpdatedByKey.Value).UserKey.Value).Entity.UserName),
                                          u => String.Format("{0} ({1})", u.ObsoletionTimeXml, m_client.GetUser(m_client.GetProvenance(u.ObsoletedByKey.Value).UserKey.Value).Entity.UserName)
                                          );
            }
        }
コード例 #2
0
        public ActionResult LeaveRealm(LeaveRealmModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var realm = unitOfWork.RealmRepository.FindById(model.CurrentRealm.Id);

                    if (realm == null)
                    {
                        TempData["error"] = Locale.RealmNotFound;
                        return(RedirectToAction("Index"));
                    }

                    MvcApplication.MemoryCache.Set(RealmConfig.RealmCacheKey, false, ObjectCache.InfiniteAbsoluteExpiration);

                    using (var amiServiceClient = new AmiServiceClient(new RestClientService(Constants.Ami, this.HttpContext)))
                    {
                        var currentDevice = amiServiceClient.GetDevices(d => d.Name == realm.DeviceId).CollectionItem.FirstOrDefault(d => d.Name == realm.DeviceId);

                        if (currentDevice != null)
                        {
                            currentDevice.Device.ObsoletedByKey = Guid.Parse(this.User.Identity.GetUserId());
                            currentDevice.Device.ObsoletionTime = DateTimeOffset.Now;
                            amiServiceClient.UpdateDevice(currentDevice.Id.ToString(), currentDevice);
                        }
                    }

                    realm.ObsoletionTime = DateTime.UtcNow;

                    // delete all the local references to the users when leaving a realm to avoid
                    // conflicts such as multiple accounts named "administrator" etc.
                    unitOfWork.RealmRepository.Delete(realm);
                    unitOfWork.Save();

                    this.Response.Cookies.Remove("access_token");
                    HttpContext.GetOwinContext().Authentication.SignOut(DefaultAuthenticationTypes.ApplicationCookie);

                    TempData["success"] = Locale.RealmLeftSuccessfully;

                    return(RedirectToAction("JoinRealm", "Realm"));
                }
            }
            catch (Exception e)
            {
                Trace.TraceError($"Unable to leave realm: { e }");
            }

            TempData["error"] = Locale.UnableToLeaveRealm;

            return(View(model));
        }