From 0692dca4e69c842015eb1a7fc81d6ac373d452d3 Mon Sep 17 00:00:00 2001 From: liukunyuan <50513095+liukunyuan@users.noreply.github.com> Date: Sun, 5 Jul 2020 21:50:42 +0800 Subject: [PATCH 1/3] update CommonUtils.java (#3137) Co-authored-by: dailidong --- .../org/apache/dolphinscheduler/common/utils/CommonUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/CommonUtils.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/CommonUtils.java index 731cdaa719..2468e62ab0 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/CommonUtils.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/CommonUtils.java @@ -48,7 +48,7 @@ public class CommonUtils { envPath = envDefaultPath.getPath(); logger.debug("env path :{}", envPath); }else{ - envPath = System.getProperty("user.home") + File.separator + ".bash_profile"; + envPath = "/etc/profile"; } } From 1f8851b90603ceefef0aea3a3db3980a300722bd Mon Sep 17 00:00:00 2001 From: iceblue510 <67048891+iceblue510@users.noreply.github.com> Date: Mon, 6 Jul 2020 17:57:30 +0800 Subject: [PATCH 2/3] modify sqlTask (#3152) --- .../dolphinscheduler/server/worker/task/sql/SqlTask.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/sql/SqlTask.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/sql/SqlTask.java index c30ca23ca2..5511c6acd6 100644 --- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/sql/SqlTask.java +++ b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/sql/SqlTask.java @@ -364,7 +364,7 @@ public class SqlTask extends AbstractTask { Connection connection){ if (resultSet != null){ try { - connection.close(); + resultSet.close(); } catch (SQLException e) { } @@ -372,7 +372,7 @@ public class SqlTask extends AbstractTask { if (pstmt != null){ try { - connection.close(); + pstmt.close(); } catch (SQLException e) { } From d4d6aded1184b803557f444c42253d02887995b9 Mon Sep 17 00:00:00 2001 From: sky <740051880@qq.com> Date: Tue, 7 Jul 2020 16:34:50 +0800 Subject: [PATCH 3/3] feature user register (#3159) fix bug fix security problem fix security problem Co-authored-by: dev_sky --- .../api/configuration/AppConfiguration.java | 3 +- .../api/controller/UsersController.java | 31 +++++++++++++ .../api/service/UsersService.java | 33 ++++++++++++++ .../api/controller/UsersControllerTest.java | 19 ++++++++ .../api/service/UsersServiceTest.java | 45 +++++++++++++++++++ 5 files changed, 130 insertions(+), 1 deletion(-) diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/configuration/AppConfiguration.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/configuration/AppConfiguration.java index 73ff74fd3d..3698370fbd 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/configuration/AppConfiguration.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/configuration/AppConfiguration.java @@ -35,6 +35,7 @@ public class AppConfiguration implements WebMvcConfigurer { public static final String LOGIN_INTERCEPTOR_PATH_PATTERN = "/**/*"; public static final String LOGIN_PATH_PATTERN = "/login"; + public static final String REGISTER_PATH_PATTERN = "/users/register"; public static final String PATH_PATTERN = "/**"; public static final String LOCALE_LANGUAGE_COOKIE = "language"; public static final int COOKIE_MAX_AGE = 3600; @@ -76,7 +77,7 @@ public class AppConfiguration implements WebMvcConfigurer { //i18n registry.addInterceptor(localeChangeInterceptor()); - registry.addInterceptor(loginInterceptor()).addPathPatterns(LOGIN_INTERCEPTOR_PATH_PATTERN).excludePathPatterns(LOGIN_PATH_PATTERN,"/swagger-resources/**", "/webjars/**", "/v2/**", "/doc.html", "*.html", "/ui/**"); + registry.addInterceptor(loginInterceptor()).addPathPatterns(LOGIN_INTERCEPTOR_PATH_PATTERN).excludePathPatterns(LOGIN_PATH_PATTERN, REGISTER_PATH_PATTERN, "/swagger-resources/**", "/webjars/**", "/v2/**", "/doc.html", "*.html", "/ui/**"); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UsersController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UsersController.java index 456d8c29c7..39b9b06337 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UsersController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UsersController.java @@ -410,5 +410,36 @@ public class UsersController extends BaseController { } } + /** + * user register + * + * @param userName user name + * @param userPassword user password + * @param repeatPassword repeat password + * @param email user email + */ + @ApiOperation(value="registerUser",notes = "REGISTER_USER_NOTES") + @ApiImplicitParams({ + @ApiImplicitParam(name = "userName", value = "USER_NAME", type = "String"), + @ApiImplicitParam(name = "userPassword", value = "USER_PASSWORD", type = "String"), + @ApiImplicitParam(name = "repeatPassword", value = "REPEAT_PASSWORD", type = "String"), + @ApiImplicitParam(name = "email", value = "EMAIL", type = "String"), + }) + @PostMapping("/register") + @ResponseStatus(HttpStatus.OK) + @ApiException(CREATE_USER_ERROR) + public Result registerUser(@RequestParam(value = "userName") String userName, + @RequestParam(value = "userPassword") String userPassword, + @RequestParam(value = "repeatPassword") String repeatPassword, + @RequestParam(value = "email") String email) throws Exception { + userName = userName.replaceAll("[\n|\r|\t]", ""); + userPassword = userPassword.replaceAll("[\n|\r|\t]", ""); + repeatPassword = repeatPassword.replaceAll("[\n|\r|\t]", ""); + email = email.replaceAll("[\n|\r|\t]", ""); + logger.info("user self-register, userName: {}, userPassword {}, repeatPassword {}, eamil {}", + userName, userPassword, repeatPassword, email); + Map result = usersService.registerUser(userName, userPassword, repeatPassword, email); + return returnDataList(result); + } } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java index 09d4824133..bf51261e15 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java @@ -908,4 +908,37 @@ public class UsersService extends BaseService { } } } + + /** + * register user, default state is 0, default tenant_id is 1, no phone, no queue + * + * @param userName user name + * @param userPassword user password + * @param repeatPassword repeat password + * @param email email + * @return register result code + * @throws Exception exception + */ + @Transactional(rollbackFor = Exception.class) + public Map registerUser(String userName, String userPassword, String repeatPassword, String email) throws Exception { + Map result = new HashMap<>(5); + + //check user params + String msg = this.checkUserParams(userName, userPassword, email, ""); + + if (!StringUtils.isEmpty(msg)) { + putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR,msg); + return result; + } + + if (!userPassword.equals(repeatPassword)) { + putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, "two passwords are not same"); + return result; + } + + createUser(userName, userPassword, email, 1, "", "", 0); + putMsg(result, Status.SUCCESS); + return result; + } + } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/UsersControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/UsersControllerTest.java index 2e305a0d89..fc86632ed7 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/UsersControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/UsersControllerTest.java @@ -268,4 +268,23 @@ public class UsersControllerTest extends AbstractControllerTest{ Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } + + @Test + public void testRegisterUser() throws Exception { + MultiValueMap paramsMap = new LinkedMultiValueMap<>(); + paramsMap.add("userName","user_test"); + paramsMap.add("userPassword","123456qwe?"); + paramsMap.add("repeatPassword", "123456qwe?"); + paramsMap.add("email","12343534@qq.com"); + + MvcResult mvcResult = mockMvc.perform(post("/users/register") + .params(paramsMap)) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) + .andReturn(); + + Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); + Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); + logger.info(mvcResult.getResponse().getContentAsString()); + } } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java index 7df3091c70..6939e6a280 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java @@ -453,6 +453,51 @@ public class UsersServiceTest { Assert.assertTrue(CollectionUtils.isNotEmpty(userList)); } + @Test + public void testRegisterUser() { + String userName = "userTest0002~"; + String userPassword = "userTest"; + String repeatPassword = "userTest"; + String email = "123@qq.com"; + try { + //userName error + Map result = usersService.registerUser(userName, userPassword, repeatPassword, email); + logger.info(result.toString()); + Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, result.get(Constants.STATUS)); + + userName = "userTest0002"; + userPassword = "userTest000111111111111111"; + //password error + result = usersService.registerUser(userName, userPassword, repeatPassword, email); + logger.info(result.toString()); + Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, result.get(Constants.STATUS)); + + userPassword = "userTest0002"; + email = "1q.com"; + //email error + result = usersService.registerUser(userName, userPassword, repeatPassword, email); + logger.info(result.toString()); + Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, result.get(Constants.STATUS)); + + //repeatPassword error + email = "7400@qq.com"; + repeatPassword = "userPassword"; + result = usersService.registerUser(userName, userPassword, repeatPassword, email); + logger.info(result.toString()); + Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, result.get(Constants.STATUS)); + + //success + repeatPassword = "userTest0002"; + result = usersService.registerUser(userName, userPassword, repeatPassword, email); + logger.info(result.toString()); + Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); + + } catch (Exception e) { + logger.error(Status.CREATE_USER_ERROR.getMsg(),e); + Assert.assertTrue(false); + } + } + /** * get user * @return