2222use OCA \User_SAML \UserResolver ;
2323use OCP \AppFramework \Controller ;
2424use OCP \AppFramework \Http ;
25+ use OCP \AppFramework \Http \Attribute \NoAdminRequired ;
26+ use OCP \AppFramework \Http \Attribute \NoCSRFRequired ;
27+ use OCP \AppFramework \Http \Attribute \PublicPage ;
28+ use OCP \AppFramework \Http \Attribute \UseSession ;
29+ use OCP \AppFramework \Services \IAppConfig ;
2530use OCP \IConfig ;
2631use OCP \IL10N ;
2732use OCP \IRequest ;
@@ -50,6 +55,7 @@ public function __construct(
5055 private SAMLSettings $ samlSettings ,
5156 private UserBackend $ userBackend ,
5257 private IConfig $ config ,
58+ private IAppConfig $ appConfig ,
5359 private IURLGenerator $ urlGenerator ,
5460 private LoggerInterface $ logger ,
5561 private IL10N $ l ,
@@ -137,20 +143,19 @@ protected function assertGroupMemberships(): void {
137143 }
138144
139145 /**
140- * @PublicPage
141- * @UseSession
142146 * @OnlyUnauthenticatedUsers
143- * @NoCSRFRequired
144- *
145147 * @throws Exception
146148 */
149+ #[PublicPage]
150+ #[UseSession]
151+ #[NoCSRFRequired]
147152 public function login (int $ idp = 1 ): Http \RedirectResponse |Http \TemplateResponse {
148153 $ originalUrl = (string )$ this ->request ->getParam ('originalUrl ' , '' );
149154 if (!$ this ->trustedDomainHelper ->isTrustedUrl ($ originalUrl )) {
150155 $ originalUrl = '' ;
151156 }
152157
153- $ type = $ this ->config -> getAppValue ( $ this -> appName , 'type ' );
158+ $ type = $ this ->appConfig -> getAppValueString ( 'type ' );
154159 switch ($ type ) {
155160 case 'saml ' :
156161 $ settings = $ this ->samlSettings ->getOneLoginSettingsArray ($ idp );
@@ -273,10 +278,10 @@ public function login(int $idp = 1): Http\RedirectResponse|Http\TemplateResponse
273278 }
274279
275280 /**
276- * @PublicPage
277- * @NoCSRFRequired
278281 * @throws Error
279282 */
283+ #[PublicPage]
284+ #[NoCSRFRequired]
280285 public function getMetadata (int $ idp = 1 ): Http \DataDownloadResponse {
281286 $ settings = new Settings ($ this ->samlSettings ->getOneLoginSettingsArray ($ idp ));
282287 $ metadata = $ settings ->getSPMetadata ();
@@ -292,16 +297,16 @@ public function getMetadata(int $idp = 1): Http\DataDownloadResponse {
292297 }
293298
294299 /**
295- * @PublicPage
296- * @NoCSRFRequired
297- * @UseSession
298300 * @OnlyUnauthenticatedUsers
299301 * @NoSameSiteCookieRequired
300302 *
301303 * @return Http\RedirectResponse
302304 * @throws Error
303305 * @throws ValidationError
304306 */
307+ #[PublicPage]
308+ #[NoCSRFRequired]
309+ #[UseSession]
305310 public function assertionConsumerService (): Http \RedirectResponse {
306311 // Fetch and decrypt the cookie
307312 $ cookie = $ this ->request ->getCookie ('saml_data ' );
@@ -423,12 +428,12 @@ public function assertionConsumerService(): Http\RedirectResponse {
423428 }
424429
425430 /**
426- * @PublicPage
427- * @NoAdminRequired
428- * @NoCSRFRequired
429- * @UseSession
430431 * @throws Error
431432 */
433+ #[PublicPage]
434+ #[NoAdminRequired]
435+ #[UseSession]
436+ #[NoCSRFRequired]
432437 public function singleLogoutService (): Http \RedirectResponse {
433438 $ isFromGS = ($ this ->config ->getSystemValueBool ('gs.enabled ' , false )
434439 && $ this ->config ->getSystemValueString ('gss.mode ' , '' ) === 'master ' );
@@ -506,7 +511,7 @@ public function singleLogoutService(): Http\RedirectResponse {
506511 }
507512
508513 /**
509- * @returns [ ?string, ?Auth]
514+ * @return array{0: ?string, 1: ?Auth}
510515 */
511516 private function tryProcessSLOResponse (?int $ idp ): array {
512517 $ idps = ($ idp !== null ) ? [$ idp ] : array_keys ($ this ->samlSettings ->getListOfIdps ());
@@ -532,28 +537,28 @@ private function tryProcessSLOResponse(?int $idp): array {
532537 }
533538
534539 /**
535- * @PublicPage
536- * @NoCSRFRequired
537540 * @OnlyUnauthenticatedUsers
538541 */
542+ #[PublicPage]
543+ #[NoCSRFRequired]
539544 public function notProvisioned (): Http \TemplateResponse {
540545 return new Http \TemplateResponse ($ this ->appName , 'notProvisioned ' , [], 'guest ' );
541546 }
542547
543548 /**
544- * @PublicPage
545- * @NoCSRFRequired
546549 * @OnlyUnauthenticatedUsers
547550 */
551+ #[PublicPage]
552+ #[NoCSRFRequired]
548553 public function notPermitted (): Http \TemplateResponse {
549554 return new Http \TemplateResponse ($ this ->appName , 'notPermitted ' , [], 'guest ' );
550555 }
551556
552557 /**
553- * @PublicPage
554- * @NoCSRFRequired
555558 * @OnlyUnauthenticatedUsers
556559 */
560+ #[PublicPage]
561+ #[NoCSRFRequired]
557562 public function genericError (string $ message ): Http \TemplateResponse {
558563 if (empty ($ message )) {
559564 $ message = $ this ->l ->t ('Unknown error, please check the log file for more details. ' );
@@ -562,17 +567,17 @@ public function genericError(string $message): Http\TemplateResponse {
562567 }
563568
564569 /**
565- * @PublicPage
566- * @NoCSRFRequired
567570 * @OnlyUnauthenticatedUsers
568571 */
572+ #[PublicPage]
573+ #[NoCSRFRequired]
569574 public function selectUserBackEnd (string $ redirectUrl = '' ): Http \TemplateResponse {
570575 $ attributes = ['loginUrls ' => []];
571576
572577 if ($ this ->samlSettings ->allowMultipleUserBackEnds ()) {
573578 $ displayName = $ this ->l ->t ('Direct log in ' );
574579
575- $ customDisplayName = $ this ->config -> getAppValue ( ' user_saml ' , ' directLoginName ' , ' ' );
580+ $ customDisplayName = $ this ->appConfig -> getAppValueString ( ' directLoginName ' );
576581 if ($ customDisplayName !== '' ) {
577582 $ displayName = $ customDisplayName ;
578583 }
@@ -584,10 +589,8 @@ public function selectUserBackEnd(string $redirectUrl = ''): Http\TemplateRespon
584589 }
585590
586591 $ attributes ['loginUrls ' ]['ssoLogin ' ] = $ this ->getIdps ($ redirectUrl );
587-
588592 $ attributes ['useCombobox ' ] = count ($ attributes ['loginUrls ' ]['ssoLogin ' ]) > 4 ;
589593
590-
591594 return new Http \TemplateResponse ($ this ->appName , 'selectUserBackEnd ' , $ attributes , 'guest ' );
592595 }
593596
@@ -651,17 +654,14 @@ protected function getSSODisplayName(?string $displayName): string {
651654 * get Nextcloud login URL
652655 */
653656 private function getDirectLoginUrl (string $ redirectUrl ): string {
654- $ directUrl = $ this ->urlGenerator ->linkToRouteAbsolute ('core.login.tryLogin ' , [
657+ return $ this ->urlGenerator ->linkToRouteAbsolute ('core.login.tryLogin ' , [
655658 'direct ' => '1 ' ,
656659 'redirect_url ' => $ redirectUrl ,
657660 ]);
658- return $ directUrl ;
659661 }
660662
661- /**
662- * @PublicPage
663- * @NoCSRFRequired
664- */
663+ #[PublicPage]
664+ #[NoCSRFRequired]
665665 public function base (): Http \TemplateResponse {
666666 $ message = $ this ->l ->t ('This page should not be visited directly. ' );
667667 return new Http \TemplateResponse ($ this ->appName , 'error ' , ['message ' => $ message ], 'guest ' );
0 commit comments