com.didiglobal.logi.security.util.HttpRequestUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of logi-security-spring-boot-starter Show documentation
Show all versions of logi-security-spring-boot-starter Show documentation
logi-security 提供项目大多都需要的一些基础功能(用户、角色、权限、登录、注册、操作记录)
package com.didiglobal.logi.security.util;
import org.springframework.util.StringUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
/**
* @author cjm
*
* http请求操作类
*/
public class HttpRequestUtil {
public static final String USER = "X-SSO-USER";
public static final String APPID = "X-LOGI-SECURITY-APP-ID";
private HttpRequestUtil() {
throw new IllegalStateException("Utility class");
}
public static String getFromHeader(HttpServletRequest request, String key, String defaultValue) {
String value = request.getHeader(key);
return value == null ? defaultValue : value;
}
public static Integer getOperatorId(HttpServletRequest request) {
HttpSession session = request.getSession();
Integer id = (Integer) session.getAttribute(HttpRequestUtil.USER);
if(id == null) {
return 1;
}
return id;
}
public static String getOperatorFromHeader(HttpServletRequest request) {
return request.getHeader(USER);
}
public static Integer getAppId(HttpServletRequest request, int defaultAppid) {
String appidStr = request.getHeader(APPID);
if (StringUtils.isEmpty(appidStr)) {
return defaultAppid;
}
return Integer.valueOf(appidStr);
}
public static Integer getAppId(HttpServletRequest request) {
String appidStr = request.getHeader(APPID);
if (StringUtils.isEmpty(appidStr)) {
return null;
}
return Integer.valueOf(appidStr);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy