Skip to content

Commit

Permalink
fix: review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tamassoltesz committed Nov 5, 2024
1 parent 6c87f28 commit d2f7e53
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ CREATE TABLE IF NOT EXISTS oauth_logout_challenges (

CREATE INDEX oauth_logout_challenges_time_created_index ON oauth_logout_challenges(time_created ASC, app_id ASC);
```
>>>>>>> origin/master

## [9.2.3] - 2024-10-09

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2024, VRAI Labs and/or its affiliates. All rights reserved.
*
* This software is licensed under the Apache License, Version 2.0 (the
* "License") as published by the Apache Software Foundation.
*
* You may not use this file except in compliance with the License. You may
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package io.supertokens.exceptions;

public class UserNotInTenantException extends Exception {

public UserNotInTenantException(String err) {
super(err);
}

}
15 changes: 6 additions & 9 deletions src/main/java/io/supertokens/session/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
import io.supertokens.authRecipe.AuthRecipe;
import io.supertokens.config.Config;
import io.supertokens.config.CoreConfig;
import io.supertokens.exceptions.AccessTokenPayloadError;
import io.supertokens.exceptions.TokenTheftDetectedException;
import io.supertokens.exceptions.TryRefreshTokenException;
import io.supertokens.exceptions.UnauthorisedException;
import io.supertokens.exceptions.*;
import io.supertokens.jwt.exceptions.UnsupportedJWTSigningAlgorithmException;
import io.supertokens.multitenancy.Multitenancy;
import io.supertokens.pluginInterface.STORAGE_TYPE;
Expand Down Expand Up @@ -79,7 +76,7 @@ public static SessionInformationHolder createNewSession(TenantIdentifier tenantI
@Nonnull JsonObject userDataInDatabase)
throws NoSuchAlgorithmException, StorageQueryException, InvalidKeyException,
InvalidKeySpecException, StorageTransactionLogicException, SignatureException, IllegalBlockSizeException,
BadPaddingException, InvalidAlgorithmParameterException, NoSuchPaddingException, UnauthorisedException,
BadPaddingException, InvalidAlgorithmParameterException, NoSuchPaddingException, UserNotInTenantException,
JWT.JWTException, UnsupportedJWTSigningAlgorithmException, AccessTokenPayloadError {
try {
return createNewSession(tenantIdentifier, storage, main, recipeUserId, userDataInJWT, userDataInDatabase,
Expand All @@ -104,7 +101,7 @@ public static SessionInformationHolder createNewSession(Main main,
new TenantIdentifier(null, null, null), storage, main,
recipeUserId, userDataInJWT, userDataInDatabase, false,
AccessToken.getLatestVersion(), false, false);
} catch (TenantOrAppNotFoundException | UnauthorisedException e) {
} catch (TenantOrAppNotFoundException | UserNotInTenantException e) {
throw new IllegalStateException(e);
}
}
Expand All @@ -124,7 +121,7 @@ public static SessionInformationHolder createNewSession(Main main, @Nonnull Stri
return createNewSession(
new TenantIdentifier(null, null, null), storage, main,
recipeUserId, userDataInJWT, userDataInDatabase, enableAntiCsrf, version, useStaticKey, false);
} catch (TenantOrAppNotFoundException | UnauthorisedException e) {
} catch (TenantOrAppNotFoundException | UserNotInTenantException e) {
throw new IllegalStateException(e);
}
}
Expand All @@ -138,7 +135,7 @@ public static SessionInformationHolder createNewSession(TenantIdentifier tenantI
throws NoSuchAlgorithmException, StorageQueryException, InvalidKeyException,
InvalidKeySpecException, StorageTransactionLogicException, SignatureException, IllegalBlockSizeException,
BadPaddingException, InvalidAlgorithmParameterException, NoSuchPaddingException, AccessTokenPayloadError,
UnsupportedJWTSigningAlgorithmException, TenantOrAppNotFoundException, UnauthorisedException {
UnsupportedJWTSigningAlgorithmException, TenantOrAppNotFoundException, UserNotInTenantException {
String sessionHandle = UUID.randomUUID().toString();
if (!tenantIdentifier.getTenantId().equals(TenantIdentifier.DEFAULT_TENANT_ID)) {
sessionHandle += "_" + tenantIdentifier.getTenantId();
Expand Down Expand Up @@ -175,7 +172,7 @@ public static SessionInformationHolder createNewSession(TenantIdentifier tenantI
storage, recipeUserId);
if (authRecipeUserInfo != null) {
if (!authRecipeUserInfo.tenantIds.contains(tenantIdentifier.getTenantId())) {
throw new UnauthorisedException("User is not part of requested tenant!");
throw new UserNotInTenantException("User is not part of requested tenant!");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.supertokens.config.Config;
import io.supertokens.exceptions.AccessTokenPayloadError;
import io.supertokens.exceptions.UnauthorisedException;
import io.supertokens.exceptions.UserNotInTenantException;
import io.supertokens.jwt.exceptions.UnsupportedJWTSigningAlgorithmException;
import io.supertokens.output.Logging;
import io.supertokens.pluginInterface.RECIPE_ID;
Expand Down Expand Up @@ -144,7 +145,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I
super.sendJsonResponse(200, result, resp);
} catch (AccessTokenPayloadError e) {
throw new ServletException(new BadRequestException(e.getMessage()));
} catch (UnauthorisedException e) {
} catch (UserNotInTenantException e) {
JsonObject reply = new JsonObject();
reply.addProperty("status", "USER_DOES_NOT_BELONG_TO_TENANT_ERROR");
reply.addProperty("message", e.getMessage());
Expand Down

0 comments on commit d2f7e53

Please sign in to comment.