UserManagement.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
  5. *
  6. * @author Bjoern Schiessle <bjoern@schiessle.org>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Lukas Reschke <lukas@statuscode.ch>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\AdminAudit\Actions;
  27. use OCP\IUser;
  28. /**
  29. * Class UserManagement logs all user management related actions.
  30. *
  31. * @package OCA\AdminAudit\Actions
  32. */
  33. class UserManagement extends Action {
  34. /**
  35. * Log creation of users
  36. *
  37. * @param array $params
  38. */
  39. public function create(array $params) {
  40. $this->log(
  41. 'User created: "%s"',
  42. $params,
  43. [
  44. 'uid',
  45. ]
  46. );
  47. }
  48. /**
  49. * Log assignments of users (typically user backends)
  50. *
  51. * @param string $uid
  52. */
  53. public function assign(string $uid) {
  54. $this->log(
  55. 'UserID assigned: "%s"',
  56. [ 'uid' => $uid ],
  57. [ 'uid' ]
  58. );
  59. }
  60. /**
  61. * Log deletion of users
  62. *
  63. * @param array $params
  64. */
  65. public function delete(array $params) {
  66. $this->log(
  67. 'User deleted: "%s"',
  68. $params,
  69. [
  70. 'uid',
  71. ]
  72. );
  73. }
  74. /**
  75. * Log unassignments of users (typically user backends, no data removed)
  76. *
  77. * @param string $uid
  78. */
  79. public function unassign(string $uid) {
  80. $this->log(
  81. 'UserID unassigned: "%s"',
  82. [ 'uid' => $uid ],
  83. [ 'uid' ]
  84. );
  85. }
  86. /**
  87. * Log enabling of users
  88. *
  89. * @param array $params
  90. */
  91. public function change(array $params) {
  92. switch($params['feature']) {
  93. case 'enabled':
  94. $this->log(
  95. $params['value'] === 'true' ? 'User enabled: "%s"' : 'User disabled: "%s"',
  96. ['user' => $params['user']->getUID()],
  97. [
  98. 'user',
  99. ]
  100. );
  101. break;
  102. case 'eMailAddress':
  103. $this->log(
  104. 'Email address changed for user %s',
  105. ['user' => $params['user']->getUID()],
  106. [
  107. 'user',
  108. ]
  109. );
  110. break;
  111. }
  112. }
  113. /**
  114. * Logs changing of the user scope
  115. *
  116. * @param IUser $user
  117. */
  118. public function setPassword(IUser $user) {
  119. if($user->getBackendClassName() === 'Database') {
  120. $this->log(
  121. 'Password of user "%s" has been changed',
  122. [
  123. 'user' => $user->getUID(),
  124. ],
  125. [
  126. 'user',
  127. ]
  128. );
  129. }
  130. }
  131. }