Commit 175a9c903db751f0c391faa4d3df8f1d4f935f8d
1 parent
92c9bc0a
OAuth: activate user with empty password - to be able to set up it later
Showing
1 changed file
with
7 additions
and
0 deletions
... | ... | @@ -19,6 +19,7 @@ import lombok.extern.slf4j.Slf4j; |
19 | 19 | import org.springframework.beans.factory.annotation.Autowired; |
20 | 20 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; |
21 | 21 | import org.springframework.security.core.userdetails.UsernameNotFoundException; |
22 | +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | |
22 | 23 | import org.springframework.util.StringUtils; |
23 | 24 | import org.thingsboard.server.common.data.Customer; |
24 | 25 | import org.thingsboard.server.common.data.Tenant; |
... | ... | @@ -27,6 +28,7 @@ import org.thingsboard.server.common.data.id.CustomerId; |
27 | 28 | import org.thingsboard.server.common.data.id.TenantId; |
28 | 29 | import org.thingsboard.server.common.data.page.TextPageLink; |
29 | 30 | import org.thingsboard.server.common.data.security.Authority; |
31 | +import org.thingsboard.server.common.data.security.UserCredentials; | |
30 | 32 | import org.thingsboard.server.dao.customer.CustomerService; |
31 | 33 | import org.thingsboard.server.dao.oauth2.OAuth2User; |
32 | 34 | import org.thingsboard.server.dao.tenant.TenantService; |
... | ... | @@ -48,6 +50,9 @@ public abstract class AbstractOAuth2ClientMapper { |
48 | 50 | private UserService userService; |
49 | 51 | |
50 | 52 | @Autowired |
53 | + private BCryptPasswordEncoder passwordEncoder; | |
54 | + | |
55 | + @Autowired | |
51 | 56 | private TenantService tenantService; |
52 | 57 | |
53 | 58 | @Autowired |
... | ... | @@ -88,6 +93,8 @@ public abstract class AbstractOAuth2ClientMapper { |
88 | 93 | user.setFirstName(oauth2User.getFirstName()); |
89 | 94 | user.setLastName(oauth2User.getLastName()); |
90 | 95 | user = userService.saveUser(user); |
96 | + UserCredentials userCredentials = userService.findUserCredentialsByUserId(user.getTenantId(), user.getId()); | |
97 | + userService.activateUserCredentials(user.getTenantId(), userCredentials.getActivateToken(), passwordEncoder.encode("")); | |
91 | 98 | } |
92 | 99 | } catch (Exception e) { |
93 | 100 | log.error("Can't get or create security user from oauth2 user", e); | ... | ... |