From d4cb2b9c16d28f3d6d18c208723eb29299ac81f5 Mon Sep 17 00:00:00 2001 From: Steve Ellis Date: Fri, 21 Feb 2025 14:00:36 -0500 Subject: [PATCH 1/2] Removed legacy endpoint - RAML - Remove usage of PostBlUsersLoginResponse - Revise all tests to use expiry endpoin TODO Module desc --- ramls/mod-users-bl.raml | 32 ---- .../java/org/folio/rest/impl/BLUsersAPI.java | 28 +--- .../org/folio/rest/HeadersForwardingTest.java | 149 +++++++----------- 3 files changed, 63 insertions(+), 146 deletions(-) diff --git a/ramls/mod-users-bl.raml b/ramls/mod-users-bl.raml index c0b8c05..8911678 100644 --- a/ramls/mod-users-bl.raml +++ b/ramls/mod-users-bl.raml @@ -186,38 +186,6 @@ resourceTypes: type: { compositeOpenTransactionsResource: { "typeName" : "username" } } /_self: type: { compositeUserResource: { "typeName" : "self reference" } } - /login: - post: - description: Allow a new user to login and return an authtoken, along with a composite user record. Deprecated and will be removed in a future release. Please use /login-with-expiry. - is: [permissionsExpandable, includeable] - headers: - User-Agent: - X-Forwarded-For: - body: - application/json: - type: loginCredentials - responses: - 201: - body: - application/json: - type: compositeUser - headers: - x-okapi-token: - 400: - description: "Bad request" - body: - text/plain: - example: "Bad request" - 422: - description: "Unprocessable Entity" - body: - application/json: - type: errors - 500: - description: "Internal server error" - body: - text/plain: - example: "Internal server error" /login-with-expiry: post: description: | diff --git a/src/main/java/org/folio/rest/impl/BLUsersAPI.java b/src/main/java/org/folio/rest/impl/BLUsersAPI.java index 072f23f..f58e921 100644 --- a/src/main/java/org/folio/rest/impl/BLUsersAPI.java +++ b/src/main/java/org/folio/rest/impl/BLUsersAPI.java @@ -139,7 +139,6 @@ public class BLUsersAPI implements BlUsers { private static final String UNDEFINED_USER = "UNDEFINED_USER__"; private static final String LOGIN_ENDPOINT = "/authn/login-with-expiry"; - private static final String LOGIN_ENDPOINT_LEGACY = "/authn/login"; private static final String FOLIO_ACCESS_TOKEN = "folioAccessToken"; private static final String SET_COOKIE_HEADER = "Set-Cookie"; @@ -853,14 +852,6 @@ public void postBlUsersLoginWithExpiry(boolean expandPerms, List include LOGIN_ENDPOINT, this::loginResponse); } - @Override - public void postBlUsersLogin(boolean expandPerms, List include, String userAgent, String xForwardedFor, - LoginCredentials entity, Map okapiHeaders, Handler> asyncResultHandler, - Context vertxContext) { - doPostBlUsersLogin(expandPerms, include, userAgent, xForwardedFor, entity, okapiHeaders, asyncResultHandler, - LOGIN_ENDPOINT_LEGACY, this::loginResponseLegacy); - } - @SuppressWarnings("java:S1874") private void doPostBlUsersLogin(boolean expandPerms, List include, String userAgent, String xForwardedFor, //NOSONAR LoginCredentials entity, Map okapiHeaders, Handler> asyncResultHandler, @@ -879,7 +870,7 @@ private void doPostBlUsersLogin(boolean expandPerms, List include, Strin if (entity == null || entity.getUsername() == null || entity.getPassword() == null) { asyncResultHandler.handle(Future.succeededFuture( - PostBlUsersLoginResponse.respond400WithTextPlain("Improperly formatted request"))); + PostBlUsersLoginWithExpiryResponse.respond400WithTextPlain("Improperly formatted request"))); } else { HttpClientInterface clientForLogin = HttpClientFactory.getHttpClient(okapiURL, okapiHeaders.get(OKAPI_TENANT_HEADER)); String moduleURL = "/authn/login"; @@ -913,7 +904,7 @@ private void doPostBlUsersLogin(boolean expandPerms, List include, Strin } catch (Exception e) { client.closeClient(); asyncResultHandler.handle(Future.succeededFuture( - PostBlUsersLoginResponse.respond500WithTextPlain(e.getLocalizedMessage()))); + PostBlUsersLoginWithExpiryResponse.respond500WithTextPlain(e.getLocalizedMessage()))); } finally { clientForLogin.closeClient(); } @@ -921,13 +912,13 @@ private void doPostBlUsersLogin(boolean expandPerms, List include, Strin .exceptionally(throwable -> { clientForLogin.closeClient(); asyncResultHandler.handle(Future.succeededFuture( - PostBlUsersLoginResponse.respond500WithTextPlain(throwable.getLocalizedMessage()))); + PostBlUsersLoginWithExpiryResponse.respond500WithTextPlain(throwable.getLocalizedMessage()))); return null; }); } catch (Exception ex) { clientForLogin.closeClient(); asyncResultHandler.handle(Future.succeededFuture( - PostBlUsersLoginResponse.respond500WithTextPlain(ex.getLocalizedMessage()))); + PostBlUsersLoginWithExpiryResponse.respond500WithTextPlain(ex.getLocalizedMessage()))); } } } @@ -999,7 +990,7 @@ okapiHeaders, null, handlePreviousResponse(false, false, false, } catch (Exception ex) { client.closeClient(); asyncResultHandler.handle(Future.succeededFuture( - PostBlUsersLoginResponse.respond500WithTextPlain(ex.getLocalizedMessage()))); + PostBlUsersLoginWithExpiryResponse.respond500WithTextPlain(ex.getLocalizedMessage()))); } } } @@ -1084,7 +1075,7 @@ okapiHeaders, null, handlePreviousResponse(false, false, false, } catch (Exception e) { if(!aRequestHasFailed[0]){ asyncResultHandler.handle(Future.succeededFuture( - PostBlUsersLoginResponse.respond500WithTextPlain(e.getLocalizedMessage()))); + PostBlUsersLoginWithExpiryResponse.respond500WithTextPlain(e.getLocalizedMessage()))); } logger.error(e.getMessage(), e); } finally { @@ -1126,13 +1117,6 @@ private static void fillCompositeUserWithServicePoint(Map Date: Fri, 21 Feb 2025 14:03:51 -0500 Subject: [PATCH 2/2] Update mod desc --- descriptors/ModuleDescriptor-template.json | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/descriptors/ModuleDescriptor-template.json b/descriptors/ModuleDescriptor-template.json index c2e3c47..2190960 100644 --- a/descriptors/ModuleDescriptor-template.json +++ b/descriptors/ModuleDescriptor-template.json @@ -4,7 +4,7 @@ "provides": [ { "id": "users-bl", - "version": "6.1", + "version": "7.0", "handlers": [ { "methods": ["GET"], @@ -33,21 +33,6 @@ "inventory-storage.service-points.item.get" ] }, - { - "methods" : [ "POST" ], - "pathPattern" : "/bl-users/login", - "permissionsRequired" : [], - "modulePermissions" : [ - "users.item.get", - "users.collection.get", - "perms.users.get", - "usergroups.item.get", - "inventory-storage.service-points-users.collection.get", - "inventory-storage.service-points-users.item.get", - "inventory-storage.service-points.collection.get", - "inventory-storage.service-points.item.get" - ] - }, { "methods" : [ "POST" ], "pathPattern" : "/bl-users/login-with-expiry", @@ -243,7 +228,7 @@ }, { "id" : "login", - "version" : "7.3" + "version" : "8.0" }, { "id": "authtoken",