Exemplo n.º 1
0
        public async Task UpdateCurrentStateAsync(string stateName, CancellationToken cancellationToken)
        {
            if (!stateName.StartsWith(StateNode.StateNamePrefix))
            {
                stateName = StateNode.StateNamePrefix + stateName;
            }

            var identityState = await _context.IdentityStates
                                .FindAsync(new object[] { _sessionContext.User.Id }, cancellationToken);

            if (identityState == null)
            {
                identityState = new IdentityState
                {
                    IdentityId = _sessionContext.User.Id,
                    StateName  = stateName
                };

                await _context.IdentityStates.AddAsync(identityState, cancellationToken);
            }
            else
            {
                identityState.StateName = stateName;
            }

            await _context.SaveChangesAsync(cancellationToken);
        }
Exemplo n.º 2
0
        public void CantContinue_WhenIdentityState_IsOtherThanApproved(IdentityState state, bool shouldContinue)
        {
            this.tagProfile.SetupGet(x => x.LegalIdentity).Returns(new LegalIdentity {
                State = state
            });

            Given(AViewModel)
            .And(async vm => await vm.Bind())
            .ThenAssert(vm => shouldContinue ? vm.ContinueCommand.IsEnabled() : vm.ContinueCommand.IsDisabled())
            .Finally(async vm => await vm.Unbind());
        }
    /// <summary>
    /// Placeholder for request handling and passing results to a watch action/event to prompt for pop-up notifications
    /// </summary>
    /// <param name="task"></param>
    /// <param name="identity"></param>
    /// <param name="properties"></param>
    /// <returns></returns>
    internal Identity ProcessRequest(ProcessTasks task, Identity identity, Dictionary <string, object> properties)
    {
        Identity retv = null;

        switch (task)
        {
        case ProcessTasks.VIEW:
            break;

        case ProcessTasks.CREATE:
            retv = Enjin.CreateIdentity(identity);
            if (retv != null)
            {
                EditorUtility.DisplayDialog("SUCCESS", "Identity " + retv.id + " has been created for app id " + retv.app_id + ".", "Ok");
            }
            else
            {
                EditorUtility.DisplayDialog("FAILURE", "Identity " + retv.id + " could not be created. Please see the Unity Console for the error returned.", "Ok");
            }

            RefreshLists();
            State = IdentityState.VIEW;
            break;

        case ProcessTasks.DELETE:
            break;

        case ProcessTasks.EDIT:
            if (CurrentIdentity.linking_code != "")
            {
                retv = Enjin.UpdateIdentity(CurrentIdentity);
            }
            else
            {
                retv = Enjin.UpdateIdentityFields(CurrentIdentity.id, CurrentIdentity.fields);
            }

            if (retv != null)
            {
                EditorUtility.DisplayDialog("SUCCESS", "Identity " + retv.id + " was updated successfully.", "Ok");
            }
            else
            {
                EditorUtility.DisplayDialog("FAILURE", "Identity " + retv.id + " could not be updated. Please see the Unity Console for the error returned.", "Ok");
            }

            RefreshLists();
            State = IdentityState.VIEW;
            break;
        }

        return(retv);
    }
Exemplo n.º 4
0
 private string GetIdentityId(bool forceRefresh)
 {
     if (!IsIdentitySet || forceRefresh)
     {
         _identityState = RefreshIdentity();
         if (!string.IsNullOrEmpty(_identityState.LoginProvider))
         {
             Logins[_identityState.LoginProvider] = _identityState.LoginToken;
         }
         UpdateIdentity(_identityState.IdentityId);
     }
     return(identityId);
 }
Exemplo n.º 5
0
 private string GetIdentityId(RefreshIdentityOptions options)
 {
     if (!IsIdentitySet || options == RefreshIdentityOptions.Refresh)
     {
         _identityState = RefreshIdentity();
         if (!string.IsNullOrEmpty(_identityState.LoginProvider))
         {
             Logins[_identityState.LoginProvider] = _identityState.LoginToken;
         }
         UpdateIdentity(_identityState.IdentityId);
     }
     return(identityId);
 }
Exemplo n.º 6
0
 private static LegalIdentity CreateIdentity(IdentityState state)
 {
     return(new LegalIdentity
     {
         State = state,
         Provider = "provider",
         Id = Guid.NewGuid().ToString(),
         Created = DateTime.UtcNow,
         Updated = DateTime.UtcNow,
         From = DateTime.UtcNow,
         To = DateTime.MaxValue,
         ClientKeyName = "key"
     });
 }
