Skip to content

Commit d080fe4

Browse files
author
sachin-maheshwari
authored
Merge pull request #34 from appirio-tech/feature/api-call-optimization
auth0 call (/v3/users/roles) optimization
2 parents 233b297 + 7f75048 commit d080fe4

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ workflows:
145145
context : org-global
146146
filters:
147147
branches:
148-
only: [dev, 'feature/RS256-Auth0']
148+
only: [dev, 'feature/api-call-optimization']
149149
# Production build is executed on "master" branch only.
150150
- "build-prod":
151151
context : org-global

src/main/java/com/appirio/tech/core/service/identity/dao/UserDAO.java

+26
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@ public abstract class UserDAO implements DaoBase<User>, Transactional<UserDAO> {
123123
)
124124
public abstract List<User> findUsersByEmail(@Bind("email") String email);
125125

126+
@RegisterMapperFactory(TCBeanMapperFactory.class)
127+
@SqlQuery(
128+
"SELECT " + USER_COLUMNS + ", " +
129+
"e.address AS email, e.status_id AS emailStatus " +
130+
"FROM common_oltp.user AS u JOIN common_oltp.email AS e ON e.user_id = u.user_id " +
131+
"WHERE e.address = :email"
132+
)
133+
public abstract List<User> findUsersByEmailCS(@Bind("email") String email);
134+
126135
@RegisterMapperFactory(TCBeanMapperFactory.class)
127136
@SqlQuery(
128137
"SELECT " + USER_COLUMNS + ", " +
@@ -356,6 +365,23 @@ public User findUserByEmail(String email) {
356365
return users.get(0);
357366
}
358367

368+
/**
369+
*
370+
* @param email - case sensitive search
371+
* @return an user object or null
372+
*/
373+
public User findUserByEmailCS(String email) {
374+
if(email==null || email.length()==0)
375+
throw new IllegalArgumentException("email must be specified.");
376+
377+
List<User> users = findUsersByEmailCS(email);
378+
if(users==null || users.size()==0)
379+
return null;
380+
381+
// if found multiple, retuning first one
382+
return users.get(0);
383+
}
384+
359385
@Transaction(TransactionIsolationLevel.READ_COMMITTED)
360386
public TCID register(User user) {
361387
if(user==null)

src/main/java/com/appirio/tech/core/service/identity/resource/UserResource.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -776,8 +776,9 @@ public ApiResponse roles(
776776
User user = null;
777777
if (!Utils.isEmpty(handle)) {
778778
user = userDao.findUserByHandle(handle);
779-
} else{
780-
user = userDao.findUserByEmail(email);
779+
} else {
780+
// email address - case sensitive - for auth0 sepecific
781+
user = userDao.findUserByEmailCS(email);
781782
}
782783

783784
if(user==null) {

0 commit comments

Comments
 (0)