public static bool AuthUser(UserDescriptor user) { lock (m_asyncAccessContolToUsers) { return(m_db.AuthValidation(user)); } }
public static void AddClientToChannel(Int32 channelId, UserDescriptor user, Socket socket) { lock (m_asyncAccessContolToChannels) { m_db.AddClientToChannel(channelId, user, socket); } }
public static bool RegisterNewUser(UserDescriptor newUser) { lock (m_asyncAccessContolToUsers) { return(m_db.RegisterUser(newUser)); } }
public static void RemoveClientFromChannel(Int32 channelId, UserDescriptor user) { lock (m_asyncAccessContolToChannels) { m_db.RemoveClientFromChannel(channelId, user); } }
public override void Deserialize(ZclFieldDeserializer deserializer) { base.Deserialize(deserializer); Status = (ZdoStatus)deserializer.Deserialize(ZclDataType.Get(DataType.ZDO_STATUS)); if (Status != ZdoStatus.SUCCESS) { // Don't read the full response if we have an error return; } NwkAddrOfInterest = (ushort)deserializer.Deserialize(ZclDataType.Get(DataType.NWK_ADDRESS)); Length = (byte)deserializer.Deserialize(ZclDataType.Get(DataType.UNSIGNED_8_BIT_INTEGER)); UserDescriptor = (UserDescriptor)deserializer.Deserialize(ZclDataType.Get(DataType.USER_DESCRIPTOR)); }
public override bool Equals(object anotherObject) { bool equalObjects = false; if (anotherObject != null && this.GetType() == anotherObject.GetType()) { UserDescriptor typedObject = (UserDescriptor)anotherObject; equalObjects = this.EmailAddress.Equals(typedObject.EmailAddress) && this.TenantId.Equals(typedObject.TenantId) && this.Username.Equals(typedObject.Username); } return(equalObjects); }
/// <summary> /// Authenticates a <see cref="User"/> given the /// <paramref name="tenantId"/>, <paramref name="username"/>, /// and <paramref name="password"/>. /// </summary> /// <param name="tenantId"> /// A <see cref="TenantId"/> identifying a <see cref="Tenant"/> /// with which a <see cref="User"/> is associated. /// </param> /// <param name="username"> /// The username to authenticate. /// </param> /// <param name="password"> /// The password to authenticate. /// </param> /// <returns> /// A <see cref="UserDescriptor"/> of the authenticated user /// if the user can be authenticated; otherwise, null reference /// in the username and password do not match an enabled /// <see cref="User"/> for an active <see cref="Tenant"/>. /// </returns> public UserDescriptor Authenticate(TenantId tenantId, string username, string password) { AssertionConcern.AssertArgumentNotNull(tenantId, "TenantId must not be null."); AssertionConcern.AssertArgumentNotEmpty(username, "Username must be provided."); AssertionConcern.AssertArgumentNotEmpty(password, "Password must be provided."); UserDescriptor userDescriptor = UserDescriptor.NullDescriptorInstance(); Tenant tenant = this.tenantRepository.Get(tenantId); if ((tenant != null) && tenant.Active) { string encryptedPassword = this.encryptionService.EncryptedValue(password); User user = this.userRepository.UserFromAuthenticCredentials(tenantId, username, encryptedPassword); if ((user != null) && user.IsEnabled) { userDescriptor = user.UserDescriptor; } } return(userDescriptor); }
protected override UserTreeItemBase CreateInstance(Authentication authentication, UserDescriptor descriptor, object owner) { return(new UserTreeViewItemViewModel(authentication, descriptor, owner)); }
internal UserTreeViewItemViewModel(Authentication authentication, UserDescriptor descriptor, object owner) : base(authentication, descriptor, owner) { }
public static void ReplaceClientToAnotherChannel(Int32 oldChannelId, Int32 newChannelId, UserDescriptor user, Socket userSocket) { lock (m_asyncAccessContolToChannels) { m_db.ReplaceClientToAnotherChannel(oldChannelId, newChannelId, user, userSocket); } }
public static void Run() { Thread cmdListener = new Thread(ServerMainThread.CmdListener); cmdListener.Start(); Socket newClient = null; string msgAll = String.Empty; string msg = String.Empty; string cmd = String.Empty; while (!closed) { try { newClient = m_Socket.Accept(); } catch (Exception e) { Console.WriteLine(e.StackTrace); } try { msgAll = SocketIO.ReceiveAll(newClient); msg = msgAll.Substring(CmdPrefix.commandPrefixSize); cmd = msgAll.Substring(0, CmdPrefix.commandPrefixSize); } catch (Exception e) { Console.WriteLine(e.StackTrace); } if (cmd == CmdPrefix.authCommandPrefix) { UserDescriptor tmpUser = SocketIO.Diserialize <UserDescriptor>(msg); Console.WriteLine("[INFO/AUTH] Accepting connection with " + tmpUser.Name); if (DataBaseControl.AuthUser(tmpUser)) { Console.WriteLine("[INFO/AUTH] Success!"); SocketIO.SendAll(newClient, CmdPrefix.authSuccessCommandPrefix + "Access allowed!"); ClientThread client = new ClientThread(newClient, tmpUser, HostSettings.defaultChannelId); DataBaseControl.AddClientToChannel(HostSettings.defaultChannelId, tmpUser, newClient); DataBaseControl.SendLast_N_MessagesToThisUser(HostSettings.defaultChannelId, newClient, 10); Thread thr = new Thread(client.Run); thr.Start(); } else { Console.WriteLine("[INFO/AUTH] Fail!"); SocketIO.SendAll(newClient, CmdPrefix.authErrorCommandPrefix + "Access denied!"); } } if (cmd == CmdPrefix.registerCommandPrefix) { UserDescriptor tmpUser = SocketIO.Diserialize <UserDescriptor>(msg); Console.WriteLine("[INFO/REG] Accepting connection with " + tmpUser.Name); if (DataBaseControl.RegisterNewUser(tmpUser)) { Console.WriteLine("[INFO/REG] Success!"); SocketIO.SendAll(newClient, CmdPrefix.registerSuccessCommandPrefix + "Register success!"); ClientThread client = new ClientThread(newClient, tmpUser, HostSettings.defaultChannelId); DataBaseControl.AddClientToChannel(HostSettings.defaultChannelId, tmpUser, newClient); DataBaseControl.SendLast_N_MessagesToThisUser(HostSettings.defaultChannelId, newClient, 10); Thread thr = new Thread(client.Run); thr.Start(); } else { Console.WriteLine("[INFO/REG] Fail!"); SocketIO.SendAll(newClient, CmdPrefix.registerErrorCommandPrefix + "This user already exists! Change name!"); } } } }
public ClientThread(Socket clientSocket, UserDescriptor user, Int32 channelId) { m_Socket = clientSocket; m_User = user; m_channelId = channelId; }
public UserDescriptorHolder(UserDescriptor descriptor) { Descriptor = descriptor; LastAccessTime = DateTime.Now; }
internal protected UserTreeViewItemViewModel(Authentication authentication, UserDescriptor descriptor, object owner) : base(authentication, descriptor, owner) { this.ModifyCommand = new DelegateCommand(async item => await this.ChangeAsync(), item => this.CanChange); this.DeleteCommand = new DelegateCommand(async item => await this.DeleteAsync(), item => this.CanDelete); }