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 28, 2022
1 parent e54c2f9 commit 926d669
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import com.webank.wedatasphere.dss.framework.admin.service.LdapService;
import com.webank.wedatasphere.dss.framework.admin.xml.DssUserMapper;
import com.webank.wedatasphere.dss.standard.app.sso.Workspace;
import com.webank.wedatasphere.dss.standard.common.exception.AppStandardWarnException;
import com.webank.wedatasphere.dss.standard.sso.utils.SSOHelper;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.linkis.server.security.SecurityFilter;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -21,7 +23,6 @@

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 @@ -92,7 +93,9 @@ public Message add(@Validated @RequestBody DssAdminUser user, HttpServletRequest

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));
try {
SSOHelper.addWorkspaceInfo(req, workspace);
} catch (AppStandardWarnException ignored) {} // ignore it.
return workspace;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import com.webank.wedatasphere.dss.framework.workspace.bean.vo.DepartmentVO;
import com.webank.wedatasphere.dss.framework.workspace.service.DSSWorkspaceService;
import com.webank.wedatasphere.dss.framework.workspace.util.WorkspaceDBHelper;
import com.webank.wedatasphere.dss.standard.app.sso.Workspace;
import com.webank.wedatasphere.dss.standard.common.exception.AppStandardWarnException;
import com.webank.wedatasphere.dss.standard.sso.utils.SSOHelper;
import org.apache.linkis.common.exception.ErrorException;
import org.apache.linkis.server.Message;
Expand Down Expand Up @@ -96,7 +98,11 @@ public Message getWorkspaces(HttpServletRequest request){
public Message getWorkspaceHomePage(HttpServletRequest request, @RequestParam(required = false, name = "micro_module") String moduleName) throws Exception{
//如果用户的工作空间大于两个,那么就直接返回/workspace页面
String username = SecurityFilter.getLoginUsername(request);
dssUserService.insertOrUpdateUser(username, SSOHelper.getWorkspace(request));
Workspace workspace = new Workspace();
try {
SSOHelper.addWorkspaceInfo(request, workspace);
} catch (AppStandardWarnException ignored) {} // ignore it.
dssUserService.insertOrUpdateUser(username, workspace);
DSSWorkspaceHomePageVO dssWorkspaceHomePageVO = dssWorkspaceService.getWorkspaceHomePage(username,moduleName);
return Message.ok().data("workspaceHomePage", dssWorkspaceHomePageVO);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,23 @@ public static Workspace getWorkspace(Map<String, String> cookies) {
return workspace;
}

private static void addWorkspaceInfo(HttpServletRequest request, Workspace workspace) {
// String forwardedHost = request.getHeader("X-Forwarded-Host");
// if(StringUtils.isNotBlank(forwardedHost)) {
// workspace.setDssUrl("http://" + forwardedHost);
// }
public static void addWorkspaceInfo(HttpServletRequest request, Workspace workspace) {
String gatewayUrl = request.getHeader("GATEWAY_URL");
if(StringUtils.isNotBlank(gatewayUrl)) {
if(gatewayUrl.startsWith("http")) {
workspace.setDssUrl(gatewayUrl);
} else {
workspace.setDssUrl("http://" + gatewayUrl);
}
}
Cookie[] cookies = request.getCookies();
Arrays.stream(cookies).forEach(cookie -> workspace.addCookie(cookie.getName(), cookie.getValue()));
if(StringUtils.isBlank(workspace.getWorkspaceName())) {
throw new AppStandardWarnException(50010, "Cannot find workspace info from cookies, please ensure front-web has injected cookie['workspaceName'](不能找到工作空间名,请确认前端是否已经注入cookie['workspaceName']).");
}
if(workspace.getWorkspaceId() <= 0) {
throw new AppStandardWarnException(50010, "Cannot find workspace info from cookies, please ensure front-web has injected cookie['workspaceId'](不能找到工作空间名,请确认前端是否已经注入cookie['workspaceId']).");
}
Cookie[] cookies = request.getCookies();
Arrays.stream(cookies).forEach(cookie -> workspace.addCookie(cookie.getName(), cookie.getValue()));
}

public static Workspace getWorkspace(HttpServletRequest request){
Expand Down
4 changes: 1 addition & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@
<module>dss-framework</module>
<module>dss-apps/dss-apiservice-server</module>
<module>dss-apps/dss-scriptis-server</module>
<module>dss-apps/dss-user-guide</module>
<module>plugins/azkaban/linkis-jobtype</module>
<module>plugins/linkis/dss-gateway-support</module>
<module>dss-data-api</module>
<module>dss-data-governance</module>
<module>dss-apps/dss-user-guide</module>
<module>assembly</module>
<module>plugins/dolphinscheduler</module>
</modules>
Expand Down

0 comments on commit 926d669

Please sign in to comment.