Skip to content

Commit

Permalink
[ALS-4793] Debug claims subject
Browse files Browse the repository at this point in the history
  • Loading branch information
Gcolon021 committed Aug 7, 2023
1 parent b73120a commit 745af96
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@ protected UserRepository() {
}

public User findBySubject(String subject) {
CriteriaQuery<User> query = em.getCriteriaBuilder().createQuery(User.class);
Root<User> queryRoot = query.from(User.class);
query.select(queryRoot);
CriteriaBuilder cb = cb();
return em.createQuery(query
.where(
eq(cb, queryRoot, "subject", subject)))
.getSingleResult();
try {
CriteriaQuery<User> query = em.getCriteriaBuilder().createQuery(User.class);
Root<User> queryRoot = query.from(User.class);
query.select(queryRoot);
CriteriaBuilder cb = cb();
return em.createQuery(query
.where(
eq(cb, queryRoot, "subject", subject)))
.getSingleResult();
} catch (NoResultException e){
return null;
}
}

public User findBySubjectAndConnection(String subject, String connectionId){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ private void setSecurityContextForUser(ContainerRequestContext requestContext, S
String userForLogging;

// Find the user when checking the claims
logger.info("Looking for user with subject: " + claimsSubject);
User authenticatedUser = userRepo.findBySubject(claimsSubject);

if (authenticatedUser == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public Response getToken(Map<String, String> authRequest){
throw new ApplicationException("cannot get sufficient user information. Please contact admin.");
}

// TODO: we need to check if the idp_provider is fence before the find by subject and connection
//Do we have this user already?
User user = userRepository.findBySubjectAndConnection(userId, connectionId);
if (user == null){
Expand Down

0 comments on commit 745af96

Please sign in to comment.