Core.ServiceResponse ISecurityService.AddProjectUser(SecurityServiceRequest securityServiceRequest) { if (string.IsNullOrEmpty(securityServiceRequest.Id) || string.IsNullOrEmpty(securityServiceRequest.Token) || string.IsNullOrEmpty(securityServiceRequest.Type)) { return new Core.ServiceResponse() { Code = 400, Message = "Id Type and Token should not null" }; } if (!securityServiceRequest.Type.Equals("Administrator") && !securityServiceRequest.Type.Equals("ProjectUser")) { return new Core.ServiceResponse() { Code = 400, Message = "Type should be Administrator or ProjectUser" }; } if (string.IsNullOrEmpty(securityServiceRequest.UserName)) { return new Core.ServiceResponse() { Code = 400, Message = "UserName should not null" }; } string message = string.Empty; if (HP.TS.Devops.Security.SecurityCode.Success != HP.TS.Devops.Security.SecurityAction.CheckAccess(this.ConnectString, securityServiceRequest, out message)) { return new Core.ServiceResponse() { Code = 403, Message = securityServiceRequest.Id + " of type " + securityServiceRequest.Type + " have no access of " + message }; } SecurityAction securityAction = new SecurityAction(this.ConnectString); if (securityAction.AddProjectUser(securityServiceRequest.UserName) <= 0) { return new Core.ServiceResponse() { Code = 500, Message = "Add ProjectUser Fail" }; } return new Core.ServiceResponse() { Code = 0, Message = "Success" }; }
public void TestRetrieveTokenByPassword() { SecurityAction securityAction = new SecurityAction(ConnectString); System.Console.WriteLine(securityAction.RetrieveTokenByPassword("CR59", "Welcome-2014", "ProjectUser")); }
public void TestResetProjectUserPassword() { SecurityAction securityAction = new SecurityAction(ConnectString); System.Console.WriteLine(securityAction.ResetProjectUserPassword("CR59")); }
public void TestRemoveProjectUser() { SecurityAction securityAction = new SecurityAction(ConnectString); System.Console.WriteLine(securityAction.RemoveProjectUser("TEST")); }
public void TestChangeProjectUserPassword() { SecurityAction securityAction = new SecurityAction(ConnectString); System.Console.WriteLine(securityAction.ChangeProjectUserPassword("CR59", "Welcome-2014", "Welcome-2015")); }
public void TestChangeAdministratorPassword() { SecurityAction securityAction = new SecurityAction(ConnectString); System.Console.WriteLine(securityAction.ChangeAdministratorPassword("Administrator", "Welcome-2015", "Welcome-2014")); }
public void TestAddProjectUser() { SecurityAction securityAction = new SecurityAction(ConnectString); System.Console.WriteLine(securityAction.AddProjectUser("CR59")); }
SecurityServiceResponse ISecurityService.RetrieveTokenByPassword(SecurityServiceRequest securityServiceRequest) { if (string.IsNullOrEmpty(securityServiceRequest.UserName) || string.IsNullOrEmpty(securityServiceRequest.CurrentPassword) || string.IsNullOrEmpty(securityServiceRequest.Type)) { return new SecurityServiceResponse() { Code = 400, Message = "Type UserName and CurrentPassword should not null" }; } if(!securityServiceRequest.Type.Equals("Administrator")&&!securityServiceRequest.Type.Equals("ProjectUser")) { return new SecurityServiceResponse() { Code = 400, Message = "Type should be Administrator or ProjectUser" }; } SecurityAction securityAction = new SecurityAction(this.ConnectString); Guid token = securityAction.RetrieveTokenByPassword(securityServiceRequest.UserName,securityServiceRequest.CurrentPassword,securityServiceRequest.Type); if(token == Guid.Empty) { return new SecurityServiceResponse() { Code = 500, Message = "Username or Password not correct" }; } return new SecurityServiceResponse() { Code = 0, Message = "Success", SecurityRequest = new SecurityRequest() { Id = securityServiceRequest.UserName, Type = securityServiceRequest.Type, Token = token.ToString() } }; }