sso
This commit is contained in:
@@ -91,6 +91,16 @@ public class SocialsProvider extends JpaBaseEntity implements Serializable {
|
||||
public SocialsProvider() {
|
||||
|
||||
}
|
||||
|
||||
public SocialsProvider(SocialsProvider copy) {
|
||||
this.clientId = copy.getClientId();
|
||||
this.id = copy.getId();
|
||||
this.provider = copy.getProvider();
|
||||
this.providerName = copy.getProviderName();
|
||||
this.agentId = copy.getAgentId();
|
||||
this.icon = copy.getIcon();
|
||||
this.scanCode = copy.getScanCode();
|
||||
}
|
||||
|
||||
public String getProvider() {
|
||||
return provider;
|
||||
|
||||
@@ -33,56 +33,28 @@ public class SocialsProviderLogin implements Serializable {
|
||||
*/
|
||||
private static final long serialVersionUID = -2672107566766342357L;
|
||||
|
||||
List<SocialsProvider> socialSignOnProviders = new ArrayList<SocialsProvider>();
|
||||
List<SocialsProvider> providers = new ArrayList<SocialsProvider>();
|
||||
|
||||
String dingTalkLogin = "none";
|
||||
|
||||
String workWeixinLogin = "none";
|
||||
|
||||
String feiShuLogin = "none";
|
||||
|
||||
String weLinkLogin = "none";
|
||||
String qrScan = null;
|
||||
|
||||
public SocialsProviderLogin(List<SocialsProvider> socialSignOnProviders) {
|
||||
super();
|
||||
this.socialSignOnProviders = socialSignOnProviders;
|
||||
this.providers = socialSignOnProviders;
|
||||
}
|
||||
|
||||
public String getDingTalkLogin() {
|
||||
return dingTalkLogin;
|
||||
public String getQrScan() {
|
||||
return qrScan;
|
||||
}
|
||||
|
||||
public void setDingTalkLogin(String dingTalkLogin) {
|
||||
this.dingTalkLogin = dingTalkLogin;
|
||||
public void setQrScan(String qrScan) {
|
||||
this.qrScan = qrScan;
|
||||
}
|
||||
|
||||
public String getWorkWeixinLogin() {
|
||||
return workWeixinLogin;
|
||||
public List<SocialsProvider> getProviders() {
|
||||
return providers;
|
||||
}
|
||||
|
||||
public void setWorkWeixinLogin(String workWeixinLogin) {
|
||||
this.workWeixinLogin = workWeixinLogin;
|
||||
public void setProviders(List<SocialsProvider> providers) {
|
||||
this.providers = providers;
|
||||
}
|
||||
|
||||
public String getFeiShuLogin() {
|
||||
return feiShuLogin;
|
||||
}
|
||||
|
||||
public void setFeiShuLogin(String feiShuLogin) {
|
||||
this.feiShuLogin = feiShuLogin;
|
||||
}
|
||||
|
||||
public String getWeLinkLogin() {
|
||||
return weLinkLogin;
|
||||
}
|
||||
|
||||
public void setWeLinkLogin(String weLinkLogin) {
|
||||
this.weLinkLogin = weLinkLogin;
|
||||
}
|
||||
|
||||
public List<SocialsProvider> getSocialSignOnProviders() {
|
||||
return socialSignOnProviders;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -36,10 +36,7 @@ public class InstitutionsRepository {
|
||||
private static Logger _logger = LoggerFactory.getLogger(InstitutionsRepository.class);
|
||||
|
||||
private static final String SELECT_STATEMENT =
|
||||
"select * from mxk_institutions where domain = ? " ;
|
||||
|
||||
private static final String SELECT_STATEMENT_BY_ID =
|
||||
"select * from mxk_institutions where id = ? " ;
|
||||
"select * from mxk_institutions where id = ? or domain = ? " ;
|
||||
|
||||
protected static final Cache<String, Institutions> institutionsStore =
|
||||
Caffeine.newBuilder()
|
||||
@@ -54,33 +51,13 @@ public class InstitutionsRepository {
|
||||
public InstitutionsRepository(JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
public Institutions findByDomain(String domain) {
|
||||
_logger.trace(" domain {}" , domain);
|
||||
Institutions inst = institutionsStore.getIfPresent(domain);
|
||||
if(inst == null) {
|
||||
List<Institutions> institutions =
|
||||
jdbcTemplate.query(SELECT_STATEMENT,new InstitutionsRowMapper(),domain);
|
||||
|
||||
if (institutions != null && institutions.size() > 0) {
|
||||
inst = institutions.get(0);
|
||||
institutionsStore.put(domain, inst);
|
||||
mapper.put(inst.getId(), domain);
|
||||
}else {
|
||||
//default institution
|
||||
inst = get("1");
|
||||
}
|
||||
}
|
||||
|
||||
return inst;
|
||||
}
|
||||
|
||||
public Institutions get(String instId) {
|
||||
_logger.trace(" instId {}" , instId);
|
||||
Institutions inst = institutionsStore.getIfPresent(mapper.get(instId)==null ? "1" : mapper.get(instId) );
|
||||
public Institutions get(String instIdOrDomain) {
|
||||
_logger.trace(" instId {}" , instIdOrDomain);
|
||||
Institutions inst = institutionsStore.getIfPresent(mapper.get(instIdOrDomain)==null ? "1" : mapper.get(instIdOrDomain) );
|
||||
if(inst == null) {
|
||||
List<Institutions> institutions =
|
||||
jdbcTemplate.query(SELECT_STATEMENT_BY_ID,new InstitutionsRowMapper(),instId);
|
||||
jdbcTemplate.query(SELECT_STATEMENT,new InstitutionsRowMapper(),instIdOrDomain,instIdOrDomain);
|
||||
|
||||
if (institutions != null && institutions.size() > 0) {
|
||||
inst = institutions.get(0);
|
||||
|
||||
@@ -49,6 +49,8 @@ public class WebConstants {
|
||||
public static final String CURRENT_INST = "current_inst";
|
||||
|
||||
public final static String INST_COOKIE_NAME = "mxk_inst";
|
||||
|
||||
public final static String FRONTEND_BASE_URI = "mxk_frontend_base_uri";
|
||||
|
||||
// SPRING_SECURITY_SAVED_REQUEST
|
||||
public static final String FIRST_SAVED_REQUEST_PARAMETER
|
||||
|
||||
@@ -31,6 +31,7 @@ import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.maxkey.configuration.ApplicationConfig;
|
||||
import org.maxkey.entity.Institutions;
|
||||
import org.maxkey.util.DateUtils;
|
||||
import org.maxkey.util.IdGenerator;
|
||||
import org.maxkey.web.message.Message;
|
||||
@@ -309,6 +310,15 @@ public final class WebContext {
|
||||
public static String getParameter(String name) {
|
||||
return getRequest().getParameter(name);
|
||||
}
|
||||
|
||||
public static Institutions getInst() {
|
||||
return (Institutions)getAttribute(WebConstants.CURRENT_INST);
|
||||
}
|
||||
|
||||
public static String getBaseUri() {
|
||||
return (String)getAttribute(WebConstants.FRONTEND_BASE_URI);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* encoding encodingString by ApplicationConfig.
|
||||
|
||||
@@ -24,7 +24,6 @@ import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.maxkey.configuration.ApplicationConfig;
|
||||
@@ -37,7 +36,9 @@ import org.springframework.web.filter.GenericFilterBean;
|
||||
public class WebInstRequestFilter extends GenericFilterBean {
|
||||
final static Logger _logger = LoggerFactory.getLogger(GenericFilterBean.class);
|
||||
|
||||
public final static String HEADER_HOST = "host";
|
||||
public final static String HEADER_HOST = "host";
|
||||
public final static String HEADER_HOSTNAME = "hostname";
|
||||
public final static String HEADER_ORIGIN = "Origin";
|
||||
|
||||
InstitutionsRepository institutionsRepository;
|
||||
|
||||
@@ -51,17 +52,29 @@ public class WebInstRequestFilter extends GenericFilterBean {
|
||||
|
||||
if(request.getSession().getAttribute(WebConstants.CURRENT_INST) == null) {
|
||||
WebContext.printRequest(request);
|
||||
String host = request.getHeader(HEADER_HOST);
|
||||
String host = request.getHeader(HEADER_HOSTNAME);
|
||||
_logger.trace("hostname {}",host);
|
||||
if(StringUtils.isEmpty(host)) {
|
||||
host = request.getHeader(HEADER_HOST);
|
||||
_logger.trace("host {}",host);
|
||||
}
|
||||
if(StringUtils.isEmpty(host)) {
|
||||
host = applicationConfig.getDomainName();
|
||||
_logger.trace("config domain {}",host);
|
||||
}
|
||||
if(host.indexOf(":")> -1 ) {
|
||||
host = host.split(":")[0];
|
||||
_logger.trace("domain split {}",host);
|
||||
}
|
||||
Institutions institution = institutionsRepository.findByDomain(host);
|
||||
Institutions institution = institutionsRepository.get(host);
|
||||
_logger.trace("{}" ,institution);
|
||||
request.getSession().setAttribute(WebConstants.CURRENT_INST, institution);
|
||||
WebContext.setCookie((HttpServletResponse)servletResponse, host, WebConstants.INST_COOKIE_NAME, institution.getId());
|
||||
|
||||
String origin = request.getHeader(HEADER_ORIGIN);
|
||||
if(StringUtils.isEmpty(origin)) {
|
||||
origin = applicationConfig.getFrontendUri();
|
||||
}
|
||||
request.getSession().setAttribute(WebConstants.FRONTEND_BASE_URI, origin);
|
||||
}
|
||||
chain.doFilter(servletRequest, servletResponse);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user