Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Authorisation and integrate sign up for users #22

Merged
merged 24 commits into from
Mar 10, 2024
Merged

Conversation

DashDeipayan
Copy link
Contributor

skill-tree /.gitignore Outdated Show resolved Hide resolved
} else {
CompletableFuture<Response> userResponse = fetchAPI.getRDSUserData(rdsUserId);
CompletableFuture.allOf(userResponse).join();
Response rdsUserResponse = userResponse.get();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get() method throws an exception if the CompletableFuture does not complete successfully. This means that if the getRDSUserData() method fails, the entire request will fail.

Copy link
Contributor

@vikhyat187 vikhyat187 Oct 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we handle this using timeouts? @iamitprakash, so that we don't perform the operation for too long and return TimeoutException in case of service taking higher time?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is any exception in making the call to the RDS backend we return an exception.

return (RSAPublicKey) keyFactory.generatePublic(keySpec);
}

public String getRDSUserId(String token) throws Exception {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getRDSUserId() method is that the method does not handle the case where the token is invalid or expired. The Jwts.parser().parseClaimsJws() method will throw a JwtException if the token is invalid or expired. To handle this exception, you should catch it and return a meaningful error message to the caller.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Tejas, we found this exception AuthenticationCredentialsNotFoundException and its being caught in the caller method.

Line Ref : https://github.com/Real-Dev-Squad/skill-tree-backend/pull/22/files#diff-7b979f99e46f3b3a2a373ff1729e27ffd99fe9798276ff9467236026d0c5236fR66

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try refreshing the token here

* @return the RSAPublicKey object converted from the public key string
* @throws Exception if there is an error during the conversion process
*/
private RSAPublicKey convertToRSAPublicKey(String publicKeyString) throws Exception {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optimize on below points please

Use a try-with-resources block. The KeyFactory.getInstance() method throws a NoSuchAlgorithmException if the specified algorithm is not supported. To handle this exception, you can use a try-with-resources block. This will ensure that the KeyFactory object is automatically closed, even if an exception is thrown.

Use a catch block to handle specific exceptions. The KeyFactory.generatePublic() method throws an InvalidKeySpecException if the specified key spec is invalid. To handle this exception, you can use a catch block. This will allow you to return a more specific error message to the caller.

Cache the public key. The convertToRSAPublicKey() method is likely to be called multiple times with the same public key string. To improve performance, you can cache the public key so that it does not need to be generated each time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a try-with-resources block. The KeyFactory.getInstance() method throws a NoSuchAlgorithmException if the specified algorithm is not supported. To handle this exception, you can use a try-with-resources block. This will ensure that the KeyFactory object is automatically closed, even if an exception is thrown.

#22 (comment)

Cache the public key. The convertToRSAPublicKey() method is likely to be called multiple times with the same public key string. To improve performance, you can cache the public key so that it does not need to be generated each time.

Tried caching this value, but the values are getting flushed from the ConcurrentHashMap the reason to be debugged.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried caching the public key, since this is used in the filter the values were getting refreshed, will once check this

@iamitprakash
Copy link
Member

@DashDeipayan please link Test setup ticket here

@iamitprakash
Copy link
Member

TEST setup task details #23

Copy link
Contributor

@bhtibrewal bhtibrewal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the PR tested? if not, please link a follow-up issue ticket for the same in the description
I do see the test setup issue ticket in the comments, but not the follow-up testing one

@vikhyat187
Copy link
Contributor

Here in this code when ever we throw an custom exception, the middleware is catching the exception and returning 401
Access Denied !! Full authentication is required to access this resource

skill-tree /pom.xml Outdated Show resolved Hide resolved
@heyrandhir heyrandhir mentioned this pull request Dec 1, 2023
8 tasks
@vikhyat187
Copy link
Contributor

We will require this file for this PR #49

@bhtibrewal bhtibrewal merged commit a7ec2c7 into develop Mar 10, 2024
1 check failed
@bhtibrewal bhtibrewal deleted the jpa-entity-rel branch March 10, 2024 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants