summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2017-08-26 18:50:52 +0200
committerGitHub <noreply@github.com>2017-08-26 18:50:52 +0200
commit0b652648cc698d3b5c2979ccb7f1d1544057294d (patch)
tree43e49602aee82520f57690bb952510b99466782d
parent2966b503ba9eac0ff1becdeb014cf8ecc0b3660a (diff)
parent2e4cd445564ba4882ab239bbfd82b6aa800436e3 (diff)
downloadnextcloud-server-0b652648cc698d3b5c2979ccb7f1d1544057294d.tar.gz
nextcloud-server-0b652648cc698d3b5c2979ccb7f1d1544057294d.zip
Merge pull request #6177 from nextcloud/properly-add-slo-url
Properly allow \OCP\Authentication\IApacheBackend to specify logout URL
-rw-r--r--core/Controller/TwoFactorChallengeController.php8
-rw-r--r--core/templates/twofactorselectchallenge.php2
-rw-r--r--core/templates/twofactorshowchallenge.php2
-rw-r--r--lib/private/NavigationManager.php24
-rw-r--r--lib/private/legacy/user.php15
-rw-r--r--lib/public/Authentication/IApacheBackend.php13
-rw-r--r--tests/Core/Controller/TwoFactorChallengeControllerTest.php8
-rw-r--r--tests/lib/NavigationManagerTest.php12
8 files changed, 46 insertions, 38 deletions
diff --git a/core/Controller/TwoFactorChallengeController.php b/core/Controller/TwoFactorChallengeController.php
index 9c22da8ae09..50d63b07403 100644
--- a/core/Controller/TwoFactorChallengeController.php
+++ b/core/Controller/TwoFactorChallengeController.php
@@ -71,8 +71,8 @@ class TwoFactorChallengeController extends Controller {
/**
* @return string
*/
- protected function getLogoutAttribute() {
- return OC_User::getLogoutAttribute();
+ protected function getLogoutUrl() {
+ return OC_User::getLogoutUrl($this->urlGenerator);
}
/**
@@ -91,7 +91,7 @@ class TwoFactorChallengeController extends Controller {
'providers' => $providers,
'backupProvider' => $backupProvider,
'redirect_url' => $redirect_url,
- 'logout_attribute' => $this->getLogoutAttribute(),
+ 'logout_url' => $this->getLogoutUrl(),
];
return new TemplateResponse($this->appName, 'twofactorselectchallenge', $data, 'guest');
}
@@ -133,7 +133,7 @@ class TwoFactorChallengeController extends Controller {
'error_message' => $errorMessage,
'provider' => $provider,
'backupProvider' => $backupProvider,
- 'logout_attribute' => $this->getLogoutAttribute(),
+ 'logout_url' => $this->getLogoutUrl(),
'redirect_url' => $redirect_url,
'template' => $tmpl->fetchPage(),
];
diff --git a/core/templates/twofactorselectchallenge.php b/core/templates/twofactorselectchallenge.php
index 431f4c78c22..a1e626567e7 100644
--- a/core/templates/twofactorselectchallenge.php
+++ b/core/templates/twofactorselectchallenge.php
@@ -19,7 +19,7 @@
</ul>
</p>
<p class="two-factor-link">
- <a class="button" <?php print_unescaped($_['logout_attribute']); ?>><?php p($l->t('Cancel log in')) ?></a>
+ <a class="button" href="<?php print_unescaped($_['logout_url']); ?>"><?php p($l->t('Cancel log in')) ?></a>
<?php if (!is_null($_['backupProvider'])): ?>
<a class="button" href="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.showChallenge',
[
diff --git a/core/templates/twofactorshowchallenge.php b/core/templates/twofactorshowchallenge.php
index ec760ead7c7..fbfeeb4255a 100644
--- a/core/templates/twofactorshowchallenge.php
+++ b/core/templates/twofactorshowchallenge.php
@@ -22,7 +22,7 @@ $template = $_['template'];
<?php endif; ?>
<?php print_unescaped($template); ?>
<p class="two-factor-link">
- <a class="button" <?php print_unescaped($_['logout_attribute']); ?>><?php p($l->t('Cancel log in')) ?></a>
+ <a class="button" href="<?php print_unescaped($_['logout_url']); ?>"><?php p($l->t('Cancel log in')) ?></a>
<?php if (!is_null($_['backupProvider'])): ?>
<a class="button" href="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.showChallenge',
[
diff --git a/lib/private/NavigationManager.php b/lib/private/NavigationManager.php
index b854b44b340..5e484bea737 100644
--- a/lib/private/NavigationManager.php
+++ b/lib/private/NavigationManager.php
@@ -187,18 +187,18 @@ class NavigationManager implements INavigationManager {
'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'),
]);
- // Logout
- $this->add([
- 'type' => 'settings',
- 'id' => 'logout',
- 'order' => 99999,
- 'href' => $this->urlGenerator->linkToRouteAbsolute(
- 'core.login.logout',
- ['requesttoken' => \OCP\Util::callRegister()]
- ),
- 'name' => $l->t('Log out'),
- 'icon' => $this->urlGenerator->imagePath('core', 'actions/logout.svg'),
- ]);
+ $logoutUrl = \OC_User::getLogoutUrl($this->urlGenerator);
+ if($logoutUrl !== '') {
+ // Logout
+ $this->add([
+ 'type' => 'settings',
+ 'id' => 'logout',
+ 'order' => 99999,
+ 'href' => $logoutUrl,
+ 'name' => $l->t('Log out'),
+ 'icon' => $this->urlGenerator->imagePath('core', 'actions/logout.svg'),
+ ]);
+ }
if ($this->isSubadmin()) {
// User management
diff --git a/lib/private/legacy/user.php b/lib/private/legacy/user.php
index 210e428a2e0..9e0ca4b9fee 100644
--- a/lib/private/legacy/user.php
+++ b/lib/private/legacy/user.php
@@ -281,26 +281,25 @@ class OC_User {
}
/**
- * Supplies an attribute to the logout hyperlink. The default behaviour
- * is to return an href with '?logout=true' appended. However, it can
- * supply any attribute(s) which are valid for <a>.
+ * Returns the current logout URL valid for the currently logged-in user
*
- * @return string with one or more HTML attributes.
+ * @param \OCP\IURLGenerator $urlGenerator
+ * @return string
*/
- public static function getLogoutAttribute() {
+ public static function getLogoutUrl(\OCP\IURLGenerator $urlGenerator) {
$backend = self::findFirstActiveUsedBackend();
if ($backend) {
- return $backend->getLogoutAttribute();
+ return $backend->getLogoutUrl();
}
- $logoutUrl = \OC::$server->getURLGenerator()->linkToRouteAbsolute(
+ $logoutUrl = $urlGenerator->linkToRouteAbsolute(
'core.login.logout',
[
'requesttoken' => \OCP\Util::callRegister(),
]
);
- return 'href="'.$logoutUrl.'"';
+ return $logoutUrl;
}
/**
diff --git a/lib/public/Authentication/IApacheBackend.php b/lib/public/Authentication/IApacheBackend.php
index 908bc5ace3d..7d43d438cbb 100644
--- a/lib/public/Authentication/IApacheBackend.php
+++ b/lib/public/Authentication/IApacheBackend.php
@@ -39,21 +39,20 @@ namespace OCP\Authentication;
interface IApacheBackend {
/**
- * In case the user has been authenticated by Apache true is returned.
+ * In case the user has been authenticated by a module true is returned.
*
- * @return boolean whether Apache reports a user as currently logged in.
+ * @return boolean whether the module reports a user as currently logged in.
* @since 6.0.0
*/
public function isSessionActive();
/**
- * Creates an attribute which is added to the logout hyperlink. It can
- * supply any attribute(s) which are valid for <a>.
+ * Gets the current logout URL
*
- * @return string with one or more HTML attributes.
- * @since 6.0.0
+ * @return string
+ * @since 12.0.3
*/
- public function getLogoutAttribute();
+ public function getLogoutUrl();
/**
* Return the id of the current user
diff --git a/tests/Core/Controller/TwoFactorChallengeControllerTest.php b/tests/Core/Controller/TwoFactorChallengeControllerTest.php
index bef343f9043..ed6452316ff 100644
--- a/tests/Core/Controller/TwoFactorChallengeControllerTest.php
+++ b/tests/Core/Controller/TwoFactorChallengeControllerTest.php
@@ -76,10 +76,10 @@ class TwoFactorChallengeControllerTest extends TestCase {
$this->session,
$this->urlGenerator,
])
- ->setMethods(['getLogoutAttribute'])
+ ->setMethods(['getLogoutUrl'])
->getMock();
$this->controller->expects($this->any())
- ->method('getLogoutAttribute')
+ ->method('getLogoutUrl')
->willReturn('logoutAttribute');
}
@@ -106,7 +106,7 @@ class TwoFactorChallengeControllerTest extends TestCase {
'providers' => $providers,
'backupProvider' => 'backup',
'redirect_url' => '/some/url',
- 'logout_attribute' => 'logoutAttribute',
+ 'logout_url' => 'logoutAttribute',
], 'guest');
$this->assertEquals($expected, $this->controller->selectChallenge('/some/url'));
@@ -155,7 +155,7 @@ class TwoFactorChallengeControllerTest extends TestCase {
'error' => true,
'provider' => $provider,
'backupProvider' => $backupProvider,
- 'logout_attribute' => 'logoutAttribute',
+ 'logout_url' => 'logoutAttribute',
'template' => '<html/>',
'redirect_url' => '/re/dir/ect/url',
'error_message' => null,
diff --git a/tests/lib/NavigationManagerTest.php b/tests/lib/NavigationManagerTest.php
index de432e1eaf2..1d3024f0530 100644
--- a/tests/lib/NavigationManagerTest.php
+++ b/tests/lib/NavigationManagerTest.php
@@ -217,6 +217,16 @@ class NavigationManagerTest extends TestCase {
$this->urlGenerator->expects($this->any())->method('linkToRoute')->willReturnCallback(function() {
return "/apps/test/";
});
+ $this->urlGenerator
+ ->expects($this->once())
+ ->method('linkToRouteAbsolute')
+ ->with(
+ 'core.login.logout',
+ [
+ 'requesttoken' => \OCP\Util::callRegister(),
+ ]
+ )
+ ->willReturn('https://example.com/logout');
$user = $this->createMock(IUser::class);
$user->expects($this->any())->method('getUID')->willReturn('user001');
$this->userSession->expects($this->any())->method('getUser')->willReturn($user);
@@ -260,7 +270,7 @@ class NavigationManagerTest extends TestCase {
[
'id' => 'logout',
'order' => 99999,
- 'href' => null,
+ 'href' => 'https://example.com/logout',
'icon' => '/apps/core/img/actions/logout.svg',
'name' => 'Log out',
'active' => false,