[5257] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 | using System;
|
---|
[4789] | 22 | using System.Collections.Generic;
|
---|
| 23 | using System.ComponentModel;
|
---|
| 24 | using System.Data;
|
---|
| 25 | using System.Drawing;
|
---|
| 26 | using System.Linq;
|
---|
| 27 | using System.Text;
|
---|
| 28 | using System.Windows.Forms;
|
---|
| 29 |
|
---|
[5257] | 30 | namespace HeuristicLab.Services.Authentication {
|
---|
| 31 | public partial class UserManagement : Form {
|
---|
[4789] | 32 |
|
---|
[5257] | 33 | private Application currentApplication;
|
---|
| 34 | private Application selectedApplication;
|
---|
| 35 | private User selectedUser;
|
---|
| 36 | private Role selectedRole;
|
---|
[4789] | 37 |
|
---|
[5257] | 38 | private List<Application> applications;
|
---|
| 39 | private List<User> users;
|
---|
| 40 | private List<Role> roles;
|
---|
[4789] | 41 |
|
---|
| 42 |
|
---|
[5257] | 43 | public UserManagement() {
|
---|
| 44 | InitializeComponent();
|
---|
| 45 | Initialize();
|
---|
| 46 | }
|
---|
[4789] | 47 |
|
---|
| 48 |
|
---|
[5257] | 49 | private void Initialize() {
|
---|
| 50 | AuthenticationClient.Instance.Refreshed += new EventHandler(Instance_Refreshed);
|
---|
| 51 | cbxApplications.DataSource = AuthenticationClient.Instance.GetApplications();
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 |
|
---|
| 55 | void Instance_Refreshed(object sender, EventArgs e) {
|
---|
| 56 |
|
---|
| 57 | if (InvokeRequired) {
|
---|
| 58 | Invoke(new EventHandler(Instance_Refreshed), sender, e);
|
---|
| 59 | } else {
|
---|
| 60 |
|
---|
| 61 | applications = AuthenticationClient.Instance.Applications.ToList();
|
---|
| 62 | dgvApplications.DataSource = applications;
|
---|
| 63 |
|
---|
| 64 | roles = AuthenticationClient.Instance.Roles.ToList();
|
---|
| 65 | dgvRoles.DataSource = roles;
|
---|
| 66 |
|
---|
| 67 | users = AuthenticationClient.Instance.Users.ToList();
|
---|
| 68 | dgvUsers.DataSource = users;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 |
|
---|
| 74 | private void RefreshApplications() {
|
---|
| 75 | if (currentApplication != null) {
|
---|
| 76 | AuthenticationClient.Instance.Refresh(currentApplication.Id);
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 |
|
---|
| 81 |
|
---|
| 82 | private void RefreshUsersAndRoles() {
|
---|
| 83 |
|
---|
| 84 |
|
---|
| 85 | if (currentApplication != null) {
|
---|
| 86 | AuthenticationClient.Instance.Refresh(currentApplication.Id);
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 |
|
---|
| 91 |
|
---|
| 92 | private void cbxApplications_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 93 | this.currentApplication = (HeuristicLab.Services.Authentication.Application)cbxApplications.SelectedItem;
|
---|
| 94 | if (currentApplication != null) {
|
---|
| 95 | AuthenticationClient.Instance.Refresh(currentApplication.Id);
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 |
|
---|
| 100 |
|
---|
| 101 |
|
---|
| 102 | private void dgvApplications_SelectionChanged(object sender, EventArgs e) {
|
---|
| 103 | if (dgvApplications.SelectedRows.Count > 0) {
|
---|
| 104 | selectedApplication = (HeuristicLab.Services.Authentication.Application)dgvApplications.SelectedRows[0].DataBoundItem;
|
---|
| 105 |
|
---|
| 106 | if (selectedApplication != null) {
|
---|
| 107 | tbApplicationName.Text = selectedApplication.Name;
|
---|
| 108 | tbApplicationDescription.Text = selectedApplication.Description;
|
---|
| 109 | selectedApplication.PropertyChanged += new PropertyChangedEventHandler(selectedApplication_PropertyChanged);
|
---|
[4789] | 110 | }
|
---|
[5257] | 111 | }
|
---|
| 112 | }
|
---|
[4789] | 113 |
|
---|
[5257] | 114 |
|
---|
| 115 |
|
---|
| 116 | void selectedApplication_PropertyChanged(object sender, PropertyChangedEventArgs e) {
|
---|
| 117 | if (selectedApplication.Modified) {
|
---|
| 118 | tssApplicationStatus.Text = "modified";
|
---|
| 119 | } else {
|
---|
| 120 | tssApplicationStatus.Text = "";
|
---|
| 121 | }
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 |
|
---|
| 125 |
|
---|
| 126 |
|
---|
| 127 | private void dgvUsers_SelectionChanged(object sender, EventArgs e) {
|
---|
| 128 | if (dgvUsers.SelectedRows.Count > 0) {
|
---|
| 129 | selectedUser = (HeuristicLab.Services.Authentication.User)dgvUsers.SelectedRows[0].DataBoundItem;
|
---|
| 130 |
|
---|
| 131 | if (selectedUser != null) {
|
---|
| 132 | tbUserComment.Text = selectedUser.Description;
|
---|
| 133 | tbUserEmail.Text = selectedUser.Email;
|
---|
| 134 | tbUserName.Text = selectedUser.Name;
|
---|
| 135 | selectedUser.PropertyChanged += new PropertyChangedEventHandler(selectedUser_PropertyChanged);
|
---|
| 136 | RefreshUserRolesList();
|
---|
[4789] | 137 | }
|
---|
[5257] | 138 | RefreshUserRolesList();
|
---|
| 139 | }
|
---|
| 140 | }
|
---|
[4789] | 141 |
|
---|
[5257] | 142 | void selectedUser_PropertyChanged(object sender, PropertyChangedEventArgs e) {
|
---|
| 143 | if (selectedUser.Modified) {
|
---|
| 144 | tssStatusUser.Text = "modified";
|
---|
| 145 | } else {
|
---|
| 146 | tssStatusUser.Text = "";
|
---|
| 147 | }
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 |
|
---|
| 151 |
|
---|
| 152 | private void dgvRoles_SelectionChanged(object sender, EventArgs e) {
|
---|
| 153 | if (dgvRoles.SelectedRows.Count > 0) {
|
---|
| 154 | selectedRole = (HeuristicLab.Services.Authentication.Role)dgvRoles.SelectedRows[0].DataBoundItem;
|
---|
| 155 |
|
---|
| 156 | if (selectedRole != null) {
|
---|
| 157 | tbRoleName.Text = selectedRole.Name;
|
---|
| 158 | tbRoleDescription.Text = selectedRole.Description;
|
---|
| 159 | selectedRole.PropertyChanged += new PropertyChangedEventHandler(selectedRole_PropertyChanged);
|
---|
[4789] | 160 | }
|
---|
| 161 |
|
---|
[5257] | 162 | RefreshRoleUsersList();
|
---|
| 163 | }
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | void selectedRole_PropertyChanged(object sender, PropertyChangedEventArgs e) {
|
---|
| 167 | if (selectedRole.Modified) {
|
---|
| 168 | tssStatusRole.Text = "modified";
|
---|
| 169 | } else {
|
---|
| 170 | tssStatusRole.Text = "";
|
---|
| 171 | }
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 |
|
---|
| 175 |
|
---|
| 176 | private void RefreshUserRolesList() {
|
---|
| 177 | IEnumerable<Guid> guidList = AuthenticationClient.Instance.GetRolesForUser(selectedUser.Id);
|
---|
| 178 | List<Role> rolesForUser = new List<Role>();
|
---|
| 179 | if (guidList != null) {
|
---|
| 180 | foreach (Guid g in guidList) {
|
---|
| 181 | rolesForUser.Add(AuthenticationClient.Instance.GetRole(g));
|
---|
[4789] | 182 | }
|
---|
[5257] | 183 | }
|
---|
| 184 | dgvUserRoles.DataSource = rolesForUser;
|
---|
| 185 | dgvUserRolesAll.DataSource = AuthenticationClient.Instance.Roles;
|
---|
[4789] | 186 |
|
---|
[5257] | 187 | }
|
---|
| 188 |
|
---|
| 189 |
|
---|
| 190 |
|
---|
| 191 | private void RefreshRoleUsersList() {
|
---|
| 192 |
|
---|
| 193 | IEnumerable<Guid> guidList = AuthenticationClient.Instance.GetUsersInRole(selectedRole.Id);
|
---|
| 194 |
|
---|
| 195 | List<User> usersForRole = new List<User>();
|
---|
| 196 |
|
---|
| 197 | if (guidList != null) {
|
---|
| 198 | foreach (Guid g in guidList) {
|
---|
| 199 | usersForRole.Add(AuthenticationClient.Instance.GetUser(g));
|
---|
[4789] | 200 | }
|
---|
[5257] | 201 | }
|
---|
[4789] | 202 |
|
---|
[5257] | 203 | dgvRoleUsers.DataSource = usersForRole;
|
---|
| 204 | dgvRoleUsersAll.DataSource = AuthenticationClient.Instance.Users;
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 |
|
---|
| 208 | private void tbApplicationName_TextChanged(object sender, EventArgs e) {
|
---|
| 209 | if (selectedApplication != null) {
|
---|
| 210 | selectedApplication.Name = tbApplicationName.Text;
|
---|
| 211 | }
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | private void tbApplicationDescription_TextChanged(object sender, EventArgs e) {
|
---|
| 215 | if (selectedApplication != null) {
|
---|
| 216 | selectedApplication.Description = tbApplicationDescription.Text;
|
---|
| 217 | }
|
---|
| 218 | }
|
---|
| 219 |
|
---|
| 220 | private void tbRoleName_TextChanged(object sender, EventArgs e) {
|
---|
| 221 | if (selectedRole != null) {
|
---|
| 222 | selectedRole.Name = tbRoleName.Text;
|
---|
| 223 | }
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 | private void tbRoleDescription_TextChanged(object sender, EventArgs e) {
|
---|
| 227 | if (selectedRole != null) {
|
---|
| 228 | selectedRole.Description = tbRoleDescription.Text;
|
---|
| 229 | }
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 | private void tbUserComment_TextChanged(object sender, EventArgs e) {
|
---|
| 233 | if (selectedUser != null) {
|
---|
| 234 | selectedUser.Description = tbUserComment.Text;
|
---|
| 235 | }
|
---|
| 236 | }
|
---|
| 237 |
|
---|
| 238 | private void tbUserName_TextChanged(object sender, EventArgs e) {
|
---|
| 239 | if (selectedUser != null) {
|
---|
| 240 | selectedUser.Name = tbUserName.Text;
|
---|
| 241 | }
|
---|
| 242 | }
|
---|
| 243 |
|
---|
| 244 | private void tbUserEmail_TextChanged(object sender, EventArgs e) {
|
---|
| 245 | if (selectedUser != null) {
|
---|
| 246 | selectedUser.Email = tbUserEmail.Text;
|
---|
| 247 | }
|
---|
| 248 | }
|
---|
| 249 |
|
---|
| 250 |
|
---|
| 251 | private void tspNewApplication_Click(object sender, EventArgs e) {
|
---|
| 252 | selectedApplication = new Application();
|
---|
| 253 | tbApplicationDescription.Text = "";
|
---|
| 254 | tbApplicationName.Text = "";
|
---|
| 255 | }
|
---|
| 256 |
|
---|
| 257 | private void tspDeleteApplication_Click(object sender, EventArgs e) {
|
---|
| 258 | if (this.dgvApplications.SelectedRows.Count > 0) {
|
---|
| 259 | selectedApplication = (HeuristicLab.Services.Authentication.Application)this.dgvApplications.SelectedRows[0].DataBoundItem;
|
---|
| 260 | if (selectedApplication != null) {
|
---|
| 261 | AuthenticationClient.Instance.Applications.Remove(selectedApplication);
|
---|
| 262 | RefreshApplications();
|
---|
[4789] | 263 | }
|
---|
[5257] | 264 | }
|
---|
| 265 | }
|
---|
[4789] | 266 |
|
---|
[5257] | 267 | private void tspSaveApplication_Click(object sender, EventArgs e) {
|
---|
| 268 | if (selectedApplication != null) {
|
---|
| 269 | selectedApplication.Store();
|
---|
| 270 | if (currentApplication != null) {
|
---|
| 271 | AuthenticationClient.Instance.Refresh(currentApplication.Id);
|
---|
[4789] | 272 | }
|
---|
[5257] | 273 | }
|
---|
[4789] | 274 |
|
---|
[5257] | 275 | }
|
---|
[4789] | 276 |
|
---|
[5257] | 277 | private void tsbNewUser_Click(object sender, EventArgs e) {
|
---|
| 278 | selectedUser = new User();
|
---|
| 279 | selectedUser.ApplicationId = currentApplication.Id;
|
---|
| 280 | selectedUser.CreateDate = DateTime.Now;
|
---|
| 281 | selectedUser.LastActivityDate = DateTime.Now;
|
---|
| 282 | selectedUser.LastLoginDate = DateTime.Now;
|
---|
| 283 | selectedUser.LastLockoutDate = DateTime.Now;
|
---|
| 284 | selectedUser.LastPasswordChangeDate = DateTime.Now;
|
---|
[4789] | 285 |
|
---|
[5257] | 286 | tbUserComment.Text = "";
|
---|
| 287 | tbUserEmail.Text = "";
|
---|
| 288 | tbUserName.Text = "";
|
---|
| 289 | }
|
---|
| 290 |
|
---|
| 291 | private void tsbDeleteUser_Click(object sender, EventArgs e) {
|
---|
| 292 | if (this.dgvUsers.SelectedRows.Count > 0) {
|
---|
| 293 | selectedUser = (HeuristicLab.Services.Authentication.User)this.dgvUsers.SelectedRows[0].DataBoundItem;
|
---|
| 294 | if (selectedUser != null) {
|
---|
| 295 | AuthenticationClient.Instance.Users.Remove(selectedUser);
|
---|
| 296 | RefreshUsersAndRoles();
|
---|
[4789] | 297 | }
|
---|
[5257] | 298 | }
|
---|
| 299 | }
|
---|
[4789] | 300 |
|
---|
[5257] | 301 | private void tsbSaveUser_Click(object sender, EventArgs e) {
|
---|
| 302 | if (selectedUser != null) {
|
---|
| 303 | selectedUser.Store();
|
---|
| 304 | if (currentApplication != null) {
|
---|
| 305 | AuthenticationClient.Instance.Refresh(currentApplication.Id);
|
---|
[4789] | 306 | }
|
---|
[5257] | 307 | }
|
---|
| 308 | }
|
---|
[4789] | 309 |
|
---|
[5257] | 310 | private void tsbRemoveRoleFromUser_Click(object sender, EventArgs e) {
|
---|
| 311 | if (this.dgvUserRoles.SelectedRows.Count > 0) {
|
---|
| 312 |
|
---|
| 313 | HeuristicLab.Services.Authentication.Role role = (HeuristicLab.Services.Authentication.Role)this.dgvUserRoles.SelectedRows[0].DataBoundItem;
|
---|
| 314 | if (role != null) {
|
---|
| 315 | AuthenticationClient.Instance.RemoveUserFromRole(role.Id, selectedUser.Id);
|
---|
| 316 | RefreshUserRolesList();
|
---|
[4789] | 317 | }
|
---|
[5257] | 318 | }
|
---|
| 319 | }
|
---|
[4789] | 320 |
|
---|
[5257] | 321 | private void tsbAddRoleToUser_Click(object sender, EventArgs e) {
|
---|
| 322 | if (this.dgvUserRolesAll.SelectedRows.Count > 0) {
|
---|
| 323 | HeuristicLab.Services.Authentication.Role role = (HeuristicLab.Services.Authentication.Role)this.dgvUserRolesAll.SelectedRows[0].DataBoundItem;
|
---|
| 324 | if (role != null) {
|
---|
| 325 | if (!AuthenticationClient.Instance.IsUserInRole(selectedUser.Id, role.Id)) {
|
---|
| 326 | AuthenticationClient.Instance.AddUserToRole(role.Id, selectedUser.Id);
|
---|
| 327 | RefreshUserRolesList();
|
---|
| 328 | }
|
---|
[4789] | 329 | }
|
---|
[5257] | 330 | }
|
---|
| 331 | }
|
---|
[4789] | 332 |
|
---|
[5257] | 333 | private void tspNewRole_Click(object sender, EventArgs e) {
|
---|
| 334 | selectedRole = new Role();
|
---|
| 335 | selectedRole.ApplicationId = currentApplication.Id;
|
---|
| 336 | tbRoleDescription.Text = "";
|
---|
| 337 | tbRoleName.Text = "";
|
---|
| 338 | }
|
---|
[4789] | 339 |
|
---|
[5257] | 340 |
|
---|
| 341 | private void tsbDeleteRole_Click(object sender, EventArgs e) {
|
---|
| 342 | if (this.dgvRoles.SelectedRows.Count > 0) {
|
---|
| 343 | selectedRole = (HeuristicLab.Services.Authentication.Role)this.dgvRoles.SelectedRows[0].DataBoundItem;
|
---|
| 344 | if (selectedRole != null) {
|
---|
| 345 | AuthenticationClient.Instance.Roles.Remove(selectedRole);
|
---|
| 346 | RefreshUsersAndRoles();
|
---|
[4789] | 347 | }
|
---|
[5257] | 348 | }
|
---|
| 349 | }
|
---|
[4789] | 350 |
|
---|
| 351 |
|
---|
[5257] | 352 | private void tsbSaveRole_Click(object sender, EventArgs e) {
|
---|
| 353 | if (selectedRole != null) {
|
---|
| 354 | selectedRole.Store();
|
---|
| 355 | if (currentApplication != null) {
|
---|
| 356 | AuthenticationClient.Instance.Refresh(currentApplication.Id);
|
---|
[4789] | 357 | }
|
---|
[5257] | 358 | }
|
---|
| 359 | }
|
---|
[4789] | 360 |
|
---|
[5257] | 361 | private void tsbRemoveUserFromRole_Click(object sender, EventArgs e) {
|
---|
| 362 | if (this.dgvRoleUsers.SelectedRows.Count > 0) {
|
---|
[4789] | 363 |
|
---|
[5257] | 364 | HeuristicLab.Services.Authentication.User user = (HeuristicLab.Services.Authentication.User)this.dgvRoleUsers.SelectedRows[0].DataBoundItem;
|
---|
| 365 | if (user != null) {
|
---|
| 366 | AuthenticationClient.Instance.RemoveUserFromRole(selectedRole.Id, user.Id);
|
---|
| 367 | RefreshRoleUsersList();
|
---|
[4789] | 368 | }
|
---|
[5257] | 369 | }
|
---|
| 370 | }
|
---|
[4789] | 371 |
|
---|
[5257] | 372 | private void tsbAddUserToRole_Click(object sender, EventArgs e) {
|
---|
| 373 | if (this.dgvRoleUsersAll.SelectedRows.Count > 0) {
|
---|
| 374 | HeuristicLab.Services.Authentication.User user = (HeuristicLab.Services.Authentication.User)this.dgvRoleUsersAll.SelectedRows[0].DataBoundItem;
|
---|
| 375 | if (user != null) {
|
---|
| 376 | if (!AuthenticationClient.Instance.IsUserInRole(user.Id, selectedRole.Id)) {
|
---|
| 377 | AuthenticationClient.Instance.AddUserToRole(selectedRole.Id, user.Id);
|
---|
| 378 | RefreshRoleUsersList();
|
---|
| 379 | }
|
---|
[4789] | 380 | }
|
---|
[5257] | 381 | }
|
---|
| 382 | }
|
---|
[4789] | 383 |
|
---|
| 384 |
|
---|
[5257] | 385 | private void btnResetPassword_Click(object sender, EventArgs e) {
|
---|
[4789] | 386 |
|
---|
[5257] | 387 | string applicationName = currentApplication.Name;
|
---|
| 388 | string userName = selectedUser.Name;
|
---|
| 389 | string password = tbPassword.Text;
|
---|
[4789] | 390 |
|
---|
[5257] | 391 | AuthenticationClient.Instance.ResetPassword(applicationName, userName, password);
|
---|
[4789] | 392 | }
|
---|
[5257] | 393 | }
|
---|
[4789] | 394 | }
|
---|