public async Task <LdapAuthenticationMode> UpdateAsync(LdapAuthenticationModeSubmit ldapAuthenticationModeSubmit, Guid updatedById) { LdapAuthenticationModeModel existingAuthenticationMode = await ldapAuthenticationModeRepository.GetByIdAsync(ldapAuthenticationModeSubmit.Uuid); if (existingAuthenticationMode == null) { throw new ItemNotFoundException($"AuthenticationMode with ID '{ldapAuthenticationModeSubmit.Uuid}' not found when attempting to update a authenticationMode using this ID!"); } if (existingAuthenticationMode.Name != ldapAuthenticationModeSubmit.Name) { // Confirm the new name is available LdapAuthenticationModeModel checkExistingNameModel = await ldapAuthenticationModeRepository.GetByNameAsync(ldapAuthenticationModeSubmit.Name, false); if (checkExistingNameModel != null) { throw new ItemNotProcessableException($"AuthenticationMode with name '{ldapAuthenticationModeSubmit.Name}' already exists."); } } existingAuthenticationMode.Name = ldapAuthenticationModeSubmit.Name; existingAuthenticationMode.Account = ldapAuthenticationModeSubmit.Account; existingAuthenticationMode.BaseDn = ldapAuthenticationModeSubmit.BaseDn; existingAuthenticationMode.HostName = ldapAuthenticationModeSubmit.HostName; existingAuthenticationMode.IsLdaps = ldapAuthenticationModeSubmit.IsLdaps; existingAuthenticationMode.Password = ldapAuthenticationModeSubmit.Password; existingAuthenticationMode.Port = ldapAuthenticationModeSubmit.Port; existingAuthenticationMode.ChangedBy = updatedById; existingAuthenticationMode.LdapAttributes = mapper.Map <List <LdapAuthenticationModeLdapAttributeModel> >(ldapAuthenticationModeSubmit.LdapAttributes); return(mapper.Map <LdapAuthenticationMode>(await ldapAuthenticationModeRepository.UpdateAsync(existingAuthenticationMode))); }
public Task <ValidationResultResponse> TestAsync(LdapAuthenticationModeSubmit ldapAuthenticationModeSubmit) { var testResult = new ValidationResultResponse(); var resultMessages = new List <string>(); var ldapModel = mapper.Map <LdapAuthenticationModeModel>(ldapAuthenticationModeSubmit); testResult.Success = ldapConnectionService.TestLdapSettings(ldapModel, ref resultMessages); testResult.Messages = resultMessages; return(Task.FromResult(testResult)); }
public async Task CreateAuthenticationModeAsync_WithTestAuthenticationMode_ReturnsUpdatedAuthenticationMode() { // Arrange var authenticationModeService = Substitute.For <ILdapAuthenticationModeService>(); var inputModel = new LdapAuthenticationModeSubmit() { Uuid = Guid.NewGuid(), Name = "Test AuthenticationMode Name", Account = "TestAccount", BaseDn = "TestBaseDN", HostName = "TestHostName", IsLdaps = true, Password = "******", Port = 389 }; authenticationModeService.CreateAsync(inputModel, Arg.Any <Guid>()) .Returns(new LdapAuthenticationMode() { Uuid = inputModel.Uuid, Name = inputModel.Name, Account = inputModel.Account, BaseDn = inputModel.BaseDn, HostName = inputModel.HostName, IsLdaps = inputModel.IsLdaps, Port = inputModel.Port } ); var controller = new LdapAuthenticationModeController(authenticationModeService); // Act IActionResult actionResult = await controller.CreateLdapAuthenticationModeAsync(inputModel); // Assert var okResult = actionResult as OkObjectResult; Assert.NotNull(okResult); var authenticationMode = okResult.Value as LdapAuthenticationMode; Assert.NotNull(authenticationMode); Assert.True(authenticationMode.Uuid == inputModel.Uuid, $"Retrieved Id {authenticationMode.Uuid} not the same as sample id {inputModel.Uuid}."); Assert.True(authenticationMode.Name == inputModel.Name, $"Retrieved Name {authenticationMode.Name} not the same as sample Name {inputModel.Name}."); Assert.True(authenticationMode.Account == inputModel.Account, $"Retrieved Account {authenticationMode.Account} not the same as sample Account {inputModel.Account}."); Assert.True(authenticationMode.BaseDn == inputModel.BaseDn, $"Retrieved BaseDn {authenticationMode.BaseDn} not the same as sample Name {inputModel.BaseDn}."); Assert.True(authenticationMode.HostName == inputModel.HostName, $"Retrieved HostName {authenticationMode.HostName} not the same as sample HostName {inputModel.HostName}."); Assert.True(authenticationMode.IsLdaps == inputModel.IsLdaps, $"Retrieved Name {authenticationMode.IsLdaps} not the same as sample Ldaps {inputModel.IsLdaps}."); Assert.True(authenticationMode.Port == inputModel.Port, $"Retrieved Port {authenticationMode.Port} not the same as sample Port {inputModel.Port}."); }
public async Task <LdapAuthenticationMode> CreateAsync(LdapAuthenticationModeSubmit ldapAuthenticationModeSubmit, Guid createdById) { LdapAuthenticationModeModel existingAuthenticationMode = await ldapAuthenticationModeRepository.GetByNameAsync(ldapAuthenticationModeSubmit.Name, includePassword : false); if (existingAuthenticationMode != null) { throw new ItemNotProcessableException($"LDAP Authentication Mode with Name '{ldapAuthenticationModeSubmit.Name}' already exist."); } var LdapAuthenticationModeModel = mapper.Map <LdapAuthenticationModeModel>(ldapAuthenticationModeSubmit); LdapAuthenticationModeModel.ChangedBy = createdById; return(mapper.Map <LdapAuthenticationMode>(await ldapAuthenticationModeRepository.CreateAsync(LdapAuthenticationModeModel))); }
public async Task TestAuthenticationModeAsync_WithTestAuthenticationMode_ReturnsUpdatedAuthenticationMode() { // Arrange var inputModel = new LdapAuthenticationModeSubmit() { Uuid = Guid.NewGuid(), Name = "Test AuthenticationMode Name", Account = "TestAccount", BaseDn = "TestBaseDN", HostName = "TestHostName", IsLdaps = true, Password = "******", Port = 389 }; ldapAuthenticationModeService.TestAsync(inputModel) .Returns(new ValidationResultResponse() { Success = false, Messages = new List <string>() { "123", "456" } }); var controller = new LdapAuthenticationModeController(ldapAuthenticationModeService, orderByHelper, paginationHelper, mapper); // Act IActionResult actionResult = await controller.TestLdapAuthenticationModeAsync(inputModel); // Assert var okResult = actionResult as OkObjectResult; Assert.NotNull(okResult); var testResult = okResult.Value as ValidationResultResponse; Assert.NotNull(testResult); Assert.True(testResult.Success == false, $"Retrieved Success {testResult.Success} not the same as sample 'false'."); Assert.True(testResult.Messages[0] == "123", $"Retrieved Message {testResult.Messages[0]} not the same as sample message '123'."); Assert.True(testResult.Messages[1] == "456", $"Retrieved Message {testResult.Messages[1]} not the same as sample message '456'."); }
public LdapAuthenticationModeService_Tests() { var config = new MapperConfiguration(cfg => { cfg.AddProfile(new LdapAuthenticationModeResourceLdapAuthenticationModeModelProfile()); cfg.AddProfile(new LdapAuthenticationModeSubmitResourceLdapAuthenticationModeModelProfile()); }); mapper = config.CreateMapper(); authenticationModeGuid = Guid.NewGuid(); mockedAuthenticationMode = new LdapAuthenticationModeModel { Id = authenticationModeGuid, Name = "Test AuthenticationMode Name", Account = "TestAccount", BaseDn = "TestBaseDN", HostName = "TestHostName", IsLdaps = true, Password = "******", Port = 389, Users = new List <UserModel>() { new UserModel(), new UserModel() } }; mockedAuthenticationModeSubmit = new LdapAuthenticationModeSubmit() { Uuid = mockedAuthenticationMode.Id, Name = mockedAuthenticationMode.Name, Account = mockedAuthenticationMode.Account, BaseDn = mockedAuthenticationMode.BaseDn, HostName = mockedAuthenticationMode.HostName, IsLdaps = mockedAuthenticationMode.IsLdaps, Password = mockedAuthenticationMode.Password, Port = mockedAuthenticationMode.Port }; }
public override async Task <IActionResult> UpdateLdapAuthenticationModeAsync([FromRoute, Required] Guid ldapAuthenticationModeId, [FromBody] LdapAuthenticationModeSubmit ldapAuthenticationModeSubmit) { if (ldapAuthenticationModeId == Guid.Empty || ldapAuthenticationModeSubmit.Uuid == Guid.Empty) { return(BadRequest()); } var loggedOnUser = ClaimsHelper.GetScalarClaimValue <Guid>(User, ClaimTypes.NameIdentifier, Guid.Empty); return(Ok(await authenticationModeService.UpdateAsync(ldapAuthenticationModeSubmit, loggedOnUser))); }
public override async Task <IActionResult> TestLdapAuthenticationModeAsync([FromBody] LdapAuthenticationModeSubmit ldapAuthenticationModeSubmit) { return(Ok(await authenticationModeService.TestAsync(ldapAuthenticationModeSubmit))); }
public override async Task <IActionResult> CreateLdapAuthenticationModeAsync([FromBody] LdapAuthenticationModeSubmit ldapAuthenticationModeSubmit) { var loggedOnUser = ClaimsHelper.GetScalarClaimValue <Guid>(User, ClaimTypes.NameIdentifier, Guid.Empty); return(Ok(await authenticationModeService.CreateAsync(ldapAuthenticationModeSubmit, loggedOnUser))); }
public abstract Task <IActionResult> CreateLdapAuthenticationModeAsync([FromBody] LdapAuthenticationModeSubmit ldapAuthenticationModeSubmit);
public abstract Task <IActionResult> UpdateLdapAuthenticationModeAsync([FromRoute][Required] Guid ldapAuthenticationModeId, [FromBody] LdapAuthenticationModeSubmit ldapAuthenticationModeSubmit);