Commit ee77444229c0157ba5a8260901afa764243c2fdd
Committed by
GitHub
Merge pull request #1247 from mp-loki/case-insensitive-login
Added option for case-insensitive username
Showing
3 changed files
with
16 additions
and
1 deletions
@@ -99,6 +99,8 @@ security: | @@ -99,6 +99,8 @@ security: | ||
99 | tokenSigningKey: "${JWT_TOKEN_SIGNING_KEY:thingsboardDefaultSigningKey}" | 99 | tokenSigningKey: "${JWT_TOKEN_SIGNING_KEY:thingsboardDefaultSigningKey}" |
100 | # Enable/disable access to Tenant Administrators JWT token by System Administrator or Customer Users JWT token by Tenant Administrator | 100 | # Enable/disable access to Tenant Administrators JWT token by System Administrator or Customer Users JWT token by Tenant Administrator |
101 | user_token_access_enabled: "${SECURITY_USER_TOKEN_ACCESS_ENABLED:true}" | 101 | user_token_access_enabled: "${SECURITY_USER_TOKEN_ACCESS_ENABLED:true}" |
102 | + # Enable/disable case-sensitive username login | ||
103 | + user_login_case_sensitive: "${SECURITY_USER_LOGIN_CASE_SENSITIVE:true}" | ||
102 | 104 | ||
103 | # Dashboard parameters | 105 | # Dashboard parameters |
104 | dashboard: | 106 | dashboard: |
@@ -20,6 +20,7 @@ import lombok.extern.slf4j.Slf4j; | @@ -20,6 +20,7 @@ import lombok.extern.slf4j.Slf4j; | ||
20 | import org.apache.commons.lang3.RandomStringUtils; | 20 | import org.apache.commons.lang3.RandomStringUtils; |
21 | import org.apache.commons.lang3.StringUtils; | 21 | import org.apache.commons.lang3.StringUtils; |
22 | import org.springframework.beans.factory.annotation.Autowired; | 22 | import org.springframework.beans.factory.annotation.Autowired; |
23 | +import org.springframework.beans.factory.annotation.Value; | ||
23 | import org.springframework.stereotype.Service; | 24 | import org.springframework.stereotype.Service; |
24 | import org.thingsboard.server.common.data.Customer; | 25 | import org.thingsboard.server.common.data.Customer; |
25 | import org.thingsboard.server.common.data.Tenant; | 26 | import org.thingsboard.server.common.data.Tenant; |
@@ -54,6 +55,9 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic | @@ -54,6 +55,9 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic | ||
54 | public static final String INCORRECT_USER_ID = "Incorrect userId "; | 55 | public static final String INCORRECT_USER_ID = "Incorrect userId "; |
55 | public static final String INCORRECT_TENANT_ID = "Incorrect tenantId "; | 56 | public static final String INCORRECT_TENANT_ID = "Incorrect tenantId "; |
56 | 57 | ||
58 | + @Value("${security.user_login_case_sensitive:true}") | ||
59 | + private boolean userLoginCaseSensitive; | ||
60 | + | ||
57 | @Autowired | 61 | @Autowired |
58 | private UserDao userDao; | 62 | private UserDao userDao; |
59 | 63 | ||
@@ -70,7 +74,11 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic | @@ -70,7 +74,11 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic | ||
70 | public User findUserByEmail(TenantId tenantId, String email) { | 74 | public User findUserByEmail(TenantId tenantId, String email) { |
71 | log.trace("Executing findUserByEmail [{}]", email); | 75 | log.trace("Executing findUserByEmail [{}]", email); |
72 | validateString(email, "Incorrect email " + email); | 76 | validateString(email, "Incorrect email " + email); |
73 | - return userDao.findByEmail(tenantId, email); | 77 | + if (userLoginCaseSensitive) { |
78 | + return userDao.findByEmail(tenantId, email); | ||
79 | + } else { | ||
80 | + return userDao.findByEmail(tenantId, email.toLowerCase()); | ||
81 | + } | ||
74 | } | 82 | } |
75 | 83 | ||
76 | @Override | 84 | @Override |
@@ -91,6 +99,9 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic | @@ -91,6 +99,9 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic | ||
91 | public User saveUser(User user) { | 99 | public User saveUser(User user) { |
92 | log.trace("Executing saveUser [{}]", user); | 100 | log.trace("Executing saveUser [{}]", user); |
93 | userValidator.validate(user, User::getTenantId); | 101 | userValidator.validate(user, User::getTenantId); |
102 | + if (user.getId() == null && !userLoginCaseSensitive) { | ||
103 | + user.setEmail(user.getEmail().toLowerCase()); | ||
104 | + } | ||
94 | User savedUser = userDao.save(user.getTenantId(), user); | 105 | User savedUser = userDao.save(user.getTenantId(), user); |
95 | if (user.getId() == null) { | 106 | if (user.getId() == null) { |
96 | UserCredentials userCredentials = new UserCredentials(); | 107 | UserCredentials userCredentials = new UserCredentials(); |
@@ -35,4 +35,6 @@ redis.connection.port=6379 | @@ -35,4 +35,6 @@ redis.connection.port=6379 | ||
35 | redis.connection.db=0 | 35 | redis.connection.db=0 |
36 | redis.connection.password= | 36 | redis.connection.password= |
37 | 37 | ||
38 | +security.user_login_case_sensitive=true | ||
39 | + | ||
38 | database.ts_max_intervals=700 | 40 | database.ts_max_intervals=700 |