|
@@ -16,6 +16,8 @@ import javax.servlet.http.HttpServletResponse;
|
|
*/
|
|
*/
|
|
public abstract class AbstractAuthServiceImpl implements AuthService {
|
|
public abstract class AbstractAuthServiceImpl implements AuthService {
|
|
|
|
|
|
|
|
+ private static final String MIDDLEWARE_GROUP_CODE="middleware.group.code";
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public boolean validateLogin(HttpServletRequest request, HttpServletResponse response) {
|
|
public boolean validateLogin(HttpServletRequest request, HttpServletResponse response) {
|
|
// 登录认证通常在网关完成,无网关服务在此完成
|
|
// 登录认证通常在网关完成,无网关服务在此完成
|
|
@@ -44,26 +46,37 @@ public abstract class AbstractAuthServiceImpl implements AuthService {
|
|
*/
|
|
*/
|
|
protected void loadContextByRequest(HttpServletRequest request) {
|
|
protected void loadContextByRequest(HttpServletRequest request) {
|
|
AppContext context = AppContext.getContext();
|
|
AppContext context = AppContext.getContext();
|
|
|
|
+ // 1.默认从url中获取
|
|
if (SpringHelper.getBoolean(AppContext.PERSAGY_COMMON_AUTH_CONTEXT_SOURCE,true)){
|
|
if (SpringHelper.getBoolean(AppContext.PERSAGY_COMMON_AUTH_CONTEXT_SOURCE,true)){
|
|
context.setGroupCode(request.getParameter(AppContext.GROUP_CODE));
|
|
context.setGroupCode(request.getParameter(AppContext.GROUP_CODE));
|
|
context.setProjectId(request.getParameter(AppContext.PROJECT_ID));
|
|
context.setProjectId(request.getParameter(AppContext.PROJECT_ID));
|
|
context.setAppId(request.getParameter(AppContext.APP_ID));
|
|
context.setAppId(request.getParameter(AppContext.APP_ID));
|
|
context.setAccountId(request.getParameter(AppContext.USER_ID));
|
|
context.setAccountId(request.getParameter(AppContext.USER_ID));
|
|
- }else {
|
|
|
|
|
|
+ }
|
|
|
|
+ context.setToken(request.getHeader(AppContext.TOKEN));
|
|
|
|
+ // 2.以下为补偿措施
|
|
|
|
+ // 2.1 处理集团编码
|
|
|
|
+ if(StrUtil.isBlank(context.getGroupCode())
|
|
|
|
+ && StrUtil.isNotBlank(request.getHeader(AppContext.GROUP_CODE))) {
|
|
context.setGroupCode(request.getHeader(AppContext.GROUP_CODE));
|
|
context.setGroupCode(request.getHeader(AppContext.GROUP_CODE));
|
|
|
|
+ }
|
|
|
|
+ if(StrUtil.isBlank(context.getGroupCode())) {
|
|
|
|
+ context.setGroupCode(SpringHelper.getString(MIDDLEWARE_GROUP_CODE));
|
|
|
|
+ }
|
|
|
|
+ // 2.2 处理项目id
|
|
|
|
+ if(StrUtil.isBlank(context.getProjectId())
|
|
|
|
+ && StrUtil.isNotBlank(request.getHeader(AppContext.PROJECT_ID))) {
|
|
context.setProjectId(request.getHeader(AppContext.PROJECT_ID));
|
|
context.setProjectId(request.getHeader(AppContext.PROJECT_ID));
|
|
|
|
+ }
|
|
|
|
+ // 2.3 处理appId
|
|
|
|
+ if(StrUtil.isBlank(context.getAppId())
|
|
|
|
+ && StrUtil.isNotBlank(request.getHeader(AppContext.APP_ID))) {
|
|
context.setAppId(request.getHeader(AppContext.APP_ID));
|
|
context.setAppId(request.getHeader(AppContext.APP_ID));
|
|
|
|
+ }
|
|
|
|
+ // 2.4 处理账号id
|
|
|
|
+ if(StrUtil.isBlank(context.getAccountId())
|
|
|
|
+ && StrUtil.isNotBlank(request.getHeader(AppContext.USER_ID))) {
|
|
context.setAccountId(request.getHeader(AppContext.USER_ID));
|
|
context.setAccountId(request.getHeader(AppContext.USER_ID));
|
|
- // 无集团编码时,默认为配置的集团编码
|
|
|
|
- String groupCode = request.getHeader(AppContext.GROUP_CODE);
|
|
|
|
- if(StrUtil.isBlank(groupCode)) {
|
|
|
|
- context.setGroupCode(SpringHelper.getString("middleware.group.code"));
|
|
|
|
- }
|
|
|
|
- // 无项目id时,尝试从请求URL中获取
|
|
|
|
- if (StrUtil.isBlank(request.getHeader(AppContext.PROJECT_ID))
|
|
|
|
- && StrUtil.isNotBlank(request.getParameter(CommonConstant.QUERY_PROJECTID))){
|
|
|
|
- context.setProjectId(request.getParameter(CommonConstant.QUERY_PROJECTID));
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
// 无用户时,默认为默认系统用户
|
|
// 无用户时,默认为默认系统用户
|
|
if(StrUtil.isBlank(context.getAccountId())) {
|
|
if(StrUtil.isBlank(context.getAccountId())) {
|