16 changed files with 935 additions and 1 deletions
Binary file not shown.
@ -1,3 +1,6 @@
|
||||
# open-JSD-8239 |
||||
|
||||
JSD-8239 |
||||
JSD-8239 开源任务材料\ |
||||
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ |
||||
仅作为开发者学习参考使用!禁止用于任何商业用途!\ |
||||
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系hugh处理。 |
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
||||
<plugin> |
||||
<id>com.fr.plugin.xxx.sso</id> |
||||
<name><![CDATA[单点登录]]></name> |
||||
<active>yes</active> |
||||
<version>1.7</version> |
||||
<env-version>10.0</env-version> |
||||
<jartime>2018-07-31</jartime> |
||||
<vendor>fr.open</vendor> |
||||
<description><![CDATA[单点登录]]></description> |
||||
<change-notes><![CDATA[]]></change-notes> |
||||
<extra-core> |
||||
<DBAccessProvider class="com.fr.plugin.xxx.sso.SyncDBAccessProvider"/> |
||||
</extra-core> |
||||
<extra-decision> |
||||
<HttpHandlerProvider class="com.fr.plugin.xxx.sso.SsoRequestHandlerBridge"/> |
||||
<URLAliasProvider class="com.fr.plugin.xxx.sso.SsoRequestURLAliasBridge" /> |
||||
<GlobalRequestFilterProvider class="com.fr.plugin.xxx.sso.SsoFilter"/> |
||||
<WebResourceProvider class="com.fr.plugin.xxx.sso.js.JSCSSBridge"/> |
||||
<LogInOutEventProvider class="com.fr.plugin.xxx.sso.CustomLogInOutEventProvider"/> |
||||
</extra-decision> |
||||
<function-recorder class="com.fr.plugin.xxx.sso.SsoFilter"/> |
||||
</plugin> |
@ -0,0 +1,17 @@
|
||||
package com.fr.plugin.xxx.sso; |
||||
|
||||
import com.fr.decision.fun.impl.AbstractLogInOutEventProvider; |
||||
import com.fr.decision.webservice.login.LogInOutResultInfo; |
||||
import com.fr.general.PropertiesUtils; |
||||
|
||||
/** |
||||
* @Author fr.open |
||||
* @Date 2020/7/18 |
||||
* @Description |
||||
**/ |
||||
public class CustomLogInOutEventProvider extends AbstractLogInOutEventProvider { |
||||
@Override |
||||
public String logoutAction(LogInOutResultInfo result) { |
||||
return PropertiesUtils.getProperties("conf").getProperty("logout"); |
||||
} |
||||
} |
@ -0,0 +1,167 @@
|
||||
package com.fr.plugin.xxx.sso; |
||||
|
||||
import com.fr.data.NetworkHelper; |
||||
import com.fr.decision.authority.data.User; |
||||
import com.fr.decision.fun.impl.AbstractGlobalRequestFilterProvider; |
||||
import com.fr.decision.mobile.terminal.TerminalHandler; |
||||
import com.fr.decision.webservice.utils.DecisionServiceConstants; |
||||
import com.fr.decision.webservice.utils.WebServiceUtils; |
||||
import com.fr.decision.webservice.v10.login.LoginService; |
||||
import com.fr.decision.webservice.v10.login.TokenResource; |
||||
import com.fr.decision.webservice.v10.user.UserService; |
||||
import com.fr.general.PropertiesUtils; |
||||
import com.fr.locale.InterProviderFactory; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.plugin.transform.FunctionRecorder; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.stable.web.Device; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.FilterChain; |
||||
import javax.servlet.ServletException; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.IOException; |
||||
import java.io.PrintWriter; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @Author fr.open |
||||
* @Date 2021/7/14 |
||||
* @Description |
||||
**/ |
||||
@FunctionRecorder |
||||
public class SsoFilter extends AbstractGlobalRequestFilterProvider { |
||||
|
||||
private static String[] NOT_FILTER = { |
||||
"/decision/file", |
||||
"/decision/resources", |
||||
"/system", |
||||
"/materials.min.js.map", |
||||
"/remote", |
||||
"/login", |
||||
"/login/config", |
||||
"/sync" |
||||
}; |
||||
|
||||
@Override |
||||
public String filterName() { |
||||
return "sso"; |
||||
} |
||||
|
||||
@Override |
||||
public String[] urlPatterns() { |
||||
return new String[]{"/*"}; |
||||
} |
||||
|
||||
@Override |
||||
public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) { |
||||
String uid = request.getHeader("OAM_UID"); |
||||
FineLoggerFactory.getLogger().info("get OAM_UID is {}",uid); |
||||
if(uid == null){ |
||||
uid = request.getHeader("LDAPUID"); |
||||
FineLoggerFactory.getLogger().info("get LDAPUID is {}",uid); |
||||
} |
||||
if(uid == null){ |
||||
uid = request.getHeader("OAM_REMOTE_USER"); |
||||
FineLoggerFactory.getLogger().info("get OAM_REMOTE_USER is {}",uid); |
||||
} |
||||
if(isAccept(request) || isLogin(request)){ |
||||
next(request, response, filterChain); |
||||
return; |
||||
} |
||||
FineLoggerFactory.getLogger().info("get OAM_UID is {}",uid); |
||||
if(StringUtils.isNotBlank(uid)){ |
||||
if(!login(uid.toUpperCase(),request,response)){ |
||||
return; |
||||
} |
||||
next(request,response,filterChain); |
||||
return; |
||||
} |
||||
try { |
||||
response.sendRedirect(PropertiesUtils.getProperties("conf").getProperty("login")); |
||||
} catch (IOException e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(),e); |
||||
} |
||||
} |
||||
|
||||
public void next(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) { |
||||
try { |
||||
filterChain.doFilter(httpServletRequest,httpServletResponse); |
||||
} catch (IOException e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(),e); |
||||
} catch (ServletException e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(),e); |
||||
} |
||||
} |
||||
|
||||
private boolean isAccept(HttpServletRequest req) { |
||||
for (int i = 0; i < NOT_FILTER.length; i++) { |
||||
if (req.getRequestURI().contains(NOT_FILTER[i])) { |
||||
return true; |
||||
} |
||||
} |
||||
if (req.getRequestURI().endsWith("/.css") || req.getRequestURI().endsWith("/.js")) { |
||||
return true; |
||||
} |
||||
if(req.getRequestURI().endsWith("/view/form") || req.getRequestURI().endsWith("/view/report")){ |
||||
String viewlet = WebUtils.getHTTPRequestParameter(req, "viewlet"); |
||||
if(StringUtils.isBlank(viewlet)){ |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
private boolean login(String username, HttpServletRequest request, HttpServletResponse response) { |
||||
try { |
||||
User user = UserService.getInstance().getUserByUserName(username); |
||||
if (user == null) { |
||||
FineLoggerFactory.getLogger().error("sso >> User \"{}\" does not exist", username); |
||||
setError(response, String.format("用户[%s]在本系统中不存在", username)); |
||||
return false; |
||||
} |
||||
FineLoggerFactory.getLogger().info("sso >> Getted user: {}", user); |
||||
String token = LoginService.getInstance().login(request, response, username); |
||||
FineLoggerFactory.getLogger().info("sso >> Getted login token: {}", token); |
||||
request.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME, token); |
||||
FineLoggerFactory.getLogger().info("sso >> User[{}] login successfully", username); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error("sso >> Failed to login with[" + username + "]", e); |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
|
||||
private boolean isLogin(HttpServletRequest request) { |
||||
String oldToken = TokenResource.COOKIE.getToken(request); |
||||
return oldToken != null && checkTokenValid(request, (String) oldToken); |
||||
} |
||||
|
||||
private boolean checkTokenValid(HttpServletRequest req, String token) { |
||||
try { |
||||
Device device = NetworkHelper.getDevice(req); |
||||
LoginService.getInstance().loginStatusValid(token, TerminalHandler.getTerminal(req, device)); |
||||
return true; |
||||
} catch (Exception ignore) { |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
private void setError(HttpServletResponse res, String reason) { |
||||
try { |
||||
PrintWriter printWriter = WebUtils.createPrintWriter(res); |
||||
Map<String, Object> map = new HashMap<>(); |
||||
map.put("result", InterProviderFactory.getProvider().getLocText("Fine-Engine_Error_Page_Result")); |
||||
map.put("reason", reason); |
||||
map.put("solution", InterProviderFactory.getProvider().getLocText("Fine-Engine_Please_Contact_Platform_Admin")); |
||||
String page = WebServiceUtils.parseWebPageResourceSafe("com/fr/web/controller/decision/entrance/resources/unavailable.html", map); |
||||
printWriter.write(page); |
||||
printWriter.flush(); |
||||
printWriter.close(); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,20 @@
|
||||
package com.fr.plugin.xxx.sso; |
||||
|
||||
import com.fr.decision.fun.HttpHandler; |
||||
import com.fr.decision.fun.impl.AbstractHttpHandlerProvider; |
||||
import com.fr.plugin.xxx.sso.handle.SyncHandler; |
||||
import com.fr.plugin.transform.FunctionRecorder; |
||||
|
||||
/** |
||||
* @author fr.open |
||||
* @since 2021/07/28 |
||||
*/ |
||||
@FunctionRecorder |
||||
public class SsoRequestHandlerBridge extends AbstractHttpHandlerProvider { |
||||
@Override |
||||
public HttpHandler[] registerHandlers() { |
||||
return new HttpHandler[]{ |
||||
new SyncHandler() |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,18 @@
|
||||
package com.fr.plugin.xxx.sso; |
||||
|
||||
import com.fr.decision.fun.impl.AbstractURLAliasProvider; |
||||
import com.fr.decision.webservice.url.alias.URLAlias; |
||||
import com.fr.decision.webservice.url.alias.URLAliasFactory; |
||||
|
||||
/** |
||||
* @author fr.open |
||||
* @since 2021/07/28 |
||||
*/ |
||||
public class SsoRequestURLAliasBridge extends AbstractURLAliasProvider { |
||||
@Override |
||||
public URLAlias[] registerAlias() { |
||||
return new URLAlias[]{ |
||||
URLAliasFactory.createPluginAlias("/sync", "/sync", true), |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,43 @@
|
||||
package com.fr.plugin.xxx.sso; |
||||
|
||||
import com.fr.db.fun.impl.AbstractDBAccessProvider; |
||||
import com.fr.plugin.xxx.sso.dao.UserInfoDao; |
||||
import com.fr.plugin.xxx.sso.entity.UserInfoEntity; |
||||
import com.fr.stable.db.accessor.DBAccessor; |
||||
import com.fr.stable.db.dao.BaseDAO; |
||||
import com.fr.stable.db.dao.DAOProvider; |
||||
|
||||
/** |
||||
* @Author fr.open |
||||
* @Date 2020/7/24 |
||||
**/ |
||||
public class SyncDBAccessProvider extends AbstractDBAccessProvider { |
||||
|
||||
private static DBAccessor dbAccessor = null; |
||||
|
||||
public static DBAccessor getDbAccessor() { |
||||
return dbAccessor; |
||||
} |
||||
|
||||
@Override |
||||
public DAOProvider[] registerDAO() { |
||||
return new DAOProvider[]{ |
||||
new DAOProvider() { |
||||
@Override |
||||
public Class getEntityClass() { |
||||
return UserInfoEntity.class; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends BaseDAO> getDAOClass() { |
||||
return UserInfoDao.class; |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
|
||||
@Override |
||||
public void onDBAvailable(DBAccessor dbAccessor) { |
||||
SyncDBAccessProvider.dbAccessor = dbAccessor; |
||||
} |
||||
} |
@ -0,0 +1,21 @@
|
||||
package com.fr.plugin.xxx.sso.dao; |
||||
|
||||
import com.fr.plugin.xxx.sso.entity.UserInfoEntity; |
||||
import com.fr.stable.db.dao.BaseDAO; |
||||
import com.fr.stable.db.session.DAOSession; |
||||
|
||||
/** |
||||
* @Author fr.open |
||||
* @Date 2021/7/5 |
||||
* @Description |
||||
**/ |
||||
public class UserInfoDao extends BaseDAO<UserInfoEntity> { |
||||
public UserInfoDao(DAOSession daoSession) { |
||||
super(daoSession); |
||||
} |
||||
|
||||
@Override |
||||
protected Class<UserInfoEntity> getEntityClass() { |
||||
return UserInfoEntity.class; |
||||
} |
||||
} |
@ -0,0 +1,104 @@
|
||||
package com.fr.plugin.xxx.sso.dao.action; |
||||
|
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.plugin.xxx.sso.SyncDBAccessProvider; |
||||
import com.fr.plugin.xxx.sso.dao.UserInfoDao; |
||||
import com.fr.plugin.xxx.sso.entity.UserInfoEntity; |
||||
import com.fr.stable.db.action.DBAction; |
||||
import com.fr.stable.db.dao.DAOContext; |
||||
import com.fr.stable.query.QueryFactory; |
||||
import com.fr.stable.query.restriction.RestrictionFactory; |
||||
|
||||
import java.util.UUID; |
||||
|
||||
/** |
||||
* @Author fr.open |
||||
* @Date 2021/7/29 |
||||
* @Description |
||||
**/ |
||||
public class UserInfoService { |
||||
/** |
||||
* 获取 |
||||
* |
||||
* @param uid |
||||
* @return |
||||
*/ |
||||
public static UserInfoEntity getUserInfoByUid(String uid) { |
||||
try { |
||||
return SyncDBAccessProvider.getDbAccessor().runDMLAction(new DBAction<UserInfoEntity>() { |
||||
@Override |
||||
public UserInfoEntity run(DAOContext daoContext) throws Exception { |
||||
return daoContext.getDAO(UserInfoDao.class).findOne(QueryFactory.create().addRestriction(RestrictionFactory.eq("uid", uid))); |
||||
} |
||||
}); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* 新增 |
||||
* |
||||
* @param entity |
||||
* @return |
||||
*/ |
||||
public static UserInfoEntity create(UserInfoEntity entity) { |
||||
try { |
||||
return SyncDBAccessProvider.getDbAccessor().runDMLAction(new DBAction<UserInfoEntity>() { |
||||
@Override |
||||
public UserInfoEntity run(DAOContext daoContext) throws Exception { |
||||
entity.setId(UUID.randomUUID().toString()); |
||||
daoContext.getDAO(UserInfoDao.class).add(entity); |
||||
return entity; |
||||
} |
||||
}); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* 更新 |
||||
* |
||||
* @param entity |
||||
* @return |
||||
*/ |
||||
public static UserInfoEntity update(UserInfoEntity entity) { |
||||
try { |
||||
return SyncDBAccessProvider.getDbAccessor().runDMLAction(new DBAction<UserInfoEntity>() { |
||||
@Override |
||||
public UserInfoEntity run(DAOContext daoContext) throws Exception { |
||||
daoContext.getDAO(UserInfoDao.class).update(entity); |
||||
return entity; |
||||
} |
||||
}); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* 删除 |
||||
* |
||||
* @param uid |
||||
* @return |
||||
*/ |
||||
public static UserInfoEntity delete(String uid) { |
||||
try { |
||||
return SyncDBAccessProvider.getDbAccessor().runDMLAction(new DBAction<UserInfoEntity>() { |
||||
@Override |
||||
public UserInfoEntity run(DAOContext daoContext) throws Exception { |
||||
UserInfoEntity byUid = getUserInfoByUid(uid); |
||||
daoContext.getDAO(UserInfoDao.class).remove(byUid.getId()); |
||||
return byUid; |
||||
} |
||||
}); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
} |
||||
return null; |
||||
} |
||||
} |
@ -0,0 +1,276 @@
|
||||
package com.fr.plugin.xxx.sso.entity; |
||||
|
||||
import com.fr.stable.db.entity.BaseEntity; |
||||
import com.fr.third.javax.persistence.Column; |
||||
import com.fr.third.javax.persistence.Entity; |
||||
import com.fr.third.javax.persistence.Table; |
||||
|
||||
/** |
||||
* @Author fr.open |
||||
* @Date 2021/7/5 |
||||
* @Description |
||||
**/ |
||||
@Entity |
||||
@Table(name = "plugin_xxx_user_info") |
||||
public class UserInfoEntity extends BaseEntity { |
||||
|
||||
private static final long serialVersionUID = 372666463409260435L; |
||||
|
||||
@Column(name = "uid") |
||||
private String uid; |
||||
@Column(name = "password") |
||||
private String password; |
||||
@Column(name = "lastName") |
||||
private String lastName; |
||||
@Column(name = "lastNameCHN") |
||||
private String lastNameCHN; |
||||
@Column(name = "firstName") |
||||
private String firstName; |
||||
@Column(name = "firstNameCHN") |
||||
private String firstNameCHN; |
||||
@Column(name = "name") |
||||
private String name; |
||||
@Column(name = "displayName") |
||||
private String displayName; |
||||
@Column(name = "nationalIDLast4") |
||||
private String nationalIDLast4; |
||||
@Column(name = "email") |
||||
private String email; |
||||
@Column(name = "buId") |
||||
private String buId; |
||||
@Column(name = "setId") |
||||
private String setId; |
||||
@Column(name = "guid") |
||||
private String guid; |
||||
@Column(name = "empno") |
||||
private String empno; |
||||
@Column(name = "memo") |
||||
private String memo; |
||||
@Column(name = "deptId") |
||||
private String deptId; |
||||
@Column(name = "mobile") |
||||
private String mobile; |
||||
@Column(name = "startDate") |
||||
private String startDate; |
||||
@Column(name = "endDate") |
||||
private String endDate; |
||||
@Column(name = "ext1") |
||||
private String ext1; |
||||
@Column(name = "ext2") |
||||
private String ext2; |
||||
@Column(name = "ext3") |
||||
private String ext3; |
||||
@Column(name = "ext4") |
||||
private String ext4; |
||||
@Column(name = "ext5") |
||||
private String ext5; |
||||
@Column(name = "enable") |
||||
private Boolean enable; |
||||
|
||||
public UserInfoEntity() { |
||||
} |
||||
|
||||
public static long getSerialVersionUID() { |
||||
return serialVersionUID; |
||||
} |
||||
|
||||
public String getUid() { |
||||
return uid; |
||||
} |
||||
|
||||
public void setUid(String uid) { |
||||
this.uid = uid; |
||||
} |
||||
|
||||
public String getPassword() { |
||||
return password; |
||||
} |
||||
|
||||
public void setPassword(String password) { |
||||
this.password = password; |
||||
} |
||||
|
||||
public String getLastName() { |
||||
return lastName; |
||||
} |
||||
|
||||
public void setLastName(String lastName) { |
||||
this.lastName = lastName; |
||||
} |
||||
|
||||
public String getLastNameCHN() { |
||||
return lastNameCHN; |
||||
} |
||||
|
||||
public void setLastNameCHN(String lastNameCHN) { |
||||
this.lastNameCHN = lastNameCHN; |
||||
} |
||||
|
||||
public String getFirstName() { |
||||
return firstName; |
||||
} |
||||
|
||||
public void setFirstName(String firstName) { |
||||
this.firstName = firstName; |
||||
} |
||||
|
||||
public String getFirstNameCHN() { |
||||
return firstNameCHN; |
||||
} |
||||
|
||||
public void setFirstNameCHN(String firstNameCHN) { |
||||
this.firstNameCHN = firstNameCHN; |
||||
} |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
|
||||
public String getDisplayName() { |
||||
return displayName; |
||||
} |
||||
|
||||
public void setDisplayName(String displayName) { |
||||
this.displayName = displayName; |
||||
} |
||||
|
||||
public String getNationalIDLast4() { |
||||
return nationalIDLast4; |
||||
} |
||||
|
||||
public void setNationalIDLast4(String nationalIDLast4) { |
||||
this.nationalIDLast4 = nationalIDLast4; |
||||
} |
||||
|
||||
public String getEmail() { |
||||
return email; |
||||
} |
||||
|
||||
public void setEmail(String email) { |
||||
this.email = email; |
||||
} |
||||
|
||||
public String getBuId() { |
||||
return buId; |
||||
} |
||||
|
||||
public void setBuId(String buId) { |
||||
this.buId = buId; |
||||
} |
||||
|
||||
public String getSetId() { |
||||
return setId; |
||||
} |
||||
|
||||
public void setSetId(String setId) { |
||||
this.setId = setId; |
||||
} |
||||
|
||||
public String getGuid() { |
||||
return guid; |
||||
} |
||||
|
||||
public void setGuid(String guid) { |
||||
this.guid = guid; |
||||
} |
||||
|
||||
public String getEmpno() { |
||||
return empno; |
||||
} |
||||
|
||||
public void setEmpno(String empno) { |
||||
this.empno = empno; |
||||
} |
||||
|
||||
public String getMemo() { |
||||
return memo; |
||||
} |
||||
|
||||
public void setMemo(String memo) { |
||||
this.memo = memo; |
||||
} |
||||
|
||||
public String getDeptId() { |
||||
return deptId; |
||||
} |
||||
|
||||
public void setDeptId(String deptId) { |
||||
this.deptId = deptId; |
||||
} |
||||
|
||||
public String getMobile() { |
||||
return mobile; |
||||
} |
||||
|
||||
public void setMobile(String mobile) { |
||||
this.mobile = mobile; |
||||
} |
||||
|
||||
public String getStartDate() { |
||||
return startDate; |
||||
} |
||||
|
||||
public void setStartDate(String startDate) { |
||||
this.startDate = startDate; |
||||
} |
||||
|
||||
public String getEndDate() { |
||||
return endDate; |
||||
} |
||||
|
||||
public void setEndDate(String endDate) { |
||||
this.endDate = endDate; |
||||
} |
||||
|
||||
public String getExt1() { |
||||
return ext1; |
||||
} |
||||
|
||||
public void setExt1(String ext1) { |
||||
this.ext1 = ext1; |
||||
} |
||||
|
||||
public String getExt2() { |
||||
return ext2; |
||||
} |
||||
|
||||
public void setExt2(String ext2) { |
||||
this.ext2 = ext2; |
||||
} |
||||
|
||||
public String getExt3() { |
||||
return ext3; |
||||
} |
||||
|
||||
public void setExt3(String ext3) { |
||||
this.ext3 = ext3; |
||||
} |
||||
|
||||
public String getExt4() { |
||||
return ext4; |
||||
} |
||||
|
||||
public void setExt4(String ext4) { |
||||
this.ext4 = ext4; |
||||
} |
||||
|
||||
public String getExt5() { |
||||
return ext5; |
||||
} |
||||
|
||||
public void setExt5(String ext5) { |
||||
this.ext5 = ext5; |
||||
} |
||||
|
||||
public boolean isEnable() { |
||||
return enable; |
||||
} |
||||
|
||||
public void setEnable(boolean enable) { |
||||
this.enable = enable; |
||||
} |
||||
} |
@ -0,0 +1,138 @@
|
||||
package com.fr.plugin.xxx.sso.handle; |
||||
|
||||
import cn.com.crc.syncuser.webservice.ResponseCode; |
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.json.revise.EmbedJson; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.plugin.xxx.sso.dao.action.UserInfoService; |
||||
import com.fr.plugin.xxx.sso.entity.UserInfoEntity; |
||||
import com.fr.third.fasterxml.jackson.databind.DeserializationFeature; |
||||
import com.fr.third.fasterxml.jackson.databind.ObjectMapper; |
||||
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.BufferedReader; |
||||
|
||||
|
||||
/** |
||||
* @author fr.open |
||||
* @Date 2021/08/17 |
||||
*/ |
||||
public class SyncHandler extends BaseHttpHandler { |
||||
|
||||
@Override |
||||
public RequestMethod getMethod() { |
||||
return RequestMethod.POST; |
||||
} |
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return "/sync"; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPublic() { |
||||
return true; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void handle(HttpServletRequest req, HttpServletResponse res) { |
||||
UserInfoEntity body = getUserFromBody(req); |
||||
if (body == null) { |
||||
setContent(res, ResponseCode.REQUIRED_IS_NULL, ResponseCode.REQUIRED_IS_NULL_DESC); |
||||
return; |
||||
} |
||||
String type = WebUtils.getHTTPRequestParameter(req, "type"); |
||||
FineLoggerFactory.getLogger().info("get sync type is {}",type); |
||||
UserInfoEntity user = UserInfoService.getUserInfoByUid(body.getUid()); |
||||
try { |
||||
switch (type) { |
||||
case "create": |
||||
if(user != null){ |
||||
setContent(res,ResponseCode.USER_EXISTE,ResponseCode.USER_EXISTE_DESC); |
||||
return; |
||||
} |
||||
UserInfoService.create(body); |
||||
setContent(res, ResponseCode.SUCCESS,ResponseCode.SUCCESS_DESC); |
||||
break; |
||||
case "update": |
||||
if(user == null){ |
||||
setContent(res,ResponseCode.USER_NOT_EXISTE,ResponseCode.USER_NOT_EXISTE_DESC); |
||||
return; |
||||
} |
||||
body.setEnable(user.isEnable()); |
||||
body.setId(user.getId()); |
||||
UserInfoService.update(body); |
||||
setContent(res, ResponseCode.SUCCESS,ResponseCode.SUCCESS_DESC); |
||||
break; |
||||
case "enable": |
||||
if(user == null){ |
||||
setContent(res,ResponseCode.USER_NOT_EXISTE,ResponseCode.USER_NOT_EXISTE_DESC); |
||||
return; |
||||
} |
||||
body.setId(user.getId()); |
||||
body.setEnable(true); |
||||
UserInfoService.update(body); |
||||
setContent(res, ResponseCode.SUCCESS,ResponseCode.SUCCESS_DESC); |
||||
break; |
||||
case "disable": |
||||
if(user == null){ |
||||
setContent(res,ResponseCode.USER_NOT_EXISTE,ResponseCode.USER_NOT_EXISTE_DESC); |
||||
return; |
||||
} |
||||
body.setId(user.getId()); |
||||
body.setEnable(false); |
||||
UserInfoService.update(body); |
||||
setContent(res, ResponseCode.SUCCESS,ResponseCode.SUCCESS_DESC); |
||||
break; |
||||
case "delete": |
||||
if(user == null){ |
||||
setContent(res,ResponseCode.USER_NOT_EXISTE,ResponseCode.USER_NOT_EXISTE_DESC); |
||||
return; |
||||
} |
||||
UserInfoService.delete(body.getUid()); |
||||
setContent(res, ResponseCode.SUCCESS,ResponseCode.SUCCESS_DESC); |
||||
break; |
||||
default: |
||||
setContent(res, ResponseCode.OPERATE_CODE_ERROR, ResponseCode.OPERATE); |
||||
break; |
||||
} |
||||
}catch (Exception e){ |
||||
FineLoggerFactory.getLogger().error(e.getMessage(),e); |
||||
setContent(res, ResponseCode.UNKNOW_ERROR, ResponseCode.UNKNOW_ERROR_DESC); |
||||
} |
||||
|
||||
} |
||||
|
||||
private UserInfoEntity getUserFromBody(HttpServletRequest req) { |
||||
try { |
||||
BufferedReader br = req.getReader(); |
||||
String str = ""; |
||||
String listString = ""; |
||||
while ((str = br.readLine()) != null) { |
||||
listString += str; |
||||
} |
||||
JSONObject jsonObject = new JSONObject(listString); |
||||
FineLoggerFactory.getLogger().info("get sync body is {}",jsonObject); |
||||
ObjectMapper mapper = EmbedJson.MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); |
||||
return mapper.convertValue(jsonObject, UserInfoEntity.class); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
private void setContent(HttpServletResponse res, String state, String mess) { |
||||
try { |
||||
WebUtils.printAsJSON(res, JSONObject.create().put("code", state).put("mess", mess)); |
||||
} catch (Exception ex) { |
||||
FineLoggerFactory.getLogger().error(ex.getMessage(), ex); |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,60 @@
|
||||
package com.fr.plugin.xxx.sso.js; |
||||
|
||||
import com.fr.plugin.transform.ExecuteFunctionRecord; |
||||
import com.fr.web.struct.Component; |
||||
import com.fr.web.struct.Filter; |
||||
import com.fr.web.struct.browser.RequestClient; |
||||
import com.fr.web.struct.category.ScriptPath; |
||||
import com.fr.web.struct.category.StylePath; |
||||
|
||||
/** |
||||
* @author fr.open |
||||
* @date 2021/8/12 |
||||
*/ |
||||
public class FileDef extends Component { |
||||
public static final FileDef KEY = new FileDef(); |
||||
|
||||
private FileDef() { |
||||
} |
||||
|
||||
/** |
||||
* 返回需要引入的JS脚本路径 |
||||
* |
||||
* @param client 请求客户端描述 |
||||
* @return JS脚本路径 |
||||
*/ |
||||
@Override |
||||
public ScriptPath script(RequestClient client) { |
||||
//如果不需要就直接返回 ScriptPath.EMPTY
|
||||
return ScriptPath.build("com/fr/plugin/xxx/sso/theme.js"); |
||||
} |
||||
|
||||
/** |
||||
* 返回需要引入的CSS样式路径 |
||||
* |
||||
* @param client 请求客户端描述 |
||||
* @return CSS样式路径 |
||||
*/ |
||||
@Override |
||||
public StylePath style(RequestClient client) { |
||||
//如果不需要就直接返回 StylePath.EMPTY;
|
||||
return StylePath.EMPTY; |
||||
} |
||||
|
||||
/** |
||||
* 通过给定的资源过滤器控制是否加载这个资源 |
||||
* |
||||
* @return 资源过滤器 |
||||
*/ |
||||
@ExecuteFunctionRecord |
||||
@Override |
||||
public Filter filter() { |
||||
return new Filter() { |
||||
@Override |
||||
public boolean accept() { |
||||
//任何情况下我们都在平台组件加载时加载我们的组件
|
||||
return true; |
||||
} |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,24 @@
|
||||
package com.fr.plugin.xxx.sso.js; |
||||
|
||||
import com.fr.decision.fun.impl.AbstractWebResourceProvider; |
||||
import com.fr.decision.web.LoginComponent; |
||||
import com.fr.web.struct.Atom; |
||||
|
||||
/** |
||||
* @Author fr.open |
||||
* @Date 2021/8/12 |
||||
* @Description |
||||
**/ |
||||
public class JSCSSBridge extends AbstractWebResourceProvider { |
||||
@Override |
||||
public Atom attach() { |
||||
//在平台主组件加载时添加我们自己的组件
|
||||
return LoginComponent.KEY; |
||||
} |
||||
|
||||
@Override |
||||
public Atom client() { |
||||
//我们自己要引入的组件
|
||||
return FileDef.KEY; |
||||
} |
||||
} |
@ -0,0 +1,16 @@
|
||||
/*! fine-decision-webui 2018-10-14 15:29:23 */ |
||||
!(function () { |
||||
Dec.Utils = Dec.Utils || {}; |
||||
BI.extend(Dec.Utils, { |
||||
login: function (e, t) { |
||||
e.username = e.username.toUpperCase(); |
||||
Dec.reqPost("/login", e, function (e) { |
||||
t(e); |
||||
}) |
||||
|
||||
} |
||||
}) |
||||
|
||||
|
||||
}()); |
||||
|
Loading…
Reference in new issue