Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

auth_configuration.php
Go to the documentation of this file.
1 <?php
19 class ezpRestAuthConfiguration
20 {
21 protected $info = null;
22 protected $req = null;
23
24 protected $filter = null;
25
26 public function __construct( ezcMvcRoutingInformation $info, ezpRestRequest $req )
27 {
28 $this->info = $info;
29 $this->req = $req;
30 }
31
32 public function setFilter( ezpRestAuthenticationStyle $filter )
33 {
34 $this->filter = $filter;
35 }
36
37 public function filter()
38 {
39 if ( eZINI::instance( 'rest.ini' )->variable( 'Authentication', 'RequireHTTPS') === 'enabled' &&
40 $this->req->isEncrypted === false )
41 {
42 // When an unencrypted connection is identified, we have to alter the
43 // flag to avoid infinite loop, when the request is rerouted to the error controller.
44 // This should be improved in the future.
45 $this->req->isEncrypted = true;
46 throw new ezpRestHTTPSRequiredException();
47 }
48
49 // 0. Check if the given route needs authentication.
50 if ( !$this->shallAuthenticate() )
51 {
52 $this->filter = new ezpRestNoAuthStyle();
53 }
54 else if ( $this->filter === null )
55 {
56 $opt = new ezpExtensionOptions();
57 $opt->iniFile = 'rest.ini';
58 $opt->iniSection = 'Authentication';
59 $opt->iniVariable = 'AuthenticationStyle';
60 $authFilter = eZExtension::getHandlerClass( $opt );
61 if ( !$authFilter instanceof ezpRestAuthenticationStyle )
62 {
63 throw new ezpRestAuthStyleNotFoundException();
64 }
65
66 $this->filter = $authFilter;
67 }
68
69 // 1. Initialize the context needed for authenticating the user.
70 $auth = $this->filter->setup( $this->req );
71 if ( $auth instanceof ezcMvcInternalRedirect )
72 return $auth;
73
74 // 2.Perform the authentication
75 // Result of authentication filter can be a valid ezp user (auth succeeded) or an internal redirect (ezcMvcInternalRedirect)
76 $user = $this->filter->authenticate( $auth, $this->req );
77 if ( $user instanceof eZUser )
78 {
79 $userID = $user->id();
80 if ( $userID != eZUser::currentUserID() )
81 {
82 eZUser::setCurrentlyLoggedInUser( $user, $userID );
83 }
84 $this->filter->setUser( $user );
85 }
86 else if ( $user instanceof ezcMvcInternalRedirect )
87 {
88 return $user;
89 }
90 }
91
96 private function shallAuthenticate()
97 {
98 $shallAuthenticate = true;
99 if ( eZINI::instance( 'rest.ini' )->variable( 'Authentication', 'RequireAuthentication' ) !== 'enabled' )
100 {
101 $shallAuthenticate = false;
102 }
103 else
104 {
105 $routeFilter = ezpRestRouteFilterInterface::getRouteFilter();
106 $shallAuthenticate = $routeFilter->shallDoActionWithRoute( $this->info );
107 }
108
109 return $shallAuthenticate;
110 }
111 }
112
113 ?>
$userID
else $userID
Definition: appointmentedit.php:121
eZExtension\getHandlerClass
static getHandlerClass(ezpExtensionOptions $options)
Definition: ezextension.php:480
eZUser
Definition: ezuser.php:76
ezpExtensionOptions
Definition: ezpextensionoptions.php:59
ezpRestAuthConfiguration
Definition: auth_configuration.php:20
ezpRestAuthConfiguration\$req
$req
Definition: auth_configuration.php:22
ezpRestAuthConfiguration\shallAuthenticate
shallAuthenticate()
Definition: auth_configuration.php:96
ezpRestAuthConfiguration\$info
$info
Definition: auth_configuration.php:21
ezpRestAuthConfiguration\__construct
__construct(ezcMvcRoutingInformation $info, ezpRestRequest $req)
Definition: auth_configuration.php:26
ezpRestAuthConfiguration\filter
filter()
Definition: auth_configuration.php:37
ezpRestAuthConfiguration\$filter
$filter
Definition: auth_configuration.php:24
ezpRestAuthConfiguration\setFilter
setFilter(ezpRestAuthenticationStyle $filter)
Definition: auth_configuration.php:32
ezpRestAuthStyleNotFoundException
Definition: auth_style_not_found.php:13
ezpRestAuthenticationStyle
Definition: abstract_auth_style.php:12
ezpRestHTTPSRequiredException
Definition: https_required.php:13
ezpRestNoAuthStyle
Definition: no_auth.php:17
ezpRestRequest
Definition: rest_request.php:21
ezpRestRouteFilterInterface\getRouteFilter
static getRouteFilter()
Definition: route_filter.php:28
$user
$user
Definition: user/adlist.php:39
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.