Browse Source

[Improve] Hide Change Pwd Page When Login With LDAP (#11041)

* hide-change-pwd-page-when-ldap-login

* add unit test
3.1.0-release
旺阳 2 years ago committed by GitHub
parent
commit
28b40da1b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/security/SecurityConfig.java
  2. 15
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/security/impl/AbstractAuthenticator.java
  3. 6
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/LoginControllerTest.java
  4. 9
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java

4
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/security/SecurityConfig.java

@ -72,4 +72,8 @@ public class SecurityConfig {
beanFactory.autowireBean(authenticator);
return authenticator;
}
public String getType() {
return type;
}
}

15
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/security/impl/AbstractAuthenticator.java

@ -19,6 +19,7 @@ package org.apache.dolphinscheduler.api.security.impl;
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.security.Authenticator;
import org.apache.dolphinscheduler.api.security.SecurityConfig;
import org.apache.dolphinscheduler.api.service.SessionService;
import org.apache.dolphinscheduler.api.service.UsersService;
import org.apache.dolphinscheduler.api.utils.Result;
@ -27,7 +28,7 @@ import org.apache.dolphinscheduler.common.enums.Flag;
import org.apache.dolphinscheduler.dao.entity.Session;
import org.apache.dolphinscheduler.dao.entity.User;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
@ -41,9 +42,13 @@ public abstract class AbstractAuthenticator implements Authenticator {
@Autowired
private UsersService userService;
@Autowired
private SessionService sessionService;
@Autowired
private SecurityConfig securityConfig;
/**
* user login and return user in db
*
@ -78,8 +83,14 @@ public abstract class AbstractAuthenticator implements Authenticator {
result.setMsg(Status.LOGIN_SESSION_FAILED.getMsg());
return result;
}
logger.info("sessionId : {}", sessionId);
result.setData(Collections.singletonMap(Constants.SESSION_ID, sessionId));
Map<String, String> data = new HashMap<>();
data.put(Constants.SESSION_ID, sessionId);
data.put(Constants.SECURITY_CONFIG_TYPE, securityConfig.getType());
result.setData(data);
result.setCode(Status.SUCCESS.getCode());
result.setMsg(Status.LOGIN_SUCCESS.getMsg());
return result;

6
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/LoginControllerTest.java

@ -23,8 +23,11 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.common.utils.JSONUtils;
import java.util.Map;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
@ -55,6 +58,9 @@ public class LoginControllerTest extends AbstractControllerTest {
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
logger.info(mvcResult.getResponse().getContentAsString());
Map<String, String> data = (Map<String, String>) result.getData();
Assert.assertEquals(Constants.SECURITY_CONFIG_TYPE_PASSWORD,data.get(Constants.SECURITY_CONFIG_TYPE));
Assert.assertNotEquals(Constants.SECURITY_CONFIG_TYPE_LDAP,data.get(Constants.SECURITY_CONFIG_TYPE));
}
@Test

9
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java

@ -842,4 +842,13 @@ public final class Constants {
public static final String FUNCTION_START_WITH = "$";
public static final Integer DEFAULT_QUEUE_ID = 1;
/**
* Security authentication types (supported types: PASSWORD,LDAP)
*/
public static final String SECURITY_CONFIG_TYPE = "securityConfigType";
public static final String SECURITY_CONFIG_TYPE_PASSWORD = "PASSWORD";
public static final String SECURITY_CONFIG_TYPE_LDAP = "LDAP";
}

Loading…
Cancel
Save