(self, request)
| 132 | return self.get_response(request) |
| 133 | |
| 134 | def process_request(self, request): |
| 135 | # AuthenticationMiddleware is required so that request.user exists. |
| 136 | if not hasattr(request, "user"): |
| 137 | raise ImproperlyConfigured( |
| 138 | "The Django remote user auth middleware requires the" |
| 139 | " authentication middleware to be installed. Edit your" |
| 140 | " MIDDLEWARE setting to insert" |
| 141 | " 'django.contrib.auth.middleware.AuthenticationMiddleware'" |
| 142 | f" before the {self.__class__.__name__} class." |
| 143 | ) |
| 144 | try: |
| 145 | username = self.get_username(request) |
| 146 | except KeyError: |
| 147 | # If specified header doesn't exist then remove any existing |
| 148 | # authenticated remote-user, or return (leaving request.user set to |
| 149 | # AnonymousUser by the AuthenticationMiddleware). |
| 150 | if self.force_logout_if_no_header and request.user.is_authenticated: |
| 151 | self._remove_invalid_user(request) |
| 152 | return |
| 153 | # If the user is already authenticated and that user is the user we are |
| 154 | # getting passed in the headers, then the correct user is already |
| 155 | # persisted in the session and we don't need to continue. |
| 156 | if request.user.is_authenticated: |
| 157 | if request.user.get_username() == self.clean_username(username, request): |
| 158 | return |
| 159 | else: |
| 160 | # An authenticated user is associated with the request, but |
| 161 | # it does not match the authorized user in the header. |
| 162 | self._remove_invalid_user(request) |
| 163 | |
| 164 | # We are seeing this user for the first time in this session, attempt |
| 165 | # to authenticate the user. |
| 166 | user = auth.authenticate(request, remote_user=username) |
| 167 | if user: |
| 168 | # User is valid. Persist the user in the session by logging the |
| 169 | # user in. |
| 170 | auth.login(request, user) |
| 171 | |
| 172 | async def __acall__(self, request): |
| 173 | await self.aprocess_request(request) |
no test coverage detected