Exemplo n.º 7
0
        public async System.Threading.Tasks.Task <string> GetIdentityIdAsync(bool forceRefresh)
        {
            if (!IsIdentitySet || forceRefresh)
            {
                IdentityState state = await RefreshIdentityAsync().ConfigureAwait(false);

                if (!string.IsNullOrEmpty(_identityState.LoginProvider))
                {
                    Logins[_identityState.LoginProvider] = _identityState.LoginToken;
                }
                UpdateIdentity(_identityState.IdentityId);
            }
            return(identityId);
        }
        private async System.Threading.Tasks.Task <string> GetIdentityIdAsync(RefreshIdentityOptions options)
        {
            if (!IsIdentitySet || options == RefreshIdentityOptions.Refresh)
            {
                _identityState = await RefreshIdentityAsync().ConfigureAwait(false);

                if (!string.IsNullOrEmpty(_identityState.LoginProvider))
                {
                    Logins[_identityState.LoginProvider] = _identityState.LoginToken;
                }
                UpdateIdentity(_identityState.IdentityId);
            }
            return(identityId);
        }
        public override async System.Threading.Tasks.Task<CognitoAWSCredentials.IdentityState> RefreshIdentityAsync()
        {
            var client = new HttpClient();
            var response = await client.GetAsync(string.Format(URL,this.Username));
            var content = await response.Content.ReadAsStringAsync();
            JsonData json = JsonMapper.ToObject(content);

            //The backend has to send us back an Identity and a OpenID token
            string identityId = json["IdentityId"].ToString();
            string token = json["Token"].ToString();

            var idState = new IdentityState(identityId, PROVIDER_NAME, token, false);

            response.Dispose();
            client.Dispose();


            return idState;
        }
        private string GetIdentityId(RefreshIdentityOptions options)
        {
            // Locking so that concurrent calls do not make separate network calls,
            // and instead wait for the first caller to cache the Identity ID.
            lock (refreshIdLock)
            {
                if (!IsIdentitySet || options == RefreshIdentityOptions.Refresh)
                {
                    _identityState = RefreshIdentity();

                    if (!string.IsNullOrEmpty(_identityState.LoginProvider))
                    {
                        Logins[_identityState.LoginProvider] = _identityState.LoginToken;
                    }
                    UpdateIdentity(_identityState.IdentityId);
                }
            }
            return(identityId);
        }
Exemplo n.º 11
0
        public override async System.Threading.Tasks.Task <CognitoAWSCredentials.IdentityState> RefreshIdentityAsync()
        {
            var client   = new HttpClient();
            var response = await client.GetAsync(string.Format(URL, this.Username));

            var content = await response.Content.ReadAsStringAsync();

            JsonData json = JsonMapper.ToObject(content);

            //The backend has to send us back an Identity and a OpenID token
            string identityId = json["IdentityId"].ToString();
            string token      = json["Token"].ToString();

            var idState = new IdentityState(identityId, PROVIDER_NAME, token, false);

            response.Dispose();
            client.Dispose();


            return(idState);
        }
Exemplo n.º 12
0
        public async Task <string> GetOrSetDefaultCurrentStateAsync(string defaultStateName, CancellationToken cancellationToken)
        {
            var identityState = await _context.IdentityStates
                                .FindAsync(new object[] { _sessionContext.User.Id }, cancellationToken);

            if (identityState != null)
            {
                return(identityState.StateName);
            }

            identityState = new IdentityState
            {
                IdentityId = _sessionContext.User.Id,
                StateName  = defaultStateName
            };

            await _context.IdentityStates.AddAsync(identityState, cancellationToken);

            await _context.SaveChangesAsync(cancellationToken);

            return(identityState.StateName);
        }
Exemplo n.º 13
0
 public ApplicationUser(string userId, IdentityState identityData)
 {
     UserId             = userId;
     UserName           = identityData.UserName;
     NormalizedUserName = identityData.NormalizedUserName;
     Email                = identityData.Email;
     NormalizedEmail      = identityData.NormalizedEmail;
     EmailConfirmed       = identityData.EmailConfirmed;
     PhoneNumber          = identityData.PhoneNumber;
     PhoneNumberConfirmed = identityData.PhoneNumberConfirmed;
     PasswordHash         = identityData.PasswordHash;
     SecurityStamp        = identityData.SecurityStamp;
     Registered           = identityData.Registered;
     LockoutEnabled       = identityData.LockoutEnabled;
     LockoutEnd           = identityData.LockoutEnd;
     AccessFailedCount    = identityData.AccessFailedCount;
     TwoFactorEnabled     = identityData.TwoFactorEnabled;
     Roles                = identityData.Roles;
     ExternalLogins       = identityData.ExternalLogins;
     AuthenticationTokens = identityData.AuthenticationTokens;
     ConcurrencyStamp     = identityData.ConcurrencyStamp;
 }
