diff --git a/src/main/java/io/supertokens/webserver/api/userroles/AddUserRoleAPI.java b/src/main/java/io/supertokens/webserver/api/userroles/AddUserRoleAPI.java index 397091c47..7d2b7f2b7 100644 --- a/src/main/java/io/supertokens/webserver/api/userroles/AddUserRoleAPI.java +++ b/src/main/java/io/supertokens/webserver/api/userroles/AddUserRoleAPI.java @@ -18,6 +18,8 @@ import com.google.gson.JsonObject; import io.supertokens.Main; +import io.supertokens.pluginInterface.Storage; +import io.supertokens.pluginInterface.multitenancy.TenantIdentifier; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.pluginInterface.RECIPE_ID; import io.supertokens.pluginInterface.exceptions.StorageQueryException; @@ -48,7 +50,7 @@ public String getPath() { @Override protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { - // API is tenant specific, but uses public tenant storage + // API is tenant specific JsonObject input = InputParser.parseJsonObjectOrThrowError(req); String userId = InputParser.parseStringOrThrowError(input, "userId", false); String role = InputParser.parseStringOrThrowError(input, "role", false); @@ -60,9 +62,11 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO } try { + TenantIdentifier tenantIdentifier = getTenantIdentifier(req); + Storage storage = getTenantStorage(req); + boolean didUserAlreadyHaveRole = !UserRoles.addRoleToUser( - this.getTenantStorage(req).withStorage(this.getPublicTenantStorage(req).getStorage()), - userId, role); + tenantIdentifier, storage, userId, role); JsonObject response = new JsonObject(); response.addProperty("status", "OK"); response.addProperty("didUserAlreadyHaveRole", didUserAlreadyHaveRole); diff --git a/src/main/java/io/supertokens/webserver/api/userroles/CreateRoleAPI.java b/src/main/java/io/supertokens/webserver/api/userroles/CreateRoleAPI.java index 082969848..24b74473a 100644 --- a/src/main/java/io/supertokens/webserver/api/userroles/CreateRoleAPI.java +++ b/src/main/java/io/supertokens/webserver/api/userroles/CreateRoleAPI.java @@ -20,6 +20,8 @@ import com.google.gson.JsonObject; import io.supertokens.Main; import io.supertokens.multitenancy.exception.BadPermissionException; +import io.supertokens.pluginInterface.Storage; +import io.supertokens.pluginInterface.multitenancy.AppIdentifier; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.pluginInterface.RECIPE_ID; import io.supertokens.pluginInterface.exceptions.StorageQueryException; @@ -81,8 +83,10 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO } try { + AppIdentifier appIdentifier = getAppIdentifier(req); + Storage storage = enforcePublicTenantAndGetPublicTenantStorage(req); boolean createdNewRole = UserRoles.createNewRoleOrModifyItsPermissions( - this.enforcePublicTenantAndGetPublicTenantStorage(req), role, permissions); + appIdentifier, storage, role, permissions); JsonObject response = new JsonObject(); response.addProperty("status", "OK"); diff --git a/src/main/java/io/supertokens/webserver/api/userroles/GetPermissionsForRoleAPI.java b/src/main/java/io/supertokens/webserver/api/userroles/GetPermissionsForRoleAPI.java index e20641b51..7b9fab585 100644 --- a/src/main/java/io/supertokens/webserver/api/userroles/GetPermissionsForRoleAPI.java +++ b/src/main/java/io/supertokens/webserver/api/userroles/GetPermissionsForRoleAPI.java @@ -21,6 +21,8 @@ import com.google.gson.JsonPrimitive; import io.supertokens.Main; import io.supertokens.multitenancy.exception.BadPermissionException; +import io.supertokens.pluginInterface.Storage; +import io.supertokens.pluginInterface.multitenancy.AppIdentifier; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.pluginInterface.RECIPE_ID; import io.supertokens.pluginInterface.exceptions.StorageQueryException; @@ -60,7 +62,10 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO } try { - String[] permissions = UserRoles.getPermissionsForRole(this.enforcePublicTenantAndGetPublicTenantStorage(req), role); + AppIdentifier appIdentifier = getAppIdentifier(req); + Storage storage = enforcePublicTenantAndGetPublicTenantStorage(req); + + String[] permissions = UserRoles.getPermissionsForRole(appIdentifier, storage, role); JsonArray arr = new JsonArray(); for (String permission : permissions) { arr.add(new JsonPrimitive(permission)); diff --git a/src/main/java/io/supertokens/webserver/api/userroles/GetRolesAPI.java b/src/main/java/io/supertokens/webserver/api/userroles/GetRolesAPI.java index 20ba99bc9..21ca5d73b 100644 --- a/src/main/java/io/supertokens/webserver/api/userroles/GetRolesAPI.java +++ b/src/main/java/io/supertokens/webserver/api/userroles/GetRolesAPI.java @@ -21,6 +21,8 @@ import com.google.gson.JsonPrimitive; import io.supertokens.Main; import io.supertokens.multitenancy.exception.BadPermissionException; +import io.supertokens.pluginInterface.Storage; +import io.supertokens.pluginInterface.multitenancy.AppIdentifier; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.pluginInterface.RECIPE_ID; import io.supertokens.pluginInterface.exceptions.StorageQueryException; @@ -50,8 +52,10 @@ public String getPath() { protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { // API is app specific try { + AppIdentifier appIdentifier = getAppIdentifier(req); + Storage storage = enforcePublicTenantAndGetPublicTenantStorage(req); - String[] roles = UserRoles.getRoles(this.enforcePublicTenantAndGetPublicTenantStorage(req)); + String[] roles = UserRoles.getRoles(appIdentifier, storage); JsonArray arr = new JsonArray(); for (String s : roles) { diff --git a/src/main/java/io/supertokens/webserver/api/userroles/GetRolesForPermissionAPI.java b/src/main/java/io/supertokens/webserver/api/userroles/GetRolesForPermissionAPI.java index df64526d6..6577c93b5 100644 --- a/src/main/java/io/supertokens/webserver/api/userroles/GetRolesForPermissionAPI.java +++ b/src/main/java/io/supertokens/webserver/api/userroles/GetRolesForPermissionAPI.java @@ -21,6 +21,8 @@ import com.google.gson.JsonPrimitive; import io.supertokens.Main; import io.supertokens.multitenancy.exception.BadPermissionException; +import io.supertokens.pluginInterface.Storage; +import io.supertokens.pluginInterface.multitenancy.AppIdentifier; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.pluginInterface.RECIPE_ID; import io.supertokens.pluginInterface.exceptions.StorageQueryException; @@ -60,8 +62,10 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO } try { + AppIdentifier appIdentifier = getAppIdentifier(req); + Storage storage = enforcePublicTenantAndGetPublicTenantStorage(req); - String[] roles = UserRoles.getRolesThatHavePermission(this.enforcePublicTenantAndGetPublicTenantStorage(req), permission); + String[] roles = UserRoles.getRolesThatHavePermission(appIdentifier, storage, permission); JsonArray arr = new JsonArray(); for (String s : roles) { diff --git a/src/main/java/io/supertokens/webserver/api/userroles/GetRolesForUserAPI.java b/src/main/java/io/supertokens/webserver/api/userroles/GetRolesForUserAPI.java index 4ce961a6a..ebc500f21 100644 --- a/src/main/java/io/supertokens/webserver/api/userroles/GetRolesForUserAPI.java +++ b/src/main/java/io/supertokens/webserver/api/userroles/GetRolesForUserAPI.java @@ -20,6 +20,8 @@ import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; import io.supertokens.Main; +import io.supertokens.pluginInterface.Storage; +import io.supertokens.pluginInterface.multitenancy.TenantIdentifier; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.pluginInterface.RECIPE_ID; import io.supertokens.pluginInterface.exceptions.StorageQueryException; @@ -48,12 +50,12 @@ public String getPath() { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { - // API is tenant specific, but using the public tenant storage + // API is tenant specific String userId = InputParser.getQueryParamOrThrowError(req, "userId", false); try { - String[] userRoles = UserRoles.getRolesForUser( - this.getTenantStorage(req).withStorage(this.getPublicTenantStorage(req).getStorage()), - userId); + TenantIdentifier tenantIdentifier = getTenantIdentifier(req); + Storage storage = getTenantStorage(req); + String[] userRoles = UserRoles.getRolesForUser(tenantIdentifier, storage, userId); JsonArray arr = new JsonArray(); for (String s : userRoles) { arr.add(new JsonPrimitive(s)); diff --git a/src/main/java/io/supertokens/webserver/api/userroles/GetUsersForRoleAPI.java b/src/main/java/io/supertokens/webserver/api/userroles/GetUsersForRoleAPI.java index 6743f89c0..c1c6cd0d1 100644 --- a/src/main/java/io/supertokens/webserver/api/userroles/GetUsersForRoleAPI.java +++ b/src/main/java/io/supertokens/webserver/api/userroles/GetUsersForRoleAPI.java @@ -20,6 +20,8 @@ import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; import io.supertokens.Main; +import io.supertokens.pluginInterface.Storage; +import io.supertokens.pluginInterface.multitenancy.TenantIdentifier; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.pluginInterface.RECIPE_ID; import io.supertokens.pluginInterface.exceptions.StorageQueryException; @@ -60,9 +62,10 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO } try { - String[] roleUsers = UserRoles.getUsersForRole( - this.getTenantStorage(req).withStorage(this.getPublicTenantStorage(req).getStorage()), - role); + TenantIdentifier tenantIdentifier = getTenantIdentifier(req); + Storage storage = getTenantStorage(req); + + String[] roleUsers = UserRoles.getUsersForRole(tenantIdentifier, storage, role); JsonArray arr = new JsonArray(); for (String s : roleUsers) { diff --git a/src/main/java/io/supertokens/webserver/api/userroles/RemovePermissionsForRoleAPI.java b/src/main/java/io/supertokens/webserver/api/userroles/RemovePermissionsForRoleAPI.java index 0c68d365d..7300e9b6b 100644 --- a/src/main/java/io/supertokens/webserver/api/userroles/RemovePermissionsForRoleAPI.java +++ b/src/main/java/io/supertokens/webserver/api/userroles/RemovePermissionsForRoleAPI.java @@ -20,6 +20,8 @@ import com.google.gson.JsonObject; import io.supertokens.Main; import io.supertokens.multitenancy.exception.BadPermissionException; +import io.supertokens.pluginInterface.Storage; +import io.supertokens.pluginInterface.multitenancy.AppIdentifier; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.pluginInterface.RECIPE_ID; import io.supertokens.pluginInterface.exceptions.StorageQueryException; @@ -81,7 +83,10 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I } try { - UserRoles.deletePermissionsFromRole(this.enforcePublicTenantAndGetPublicTenantStorage(req), role, permissions); + AppIdentifier appIdentifier = getAppIdentifier(req); + Storage storage = enforcePublicTenantAndGetPublicTenantStorage(req); + + UserRoles.deletePermissionsFromRole(appIdentifier, storage, role, permissions); JsonObject response = new JsonObject(); response.addProperty("status", "OK"); super.sendJsonResponse(200, response, resp); diff --git a/src/main/java/io/supertokens/webserver/api/userroles/RemoveRoleAPI.java b/src/main/java/io/supertokens/webserver/api/userroles/RemoveRoleAPI.java index b49446b04..acc130085 100644 --- a/src/main/java/io/supertokens/webserver/api/userroles/RemoveRoleAPI.java +++ b/src/main/java/io/supertokens/webserver/api/userroles/RemoveRoleAPI.java @@ -19,6 +19,8 @@ import com.google.gson.JsonObject; import io.supertokens.Main; import io.supertokens.multitenancy.exception.BadPermissionException; +import io.supertokens.pluginInterface.Storage; +import io.supertokens.pluginInterface.multitenancy.AppIdentifier; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.pluginInterface.RECIPE_ID; import io.supertokens.pluginInterface.exceptions.StorageQueryException; @@ -58,7 +60,10 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I } try { - boolean didRoleExist = UserRoles.deleteRole(this.enforcePublicTenantAndGetPublicTenantStorage(req), role); + AppIdentifier appIdentifier = getAppIdentifier(req); + Storage storage = enforcePublicTenantAndGetPublicTenantStorage(req); + + boolean didRoleExist = UserRoles.deleteRole(appIdentifier, storage, role); JsonObject response = new JsonObject(); response.addProperty("status", "OK"); diff --git a/src/main/java/io/supertokens/webserver/api/userroles/RemoveUserRoleAPI.java b/src/main/java/io/supertokens/webserver/api/userroles/RemoveUserRoleAPI.java index 4eb665fd9..ff94b4bbd 100644 --- a/src/main/java/io/supertokens/webserver/api/userroles/RemoveUserRoleAPI.java +++ b/src/main/java/io/supertokens/webserver/api/userroles/RemoveUserRoleAPI.java @@ -18,6 +18,8 @@ import com.google.gson.JsonObject; import io.supertokens.Main; +import io.supertokens.pluginInterface.Storage; +import io.supertokens.pluginInterface.multitenancy.TenantIdentifier; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.pluginInterface.RECIPE_ID; import io.supertokens.pluginInterface.exceptions.StorageQueryException; @@ -60,9 +62,10 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I } try { - boolean didUserHaveRole = UserRoles.removeUserRole( - this.getTenantStorage(req).withStorage(this.getPublicTenantStorage(req).getStorage()), - userId, role); + TenantIdentifier tenantIdentifier = getTenantIdentifier(req); + Storage storage = getTenantStorage(req); + + boolean didUserHaveRole = UserRoles.removeUserRole(tenantIdentifier, storage, userId, role); JsonObject response = new JsonObject(); response.addProperty("status", "OK");