Commit a4414bbc2aa4f5a4ecd9ca822fe79dc97f8c162f

Authored by 云中非
2 parents 2232eac8 42293df9

Merge branch 'master' into 20200305

... ... @@ -29,6 +29,7 @@ import org.thingsboard.server.common.data.yunteng.common.UpdateGroup;
29 29 import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants;
30 30 import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException;
31 31 import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage;
  32 +import org.thingsboard.server.common.data.yunteng.core.utils.AccountProperties;
32 33 import org.thingsboard.server.common.data.yunteng.utils.Demo;
33 34 import org.thingsboard.server.common.data.yunteng.utils.ExcelUtil;
34 35 import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO;
... ... @@ -65,6 +66,7 @@ public class YtUserController extends BaseController {
65 66 private final UserService tbUserService;
66 67 private final ApplicationEventPublisher eventPublisher;
67 68 private final SystemSecurityService systemSecurityService;
  69 + private final AccountProperties accountProperties;
68 70
69 71 @GetMapping("{userId}")
70 72 public ResponseEntity<UserDTO> getUser(@PathVariable("userId") String userId)
... ... @@ -187,7 +189,7 @@ public class YtUserController extends BaseController {
187 189 if (null == userDTO.getId()) {
188 190 tbUser = createTBUser(tbUser, userDTO, tenantId, customerId, Authority.TENANT_ADMIN);
189 191 // 激活租户管理员
190   - activeTBUser(tbUser.getId(),FastIotConstants.DEFAULT_PWD);
  192 + activeTBUser(tbUser.getId(),accountProperties.getDefaultPassword());
191 193 }
192 194 } catch (Exception e) {
193 195 throw handleException(e);
... ... @@ -362,7 +364,7 @@ public class YtUserController extends BaseController {
362 364 tbUser.setAuthority(authority);
363 365 tbUser.setTenantId(tenantId);
364 366 tbUser.setCustomerId(customerId);
365   - tbUser.setEmail(userDTO.getUsername() + FastIotConstants.DEFAULT_EMAIL_SUFFIX_FOR_TB);
  367 + tbUser.setEmail(userDTO.getUsername() +"@"+ accountProperties.getEmailSuffix());
366 368 tbUser = tbUserService.saveUser(tbUser);
367 369 userDTO.setTbUser(tbUser.getId().getId().toString());
368 370 logEntityAction(
... ...
... ... @@ -35,6 +35,7 @@ import org.thingsboard.server.common.data.id.TenantId;
35 35 import org.thingsboard.server.common.data.id.UserId;
36 36 import org.thingsboard.server.common.data.security.Authority;
37 37 import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants;
  38 +import org.thingsboard.server.common.data.yunteng.core.utils.AccountProperties;
38 39 import org.thingsboard.server.common.data.yunteng.dto.UserDTO;
39 40 import org.thingsboard.server.common.data.yunteng.dto.UserDetailsDTO;
40 41 import org.thingsboard.server.dao.yunteng.service.YtUserService;
... ... @@ -59,6 +60,7 @@ public class RefreshTokenAuthenticationProvider implements AuthenticationProvide
59 60 private final CustomerService customerService;
60 61 private final TokenOutdatingService tokenOutdatingService;
61 62 private final YtUserService ytUserService;
  63 + private final AccountProperties accountProperties;
62 64
63 65 @Override
64 66 public Authentication authenticate(Authentication authentication) throws AuthenticationException {
... ... @@ -116,7 +118,7 @@ public class RefreshTokenAuthenticationProvider implements AuthenticationProvide
116 118 private SecurityUser authenticateByPlatFormUserId(UserId userId){
117 119 UserDTO userDTO =ytUserService.findUserInfoById(userId.getId().toString());
118 120 if(null != userDTO){
119   - String email = userDTO.getUsername() + FastIotConstants.DEFAULT_EMAIL_SUFFIX_FOR_TB;
  121 + String email = userDTO.getUsername() + "@" +accountProperties.getEmailSuffix();
120 122 UserPrincipal userPrincipal = new UserPrincipal(UserPrincipal.Type.USER_NAME, email);
121 123 User user = new User();
122 124 user.setAuthority(Authority.PLATFORM_USER);
... ...
... ... @@ -33,6 +33,7 @@ import org.thingsboard.server.common.data.security.Authority;
33 33 import org.thingsboard.server.common.data.security.UserCredentials;
34 34 import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants;
35 35 import org.thingsboard.server.common.data.yunteng.core.cache.CacheUtils;
  36 +import org.thingsboard.server.common.data.yunteng.core.utils.AccountProperties;
36 37 import org.thingsboard.server.common.data.yunteng.dto.UserDetailRoleDTO;
37 38 import org.thingsboard.server.common.data.yunteng.dto.UserDetailsDTO;
38 39 import org.thingsboard.server.common.data.yunteng.dto.request.CodeTTL;
... ... @@ -63,17 +64,20 @@ public class RestAuthenticationProvider implements AuthenticationProvider {
63 64 private final UserService userService;
64 65 private final CustomerService customerService;
65 66 private final AuditLogService auditLogService;
  67 + private final AccountProperties accountProperties;
66 68
67 69 @Autowired
68 70 public RestAuthenticationProvider(
69 71 final UserService userService,
70 72 final CustomerService customerService,
71 73 final SystemSecurityService systemSecurityService,
72   - final AuditLogService auditLogService) {
  74 + final AuditLogService auditLogService,
  75 + final AccountProperties accountProperties) {
73 76 this.userService = userService;
74 77 this.customerService = customerService;
75 78 this.systemSecurityService = systemSecurityService;
76 79 this.auditLogService = auditLogService;
  80 + this.accountProperties = accountProperties;
77 81 }
78 82
79 83 @Override
... ... @@ -92,7 +96,7 @@ public class RestAuthenticationProvider implements AuthenticationProvider {
92 96 String ytUserName = username;
93 97 UserDetailsDTO ytDetailDTO = new UserDetailsDTO();
94 98 if (!FastIotConstants.EMAIL_PATTERN.matcher(username).matches()) {
95   - username += FastIotConstants.DEFAULT_EMAIL_SUFFIX_FOR_TB;
  99 + username += "@"+accountProperties.getEmailSuffix();
96 100 ytDetailDTO = ytUserDetailsByUserName(ytUserName, password).get();
97 101 // 如果是平台用户单独处理
98 102 if (isPlatFormUser(ytDetailDTO)) {
... ... @@ -125,7 +129,7 @@ public class RestAuthenticationProvider implements AuthenticationProvider {
125 129 user.setTenantId(new TenantId(EntityId.NULL_UUID));
126 130 user.setId(new UserId(UUID.fromString(ytDetailDTO.getId())));
127 131 String email = ytDetailDTO.getUsername();
128   - email += FastIotConstants.DEFAULT_EMAIL_SUFFIX_FOR_TB;
  132 + email += "@"+accountProperties.getEmailSuffix();
129 133 user.setEmail(email);
130 134 UserCredentials userCredentials = new UserCredentials();
131 135 SecurityUser securityUser = new SecurityUser(user, userCredentials.isEnabled(), userPrincipal);
... ... @@ -333,7 +337,7 @@ public class RestAuthenticationProvider implements AuthenticationProvider {
333 337 throw new BadCredentialsException("验证码不正确");
334 338 }
335 339 User user = new User();
336   - String tbEmail = optionalUser.get().getUsername() + FastIotConstants.DEFAULT_EMAIL_SUFFIX_FOR_TB;
  340 + String tbEmail = optionalUser.get().getUsername() + "@" + accountProperties.getEmailSuffix();
337 341 UserDetailsDTO ytDetailDTO = optionalUser.get();
338 342 //如果是平台管理员
339 343 if(isPlatFormUser(ytDetailDTO)){
... ...
... ... @@ -18,7 +18,7 @@ server:
18 18 # Server bind address
19 19 address: "${HTTP_BIND_ADDRESS:0.0.0.0}"
20 20 # Server bind port
21   - port: "${HTTP_BIND_PORT:8080}"
  21 + port: "${HTTP_BIND_PORT:36852}"
22 22 # Server SSL configuration
23 23 ssl:
24 24 # Enable/disable SSL support
... ... @@ -529,9 +529,12 @@ spring:
529 529 database-platform: "${SPRING_JPA_DATABASE_PLATFORM:org.hibernate.dialect.PostgreSQLDialect}"
530 530 datasource:
531 531 driverClassName: "${SPRING_DRIVER_CLASS_NAME:org.postgresql.Driver}"
532   - url: "${SPRING_DATASOURCE_URL:jdbc:postgresql://101.133.234.90:5432/thingsboard-3.3.2}"
  532 + #url: "${SPRING_DATASOURCE_URL:jdbc:postgresql://47.99.141.212:20638/thingsboard-3.3.2}"
  533 + #username: "${SPRING_DATASOURCE_USERNAME:postgres}"
  534 + #password: "${SPRING_DATASOURCE_PASSWORD:Vrr861!@waja}"
  535 + url: "${SPRING_DATASOURCE_URL:jdbc:postgresql://101.133.234.90:28776/thingsboard-3.3.2}"
533 536 username: "${SPRING_DATASOURCE_USERNAME:postgres}"
534   - password: "${SPRING_DATASOURCE_PASSWORD:Pgsql@yunteng}"
  537 + password: "${SPRING_DATASOURCE_PASSWORD:Bua312!!iwcw}"
535 538 hikari:
536 539 maximumPoolSize: "${SPRING_DATASOURCE_MAXIMUM_POOL_SIZE:16}"
537 540
... ... @@ -1114,11 +1117,15 @@ file:
1114 1117 staticUrl: /oss/files/** #oss静态访问路径 只有type = local需要
1115 1118 randomFileName: ${file.storage.randomFileName}
1116 1119 minio:
1117   - minioUrl: http://101.133.234.90:9000 #minio储存地址
  1120 + minioUrl: http://47.99.141.212:9000 #minio储存地址
1118 1121 minioName: YunTeng #minio账户
1119 1122 minioPass: YunTeng123456 #minio访问密码
1120 1123 bucketName: yunteng #minio储存桶名称
1121 1124 randomFileName: ${file.storage.randomFileName}
  1125 +account:
  1126 + info:
  1127 + emailSuffix: thingskit.com
  1128 + defaultPassword: 123456
1122 1129 logging:
1123 1130 level:
1124 1131 org.thingsboard.server.dao.yunteng.mapper: error
... ...
... ... @@ -25,6 +25,7 @@ import org.thingsboard.server.common.data.id.UserId;
25 25 import org.thingsboard.server.common.data.security.Authority;
26 26 import org.thingsboard.server.common.data.security.UserCredentials;
27 27 import org.thingsboard.server.common.data.security.model.JwtToken;
  28 +import org.thingsboard.server.common.data.yunteng.core.utils.AccountProperties;
28 29 import org.thingsboard.server.config.JwtSettings;
29 30 import org.thingsboard.server.dao.customer.CustomerService;
30 31 import org.thingsboard.server.dao.user.UserService;
... ... @@ -62,9 +63,15 @@ public class TokenOutdatingTest {
62 63 private JwtTokenFactory tokenFactory;
63 64 private JwtSettings jwtSettings;
64 65 private YtUserService ytUserService;
  66 + private AccountProperties accountProperties;
65 67
66 68 private UserId userId;
67 69
  70 + public TokenOutdatingTest(YtUserService ytUserService, AccountProperties accountProperties) {
  71 + this.ytUserService = ytUserService;
  72 + this.accountProperties = accountProperties;
  73 + }
  74 +
68 75 @BeforeEach
69 76 public void setUp() {
70 77 jwtSettings = new JwtSettings();
... ... @@ -94,7 +101,7 @@ public class TokenOutdatingTest {
94 101
95 102 accessTokenAuthenticationProvider = new JwtAuthenticationProvider(tokenFactory, tokenOutdatingService);
96 103 refreshTokenAuthenticationProvider = new RefreshTokenAuthenticationProvider(tokenFactory, userService, mock(CustomerService.class), tokenOutdatingService,
97   - ytUserService);
  104 + ytUserService,accountProperties);
98 105 }
99 106
100 107 @Test
... ...
... ... @@ -3,9 +3,6 @@ package org.thingsboard.server.common.data.yunteng.constant;
3 3 import java.util.regex.Pattern;
4 4
5 5 public interface FastIotConstants {
6   -
7   - /** 默认密码 */
8   - String DEFAULT_PWD = "123456";
9 6 Integer JAVA_SCRIPT = 0;
10 7 Integer CONVERT_DATA = 1;
11 8 Integer SCENE_REACT = 2;
... ... @@ -65,8 +62,6 @@ public interface FastIotConstants {
65 62 String MOBILE_LOGIN_SMS_CODE = "mobileLoginSmsCode";
66 63 }
67 64
68   - String DEFAULT_EMAIL_SUFFIX_FOR_TB ="@yunteng.com";
69   -
70 65 interface TBCacheConfig {
71 66 String TB_CACHE_CONFIG_KEY = "TB_CONNECT_CACHE";
72 67 String EXISTING_TENANT = "EXISTING_TENANT";
... ...
  1 +package org.thingsboard.server.common.data.yunteng.core.utils;
  2 +
  3 +import lombok.Data;
  4 +import org.springframework.boot.context.properties.ConfigurationProperties;
  5 +import org.springframework.stereotype.Component;
  6 +
  7 +@ConfigurationProperties(prefix = "account.info")
  8 +@Component
  9 +@Data
  10 +public class AccountProperties {
  11 + private String emailSuffix;
  12 + private String defaultPassword;
  13 +}
... ...
... ... @@ -31,6 +31,7 @@ import org.thingsboard.server.common.data.yunteng.core.cache.CacheUtils;
31 31 import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException;
32 32 import org.thingsboard.server.common.data.yunteng.core.exception.NoneTenantAssetException;
33 33 import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage;
  34 +import org.thingsboard.server.common.data.yunteng.core.utils.AccountProperties;
34 35 import org.thingsboard.server.common.data.yunteng.dto.*;
35 36 import org.thingsboard.server.common.data.yunteng.dto.request.*;
36 37 import org.thingsboard.server.common.data.yunteng.enums.MessageTypeEnum;
... ... @@ -78,6 +79,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User>
78 79 private final CacheUtils cacheUtils;
79 80 private final UserService tbUserService;
80 81 private final ApplicationEventPublisher eventPublisher;
  82 + private final AccountProperties accountProperties;
81 83
82 84 @Override
83 85 public List<UserDetailsDTO> findUserDetailsByUsername(String username,String tenantId) {
... ... @@ -104,7 +106,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User>
104 106 if (StringUtils.isNotBlank(userDTO.getPassword())) {
105 107 user.setPassword(passwordEncoder.encode(userDTO.getPassword()));
106 108 } else {
107   - user.setPassword(passwordEncoder.encode(FastIotConstants.DEFAULT_PWD));
  109 + user.setPassword(passwordEncoder.encode(accountProperties.getDefaultPassword()));
108 110 }
109 111 userExist =
110 112 baseMapper.selectCount(
... ... @@ -394,7 +396,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User>
394 396 }
395 397 User user = new User();
396 398 userDTO.copyToEntity(user, ID, PASSWORD, CREATE_TIME, UPDATE_TIME, ACTIVATE_TOKEN);
397   - user.setPassword(passwordEncoder.encode(FastIotConstants.DEFAULT_PWD));
  399 + user.setPassword(passwordEncoder.encode(accountProperties.getDefaultPassword()));
398 400 user.setLevel(FastIotConstants.LevelValue.IS_TENANT_ADMIN);
399 401 List<User> users =
400 402 baseMapper.selectList(
... ... @@ -510,7 +512,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User>
510 512 smsReqDTO.setPhoneNumbers(user.getPhoneNumber());
511 513 smsReqDTO.setId(templateDTOList.get(0).getId());
512 514 LinkedHashMap<String, String> params = new LinkedHashMap<>();
513   - params.put("code", FastIotConstants.DEFAULT_PWD);
  515 + params.put("code", accountProperties.getDefaultPassword());
514 516 smsReqDTO.setParams(params);
515 517 ytSmsService.sendSms(smsReqDTO);
516 518 }
... ...