-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
- Loading branch information
1 parent
2880459
commit 2d4057e
Showing
36 changed files
with
2,442 additions
and
696 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* @author Jörn Friedrich Dreyer <[email protected]> | ||
* | ||
* @copyright Copyright (c) 2018, ownCloud GmbH | ||
* @license GPL-2.0 | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
$(document).ready(function() { | ||
var $newPassword = $("#password_policy #new_password"), | ||
$confirmPassword = $("#password_policy #confirm_password"), | ||
$submit = $("#password_policy #submit"), | ||
check = function() { | ||
if ($confirmPassword.val() !== '' && $newPassword.val() !== $confirmPassword.val()) { | ||
$newPassword.addClass('password-mismatch'); | ||
$confirmPassword.addClass('password-mismatch'); | ||
$submit.attr('disabled', 'disabled'); | ||
} else { | ||
$newPassword.removeClass('password-mismatch'); | ||
$confirmPassword.removeClass('password-mismatch'); | ||
$submit.removeAttr('disabled'); | ||
} | ||
}; | ||
$newPassword.keyup(check); | ||
$confirmPassword.keyup(check); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
/** | ||
* @author Jörn Friedrich Dreyer <[email protected]> | ||
* | ||
* @copyright Copyright (c) 2018, ownCloud GmbH | ||
* @license GPL-2.0 | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace OCA\PasswordPolicy\Authentication; | ||
|
||
use OCP\Authentication\Exceptions\AccountCheckException; | ||
use OCP\AppFramework\Http\RedirectResponse; | ||
use OCP\Authentication\IAccountModule; | ||
use OCP\IRequest; | ||
use OCP\ISession; | ||
use OCP\IURLGenerator; | ||
use OCP\IUser; | ||
|
||
class AccountModule implements IAccountModule { | ||
|
||
/** | ||
* @var ISession | ||
*/ | ||
private $session; | ||
/** | ||
* @var IRequest | ||
*/ | ||
private $request; | ||
/** | ||
* @var IURLGenerator | ||
*/ | ||
private $urlGenerator; | ||
|
||
public function __construct(ISession $session, IRequest $request, IURLGenerator $urlGenerator) { | ||
$this->session = $session; | ||
$this->request = $request; | ||
$this->urlGenerator = $urlGenerator; | ||
} | ||
|
||
/** | ||
* Checks a session variable to not interfere with existing sessions | ||
* | ||
* @param IUser $user | ||
* @throws AccountCheckException | ||
*/ | ||
public function check(IUser $user) { | ||
$forcePasswordChange = $this->session->get('password_policy.forcePasswordChange'); | ||
if ($forcePasswordChange) { | ||
$redirectUrl = $this->request->getRequestUri(); | ||
$response = new RedirectResponse( | ||
$this->urlGenerator->linkToRoute( 'password_policy.password.show', [ | ||
'redirect_url' => $redirectUrl | ||
]) | ||
); | ||
// full list of error codes https://msdn.microsoft.com/en-us/library/windows/desktop/ms681386(v=vs.85).aspx | ||
// ldap relevant: https://github.com/rancher/rancher/issues/1941#issue-104315860 | ||
// we use 'user must reset password', not 'password expired' because the letter indicates password cannot be changed | ||
throw new AccountCheckException($response, 'The user must reset their password.', 0x773); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
/** | ||
* @author Jörn Friedrich Dreyer <[email protected]> | ||
* | ||
* @copyright Copyright (c) 2018, ownCloud GmbH | ||
* @license GPL-2.0 | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace OCA\PasswordPolicy\Command; | ||
|
||
use OCP\IConfig; | ||
use OCP\IUserManager; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
|
||
class ExpirePassword extends Command { | ||
/** @var \OCP\IConfig */ | ||
private $config; | ||
|
||
/** @var \OCP\IUserManager */ | ||
protected $userManager; | ||
|
||
/** | ||
* @param IConfig $config | ||
* @param IUserManager $userManager | ||
*/ | ||
public function __construct(IConfig $config, IUserManager $userManager) { | ||
parent::__construct(); | ||
$this->config = $config; | ||
$this->userManager = $userManager; | ||
} | ||
|
||
protected function configure() { | ||
$this | ||
->setName('user:expire-password') | ||
->setDescription('Expire a user\'s password') | ||
->addArgument( | ||
'uid', | ||
InputArgument::REQUIRED, | ||
'The user\'s ownCloud uid (username).' | ||
) | ||
->addArgument( | ||
'expiredate', | ||
InputArgument::OPTIONAL, | ||
'The date and time when a password expires, e.g. "2019-01-01 14:00:00 CET".', | ||
'-1 days' // base.php sets timezone to utc, so | ||
// make sure date is in the past | ||
) | ||
; | ||
} | ||
|
||
/** | ||
* sets a user value as a flag in the user config that will be checked by | ||
* the AccountModule on login. | ||
* | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* @return int | ||
* @throws \OCP\PreConditionNotMetException | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) { | ||
$uid = $input->getArgument('uid'); | ||
|
||
$exists = $this->userManager->userExists($uid); | ||
if($exists === false) { | ||
$output->writeln("<error>Unknown user: $uid</error>"); | ||
/** | ||
* return EX_NOUSER from /usr/include/sysexits.h | ||
* @see http://tldp.org/LDP/abs/html/exitcodes.html#FTN.AEN23647 | ||
*/ | ||
return 67; | ||
} | ||
|
||
$date = new \DateTime($input->getArgument('expiredate')); | ||
$date->setTimezone(new \DateTimeZone('UTC')); | ||
$value = $date->format('Y-m-d\TH:i:s\Z'); // ISO8601 with Zulu = UTC | ||
|
||
$this->config->setUserValue( | ||
$uid, | ||
'password_policy', | ||
'forcePasswordChange', | ||
$value | ||
); | ||
|
||
// show expire date if it was given | ||
if ($input->hasArgument('expiredate')) { | ||
$output->writeln("The password for $uid is set to expire on ". $date->format('Y-m-d H:i:s T').'.'); | ||
} | ||
return 0; | ||
} | ||
} |
Oops, something went wrong.