Commit 0a07e2d226a92ac5d4ec32aa4271497a237927b7
1 parent
289a5f5f
Added option for case-insensitive username
Showing
2 changed files
with
14 additions
and
1 deletions
... | ... | @@ -99,6 +99,8 @@ security: |
99 | 99 | tokenSigningKey: "${JWT_TOKEN_SIGNING_KEY:thingsboardDefaultSigningKey}" |
100 | 100 | # Enable/disable access to Tenant Administrators JWT token by System Administrator or Customer Users JWT token by Tenant Administrator |
101 | 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 | 105 | # Dashboard parameters |
104 | 106 | dashboard: | ... | ... |
... | ... | @@ -20,6 +20,7 @@ import lombok.extern.slf4j.Slf4j; |
20 | 20 | import org.apache.commons.lang3.RandomStringUtils; |
21 | 21 | import org.apache.commons.lang3.StringUtils; |
22 | 22 | import org.springframework.beans.factory.annotation.Autowired; |
23 | +import org.springframework.beans.factory.annotation.Value; | |
23 | 24 | import org.springframework.stereotype.Service; |
24 | 25 | import org.thingsboard.server.common.data.Customer; |
25 | 26 | import org.thingsboard.server.common.data.Tenant; |
... | ... | @@ -54,6 +55,9 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic |
54 | 55 | public static final String INCORRECT_USER_ID = "Incorrect userId "; |
55 | 56 | public static final String INCORRECT_TENANT_ID = "Incorrect tenantId "; |
56 | 57 | |
58 | + @Value("${security.user_login_case_sensitive}") | |
59 | + private boolean userLoginCaseSensitive; | |
60 | + | |
57 | 61 | @Autowired |
58 | 62 | private UserDao userDao; |
59 | 63 | |
... | ... | @@ -70,7 +74,11 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic |
70 | 74 | public User findUserByEmail(TenantId tenantId, String email) { |
71 | 75 | log.trace("Executing findUserByEmail [{}]", email); |
72 | 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 | 84 | @Override |
... | ... | @@ -91,6 +99,9 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic |
91 | 99 | public User saveUser(User user) { |
92 | 100 | log.trace("Executing saveUser [{}]", user); |
93 | 101 | userValidator.validate(user, User::getTenantId); |
102 | + if (user.getId() == null && !userLoginCaseSensitive) { | |
103 | + user.setEmail(user.getEmail().toLowerCase()); | |
104 | + } | |
94 | 105 | User savedUser = userDao.save(user.getTenantId(), user); |
95 | 106 | if (user.getId() == null) { |
96 | 107 | UserCredentials userCredentials = new UserCredentials(); | ... | ... |