|
2 | 2 | from collections import OrderedDict
|
3 | 3 |
|
4 | 4 | from django.conf import settings
|
5 |
| -from django.contrib.auth import get_user_model |
6 | 5 | from django.db.models import Q
|
7 | 6 | from django.http import HttpResponseNotFound
|
8 | 7 | from django.shortcuts import get_object_or_404
|
9 | 8 | from django.urls.exceptions import NoReverseMatch
|
10 | 9 | from rest_framework import permissions
|
11 | 10 | from rest_framework.decorators import action
|
12 | 11 | from rest_framework.pagination import PageNumberPagination
|
13 |
| -from rest_framework.permissions import AllowAny |
14 | 12 | from rest_framework.response import Response
|
15 | 13 | from rest_framework.viewsets import GenericViewSet, mixins
|
16 | 14 |
|
|
19 | 17 | from ansible_base.lib.utils.views.permissions import try_add_oauth2_scope_permission
|
20 | 18 | from ansible_base.resource_registry.models import Resource, ResourceType, service_id
|
21 | 19 | from ansible_base.resource_registry.registry import get_registry
|
22 |
| -from ansible_base.resource_registry.serializers import ResourceListSerializer, ResourceSerializer, ResourceTypeSerializer, UserAuthenticationSerializer |
23 |
| -from ansible_base.resource_registry.utils.auth_code import get_user_auth_code |
| 20 | +from ansible_base.resource_registry.serializers import ResourceListSerializer, ResourceSerializer, ResourceTypeSerializer |
24 | 21 | from ansible_base.rest_filters.rest_framework.field_lookup_backend import FieldLookupBackend
|
25 | 22 | from ansible_base.rest_filters.rest_framework.order_backend import OrderByBackend
|
26 | 23 | from ansible_base.rest_filters.rest_framework.type_filter_backend import TypeFilterBackend
|
@@ -193,43 +190,3 @@ def get(self, request, format=None):
|
193 | 190 | except NoReverseMatch:
|
194 | 191 | logger.info('DAB RBAC service-index views were not included, so not linked')
|
195 | 192 | return Response(data)
|
196 |
| - |
197 |
| - |
198 |
| -class ValidateLocalUserView(AnsibleBaseDjangoAppApiView): |
199 |
| - """ |
200 |
| - Validate a user's username and password. |
201 |
| - """ |
202 |
| - |
203 |
| - custom_action_label = "validate-local-user" |
204 |
| - |
205 |
| - permission_classes = [AllowAny] |
206 |
| - |
207 |
| - def post(self, request, **kwargs): |
208 |
| - serializer = UserAuthenticationSerializer(data=request.data) |
209 |
| - serializer.is_valid(raise_exception=True) |
210 |
| - |
211 |
| - # Ensure the users exists before authenticating |
212 |
| - PREFIX = getattr(settings, "RENAMED_USERNAME_PREFIX", "") |
213 |
| - viable_usernames = [serializer.validated_data["username"], PREFIX + serializer.validated_data["username"]] |
214 |
| - if not get_user_model().objects.filter(username__in=viable_usernames).exists(): |
215 |
| - logger.debug(f"User {serializer.validated_data['username']} does not exist, not validating authentication") |
216 |
| - return Response(status=401) |
217 |
| - |
218 |
| - api_config = get_registry().api_config |
219 |
| - user = api_config.authenticate_local_user(serializer.validated_data["username"], serializer.validated_data["password"]) |
220 |
| - |
221 |
| - if not user: |
222 |
| - return Response(status=401) |
223 |
| - |
224 |
| - try: |
225 |
| - auth_code = get_user_auth_code(user) |
226 |
| - except AttributeError: |
227 |
| - logger.exception(f"Cannot generate auth code for user {user}") |
228 |
| - auth_code = None |
229 |
| - |
230 |
| - response = { |
231 |
| - "ansible_id": Resource.get_resource_for_object(user).ansible_id, |
232 |
| - "auth_code": auth_code, |
233 |
| - } |
234 |
| - |
235 |
| - return Response(data=response) |
0 commit comments