Skip to content

Commit

Permalink
Optimize the user manage of admin and workspace framework.
Browse files Browse the repository at this point in the history
  • Loading branch information
wushengyeyouya committed Apr 26, 2022
1 parent 21cc4db commit b6cd8d1
Show file tree
Hide file tree
Showing 27 changed files with 227 additions and 533 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
import com.webank.wedatasphere.dss.standard.app.sso.SSOIntegrationStandard;
import com.webank.wedatasphere.dss.standard.app.sso.SSOIntegrationStandardFactory;
import com.webank.wedatasphere.dss.standard.app.sso.origin.OriginSSOIntegrationStandardFactory;
import com.webank.wedatasphere.dss.standard.app.sso.user.SSOUserService;
import com.webank.wedatasphere.dss.standard.app.sso.user.impl.SSOUserServiceImpl;
import com.webank.wedatasphere.dss.standard.common.utils.AppStandardClassUtils;
import com.webank.wedatasphere.dss.standard.sso.utils.SSOHelper;
import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.LoggerFactory;

public abstract class AbstractOnlySSOAppConn extends AbstractAppConn implements OnlySSOAppConn {
Expand All @@ -37,6 +40,14 @@ public final void init() throws AppConnErrorException {
SSO_INTEGRATION_STANDARD = ssoIntegrationStandardFactory.getSSOIntegrationStandard();
LoggerFactory.getLogger(AbstractOnlySSOAppConn.class).info("For the first SSO Standard of {} AppConn, {} has created {}.", getAppDesc().getAppName(),
ssoIntegrationStandardFactory.getClass().getName(), SSO_INTEGRATION_STANDARD.getClass().getName());
if(CollectionUtils.isNotEmpty(getAppDesc().getAppInstances())) {
getAppDesc().getAppInstances().forEach(appInstance -> {
SSOUserService ssoUserService = SSO_INTEGRATION_STANDARD.getSSOUserService(appInstance);
if(ssoUserService instanceof SSOUserServiceImpl) {
((SSOUserServiceImpl) ssoUserService).setAppConnName(getAppDesc().getAppName());
}
});
}
// considering the plugin design model in different classloader, We must set it when each AppConn is instanced.
SSOHelper.setSSOBuilderService(SSO_INTEGRATION_STANDARD.getSSOBuilderService());
super.init();
Expand Down
6 changes: 6 additions & 0 deletions dss-framework/dss-framework-admin-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@
<version>${linkis.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.webank.wedatasphere.dss</groupId>
<artifactId>dss-appconn-manager-client</artifactId>
<version>${dss.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonFormat;

public class BaseEntity implements Serializable
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@

import org.apache.linkis.common.conf.CommonVars;

public interface ProjectConf {

CommonVars<String> SUPPORT_ABILITY = CommonVars.apply("wds.dss.framework.project.support.ability", "import,export,publish");
CommonVars<String> SERVICE_NAME = CommonVars.apply("wds.dss.framework.project.service.name", "dss-framework-project-server");

CommonVars<String> DS_ADMIN_TOKEN = CommonVars.apply("wds.dss.ds.token", "");
CommonVars<String> DS_URL = CommonVars.apply("wds.dss.ds.url", "");
public interface AdminConf {

CommonVars<String> LDAP_ADMIN_NAME = CommonVars.apply("wds.dss.ldap.admin.name", "");
CommonVars<String> LDAP_ADMIN_PASS = CommonVars.apply("wds.dss.ldap.admin.password", "");
Expand All @@ -35,5 +29,6 @@ public interface ProjectConf {
CommonVars<String> EXCHANGE_URL = CommonVars.apply("wds.dss.exchange.url", "");
CommonVars<String> EXCHANGE_ADMIN_COOKIE = CommonVars.apply("wds.dss.exchange.cookie", "");

String[] SUPER_ADMIN_LIST = CommonVars.apply("wds.dss.super.admin", "").getValue().split(",");

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,13 @@

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;

import java.time.LocalDateTime;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.webank.wedatasphere.dss.framework.admin.common.domain.BaseEntity;
//import io.swagger.annotations.ApiModel;
//import io.swagger.annotations.ApiModelProperty;
//import lombok.Data;
//import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.util.Date;

/**
* <p>
* 用户信息表
Expand All @@ -30,7 +21,6 @@ public class DssAdminUser extends BaseEntity {
* user_id
*/
@TableId(type = IdType.AUTO)

private Long id;

/**
Expand Down Expand Up @@ -76,6 +66,10 @@ public class DssAdminUser extends BaseEntity {
*/
private String delFlag;

private Date lastLoginTime;

private Integer loginNum;

public void setId(Long id) {
this.id = id;
}
Expand Down Expand Up @@ -156,6 +150,22 @@ public String getDelFlag() {
return delFlag;
}

public Date getLastLoginTime() {
return lastLoginTime;
}

public void setLastLoginTime(Date lastLoginTime) {
this.lastLoginTime = lastLoginTime;
}

public Integer getLoginNum() {
return loginNum;
}

public void setLoginNum(Integer loginNum) {
this.loginNum = loginNum;
}

@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
Expand All @@ -172,6 +182,8 @@ public String toString() {
.append("createTime" , getCreateTime())
.append("updateTime" , getUpdateTime())
.append("remark" , getRemark())
.append("lastLoginTime", lastLoginTime)
.append("loginNum" , loginNum)
.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@
import com.webank.wedatasphere.dss.framework.admin.common.domain.TableDataInfo;
import com.webank.wedatasphere.dss.framework.admin.common.utils.PasswordUtils;
import com.webank.wedatasphere.dss.framework.admin.common.utils.StringUtils;
import com.webank.wedatasphere.dss.framework.admin.conf.ProjectConf;
import com.webank.wedatasphere.dss.framework.admin.conf.AdminConf;
import com.webank.wedatasphere.dss.framework.admin.pojo.entity.DssAdminUser;
import com.webank.wedatasphere.dss.framework.admin.service.DssAdminUserService;
import com.webank.wedatasphere.dss.framework.admin.service.LdapService;
import com.webank.wedatasphere.dss.framework.admin.xml.DssUserMapper;
import org.apache.linkis.server.security.SecurityFilter;
import com.webank.wedatasphere.dss.standard.app.sso.Workspace;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.linkis.server.security.SecurityFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -72,24 +73,29 @@ public Message add(@Validated @RequestBody DssAdminUser user, HttpServletRequest
} else if (!PasswordResult.PASSWORD_RULE_PASS.equals(passwordResult)) {
return Message.error().data("弱密码请关注:", passwordResult.getMessage());
}
boolean ldapExist = ldapService.exist(ProjectConf.LDAP_ADMIN_NAME.getValue(), ProjectConf.LDAP_ADMIN_PASS.getValue(), ProjectConf.LDAP_URL.getValue(), ProjectConf.LDAP_BASE_DN.getValue(), user.getUserName());
boolean ldapExist = ldapService.exist(AdminConf.LDAP_ADMIN_NAME.getValue(), AdminConf.LDAP_ADMIN_PASS.getValue(), AdminConf.LDAP_URL.getValue(), AdminConf.LDAP_BASE_DN.getValue(), user.getUserName());
if (ldapExist) {
return Message.error().message("新增用户'" + user.getUserName() + "'失败,登录账号在ldap已存在");
}

String pwd = user.getPassword();
user.setPassword(DigestUtils.md5Hex(pwd));
user.setCreateBy(SecurityFilter.getLoginUsername(req));
int rows = dssAdminUserService.insertUser(user);
int rows = dssAdminUserService.insertUser(user, getWorkspace(req));
String userName = user.getUserName();
ldapService.addUser(ProjectConf.LDAP_ADMIN_NAME.getValue(), ProjectConf.LDAP_ADMIN_PASS.getValue(), ProjectConf.LDAP_URL.getValue(), ProjectConf.LDAP_BASE_DN.getValue(), userName, pwd);
ldapService.addUser(AdminConf.LDAP_ADMIN_NAME.getValue(), AdminConf.LDAP_ADMIN_PASS.getValue(), AdminConf.LDAP_URL.getValue(), AdminConf.LDAP_BASE_DN.getValue(), userName, pwd);
return Message.ok().data("rows", rows).message("新增成功");
} catch (Exception exception) {
return Message.error().data("rows", 0).message(exception.getMessage());
}

}

private Workspace getWorkspace(HttpServletRequest req) {
Workspace workspace = new Workspace();
workspace.setCookies(Arrays.stream(req.getCookies()).collect(HashMap::new, (map, cookie) -> map.put(cookie.getName(), cookie.getValue()), HashMap::putAll));
return workspace;
}


@RequestMapping(path = "{id}", method = RequestMethod.GET)
public Message getInfo(@PathVariable("id") Long userId) {
Expand All @@ -98,35 +104,16 @@ public Message getInfo(@PathVariable("id") Long userId) {


@RequestMapping(path = "edit", method = RequestMethod.POST)
public Message edit(@Validated @RequestBody DssAdminUser user) {
public Message edit(@Validated @RequestBody DssAdminUser user, HttpServletRequest req) {
if (StringUtils.isNotEmpty(user.getPhonenumber())
&& UserConstants.NOT_UNIQUE.equals(dssAdminUserService.checkPhoneUnique(user))) {
return Message.error().message("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
} else if (StringUtils.isNotEmpty(user.getEmail())
&& UserConstants.NOT_UNIQUE.equals(dssAdminUserService.checkEmailUnique(user))) {
return Message.error().message("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
}
// user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
return Message.ok().data("修改用户成功", dssAdminUserService.updateUser(user));
return Message.ok().data("修改用户成功。", dssAdminUserService.updateUser(user, getWorkspace(req)));
}

// @POST
// @Path("/resetPsw")
/* @RequestMapping(path ="resetPsw", method = RequestMethod.POST)
public Message resetPwd(@RequestBody DssAdminUser user) {
try {
PasswordResult passwordResult = PasswordUtils.checkPwd(user.getPassword(), user);
if (!PasswordResult.PASSWORD_RULE_PASS.equals(passwordResult)) {
return Message.error().data("弱密码请关注:",passwordResult.getMessage());
}
DssAdminUser dssAdminUser = dssUserMapper.selectUserById(user.getId());
ldapService.update(ProjectConf.LDAP_ADMIN_NAME.getValue(), ProjectConf.LDAP_ADMIN_PASS.getValue(), ProjectConf.LDAP_URL.getValue(), ProjectConf.LDAP_BASE_DN.getValue(), dssAdminUser.getUserName(), user.getPassword());
user.setPassword(DigestUtils.md5Hex(user.getPassword()));
return Message.ok().data("重置密码成功", dssAdminUserService.resetPwd(user));
} catch (Exception exception) {
return Message.error().message(exception.getMessage());
}
}*/
}

Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import java.util.List;
import java.util.stream.Collectors;

import static com.webank.wedatasphere.dss.framework.admin.conf.ProjectConf.*;

@RequestMapping(path = "/dss/framework/admin/user", produces = {"application/json"})
@RestController
public class DssProxyUserController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.webank.wedatasphere.dss.framework.admin.pojo.entity.DssAdminUser;
import com.baomidou.mybatisplus.extension.service.IService;
import com.webank.wedatasphere.dss.standard.app.sso.Workspace;

import java.util.List;

Expand All @@ -13,13 +14,14 @@ public interface DssAdminUserService extends IService<DssAdminUser> {

String checkEmailUnique(DssAdminUser user);

int insertUser(DssAdminUser user);
void insertOrUpdateUser(String username, Workspace workspace);

int insertUser(DssAdminUser user, Workspace workspace);

List<DssAdminUser> selectUserList(DssAdminUser user);

DssAdminUser selectUserById(Long userId);

int updateUser(DssAdminUser user);
int updateUser(DssAdminUser user, Workspace workspace);

public int resetPwd(DssAdminUser user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.squareup.okhttp.Call;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import com.webank.wedatasphere.dss.framework.admin.conf.ProjectConf;
import com.webank.wedatasphere.dss.framework.admin.conf.AdminConf;
import com.webank.wedatasphere.dss.framework.admin.pojo.entity.DssExchangeTask;
import com.webank.wedatasphere.dss.framework.admin.pojo.entity.DssExchangeTaskRes;
import com.webank.wedatasphere.dss.framework.admin.pojo.entity.DssExchangisProject;
Expand All @@ -18,7 +16,6 @@
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -34,11 +31,11 @@ public class DssExchangeService {
private static final Logger LOGGER = LoggerFactory.getLogger(OkHttpHelper.class);

public List<DssExchangisProject> queryExchangeProject(String userName) throws Exception {
String url = ProjectConf.EXCHANGE_URL.getValue() + PROJECT_TREE_PATH + "/"+userName;
String url = AdminConf.EXCHANGE_URL.getValue() + PROJECT_TREE_PATH + "/"+userName;
Request getRequest = new Request.Builder()
.url(url)
.addHeader("Content-Type", "application/json")
.addHeader("Cookie", ProjectConf.EXCHANGE_ADMIN_COOKIE.getValue())
.addHeader("Cookie", AdminConf.EXCHANGE_ADMIN_COOKIE.getValue())
.build();
Response response = OkHttpHelper.syncGet(getRequest);
JsonObject returnData = new JsonParser().parse(response.body().string()).getAsJsonObject();
Expand All @@ -50,12 +47,12 @@ public List<DssExchangisProject> queryExchangeProject(String userName) throws Ex
}

public DssExchangeTaskRes queryExchangeTask(int projectId, String userName, int pageNum, String fullName) throws Exception {
String url = ProjectConf.EXCHANGE_URL.getValue() + TASK_TREE_PATH + "/" + userName +
String url = AdminConf.EXCHANGE_URL.getValue() + TASK_TREE_PATH + "/" + userName +
"?projectId=" + projectId + "&page=" + pageNum + "&pageSize=10&fuzzyName=&jobId=";
Request getRequest = new Request.Builder()
.url(url)
.addHeader("Content-Type", "application/json")
.addHeader("Cookie", ProjectConf.EXCHANGE_ADMIN_COOKIE.getValue())
.addHeader("Cookie", AdminConf.EXCHANGE_ADMIN_COOKIE.getValue())
.get()
.build();
Response response = OkHttpHelper.syncGet(getRequest);
Expand Down Expand Up @@ -95,7 +92,7 @@ public DssExchangeTaskRes queryExchangeTask(int projectId, String userName, int
public String getSellScript(int taskId, int projectId) {
String shellScript = "str=`curl -X GET --data '{\"project_id\":" + projectId + ",\"task_id\":" + taskId + "}' " +
"--header 'Content-Type: application/json' --header 'Accept: application/json' " +
"--header 'Cookie:" + ProjectConf.EXCHANGE_ADMIN_COOKIE.getValue() + "' " + ProjectConf.EXCHANGE_URL.getValue() +
"--header 'Cookie:" + AdminConf.EXCHANGE_ADMIN_COOKIE.getValue() + "' " + AdminConf.EXCHANGE_URL.getValue() +
"/api/v1/jobinfo/runTask/" + taskId + "?userName=admin`;if [[ ${str} =~ 'job execution successed' ]];then exit 0;else exit 1;fi";
return shellScript;
}
Expand Down
Loading

0 comments on commit b6cd8d1

Please sign in to comment.