Exemplo n.º 14
0
        internal void SetParamaters(byte currentPowerState, byte lastEvent, byte miscState)
        {
            if (base.CompletionCode == 0)
            {

                #region Power State

                // [0] Power is on, 1 = On, 0 = Off
                byte state = Convert.ToByte((currentPowerState & 0x01));

                // Translate the current power state into an enumeration.
                switch (state)
                {
                    case 0x00:
                        this.powerstate = IpmiPowerState.Off;
                        break;
                    case 0x01:
                        this.powerstate = IpmiPowerState.On;
                        break;
                    default:
                        this.powerstate = IpmiPowerState.Invalid;
                        break;
                }

                #endregion

                #region Power Policy

                state = Convert.ToByte((currentPowerState & 0x60) >> 5);

                // Translate the state into Power on Policy.
                switch (state)
                {
                    case 0x00:
                        this.powerOnPolicy = PowerRestoreOption.StayOff;
                        break;
                    case 0x01:
                        this.powerOnPolicy = PowerRestoreOption.PreviousState;
                        break;
                    case 0x02:
                        this.powerOnPolicy = PowerRestoreOption.AlwaysPowerUp;
                        break;
                    default:
                        this.powerOnPolicy = PowerRestoreOption.Unknown;
                        break;
                }

                #endregion

                #region Power Fault

                // [7:5] -  reserved
                // [4]   -   1b = last ‘Power is on’ state was entered via IPMI command 
                // [3]   -   1b = last power downcaused by power fault
                // [2]   -   1b = last power down caused by a power interlockbeing activated 
                // [1]   -   1b = last power down caused by a Power overload
                // [0]   -   1b = AC failed
                state = Convert.ToByte((lastEvent & 0x1F));

                switch (state)
                {
                    case 0x00:
                        this.lastPowerEvent = PowerEvent.ACfailed;
                        break;
                    case 0x01:
                        this.lastPowerEvent = PowerEvent.PowerOverload;
                        break;
                    case 0x02:
                        this.lastPowerEvent = PowerEvent.PowerInterlockActive;
                        break;
                    case 0x03:
                        this.lastPowerEvent = PowerEvent.PowerFault;
                        break;
                    case 0x04:
                        this.lastPowerEvent = PowerEvent.IpmiSetState;
                        break;
                    default:
                        this.lastPowerEvent = PowerEvent.Unknown;
                        break;
                }

                #endregion

                #region Identity LED

                // [7:4] -  reserved
                // [6] -    1b = Chassis Identify command and state info supported (Optional)
                //          0b = Chassis Identify command support unspecified via this 
                //          command.
                byte identitySupport = Convert.ToByte((miscState & 0x40) >> 6);

                if (identitySupport == 0x01)
                    this.identitySupported = true;

                // [5:4] -  Chassis Identify State.  Mandatory when bit [6] = 1b, reserved (return 
                // as 00b) otherwise.Returns the present chassis identify state. Refer to 
                // the Chassis Identify command for more info.
                // 00b = chassis identify state = Off
                // 01b = chassis identify state = Temporary (timed) On
                // 10b = chassis identify state = Indefinite On
                // 11b = reserved

                byte Identity = Convert.ToByte((miscState & 0x30) >> 4);

                switch (Identity)
                {
                    case 0x00:
                        this.identityState = IdentityState.Off;
                        break;
                    case 0x01:
                        this.identityState = IdentityState.TemporaryOn;
                        break;
                    case 0x02:
                        this.identityState = IdentityState.On;
                        break;
                    default:
                        this.identityState = IdentityState.Unknown;
                        break;
                }

                #endregion

            }
            else
            {
                this.powerstate = IpmiPowerState.Invalid;
            }          
        }
 public void NeedsUpdating(IdentityState state, bool expected)
 {
     Assert.AreEqual(expected, new LegalIdentity {
         State = state
     }.NeedsUpdating());
 }
 public void IsCreatedOrApproved(IdentityState state, bool expected)
 {
     Assert.AreEqual(expected, new LegalIdentity {
         State = state
     }.IsCreatedOrApproved());
 }
Exemplo n.º 17
0
        public void CantInvite_WhenIdentityState_IsOtherThanCreated_Or_NeuronServiceIsOffline(IdentityState state, bool isOnline, bool shouldContinue)
        {
            this.tagProfile.SetupGet(x => x.LegalIdentity).Returns(new LegalIdentity {
                State = state
            });
            this.neuronService.SetupGet(x => x.IsOnline).Returns(isOnline);

            Given(AViewModel)
            .And(async vm => await vm.Bind())
            .ThenAssert(vm => shouldContinue ? vm.InviteReviewerCommand.IsEnabled() : vm.InviteReviewerCommand.IsDisabled())
            .Finally(async vm => await vm.Unbind());
        }
Exemplo n.º 18
0
 private async System.Threading.Tasks.Task<string> GetIdentityIdAsync(RefreshIdentityOptions options)
 {
     if (!IsIdentitySet || options == RefreshIdentityOptions.Refresh)
     {
         _identityState = await RefreshIdentityAsync().ConfigureAwait(false);
         if (!string.IsNullOrEmpty(_identityState.LoginProvider))
         {
             Logins[_identityState.LoginProvider] = _identityState.LoginToken;
         }
         UpdateIdentity(_identityState.IdentityId);
     }
     return identityId;
 }
Exemplo n.º 19
0
 private string GetIdentityId(RefreshIdentityOptions options)
 {
     if (!IsIdentitySet || options == RefreshIdentityOptions.Refresh)
     {
         _identityState = RefreshIdentity();
         if (!string.IsNullOrEmpty(_identityState.LoginProvider))
         {
             Logins[_identityState.LoginProvider] = _identityState.LoginToken;
         }
         UpdateIdentity(_identityState.IdentityId);
     }
     return identityId;
 }