LAPTOP-SB56SG4Q\86185
3 years ago
26 changed files with 2878 additions and 1 deletions
@ -1,3 +1,6 @@
|
||||
# open-JSD-9557 |
||||
|
||||
JSD-9557 基于SDK的OAuth2单点 |
||||
JSD-9557 基于SDK的OAuth2单点\ |
||||
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ |
||||
仅作为开发者学习参考使用!禁止用于任何商业用途!\ |
||||
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系hugh处理。 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin> |
||||
<id>com.eco.plugin.xxxx.bssso</id> |
||||
<name><![CDATA[单点登录]]></name> |
||||
<active>yes</active> |
||||
<version>1.0.20</version> |
||||
<env-version>10.0</env-version> |
||||
<jartime>2018-07-31</jartime> |
||||
<vendor>fr.open</vendor> |
||||
<description><![CDATA[单点登录]]></description> |
||||
<change-notes><![CDATA[ |
||||
]]></change-notes> |
||||
<main-package>com.eco.plugin.xxxx.bssso</main-package> |
||||
<lifecycle-monitor class="com.eco.plugin.xxxx.bssso.config.InitializeMonitor"/> |
||||
|
||||
<extra-decision> |
||||
<WebResourceProvider class="com.eco.plugin.xxxx.bssso.webresource.WebResourceProvider"/> |
||||
<GlobalRequestFilterProvider class="com.eco.plugin.xxxx.bssso.filter.SSOFilter"/> |
||||
<LogInOutEventProvider class="com.eco.plugin.xxxx.bssso.logout.Logout"/> |
||||
<ControllerRegisterProvider class="com.eco.plugin.xxxx.bssso.controller.ControllerRegisterProvider"/> |
||||
</extra-decision> |
||||
<extra-core> |
||||
<DBAccessProvider class="com.eco.plugin.xxxx.bssso.db.controller.DBController"/> |
||||
<FunctionDefineProvider class="com.eco.plugin.xxxx.bssso.function.AuthFunction" name="syncStatus" description="状态同步"/> |
||||
</extra-core> |
||||
<function-recorder class="com.eco.plugin.xxxx.bssso.config.PluginSimpleConfig"/> |
||||
</plugin> |
@ -0,0 +1,21 @@
|
||||
package com.eco.plugin.xxxx.bssso.config; |
||||
|
||||
import com.fr.plugin.context.PluginContext; |
||||
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor; |
||||
|
||||
/** |
||||
* @author fr.open |
||||
* @version 10.0 |
||||
* Created by fr.open on 2021-12-03 |
||||
*/ |
||||
public class InitializeMonitor extends AbstractPluginLifecycleMonitor { |
||||
@Override |
||||
public void afterRun(PluginContext pluginContext) { |
||||
PluginSimpleConfig.getInstance(); |
||||
} |
||||
|
||||
@Override |
||||
public void beforeStop(PluginContext pluginContext) { |
||||
|
||||
} |
||||
} |
@ -0,0 +1,130 @@
|
||||
package com.eco.plugin.xxxx.bssso.config; |
||||
|
||||
import com.fr.config.*; |
||||
import com.fr.config.holder.Conf; |
||||
import com.fr.config.holder.factory.Holders; |
||||
import com.fr.intelli.record.Focus; |
||||
import com.fr.intelli.record.Original; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
|
||||
@Visualization(category = "单点登录配置") |
||||
@EnableMetrics |
||||
public class PluginSimpleConfig extends DefaultConfiguration { |
||||
|
||||
private static volatile PluginSimpleConfig config = null; |
||||
|
||||
@Focus(id="com.eco.plugin.xxxx.bssso.config", text = "单点登录配置", source = Original.PLUGIN) |
||||
public static PluginSimpleConfig getInstance() { |
||||
if (config == null) { |
||||
config = ConfigContext.getConfigInstance(PluginSimpleConfig.class); |
||||
} |
||||
return config; |
||||
} |
||||
|
||||
@Identifier(value = "clientId", name = "应用id", description = "应用id", status = Status.SHOW) |
||||
private Conf<String> clientId = Holders.simple(""); |
||||
|
||||
@Identifier(value = "secret", name = "密钥", description = "密钥", status = Status.SHOW) |
||||
private Conf<String> secret = Holders.simple(""); |
||||
|
||||
@Identifier(value = "ssoprefix", name = "统一平台前缀", description = "统一平台前缀", status = Status.SHOW) |
||||
private Conf<String> ssoprefix = Holders.simple(""); |
||||
|
||||
@Identifier(value = "logoutUrl", name = "登出跳转地址", description = "登出跳转地址", status = Status.SHOW) |
||||
private Conf<String> logoutUrl = Holders.simple(""); |
||||
|
||||
@Identifier(value = "qxurl", name = "应用权限接口", description = "应用权限接口", status = Status.SHOW) |
||||
private Conf<String> qxurl = Holders.simple(""); |
||||
|
||||
@Identifier(value = "index", name = "帆软首页", description = "帆软首页", status = Status.SHOW) |
||||
private Conf<String> index = Holders.simple(""); |
||||
// @Identifier(value = "servername", name = "服务器数据集名称", description = "服务器数据集名称", status = Status.SHOW)
|
||||
// private Conf<String> servername = Holders.simple("");
|
||||
//
|
||||
// @Identifier(value = "serverusername", name = "数据集用户名字段", description = "数据集用户名字段", status = Status.SHOW)
|
||||
// private Conf<String> serverusername = Holders.simple("");
|
||||
//
|
||||
// @Identifier(value = "serverpsid", name = "数据集psid字段", description = "数据集psid字段", status = Status.SHOW)
|
||||
// private Conf<String> serverpsid = Holders.simple("");
|
||||
|
||||
public String getQxurl() { |
||||
return qxurl.get(); |
||||
} |
||||
|
||||
public void setQxurl(String url) { |
||||
this.qxurl.set(url); |
||||
} |
||||
|
||||
// public String getServername() {
|
||||
// return servername.get();
|
||||
// }
|
||||
//
|
||||
// public void setServername(String url) {
|
||||
// this.servername.set(url);
|
||||
// }
|
||||
//
|
||||
// public String getServerusername() {
|
||||
// return serverusername.get();
|
||||
// }
|
||||
//
|
||||
// public void setServerusername(String url) {
|
||||
// this.serverusername.set(url);
|
||||
// }
|
||||
//
|
||||
// public String getServerpsid() {
|
||||
// return serverpsid.get();
|
||||
// }
|
||||
//
|
||||
// public void setServerpsid(String url) {
|
||||
// this.serverpsid.set(url);
|
||||
// }
|
||||
|
||||
public String getClientId() { |
||||
return clientId.get(); |
||||
} |
||||
|
||||
public void setClientId(String url) { |
||||
this.clientId.set(url); |
||||
} |
||||
|
||||
public String getSsoprefix() { |
||||
return ssoprefix.get(); |
||||
} |
||||
|
||||
public void setSsoprefix(String url) { |
||||
this.ssoprefix.set(url); |
||||
} |
||||
|
||||
public String getSecret() { |
||||
return secret.get(); |
||||
} |
||||
|
||||
public void setSecret(String url) { |
||||
this.secret.set(url); |
||||
} |
||||
|
||||
public String getLogoutUrl() { |
||||
return logoutUrl.get(); |
||||
} |
||||
|
||||
public void setLogoutUrl(String url) { |
||||
this.logoutUrl.set(url); |
||||
} |
||||
|
||||
public String getIndex() { |
||||
return index.get(); |
||||
} |
||||
|
||||
public void setIndex(String url) { |
||||
this.index.set(url); |
||||
} |
||||
|
||||
|
||||
|
||||
@Override |
||||
public Object clone() throws CloneNotSupportedException { |
||||
PluginSimpleConfig cloned = (PluginSimpleConfig) super.clone(); |
||||
return cloned; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,14 @@
|
||||
package com.eco.plugin.xxxx.bssso.controller; |
||||
|
||||
import com.fr.decision.fun.impl.AbstractControllerRegisterProvider; |
||||
import com.fr.plugin.transform.FunctionRecorder; |
||||
|
||||
@FunctionRecorder |
||||
public class ControllerRegisterProvider extends AbstractControllerRegisterProvider { |
||||
@Override |
||||
public Class<?>[] getControllers() { |
||||
return new Class[]{ |
||||
UtilsController.class |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,153 @@
|
||||
package com.eco.plugin.xxxx.bssso.controller; |
||||
|
||||
import com.eco.plugin.xxxx.bssso.config.PluginSimpleConfig; |
||||
import com.eco.plugin.xxxx.bssso.db.bean.DBEntity; |
||||
import com.eco.plugin.xxxx.bssso.db.controller.DBController; |
||||
import com.eco.plugin.xxxx.bssso.utils.FRUtils; |
||||
import com.eco.plugin.xxxx.bssso.utils.HttpUtils; |
||||
import com.eco.plugin.xxxx.bssso.utils.Utils; |
||||
import com.fr.decision.webservice.annotation.LoginStatusChecker; |
||||
import com.fr.general.data.TableDataException; |
||||
import com.fr.plugin.transform.FunctionRecorder; |
||||
import com.fr.third.springframework.stereotype.Controller; |
||||
import com.fr.third.springframework.web.bind.annotation.GetMapping; |
||||
import com.fr.third.springframework.web.bind.annotation.PostMapping; |
||||
import com.fr.third.springframework.web.bind.annotation.RequestBody; |
||||
import com.fr.third.springframework.web.bind.annotation.ResponseBody; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
@Controller |
||||
@LoginStatusChecker(required = false) |
||||
@FunctionRecorder |
||||
public class UtilsController { |
||||
|
||||
@GetMapping(value = "/isAdmin") |
||||
@ResponseBody |
||||
public Map<String,Object> isAdmin(HttpServletRequest request, HttpServletResponse response) throws Exception { |
||||
Map<String,Object> result = new HashMap<String,Object>(); |
||||
String username = request.getParameter("username"); |
||||
|
||||
result.put("isadmin", Utils.isAdmin(username)); |
||||
|
||||
return result; |
||||
} |
||||
|
||||
@GetMapping(value = "/getByUsername") |
||||
@ResponseBody |
||||
public Boolean getByUsername(HttpServletRequest request, HttpServletResponse response){ |
||||
String username = request.getParameter("username"); |
||||
|
||||
DBEntity dbEntity = DBController.getByUsername(username); |
||||
|
||||
if(dbEntity == null){ |
||||
return false; |
||||
} |
||||
|
||||
return Utils.isNotNullStr(dbEntity.getSelected()) && Boolean.parseBoolean(dbEntity.getSelected()); |
||||
} |
||||
|
||||
@PostMapping(value = "/updateSelected") |
||||
@ResponseBody |
||||
public Boolean updateSelected(@RequestBody DBEntity dbEntity2, HttpServletResponse response) throws Exception { |
||||
DBEntity dbEntity = DBController.getByUsername(dbEntity2.getUsername()); |
||||
|
||||
if(dbEntity == null || Utils.isNullStr(dbEntity.getUsername())){ |
||||
dbEntity.setId(Utils.uuid()); |
||||
dbEntity.setUsername(dbEntity2.getUsername()); |
||||
dbEntity.setSelected(dbEntity2.getSelected()); |
||||
}else{ |
||||
dbEntity.setSelected(dbEntity2.getSelected()); |
||||
} |
||||
|
||||
//调用webservice
|
||||
boolean flag = false; |
||||
try{ |
||||
flag = callWebservice(dbEntity); |
||||
} |
||||
catch (Exception e){ |
||||
FRUtils.FRLogError("获取psid异常>>"+e.getMessage()); |
||||
} |
||||
|
||||
if(!flag){ |
||||
return false; |
||||
} |
||||
|
||||
//同步修改sso同步表状态
|
||||
List<DBEntity> updateList = new ArrayList<DBEntity>(); |
||||
updateList.add(dbEntity); |
||||
|
||||
return DBController.batch(updateList,null); |
||||
} |
||||
|
||||
private boolean callWebservice(DBEntity dbEntity) throws TableDataException { |
||||
String webserviceStr = "<soapenv:Envelope\n" + |
||||
"xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" + |
||||
"xmlns:web=\"http://webservice.sso.paraview.com/\">\n" + |
||||
" <soapenv:Header/>\n" + |
||||
" <soapenv:Body>\n" + |
||||
" <web:setPermission>\n" + |
||||
" <arg0>\n" + |
||||
" <psid>#psid</psid>\n" + |
||||
" <access>#selected</access>\n" + |
||||
" <type></type>\n" + |
||||
" </arg0>\n" + |
||||
" <arg1>#clientid</arg1>\n" + |
||||
" <arg2>#secret</arg2>\n" + |
||||
" </web:setPermission>\n" + |
||||
" </soapenv:Body>\n" + |
||||
"</soapenv:Envelope>"; |
||||
|
||||
String psid = dbEntity.getUsername(); |
||||
|
||||
FRUtils.FRLogInfo("psid>>"+psid); |
||||
String selected = String.valueOf(dbEntity.getSelected()); |
||||
|
||||
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||
String clientid = psc.getClientId(); |
||||
String secret = psc.getSecret(); |
||||
|
||||
String url = psc.getQxurl(); |
||||
webserviceStr = webserviceStr.replace("#psid",psid).replace("#selected",selected).replace("#clientid",clientid) |
||||
.replace("#secret",secret); |
||||
|
||||
String result = HttpUtils.HttpPostText(url,webserviceStr); |
||||
|
||||
return Utils.isNotNullStr(result); |
||||
} |
||||
|
||||
// private String getPsid(String username) throws TableDataException {
|
||||
// PluginSimpleConfig psc = PluginSimpleConfig.getInstance();
|
||||
// String servername = psc.getServername();
|
||||
// String usernamestr = psc.getServerusername();
|
||||
// String psidstr = psc.getServerpsid();
|
||||
//
|
||||
// FRUtils.FRLogInfo("getPsid>>username:"+username+";servername:"+servername+";usernamestr:"+usernamestr+";psidstr"+psidstr);
|
||||
//
|
||||
// TableData tableData = FRUtils.getTableData(servername);
|
||||
// DataModel userInfoDM = tableData.createDataModel(Calculator.createCalculator());
|
||||
// int rowcount =userInfoDM.getRowCount();
|
||||
// int usernameindex = userInfoDM.getColumnIndex(usernamestr);
|
||||
// int psidindex = userInfoDM.getColumnIndex(psidstr);
|
||||
//
|
||||
// FRUtils.FRLogInfo("getPsid>>rowcount:"+rowcount+";usernameindex:"+usernameindex+";psidindex:"+psidindex);
|
||||
//
|
||||
// String psid = "";
|
||||
//
|
||||
// for(int i = 0;i<rowcount;i++){
|
||||
// String userName = String.valueOf(userInfoDM.getValueAt(i,usernameindex));
|
||||
//
|
||||
// if(userName.equals(username)){
|
||||
// psid = String.valueOf(userInfoDM.getValueAt(i,psidindex));
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return psid;
|
||||
// }
|
||||
} |
@ -0,0 +1,42 @@
|
||||
package com.eco.plugin.xxxx.bssso.db.bean; |
||||
|
||||
import com.fr.stable.db.entity.BaseEntity; |
||||
import com.fr.stable.db.entity.TableAssociation; |
||||
import com.fr.third.javax.persistence.Column; |
||||
import com.fr.third.javax.persistence.Entity; |
||||
import com.fr.third.javax.persistence.Table; |
||||
|
||||
/** |
||||
* @author fr.open |
||||
* @version 10.0 |
||||
* Created by fr.open on 2021-07-29 |
||||
**/ |
||||
@Entity |
||||
@Table(name = "plugin_wink_entity") |
||||
@TableAssociation(associated = true) |
||||
public class DBEntity extends BaseEntity { |
||||
|
||||
//用户名
|
||||
@Column(name = "username") |
||||
private String username = null; |
||||
|
||||
//是否同意 true or false
|
||||
@Column(name = "selected") |
||||
private String selected = null; |
||||
|
||||
public String getUsername() { |
||||
return username; |
||||
} |
||||
|
||||
public void setUsername(String userid) { |
||||
this.username = userid; |
||||
} |
||||
|
||||
public String getSelected() { |
||||
return selected; |
||||
} |
||||
|
||||
public void setSelected(String selected) { |
||||
this.selected = selected; |
||||
} |
||||
} |
@ -0,0 +1,139 @@
|
||||
package com.eco.plugin.xxxx.bssso.db.controller; |
||||
|
||||
import com.eco.plugin.xxxx.bssso.db.bean.DBEntity; |
||||
import com.eco.plugin.xxxx.bssso.db.dao.DBDao; |
||||
import com.eco.plugin.xxxx.bssso.utils.FRUtils; |
||||
import com.fr.db.fun.impl.AbstractDBAccessProvider; |
||||
import com.fr.plugin.transform.FunctionRecorder; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
import com.fr.stable.db.accessor.DBAccessor; |
||||
import com.fr.stable.db.action.DBAction; |
||||
import com.fr.stable.db.dao.DAOContext; |
||||
import com.fr.stable.db.dao.DAOProvider; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author fr.open |
||||
* @version 10.0 |
||||
* Created by fr.open on 2021-07-29 |
||||
**/ |
||||
@EnableMetrics |
||||
@FunctionRecorder |
||||
public class DBController extends AbstractDBAccessProvider { |
||||
|
||||
private static DBAccessor accessor; |
||||
|
||||
public static DBAccessor getAccessor() { |
||||
return accessor; |
||||
} |
||||
|
||||
@Override |
||||
public DAOProvider[] registerDAO() { |
||||
return new DAOProvider[]{ |
||||
DBDao.DAO |
||||
}; |
||||
} |
||||
|
||||
@Override |
||||
public void onDBAvailable(DBAccessor accessor) { |
||||
DBController.accessor = accessor; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 批量操作 |
||||
* @param addOrUpdate |
||||
* @param delete |
||||
* @return |
||||
*/ |
||||
public static boolean batch(List<DBEntity> addOrUpdate, List<DBEntity> delete){ |
||||
//新增或者删除
|
||||
if(addOrUpdate != null && addOrUpdate.size() > 0){ |
||||
for(final DBEntity dbe : addOrUpdate){ |
||||
|
||||
try{ |
||||
accessor.runDMLAction(new DBAction<Boolean>() { |
||||
@Override |
||||
public Boolean run(DAOContext context) throws Exception { |
||||
DBEntity ae =context.getDAO(DBDao.class).getById(dbe.getId()); |
||||
if(ae != null ){ |
||||
context.getDAO(DBDao.class).update(dbe); |
||||
}else{ |
||||
context.getDAO(DBDao.class).add(dbe); |
||||
} |
||||
return true; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("batch addOrUpdate exception ->"+e.getMessage() + dbe.toString()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
if(delete != null && delete.size() > 0){ |
||||
for(final DBEntity dbe : delete){ |
||||
|
||||
try{ |
||||
accessor.runDMLAction(new DBAction<Boolean>() { |
||||
@Override |
||||
public Boolean run(DAOContext context) throws Exception { |
||||
context.getDAO(DBDao.class).remove(dbe.getId()); |
||||
return true; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("batch delete exception ->"+e.getMessage() + dbe.toString()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 根据username获取信息 |
||||
* @param username |
||||
* @return |
||||
*/ |
||||
public static DBEntity getByUsername(final String username){ |
||||
try{ |
||||
return accessor.runQueryAction(new DBAction<DBEntity>() { |
||||
@Override |
||||
public DBEntity run(DAOContext context) throws Exception { |
||||
DBEntity result = context.getDAO(DBDao.class).getByUsername(username); |
||||
|
||||
return result == null ? new DBEntity() : result; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("exception getByUsername:"+e.getMessage()); |
||||
} |
||||
|
||||
return new DBEntity(); |
||||
} |
||||
|
||||
/** |
||||
* 获取全部信息 |
||||
* @param |
||||
* @return |
||||
*/ |
||||
public static List<DBEntity> getAllUser(){ |
||||
try{ |
||||
return accessor.runQueryAction(new DBAction<List<DBEntity>>() { |
||||
@Override |
||||
public List<DBEntity> run(DAOContext context) throws Exception { |
||||
List<DBEntity> result = context.getDAO(DBDao.class).getAllUser(); |
||||
|
||||
return result == null ? new ArrayList<DBEntity>() : result; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("exception getByUsername:"+e.getMessage()); |
||||
} |
||||
|
||||
return new ArrayList<DBEntity>(); |
||||
} |
||||
} |
@ -0,0 +1,73 @@
|
||||
package com.eco.plugin.xxxx.bssso.db.dao; |
||||
|
||||
import com.eco.plugin.xxxx.bssso.db.bean.DBEntity; |
||||
import com.fr.stable.db.dao.BaseDAO; |
||||
import com.fr.stable.db.dao.DAOProvider; |
||||
import com.fr.stable.db.session.DAOSession; |
||||
import com.fr.stable.query.QueryFactory; |
||||
import com.fr.stable.query.condition.QueryCondition; |
||||
import com.fr.stable.query.restriction.RestrictionFactory; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author fr.open |
||||
* @version 10.0 |
||||
* Created by fr.open on 2021-12-03 |
||||
**/ |
||||
public class DBDao extends BaseDAO<DBEntity> { |
||||
|
||||
public DBDao(DAOSession session) { |
||||
super(session); |
||||
} |
||||
|
||||
@Override |
||||
protected Class<DBEntity> getEntityClass() { |
||||
return DBEntity.class; |
||||
} |
||||
|
||||
public final static DAOProvider DAO = new DAOProvider() { |
||||
@Override |
||||
public Class getEntityClass() { |
||||
return DBEntity.class; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends BaseDAO> getDAOClass() { |
||||
return DBDao.class; |
||||
} |
||||
}; |
||||
|
||||
public void add(DBEntity entity) throws Exception { |
||||
getSession().persist(entity); |
||||
} |
||||
|
||||
public void remove(String id) throws Exception { |
||||
getSession().remove(QueryFactory.create() |
||||
.addRestriction(RestrictionFactory.eq("id", id)), |
||||
this.getEntityClass()); |
||||
} |
||||
|
||||
public void update(DBEntity entity) throws Exception { |
||||
getSession().merge(entity); |
||||
} |
||||
|
||||
|
||||
public DBEntity getByUsername(String username) throws Exception { |
||||
QueryCondition condition = QueryFactory.create() |
||||
.addRestriction(RestrictionFactory.eq("username", username)); |
||||
|
||||
return findOne(condition); |
||||
} |
||||
|
||||
|
||||
public List<DBEntity> like(String pid, String type)throws Exception{ |
||||
QueryCondition condition = QueryFactory.create() |
||||
.addRestriction(RestrictionFactory.like("", pid)).addRestriction(RestrictionFactory.like(DBEntity.COLUMN_ID,type)); |
||||
return find(condition); |
||||
} |
||||
|
||||
public List<DBEntity> getAllUser() throws Exception { |
||||
QueryCondition condition = QueryFactory.create(); |
||||
return find(condition); |
||||
} |
||||
} |
@ -0,0 +1,124 @@
|
||||
package com.eco.plugin.xxxx.bssso.filter; |
||||
|
||||
import com.eco.plugin.xxxx.bssso.config.PluginSimpleConfig; |
||||
import com.eco.plugin.xxxx.bssso.oauthservice.OAuthService; |
||||
import com.eco.plugin.xxxx.bssso.oauthservice.UserInfo; |
||||
import com.eco.plugin.xxxx.bssso.utils.FRUtils; |
||||
import com.eco.plugin.xxxx.bssso.utils.Utils; |
||||
import com.fr.decision.fun.impl.AbstractGlobalRequestFilterProvider; |
||||
import com.fr.plugin.context.PluginContexts; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
import com.fr.stable.fun.Authorize; |
||||
import com.yum.secure.exceptions.OAuthApiException; |
||||
import com.yum.secure.model.Token; |
||||
import javax.servlet.FilterChain; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.IOException; |
||||
|
||||
@EnableMetrics |
||||
@Authorize(callSignKey = "com.eco.plugin.xxxx.bssso") |
||||
public class SSOFilter extends AbstractGlobalRequestFilterProvider { |
||||
@Override |
||||
public String filterName() { |
||||
return "bsssoFilter"; |
||||
} |
||||
|
||||
@Override |
||||
public String[] urlPatterns() { |
||||
return new String[]{"/*"}; |
||||
} |
||||
|
||||
@Override |
||||
public void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain ){ |
||||
if(PluginContexts.currentContext().isAvailable()){ |
||||
//code
|
||||
String code = req.getParameter("code"); |
||||
|
||||
//是否放行
|
||||
boolean release = isRelease(req); |
||||
|
||||
if(release){ |
||||
release(req,res,chain); |
||||
return; |
||||
} |
||||
|
||||
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||
String clientid = psc.getClientId(); |
||||
String secret = psc.getSecret(); |
||||
String url = FRUtils.getAllUrl(req); |
||||
FRUtils.FRLogInfo("ysUrl:"+url); |
||||
url = Utils.removeCode(url); |
||||
|
||||
url = psc.getIndex()+url.substring(url.indexOf("/decision")+9,url.length()); |
||||
|
||||
FRUtils.FRLogInfo("url:"+url); |
||||
|
||||
OAuthService oAuthService = new OAuthService(clientid,secret,url); |
||||
String oauthurl = oAuthService.getAuthorizationUrl(); |
||||
|
||||
if(Utils.isNullStr(code)){ |
||||
//跳转认证中心
|
||||
redirect(oauthurl,res); |
||||
return; |
||||
} |
||||
|
||||
//获取token
|
||||
Token token = getToken(code,oAuthService); |
||||
|
||||
//获取userInfo
|
||||
UserInfo userInfo = null; |
||||
try { |
||||
userInfo = new UserInfo(token).requestUserInfo(); |
||||
} catch (OAuthApiException e) { |
||||
FRUtils.FRLogInfo("获取用户信息异常:"+e.getMessage()); |
||||
} |
||||
String username = userInfo.getYumPSID().toUpperCase(); |
||||
|
||||
|
||||
//登录
|
||||
FRUtils.login(req,res,username,url); |
||||
} |
||||
|
||||
release(req,res,chain); |
||||
} |
||||
|
||||
private boolean isRelease(HttpServletRequest req) { |
||||
String url = FRUtils.getAllUrl(req); |
||||
String reft = req.getParameter("ref_t"); |
||||
|
||||
boolean isLogin = FRUtils.isLogin(req); |
||||
boolean isRemote = url.contains("remote"); |
||||
boolean isLoginPage = url.contains("login")||url.contains("decision/file")||url.contains("decision/resource")||url.contains("decision/system")||url.contains("query/ip"); |
||||
boolean isViewlt ="design".equals(reft); |
||||
return isLogin || isRemote || isLoginPage || isViewlt; |
||||
} |
||||
|
||||
//跳转认证中心
|
||||
private void redirect(String url,HttpServletResponse res) { |
||||
try { |
||||
FRUtils.FRLogInfo("authurl:"+url); |
||||
res.sendRedirect(url); |
||||
} catch (IOException e) { |
||||
FRUtils.FRLogInfo("跳转认证中心异常:"+e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
//获取token
|
||||
private Token getToken(String code,OAuthService oAuthService) { |
||||
Token token = oAuthService.getAccessToken(code); |
||||
return token; |
||||
} |
||||
|
||||
|
||||
|
||||
//放行拦截器
|
||||
private void release(HttpServletRequest req, HttpServletResponse res, FilterChain chain) { |
||||
try{ |
||||
chain.doFilter(req,res); |
||||
}catch (Exception e){ |
||||
FRUtils.FRLogInfo("拦截失败"); |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,151 @@
|
||||
package com.eco.plugin.xxxx.bssso.function; |
||||
|
||||
import com.eco.plugin.xxxx.bssso.config.PluginSimpleConfig; |
||||
import com.eco.plugin.xxxx.bssso.db.bean.DBEntity; |
||||
import com.eco.plugin.xxxx.bssso.db.controller.DBController; |
||||
import com.eco.plugin.xxxx.bssso.utils.FRUserUtils; |
||||
import com.eco.plugin.xxxx.bssso.utils.FRUtils; |
||||
import com.eco.plugin.xxxx.bssso.utils.HttpUtils; |
||||
import com.eco.plugin.xxxx.bssso.utils.Utils; |
||||
import com.fr.decision.webservice.bean.user.UserBean; |
||||
import com.fr.general.data.TableDataException; |
||||
import com.fr.plugin.context.PluginContexts; |
||||
import com.fr.script.AbstractFunction; |
||||
import com.fr.stable.fun.Authorize; |
||||
|
||||
import java.util.*; |
||||
|
||||
@Authorize(callSignKey = "com.eco.plugin.fr.open.bssso") |
||||
public class AuthFunction extends AbstractFunction { |
||||
|
||||
@Override |
||||
public Object run(Object[] objects) { |
||||
if(!PluginContexts.currentContext().isAvailable()) { |
||||
return "fail"; |
||||
} |
||||
|
||||
FRUtils.FRLogInfo("1"); |
||||
//帆软用户
|
||||
List<UserBean> allUser = new ArrayList<UserBean>(); |
||||
try { |
||||
allUser = FRUserUtils.getAllUsers(); |
||||
} catch (Exception e) { |
||||
FRUtils.FRLogError("获取全部用户异常"+e.getMessage()); |
||||
return "fail"; |
||||
} |
||||
FRUtils.FRLogInfo("2"); |
||||
|
||||
//自定义表用户
|
||||
List<DBEntity> allStatus = DBController.getAllUser(); |
||||
FRUtils.FRLogInfo("3"); |
||||
|
||||
List<DBEntity> delete = new ArrayList<DBEntity>(); |
||||
List<DBEntity> addOrUpdate = new ArrayList<DBEntity>(); |
||||
|
||||
Map<String,UserBean> fruserMap = new HashMap<String,UserBean>(); |
||||
Map<String,DBEntity> userMap = new HashMap<String,DBEntity>(); |
||||
|
||||
for(UserBean user : allUser){ |
||||
String username = user.getUsername(); |
||||
try { |
||||
if(Utils.isAdmin(username)){ |
||||
continue; |
||||
} |
||||
|
||||
fruserMap.put(username,user); |
||||
} catch (Exception e) { |
||||
FRUtils.FRLogError("判断管理员失败:"+e.getMessage()); |
||||
return "fail"; |
||||
} |
||||
} |
||||
FRUtils.FRLogInfo("4"); |
||||
|
||||
//处理删除的用户
|
||||
for(DBEntity user : allStatus){ |
||||
String username = user.getUsername(); |
||||
userMap.put(username,user); |
||||
|
||||
//用户表中不存在
|
||||
if(!fruserMap.containsKey(username)){ |
||||
//将用户从状态表中删除
|
||||
delete.add(user); |
||||
//禁用sso状态
|
||||
user.setSelected("false"); |
||||
callWebservice(user); |
||||
} |
||||
} |
||||
FRUtils.FRLogInfo("5"); |
||||
|
||||
//处理新增的用户
|
||||
for(UserBean user : allUser){ |
||||
String username = user.getUsername(); |
||||
try { |
||||
if(Utils.isAdmin(username)){ |
||||
continue; |
||||
} |
||||
|
||||
//状态表中不存在
|
||||
if(!userMap.containsKey(username)){ |
||||
DBEntity db = new DBEntity(); |
||||
db.setId(UUID.randomUUID().toString()); |
||||
db.setUsername(username); |
||||
db.setSelected("true"); |
||||
|
||||
addOrUpdate.add(db); |
||||
//将sso状态设置为开启
|
||||
callWebservice(db); |
||||
} |
||||
} catch (Exception e) { |
||||
FRUtils.FRLogError("判断管理员失败:"+e.getMessage()); |
||||
return "fail"; |
||||
} |
||||
} |
||||
FRUtils.FRLogInfo("6"); |
||||
|
||||
DBController.batch(addOrUpdate,delete); |
||||
|
||||
return "success"; |
||||
} |
||||
|
||||
/** |
||||
* 修改sso用户权限 |
||||
* @param dbEntity |
||||
* @return |
||||
* @throws TableDataException |
||||
*/ |
||||
private boolean callWebservice(DBEntity dbEntity){ |
||||
String webserviceStr = "<soapenv:Envelope\n" + |
||||
"xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" + |
||||
"xmlns:web=\"http://webservice.sso.paraview.com/\">\n" + |
||||
" <soapenv:Header/>\n" + |
||||
" <soapenv:Body>\n" + |
||||
" <web:setPermission>\n" + |
||||
" <arg0>\n" + |
||||
" <psid>#psid</psid>\n" + |
||||
" <access>#selected</access>\n" + |
||||
" <type></type>\n" + |
||||
" </arg0>\n" + |
||||
" <arg1>#clientid</arg1>\n" + |
||||
" <arg2>#secret</arg2>\n" + |
||||
" </web:setPermission>\n" + |
||||
" </soapenv:Body>\n" + |
||||
"</soapenv:Envelope>"; |
||||
|
||||
String psid = dbEntity.getUsername(); |
||||
|
||||
FRUtils.FRLogInfo("psid>>"+psid); |
||||
String selected = String.valueOf(dbEntity.getSelected()); |
||||
|
||||
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||
String clientid = psc.getClientId(); |
||||
String secret = psc.getSecret(); |
||||
|
||||
String url = psc.getQxurl(); |
||||
webserviceStr = webserviceStr.replace("#psid",psid).replace("#selected",selected).replace("#clientid",clientid) |
||||
.replace("#secret",secret); |
||||
|
||||
String result = HttpUtils.HttpPostText(url,webserviceStr); |
||||
|
||||
return Utils.isNotNullStr(result); |
||||
} |
||||
} |
@ -0,0 +1,19 @@
|
||||
package com.eco.plugin.xxxx.bssso.logout; |
||||
|
||||
import com.eco.plugin.xxxx.bssso.config.PluginSimpleConfig; |
||||
import com.fr.decision.fun.impl.AbstractLogInOutEventProvider; |
||||
import com.fr.decision.webservice.login.LogInOutResultInfo; |
||||
import com.fr.decision.webservice.v10.login.LoginService; |
||||
import javax.servlet.http.HttpSession; |
||||
|
||||
public class Logout extends AbstractLogInOutEventProvider { |
||||
|
||||
@Override |
||||
public String logoutAction(LogInOutResultInfo result) { |
||||
HttpSession session = result.getRequest().getSession(true); |
||||
LoginService.getInstance().crossDomainLogout(result.getRequest(),result.getResponse(),""); |
||||
session.invalidate(); |
||||
return PluginSimpleConfig.getInstance().getLogoutUrl(); |
||||
} |
||||
} |
||||
|
@ -0,0 +1,37 @@
|
||||
package com.eco.plugin.xxxx.bssso.oauthservice; |
||||
|
||||
import com.eco.plugin.xxxx.bssso.config.PluginSimpleConfig; |
||||
import com.eco.plugin.xxxx.bssso.utils.FRUtils; |
||||
import com.yum.secure.builder.OAuthServiceBuilder; |
||||
import com.yum.secure.model.OAuth20Config; |
||||
import com.yum.secure.model.Token; |
||||
import com.yum.secure.oauth.IOAuth20Service; |
||||
|
||||
public class OAuthService { |
||||
IOAuth20Service oAuth20Service; |
||||
|
||||
|
||||
public OAuthService(String clientId, String clientSerect, String redirectUri) { |
||||
String authorizeUrl = PluginSimpleConfig.getInstance().getSsoprefix()+"/oauth/authorize"; |
||||
String accessTokenUrl = PluginSimpleConfig.getInstance().getSsoprefix()+"/oauth/token"; |
||||
OAuth20Config oAuth20Config = new OAuth20Config(clientId, clientSerect, redirectUri, authorizeUrl, accessTokenUrl); |
||||
this.oAuth20Service = (new OAuthServiceBuilder(oAuth20Config)).build20Service(); |
||||
} |
||||
|
||||
public String getAuthorizationUrl() { |
||||
return this.oAuth20Service.getAuthorizationUrl(); |
||||
} |
||||
|
||||
public Token getAccessToken(String code) { |
||||
FRUtils.FRLogInfo("code:"+code); |
||||
Token accessToken = this.oAuth20Service.getAccessToken(code); |
||||
if(accessToken != null){ |
||||
FRUtils.FRLogInfo("token:"+accessToken.getToken()); |
||||
}else{ |
||||
FRUtils.FRLogInfo("token为空"); |
||||
|
||||
} |
||||
return accessToken; |
||||
} |
||||
} |
||||
|
@ -0,0 +1,121 @@
|
||||
package com.eco.plugin.xxxx.bssso.oauthservice; |
||||
|
||||
import com.eco.plugin.xxxx.bssso.config.PluginSimpleConfig; |
||||
import com.eco.plugin.xxxx.bssso.utils.FRUtils; |
||||
import com.yum.secure.client.BaseEntity; |
||||
import com.yum.secure.client.OAuthClient; |
||||
import com.yum.secure.exceptions.OAuthApiException; |
||||
import com.yum.secure.model.Response; |
||||
import com.yum.secure.model.Token; |
||||
import com.yum.secure.utils.Json2ObjectUtil; |
||||
import com.yum.secure.utils.OAuthConfigUtil; |
||||
import com.yum.secure.utils.Preconditions; |
||||
|
||||
public class UserInfo extends BaseEntity { |
||||
private String yumPSID; |
||||
private String yumJDECode; |
||||
private String yumADAccount; |
||||
private String yumHyperionCode; |
||||
private String yumVendorId; |
||||
private String yumEPRole1; |
||||
private Token accessToken; |
||||
|
||||
public UserInfo() { |
||||
} |
||||
|
||||
public UserInfo(Token accessToken) { |
||||
this.accessToken = accessToken; |
||||
} |
||||
|
||||
public Token getAccessToken() { |
||||
return this.accessToken; |
||||
} |
||||
|
||||
public void setAccessToken(Token accessToken) { |
||||
this.accessToken = accessToken; |
||||
} |
||||
|
||||
public String getYumPSID() { |
||||
return this.yumPSID; |
||||
} |
||||
|
||||
public void setYumPSID(String yumPSID) { |
||||
this.yumPSID = yumPSID; |
||||
} |
||||
|
||||
public String getYumJDECode() { |
||||
return this.yumJDECode; |
||||
} |
||||
|
||||
public void setYumJDECode(String yumJDECode) { |
||||
this.yumJDECode = yumJDECode; |
||||
} |
||||
|
||||
public String getYumADAccount() { |
||||
return this.yumADAccount; |
||||
} |
||||
|
||||
public void setYumADAccount(String yumADAccount) { |
||||
this.yumADAccount = yumADAccount; |
||||
} |
||||
|
||||
public String getYumHyperionCode() { |
||||
return this.yumHyperionCode; |
||||
} |
||||
|
||||
public void setYumHyperionCode(String yumHyperionCode) { |
||||
this.yumHyperionCode = yumHyperionCode; |
||||
} |
||||
|
||||
public String getYumVendorId() { |
||||
return this.yumVendorId; |
||||
} |
||||
|
||||
public void setYumVendorId(String yumVendorId) { |
||||
this.yumVendorId = yumVendorId; |
||||
} |
||||
|
||||
public String getYumEPRole1() { |
||||
return yumEPRole1; |
||||
} |
||||
|
||||
public void setYumEPRole1(String yumEPRole1) { |
||||
this.yumEPRole1 = yumEPRole1; |
||||
} |
||||
|
||||
public UserInfo requestUserInfo() throws OAuthApiException { |
||||
FRUtils.FRLogInfo("getUserInfo"); |
||||
Preconditions.checkNotNull(this.accessToken, "accessToken is null"); |
||||
OAuthClient client = new OAuthClient(PluginSimpleConfig.getInstance().getSsoprefix() + "/oauth/userinfo"); |
||||
client.signAccessToken(this.accessToken); |
||||
Response response = client.execute(); |
||||
UserInfo user = new UserInfo(); |
||||
FRUtils.FRLogInfo("body:"+response.getBody()); |
||||
|
||||
System.out.println("response.getBody()>>>" + response.getBody()); |
||||
user = (UserInfo)Json2ObjectUtil.json2Object(response.getBody(), user); |
||||
if (user.getError() != null && !"".equals(user.getError().trim())) { |
||||
throw new OAuthApiException(user.getError(), user.getError_description()); |
||||
} else { |
||||
return user; |
||||
} |
||||
} |
||||
|
||||
public String requestJsonUserInfo() throws OAuthApiException { |
||||
Preconditions.checkNotNull(this.accessToken, "accessToken is null"); |
||||
OAuthClient client = new OAuthClient(OAuthConfigUtil.getUserInfoUrl()); |
||||
client.signAccessToken(this.accessToken); |
||||
Response response = client.execute(); |
||||
com.yum.secure.client.model.UserInfo user = new com.yum.secure.client.model.UserInfo(); |
||||
System.out.println("response.getBody()>>>" + response.getBody()); |
||||
if (user.getError() != null && !"".equals(user.getError().trim())) { |
||||
throw new OAuthApiException(user.getError(), user.getError_description()); |
||||
} else { |
||||
return response.getBody(); |
||||
} |
||||
} |
||||
|
||||
public String toString() { |
||||
return "UserInfo [yumPSID=" + this.yumPSID + ", yumJDECode=" + this.yumJDECode + ", yumADAccount=" + this.yumADAccount + ", yumHyperionCode=" + this.yumHyperionCode + ", yumVendorId=" + this.yumVendorId + ", accessToken=" + this.accessToken + "]"; |
||||
} |
||||
} |
@ -0,0 +1,220 @@
|
||||
package com.eco.plugin.xxxx.bssso.utils; |
||||
|
||||
import com.fr.decision.authority.data.User; |
||||
import com.fr.decision.privilege.TransmissionTool; |
||||
import com.fr.decision.webservice.bean.user.*; |
||||
import com.fr.decision.webservice.service.user.UserMiddleRoleService; |
||||
import com.fr.decision.webservice.v10.login.ExtendTokenProcessor; |
||||
import com.fr.decision.webservice.v10.login.LoginService; |
||||
import com.fr.decision.webservice.v10.user.UserService; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
public class FRUserUtils { |
||||
|
||||
/** |
||||
* 获取用户Service |
||||
* @return |
||||
*/ |
||||
public static UserService getUserService(){ |
||||
return UserService.getInstance(); |
||||
} |
||||
|
||||
/** |
||||
* 获取全量用户 |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static List<UserBean> getAllUsers(){ |
||||
List<UserBean> userbean = UserMiddleRoleService.getInstance().getAllUsers(false); |
||||
// List<UserAdditionBean> users = new ArrayList<UserAdditionBean>();
|
||||
// getAllUser(getAdminUser().getUsername(),0,1000,users);
|
||||
return userbean; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param adminUsername 管理员用户名 |
||||
* @param page 页数 |
||||
* @param num 每页的数据 |
||||
* @param users 保存用户的列表 |
||||
*/ |
||||
private static void getAllUser(String adminUsername,int page,int num,List<UserAdditionBean> users) throws Exception { |
||||
Map<String,Object> result = getUserService().getAllUsers(adminUsername,page,num,"","",true); |
||||
Long total = (Long)result.get("total"); |
||||
List<UserAdditionBean> item = (List<UserAdditionBean>)result.get("items"); |
||||
users.addAll(item); |
||||
|
||||
page = page+1; |
||||
|
||||
if(page * num >= total){ |
||||
return ; |
||||
} |
||||
|
||||
getAllUser(adminUsername,page,num,users); |
||||
} |
||||
/** |
||||
* 添加用户 |
||||
* @param userBean |
||||
*/ |
||||
public static void addUser(UserBean userBean) throws Exception { |
||||
userBean.setPassword(TransmissionTool.defaultEncrypt(userBean.getPassword())); |
||||
getUserService().addUser(userBean); |
||||
} |
||||
|
||||
/** |
||||
* 删除用户 |
||||
* @param userBean |
||||
*/ |
||||
public static void updateUser(UserBean userBean) throws Exception { |
||||
getUserService().editUser(userBean,getAdminUser().getId()); |
||||
} |
||||
|
||||
/** |
||||
* 删除用户 |
||||
* @param user |
||||
* @return |
||||
*/ |
||||
public static int deleteUser(User user) throws Exception { |
||||
String userId = user.getId(); |
||||
|
||||
UserUpdateBean userUpdateBean = new UserUpdateBean(); |
||||
userUpdateBean.setRemoveUserIds(new String[]{userId}); |
||||
|
||||
return getUserService().deleteUsers(userUpdateBean); |
||||
} |
||||
|
||||
/** |
||||
* 根据用户名获取用户实体 |
||||
* @param userName |
||||
* @return |
||||
*/ |
||||
public static User getUserByUserName(String userName) throws Exception { |
||||
return getUserService().getUserByUserName(userName); |
||||
} |
||||
|
||||
/** |
||||
* 根据用户名获取用户实体 |
||||
* @param userName |
||||
* @return |
||||
*/ |
||||
public static UserBean getUserBeanByUserName(String userName ) throws Exception { |
||||
String id = getUserService().getUserByUserName(userName).getId(); |
||||
return getUser(id); |
||||
} |
||||
|
||||
/** |
||||
* 根据id获取用户 |
||||
* @param id |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static UserBean getUser(String id) throws Exception { |
||||
return getUserService().getUser(id); |
||||
} |
||||
|
||||
/** |
||||
* 判断是否是管理员 |
||||
* @param username |
||||
* @return |
||||
*/ |
||||
public static boolean isAdmin(String username) throws Exception{ |
||||
return getUserService().isAdmin(getUserByUserName(username).getId()); |
||||
} |
||||
|
||||
/** |
||||
* 禁用启用用户 |
||||
* @param userId |
||||
* @param state false 禁用 true 启用 |
||||
* @throws Exception 异常说明失败 |
||||
*/ |
||||
public static void forbidUser(String userId,boolean state) throws Exception { |
||||
getUserService().forbidUser(userId,state); |
||||
} |
||||
|
||||
/** |
||||
* 修改用户部门 |
||||
* @param departmentId |
||||
* @param postId |
||||
* @param ud |
||||
* @throws Exception |
||||
*/ |
||||
public static void updateDepartmentPostUsers(String departmentId, String postId, UserUpdateBean ud) throws Exception { |
||||
getUserService().updateDepartmentPostUsers(departmentId,"",ud); |
||||
} |
||||
|
||||
|
||||
// /**
|
||||
// * 验证密码是否正确
|
||||
// * @param psd 明文密码
|
||||
// * @param user 根据用户名获取得用户对象
|
||||
// * @return
|
||||
// */
|
||||
// public static boolean checkPsd(String psd,User user){
|
||||
// String shaPsd = CipherUtils.jdksha256(psd);
|
||||
//
|
||||
// return shaPsd.equals(user.getPassword());
|
||||
// }
|
||||
public static User getCurrentUser(HttpServletRequest req) throws Exception { |
||||
String username = LoginService.getInstance().getCurrentUserNameFromRequestCookie(req); |
||||
|
||||
if(Utils.isNullStr(username)){ |
||||
return null; |
||||
} |
||||
|
||||
return getUserByUserName(username); |
||||
} |
||||
|
||||
public static UserBean getCurrentUserBean(HttpServletRequest req) throws Exception { |
||||
String username = LoginService.getInstance().getCurrentUserNameFromRequestCookie(req); |
||||
|
||||
if(Utils.isNullStr(username)){ |
||||
return null; |
||||
} |
||||
|
||||
return getUserBeanByUserName(username); |
||||
} |
||||
|
||||
/** |
||||
* 获取用户部门角色 |
||||
* @param username |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
private static UserRolesBean getUserRolesBean(String username) throws Exception { |
||||
return FRUserUtils.getUserService().getUserDepAndCustomRoles(username); |
||||
} |
||||
|
||||
/** |
||||
* 获取部门职务 |
||||
* @param username |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static List<DepRoleBean> getDepRoleBean(String username) throws Exception{ |
||||
return getUserRolesBean(username).getDepRoles(); |
||||
} |
||||
|
||||
/** |
||||
* 获取角色 |
||||
* @param username |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static List<String> getCustomRoles(String username) throws Exception{ |
||||
return getUserRolesBean(username).getCustomRoles(); |
||||
} |
||||
|
||||
public static UserBean getAdminUser() throws Exception { |
||||
String adminid = getUserService().getAdminUserIdList().get(0); |
||||
return getUser(adminid); |
||||
} |
||||
|
||||
public static String getUsernameFromToken(String token){ |
||||
String username = ExtendTokenProcessor.KEY.getUsername(token); |
||||
return username; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,255 @@
|
||||
package com.eco.plugin.xxxx.bssso.utils; |
||||
|
||||
import com.fr.base.ServerConfig; |
||||
import com.fr.base.TableData; |
||||
import com.fr.decision.authority.AuthorityContext; |
||||
import com.fr.decision.authority.data.User; |
||||
import com.fr.decision.webservice.login.LogInOutResultInfo; |
||||
import com.fr.decision.webservice.utils.DecisionServiceConstants; |
||||
import com.fr.decision.webservice.v10.login.LoginService; |
||||
import com.fr.decision.webservice.v10.login.event.LogInOutEvent; |
||||
import com.fr.decision.webservice.v10.user.UserService; |
||||
import com.fr.event.EventDispatcher; |
||||
import com.fr.file.TableDataConfig; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.stable.query.QueryFactory; |
||||
import com.fr.stable.query.restriction.RestrictionFactory; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.Cookie; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import javax.servlet.http.HttpSession; |
||||
import java.io.IOException; |
||||
import java.util.List; |
||||
|
||||
public class FRUtils { |
||||
/** |
||||
* 判断用户是否存在 |
||||
* @param userName |
||||
* @return |
||||
*/ |
||||
public static boolean isUserExist(String userName){ |
||||
if (StringUtils.isEmpty(userName)) { |
||||
return false; |
||||
} else { |
||||
try { |
||||
List param1 = AuthorityContext.getInstance().getUserController().find(QueryFactory.create().addRestriction(RestrictionFactory.eq("userName", userName))); |
||||
return param1 != null && !param1.isEmpty(); |
||||
} catch (Exception param2) { |
||||
FineLoggerFactory.getLogger().error(param2.getMessage()); |
||||
return false; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 判断是否登录FR |
||||
* @param req |
||||
* @return |
||||
*/ |
||||
public static boolean isLogin(HttpServletRequest req){ |
||||
return LoginService.getInstance().isLogged(req); |
||||
} |
||||
|
||||
/** |
||||
* 帆软登录 |
||||
* @param httpServletRequest |
||||
* @param httpServletResponse |
||||
* @param userName |
||||
* @param url |
||||
*/ |
||||
public static void login(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,String userName,String url){ |
||||
|
||||
FineLoggerFactory.getLogger().info("FRLOG:用户名:"+userName); |
||||
FineLoggerFactory.getLogger().info("FRLOG:跳转链接:"+url); |
||||
|
||||
|
||||
//判断用户名是否为空
|
||||
if(!Utils.isNullStr(userName)){ |
||||
if(isUserExist(userName)){ |
||||
String FRToken = ""; |
||||
|
||||
try { |
||||
//HttpSession session = httpServletRequest.getSession(true);
|
||||
|
||||
FRToken = LoginService.getInstance().login(httpServletRequest, httpServletResponse, userName); |
||||
|
||||
//httpServletRequest.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME,FRToken);
|
||||
|
||||
//session.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME, FRToken);
|
||||
EventDispatcher.fire(LogInOutEvent.LOGIN,new LogInOutResultInfo(httpServletRequest,httpServletResponse,userName,true)); |
||||
FineLoggerFactory.getLogger().info("FRLOG:登陆成功!"); |
||||
|
||||
if(!Utils.isNullStr(url)){ |
||||
httpServletResponse.sendRedirect(url); |
||||
} |
||||
} catch (Exception e) { |
||||
ResponseUtils.failedResponse(httpServletResponse,"登录异常,请联系管理员!"); |
||||
FineLoggerFactory.getLogger().info("FRLOG:登录异常,请联系管理员!"); |
||||
FineLoggerFactory.getLogger().info("FRLOGException:"+e.getMessage()); |
||||
} |
||||
}else{ |
||||
ResponseUtils.failedResponse(httpServletResponse,"用户在报表系统中不存在!"); |
||||
FineLoggerFactory.getLogger().info("FRLOG:用户在报表系统中不存在!"); |
||||
} |
||||
}else{ |
||||
ResponseUtils.failedResponse(httpServletResponse,"用户名不能为空!"); |
||||
FineLoggerFactory.getLogger().info("FRLOG:用户名不能为空!"); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 帆软登录 |
||||
* @param httpServletRequest |
||||
* @param httpServletResponse |
||||
* @param token |
||||
* @param url |
||||
*/ |
||||
public static void loginByToken(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,String token,String url){ |
||||
|
||||
FineLoggerFactory.getLogger().info("FRLOG:token:"+token); |
||||
FineLoggerFactory.getLogger().info("FRLOG:跳转链接:"+url); |
||||
|
||||
|
||||
//判断用户名是否为空
|
||||
if(!Utils.isNullStr(token)){ |
||||
writeToken2Cookie(httpServletResponse,token,-1); |
||||
|
||||
HttpSession session = httpServletRequest.getSession(true); |
||||
|
||||
httpServletRequest.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME,token); |
||||
|
||||
session.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME, token); |
||||
|
||||
if(!Utils.isNullStr(url)){ |
||||
try { |
||||
httpServletResponse.sendRedirect(url); |
||||
} catch (IOException e) { |
||||
ResponseUtils.failedResponse(httpServletResponse,"跳转异常!"); |
||||
FineLoggerFactory.getLogger().info("FRLOG:跳转异常!"); |
||||
} |
||||
} |
||||
}else{ |
||||
ResponseUtils.failedResponse(httpServletResponse,"token不能为空!"); |
||||
FineLoggerFactory.getLogger().info("FRLOG:token不能为空!"); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 获取token |
||||
* @param httpServletRequest |
||||
* @param httpServletResponse |
||||
* @param username |
||||
* @return |
||||
*/ |
||||
public static String getToken(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,String username){ |
||||
String token = ""; |
||||
try { |
||||
token = LoginService.getInstance().login(httpServletRequest, httpServletResponse, username); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:获取token失败"+e.getMessage()); |
||||
} |
||||
|
||||
return token; |
||||
} |
||||
|
||||
private static void writeToken2Cookie(HttpServletResponse param1, String param2, int param3) { |
||||
try { |
||||
if (StringUtils.isNotEmpty(param2)) { |
||||
Cookie param4 = new Cookie("fine_auth_token", param2); |
||||
long param5 = param3 == -2 ? 1209600000L : (long)param3; |
||||
param4.setMaxAge((int)param5); |
||||
param4.setPath(ServerConfig.getInstance().getCookiePath()); |
||||
param1.addCookie(param4); |
||||
Cookie param7 = new Cookie("fine_remember_login", String.valueOf(param3 == -2 ? -2 : -1)); |
||||
param7.setMaxAge((int)param5); |
||||
param7.setPath(ServerConfig.getInstance().getCookiePath()); |
||||
param1.addCookie(param7); |
||||
} else { |
||||
FineLoggerFactory.getLogger().error("empty token cannot save."); |
||||
} |
||||
} catch (Exception param8) { |
||||
FineLoggerFactory.getLogger().error(param8.getMessage(), param8); |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param httpServletRequest |
||||
* @param httpServletResponse |
||||
*/ |
||||
public static void logout(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse) |
||||
{ |
||||
if(!isLogin(httpServletRequest)){ |
||||
return ; |
||||
} |
||||
|
||||
try { |
||||
LoginService.getInstance().logout(httpServletRequest,httpServletResponse); |
||||
} catch (Exception e) { |
||||
ResponseUtils.failedResponse(httpServletResponse,"登出异常,请联系管理员!"); |
||||
FineLoggerFactory.getLogger().info("FRLOG:登出异常,请联系管理员!"); |
||||
FineLoggerFactory.getLogger().info("FRLOGException:"+e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 打印FR日志 |
||||
* @param message |
||||
*/ |
||||
public static void FRLogInfo(String message){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:"+message); |
||||
} |
||||
|
||||
/** |
||||
* 打印FR日志-error |
||||
* @param message |
||||
*/ |
||||
public static void FRLogError(String message){ |
||||
FineLoggerFactory.getLogger().error("FRLOG:"+message); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 根据用户名获取用户信息 |
||||
* @param userName |
||||
* @return |
||||
*/ |
||||
public static User getFRUserByUserName(String userName){ |
||||
try { |
||||
return UserService.getInstance().getUserByUserName(userName); |
||||
} catch (Exception e) { |
||||
FRLogInfo("获取用户信息异常:"+e.getMessage()); |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* 解密FR密码 |
||||
* @param password |
||||
* @return |
||||
*/ |
||||
// public static String decryptFRPsd(String password){
|
||||
// FRLogInfo("解密密码:"+password);
|
||||
// return TransmissionTool.decrypt(password);
|
||||
// }
|
||||
|
||||
/** |
||||
* 获取带参数的访问链接 |
||||
* @return |
||||
*/ |
||||
public static String getAllUrl(HttpServletRequest httpServletRequest){ |
||||
return WebUtils.getOriginalURL(httpServletRequest); |
||||
} |
||||
|
||||
public static TableData getTableData(String serverDataSetName){ |
||||
TableData userInfo = TableDataConfig.getInstance().getTableData("serverDataSetName"); |
||||
|
||||
// DataModel userInfoDM = userInfo.createDataModel(Calculator.createCalculator());
|
||||
return userInfo; |
||||
} |
||||
} |
@ -0,0 +1,262 @@
|
||||
package com.eco.plugin.xxxx.bssso.utils; |
||||
|
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.third.org.apache.http.HttpEntity; |
||||
import com.fr.third.org.apache.http.HttpResponse; |
||||
import com.fr.third.org.apache.http.HttpStatus; |
||||
import com.fr.third.org.apache.http.NameValuePair; |
||||
import com.fr.third.org.apache.http.client.CookieStore; |
||||
import com.fr.third.org.apache.http.client.entity.UrlEncodedFormEntity; |
||||
import com.fr.third.org.apache.http.client.methods.HttpGet; |
||||
import com.fr.third.org.apache.http.client.methods.HttpPost; |
||||
import com.fr.third.org.apache.http.conn.ssl.NoopHostnameVerifier; |
||||
import com.fr.third.org.apache.http.entity.StringEntity; |
||||
import com.fr.third.org.apache.http.impl.client.BasicCookieStore; |
||||
import com.fr.third.org.apache.http.impl.client.CloseableHttpClient; |
||||
import com.fr.third.org.apache.http.impl.client.HttpClients; |
||||
import com.fr.third.org.apache.http.impl.cookie.BasicClientCookie; |
||||
import com.fr.third.org.apache.http.message.BasicNameValuePair; |
||||
import com.fr.third.org.apache.http.ssl.SSLContexts; |
||||
import com.fr.third.org.apache.http.ssl.TrustStrategy; |
||||
import com.fr.third.org.apache.http.util.EntityUtils; |
||||
|
||||
import javax.net.ssl.SSLContext; |
||||
import javax.servlet.http.Cookie; |
||||
import java.io.UnsupportedEncodingException; |
||||
import java.security.cert.CertificateException; |
||||
import java.security.cert.X509Certificate; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.Set; |
||||
|
||||
public class HttpUtils { |
||||
|
||||
/** |
||||
* httpGet请求 |
||||
* @param url |
||||
* @return |
||||
*/ |
||||
public static String httpGet(String url,Cookie[] cookies,Map<String,String> header){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--url:"+url); |
||||
|
||||
//创建httpClient
|
||||
CloseableHttpClient httpclient = createHttpClient(cookies); |
||||
|
||||
HttpGet getMethod = new HttpGet(url); |
||||
|
||||
if(header != null && header.size() > 0){ |
||||
Set<String> keySet = header.keySet(); |
||||
|
||||
for(String key : keySet){ |
||||
getMethod.setHeader(key,header.get(key)); |
||||
} |
||||
} |
||||
|
||||
try { |
||||
HttpResponse response = httpclient.execute(getMethod); |
||||
int status =response.getStatusLine().getStatusCode(); |
||||
HttpEntity entity = response.getEntity(); |
||||
String returnResult = EntityUtils.toString(entity, "utf-8"); |
||||
|
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--status:"+status); |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--returnResult:"+returnResult); |
||||
|
||||
httpclient.close(); |
||||
|
||||
if (status == HttpStatus.SC_OK) { |
||||
return returnResult; |
||||
} |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--exception:"+e.getMessage()); |
||||
} |
||||
|
||||
try { |
||||
httpclient.close(); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:http关闭异常:"+e.getMessage()); |
||||
} |
||||
|
||||
return ""; |
||||
} |
||||
|
||||
/** |
||||
* HttpPost请求 |
||||
* @param postMethod |
||||
* @return |
||||
*/ |
||||
private static String HttpPost(HttpPost postMethod){ |
||||
CloseableHttpClient httpclient = createHttpClient(null); |
||||
|
||||
try { |
||||
HttpResponse response = httpclient.execute(postMethod); |
||||
int status = response.getStatusLine().getStatusCode(); |
||||
HttpEntity entity = response.getEntity(); |
||||
String returnResult = EntityUtils.toString(entity, "utf-8"); |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPost:status:"+status); |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPost:returnResult:"+returnResult); |
||||
httpclient.close(); |
||||
|
||||
if (status == HttpStatus.SC_OK) { |
||||
return returnResult; |
||||
} |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPost:exception:"+e.getMessage()); |
||||
} |
||||
|
||||
try { |
||||
httpclient.close(); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:http关闭异常:"+e.getMessage()); |
||||
} |
||||
|
||||
return ""; |
||||
} |
||||
|
||||
public static String HttpPostXML(String url, String xmlParam){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPostXML:url:"+url); |
||||
|
||||
HttpPost postMethod = new HttpPost(url); |
||||
|
||||
postMethod.setHeader("Content-type", "text/html"); |
||||
HttpEntity entity2 = null; |
||||
try { |
||||
entity2 = new StringEntity(xmlParam); |
||||
} catch (UnsupportedEncodingException e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPostXML:参数异常:"+e.getMessage()); |
||||
return ""; |
||||
} |
||||
|
||||
postMethod.setEntity(entity2); |
||||
|
||||
return HttpPost(postMethod); |
||||
} |
||||
|
||||
public static String HttpPostText(String url, String xmlParam){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPostText:url:"+url); |
||||
|
||||
HttpPost postMethod = new HttpPost(url); |
||||
|
||||
postMethod.setHeader("Content-type", "text/plain"); |
||||
HttpEntity entity2 = null; |
||||
try { |
||||
entity2 = new StringEntity(xmlParam); |
||||
} catch (UnsupportedEncodingException e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPostText:参数异常:"+e.getMessage()); |
||||
return ""; |
||||
} |
||||
|
||||
postMethod.setEntity(entity2); |
||||
|
||||
return HttpPost(postMethod); |
||||
} |
||||
|
||||
public static String HttpPostJson(String url, String param,Map<String,String> header){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPostJSON:url:"+url); |
||||
|
||||
HttpPost postMethod = new HttpPost(url); |
||||
|
||||
postMethod.setHeader("Content-Type","application/json"); |
||||
|
||||
if(header != null && header.size() > 0){ |
||||
Set<String> keySet = header.keySet(); |
||||
|
||||
for(String key : keySet){ |
||||
postMethod.setHeader(key,header.get(key)); |
||||
} |
||||
} |
||||
|
||||
if(!Utils.isNullStr(param)){ |
||||
HttpEntity entity2 = null; |
||||
try { |
||||
entity2 = new StringEntity(param); |
||||
} catch (UnsupportedEncodingException e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPostJSON:参数异常:"+e.getMessage()); |
||||
return ""; |
||||
} |
||||
|
||||
postMethod.setEntity(entity2); |
||||
} |
||||
|
||||
return HttpPost(postMethod); |
||||
} |
||||
|
||||
public static String HttpPostWWWForm(String url, Map<String,String> header,Map<String,String> param){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpWWWForm:url:"+url); |
||||
|
||||
HttpPost postMethod = new HttpPost(url); |
||||
|
||||
if(header != null && header.size() > 0){ |
||||
Set<String> keySet = header.keySet(); |
||||
|
||||
for(String key : keySet){ |
||||
postMethod.setHeader(key,header.get(key)); |
||||
} |
||||
} |
||||
|
||||
if(param != null && param.size() > 0){ |
||||
List<NameValuePair> params = new ArrayList<NameValuePair>(param.size()); |
||||
|
||||
for(Map.Entry<String,String> map : param.entrySet()){ |
||||
params.add(new BasicNameValuePair(map.getKey(), map.getValue())); |
||||
} |
||||
|
||||
try { |
||||
postMethod.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); |
||||
} catch (UnsupportedEncodingException e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpWWWForm:异常:"+e.getMessage()); |
||||
return ""; |
||||
} |
||||
} |
||||
|
||||
return HttpPost(postMethod); |
||||
} |
||||
|
||||
private static CloseableHttpClient createHttpClient(Cookie[] cookies){ |
||||
|
||||
SSLContext sslContext = null; |
||||
try { |
||||
sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustStrategy() { |
||||
@Override |
||||
public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { |
||||
return true; |
||||
} |
||||
}).build(); |
||||
} catch (Exception e) { |
||||
FRUtils.FRLogInfo("exception:"+e.getMessage()); |
||||
} |
||||
|
||||
CloseableHttpClient httpclient = null; |
||||
|
||||
if(cookies != null && cookies.length > 0){ |
||||
CookieStore cookieStore = cookieToCookieStore(cookies); |
||||
|
||||
httpclient = HttpClients.custom().setSslcontext(sslContext). |
||||
setSSLHostnameVerifier(new NoopHostnameVerifier()).setDefaultCookieStore(cookieStore).build(); |
||||
} |
||||
else{ |
||||
httpclient = HttpClients.custom().setSslcontext(sslContext). |
||||
setSSLHostnameVerifier(new NoopHostnameVerifier()).build(); |
||||
} |
||||
|
||||
return httpclient; |
||||
} |
||||
|
||||
/** |
||||
* cookies转cookieStore |
||||
* @param cookies |
||||
* @return |
||||
*/ |
||||
public static CookieStore cookieToCookieStore(Cookie[] cookies){ |
||||
CookieStore cookieStore = new BasicCookieStore(); |
||||
|
||||
if(cookies != null && cookies.length>0){ |
||||
for(Cookie cookie : cookies){ |
||||
BasicClientCookie cookie1 = new BasicClientCookie(cookie.getName(), cookie.getValue()); |
||||
cookieStore.addCookie(cookie1); |
||||
} |
||||
} |
||||
|
||||
return cookieStore; |
||||
} |
||||
} |
@ -0,0 +1,94 @@
|
||||
package com.eco.plugin.xxxx.bssso.utils; |
||||
|
||||
import com.fr.json.JSONObject; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.PrintWriter; |
||||
|
||||
public class ResponseUtils { |
||||
private static final int SUCCESS = 200; |
||||
private static final int FAILED = -1; |
||||
|
||||
public static void successResponse(HttpServletResponse res, String body) { |
||||
response(res, body, SUCCESS); |
||||
} |
||||
|
||||
public static void failedResponse(HttpServletResponse res, String body) { |
||||
response(res, body, FAILED); |
||||
} |
||||
|
||||
private static void response(HttpServletResponse res, String body, int code) { |
||||
JSONObject object = new JSONObject(); |
||||
PrintWriter pw; |
||||
try { |
||||
object.put("code", code); |
||||
object.put("data", body); |
||||
pw = WebUtils.createPrintWriter(res); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info(e.getMessage()); |
||||
return; |
||||
} |
||||
res.setContentType("application/json;charset=utf-8"); |
||||
String result = object.toString(); |
||||
pw.println(result); |
||||
pw.flush(); |
||||
pw.close(); |
||||
} |
||||
|
||||
public static void response(HttpServletResponse res,JSONObject json){ |
||||
PrintWriter pw; |
||||
try { |
||||
pw = WebUtils.createPrintWriter(res); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info(e.getMessage()); |
||||
return; |
||||
} |
||||
res.setContentType("application/json;charset=utf-8"); |
||||
String result = json.toString(); |
||||
pw.println(result); |
||||
pw.flush(); |
||||
pw.close(); |
||||
} |
||||
|
||||
public static void responseXml(HttpServletResponse res,String xml){ |
||||
PrintWriter pw; |
||||
try { |
||||
pw = WebUtils.createPrintWriter(res); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info(e.getMessage()); |
||||
return; |
||||
} |
||||
res.setContentType("text/xml;charset=utf-8"); |
||||
pw.println(xml); |
||||
pw.flush(); |
||||
pw.close(); |
||||
} |
||||
|
||||
public static void setCSRFHeader(HttpServletResponse httpServletResponse){ |
||||
httpServletResponse.setHeader("Access-Control-Allow-Origin", "*"); |
||||
httpServletResponse.setHeader("Access-Control-Allow-Methods", "POST,GET,OPTIONS,DELETE,HEAD,PUT,PATCH"); |
||||
httpServletResponse.setHeader("Access-Control-Max-Age", "36000"); |
||||
httpServletResponse.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept,Authorization,authorization"); |
||||
} |
||||
|
||||
public static void responseJsonp(HttpServletRequest req, HttpServletResponse res, JSONObject json){ |
||||
PrintWriter pw; |
||||
try { |
||||
pw = WebUtils.createPrintWriter(res); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info(e.getMessage()); |
||||
return; |
||||
} |
||||
res.setContentType("text/javascript;charset=utf-8;charset=utf-8"); |
||||
String result = json.toString(); |
||||
|
||||
String jsonp=req.getParameter("callback"); |
||||
|
||||
pw.println(jsonp+"("+result+")"); |
||||
pw.flush(); |
||||
pw.close(); |
||||
} |
||||
} |
@ -0,0 +1,244 @@
|
||||
package com.eco.plugin.xxxx.bssso.utils; |
||||
|
||||
import com.fr.base.TemplateUtils; |
||||
import com.fr.data.NetworkHelper; |
||||
import com.fr.decision.webservice.v10.user.UserService; |
||||
import com.fr.io.utils.ResourceIOUtils; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.stable.CodeUtils; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.third.org.apache.commons.codec.digest.DigestUtils; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.Cookie; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.BufferedReader; |
||||
import java.io.InputStream; |
||||
import java.net.URLEncoder; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
import java.util.UUID; |
||||
import java.util.regex.Matcher; |
||||
import java.util.regex.Pattern; |
||||
|
||||
public class Utils { |
||||
|
||||
/** |
||||
* 判断字符串是否为空 |
||||
* @param str |
||||
* @return true 空字符串 false 非空字符串 |
||||
*/ |
||||
public static boolean isNullStr(String str){ |
||||
return !(str != null && !str.isEmpty() && !"null".equals(str)); |
||||
} |
||||
|
||||
/** |
||||
* 判断字符串是否非空 |
||||
* @param str |
||||
* @return |
||||
*/ |
||||
public static boolean isNotNullStr(String str){ |
||||
return !isNullStr(str); |
||||
} |
||||
|
||||
/** |
||||
* MD5加密 |
||||
* @param str |
||||
* @return |
||||
*/ |
||||
public static String getMd5Str(String str) |
||||
{ |
||||
return DigestUtils.md5Hex(str); |
||||
} |
||||
|
||||
/** |
||||
* 帆软shaEncode加密 |
||||
*/ |
||||
|
||||
public static String shaEncode(String str){ |
||||
return CodeUtils.sha256Encode(str); |
||||
} |
||||
|
||||
/** |
||||
* 获取uuid |
||||
*/ |
||||
public static String uuid(){ |
||||
return UUID.randomUUID().toString(); |
||||
} |
||||
|
||||
/** |
||||
* 替换空字符串 |
||||
* @param str |
||||
* @param replace |
||||
* @return |
||||
*/ |
||||
public static String replaceNullStr(String str,String replace){ |
||||
if(isNullStr(str)){ |
||||
return replace; |
||||
} |
||||
|
||||
return str; |
||||
} |
||||
|
||||
/** |
||||
* 获取请求体 |
||||
* @param req |
||||
* @return |
||||
*/ |
||||
public static JSONObject getRequestBody(HttpServletRequest req){ |
||||
StringBuffer sb = new StringBuffer(); |
||||
String line = null; |
||||
try { |
||||
BufferedReader reader = req.getReader(); |
||||
while ((line = reader.readLine()) != null) |
||||
sb.append(line); |
||||
} catch (Exception e) { |
||||
FRUtils.FRLogInfo("getRequestBody:exception:"+e.getMessage()); |
||||
} |
||||
//将空格和换行符替换掉避免使用反序列化工具解析对象时失败
|
||||
String jsonString = sb.toString().replaceAll("\\s","").replaceAll("\n",""); |
||||
|
||||
JSONObject json = new JSONObject(jsonString); |
||||
|
||||
return json; |
||||
} |
||||
|
||||
/** |
||||
* 获取ip |
||||
* @return |
||||
*/ |
||||
public static String getIp(HttpServletRequest req){ |
||||
String realIp = req.getHeader("X-Real-IP"); |
||||
String fw = req.getHeader("X-Forwarded-For"); |
||||
if (StringUtils.isNotEmpty(fw) && !"unKnown".equalsIgnoreCase(fw)) { |
||||
int param3 = fw.indexOf(","); |
||||
return param3 != -1 ? fw.substring(0, param3) : fw; |
||||
} else { |
||||
fw = realIp; |
||||
if (StringUtils.isNotEmpty(realIp) && !"unKnown".equalsIgnoreCase(realIp)) { |
||||
return realIp; |
||||
} else { |
||||
if (StringUtils.isBlank(realIp) || "unknown".equalsIgnoreCase(realIp)) { |
||||
fw = req.getHeader("Proxy-Client-IP"); |
||||
} |
||||
|
||||
if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) { |
||||
fw = req.getHeader("WL-Proxy-Client-IP"); |
||||
} |
||||
|
||||
if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) { |
||||
fw = req.getHeader("HTTP_CLIENT_IP"); |
||||
} |
||||
|
||||
if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) { |
||||
fw = req.getHeader("HTTP_X_FORWARDED_FOR"); |
||||
} |
||||
|
||||
if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) { |
||||
fw = req.getRemoteAddr(); |
||||
} |
||||
|
||||
return fw; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 根据key获取cookie |
||||
* @param req |
||||
* @return |
||||
*/ |
||||
public static String getCookieByKey(HttpServletRequest req,String key){ |
||||
Cookie[] cookies = req.getCookies(); |
||||
String cookie = ""; |
||||
|
||||
if(cookies == null || cookies.length <=0){ |
||||
return ""; |
||||
} |
||||
|
||||
for(int i = 0; i < cookies.length; i++) { |
||||
Cookie item = cookies[i]; |
||||
if (item.getName().equalsIgnoreCase(key)) { |
||||
cookie = item.getValue(); |
||||
} |
||||
} |
||||
|
||||
FRUtils.FRLogInfo("cookie:"+cookie); |
||||
|
||||
return cookie; |
||||
} |
||||
|
||||
/** |
||||
* 判断是否是手机端的链接 |
||||
* @param req |
||||
* @return |
||||
*/ |
||||
public static boolean isMobile(HttpServletRequest req) { |
||||
String[] mobileArray = {"iPhone", "iPad", "android", "windows phone", "xiaomi"}; |
||||
String userAgent = req.getHeader("user-agent"); |
||||
if (userAgent != null && userAgent.toUpperCase().contains("MOBILE")) { |
||||
for(String mobile : mobileArray) { |
||||
if(userAgent.toUpperCase().contains(mobile.toUpperCase())) { |
||||
return true; |
||||
} |
||||
} |
||||
} |
||||
return NetworkHelper.getDevice(req).isMobile(); |
||||
} |
||||
|
||||
/** |
||||
* 只编码中文 |
||||
* @param url |
||||
* @return |
||||
*/ |
||||
public static String encodeCH(String url ){ |
||||
Matcher matcher = Pattern.compile("[\\u4e00-\\u9fa5]").matcher(url); |
||||
|
||||
while(matcher.find()){ |
||||
String chn = matcher.group(); |
||||
url = url.replaceAll(chn, URLEncoder.encode(chn)); |
||||
} |
||||
|
||||
return url; |
||||
} |
||||
|
||||
/** |
||||
* 获取web-inf文件夹下的文件 |
||||
* filename /resources/ip4enc.properties |
||||
*/ |
||||
public static InputStream getResourcesFile(String filename){ |
||||
return ResourceIOUtils.read(filename); |
||||
} |
||||
|
||||
public static void toErrorPage(HttpServletResponse res,String path,Map<String, String> parameterMap){ |
||||
if(parameterMap == null){ |
||||
parameterMap = new HashMap<String, String>(); |
||||
} |
||||
|
||||
try { |
||||
String macPage = TemplateUtils.renderTemplate(path, parameterMap); |
||||
WebUtils.printAsString(res, macPage); |
||||
}catch (Exception e){ |
||||
FRUtils.FRLogError("跳转页面异常"); |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 判断是否是管理员 |
||||
* @param username |
||||
* @return |
||||
*/ |
||||
public static boolean isAdmin(String username) throws Exception{ |
||||
return UserService.getInstance().isAdmin(UserService.getInstance().getUserByUserName(username).getId()); |
||||
} |
||||
|
||||
public static String removeCode(String url){ |
||||
if(!url.contains("?code") && !url.contains("&code")){ |
||||
return url; |
||||
} |
||||
|
||||
return url.substring(0,url.indexOf(url.contains("?code") ? "?code" : "&code")); |
||||
} |
||||
} |
@ -0,0 +1,35 @@
|
||||
package com.eco.plugin.xxxx.bssso.webresource; |
||||
|
||||
import com.fr.decision.fun.impl.AbstractWebResourceProvider; |
||||
import com.fr.decision.web.MainComponent; |
||||
import com.fr.web.struct.Atom; |
||||
import com.fr.web.struct.Component; |
||||
import com.fr.web.struct.browser.RequestClient; |
||||
import com.fr.web.struct.category.ScriptPath; |
||||
import com.fr.web.struct.category.StylePath; |
||||
|
||||
/** |
||||
* Created by fr.open on 2021-12-03 |
||||
*/ |
||||
public class WebResourceProvider extends AbstractWebResourceProvider { |
||||
@Override |
||||
public Atom attach() { |
||||
return MainComponent.KEY; |
||||
} |
||||
|
||||
@Override |
||||
public Atom client() { |
||||
return new Component() { |
||||
@Override |
||||
public ScriptPath script(RequestClient requestClient) { |
||||
return ScriptPath.build("/com/eco/plugin/xxxx/bssso/js/login.js"); |
||||
} |
||||
|
||||
@Override |
||||
public StylePath style(RequestClient requestClient) { |
||||
return StylePath.EMPTY; |
||||
// return StylePath.build("/com/fr/plugin/jdfSSO/css/icon.css");
|
||||
} |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,714 @@
|
||||
|
||||
<!-- 根据用户名获取选中状态 --> |
||||
function getSelected(username){ |
||||
var selected = false; |
||||
|
||||
$.ajax({ |
||||
async:false, |
||||
url:"/webroot/decision/getByUsername?username="+username, |
||||
type:"get", |
||||
success:function(data){ |
||||
selected = data; |
||||
} |
||||
}) |
||||
return selected; |
||||
} |
||||
|
||||
<!-- 根据用户名修改选中状态 --> |
||||
function updateSelected(username,selected){ |
||||
var result = false; |
||||
$.ajax({ |
||||
async:false, |
||||
url:"/webroot/decision/updateSelected", |
||||
type:"post", |
||||
contentType:"application/json", |
||||
data:JSON.stringify({username:username,selected:selected}), |
||||
success:function(data){ |
||||
result = data; |
||||
} |
||||
}) |
||||
return result; |
||||
} |
||||
|
||||
<!-- 表头--> |
||||
var e = BI.inherit(BI.Widget, { |
||||
props: { |
||||
baseCls: "dec-user-table-header", |
||||
columnSize: [], |
||||
items: [], |
||||
onSortChange: BI.emptyFn, |
||||
onFilterChange: BI.emptyFn, |
||||
height: 32 |
||||
}, |
||||
_store: function () { |
||||
return BI.Models.getModel("dec.model.user.all.table.header") |
||||
}, |
||||
watch: { |
||||
enableCheck: function (e) { |
||||
this.checkbox.setEnable(e) |
||||
} |
||||
}, |
||||
render: function () { |
||||
var e = this.options; |
||||
return { |
||||
type: "bi.htape", |
||||
columnSize: e.columnSize, |
||||
items: this._formatItems(e.items) |
||||
} |
||||
}, |
||||
_formatItems: function (e) { |
||||
var t = this, |
||||
i = this.options, |
||||
n = [], |
||||
title =BI.map(e, function (e, t) { |
||||
var text = t.text; |
||||
return { |
||||
el: BI.extend({ |
||||
rgap: 10, |
||||
type: "bi.label", |
||||
textAlign: "left" |
||||
}, t, { |
||||
width: null |
||||
}), |
||||
width: text == '用户名' ? 0.16 : (text == '手机' ? 0.12 : t.width) |
||||
} |
||||
}); |
||||
title.push({ |
||||
el: { |
||||
rgap: 10, |
||||
text: "sso同步", |
||||
textAlign: "left", |
||||
type: "bi.label", |
||||
width: null |
||||
}, |
||||
width: 0.07 |
||||
}); |
||||
return n.push(BI.extend({ |
||||
type: "bi.center", |
||||
width: 50, |
||||
height: i.height, |
||||
items: [{ |
||||
type: "dec.multi.checkbox", |
||||
ref: function (e) { |
||||
t.checkbox = e |
||||
}, |
||||
disabled: !this.model.enableCheck, |
||||
listeners: [{ |
||||
eventName: BI.Controller.EVENT_CHANGE, |
||||
action: function () { |
||||
t.fireEvent(BI.Controller.EVENT_CHANGE, arguments) |
||||
} |
||||
} |
||||
] |
||||
} |
||||
] |
||||
})), |
||||
|
||||
n.push({ |
||||
type: "bi.htape", |
||||
items:title |
||||
}), |
||||
(n = BI.concat(n, this._createExtraItems())).push({ |
||||
type: "bi.layout", |
||||
width: 100 |
||||
}), |
||||
n |
||||
}, |
||||
_createExtraItems: function () { |
||||
var i = [], |
||||
e = BI.Providers.getProvider("dec.provider.all_user").getExtraAttributes(); |
||||
return BI.each(e, function (e, t) { |
||||
BI.isKey(t.header) ? i.push({ |
||||
type: "bi.label", |
||||
textAlign: "left", |
||||
text: t.header, |
||||
title: t.header, |
||||
width: t.width |
||||
}) : BI.isObject(t.header) ? i.push(BI.extend({ |
||||
width: t.width |
||||
}, t.header)) : i.push({ |
||||
type: "bi.layout", |
||||
width: t.width |
||||
}) |
||||
}), |
||||
i |
||||
}, |
||||
setSelected: function (e) { |
||||
this.checkbox.setSelected(e) |
||||
}, |
||||
setHalfSelected: function (e) { |
||||
this.checkbox.setHalfSelected(e) |
||||
}, |
||||
isHalfSelected: function () { |
||||
return this.checkbox.isHalfSelected() |
||||
}, |
||||
isSelected: function () { |
||||
return this.checkbox.isSelected() |
||||
} |
||||
}); |
||||
BI.shortcut("dec.user.table.header", e); |
||||
|
||||
<!-- 数据行 --> |
||||
var e = BI.inherit(BI.Widget, { |
||||
props: { |
||||
baseCls: "dec-user-table-row bi-border-bottom", |
||||
columnSize: [50, "fill", 100], |
||||
userInfo: {}, |
||||
value: BI.UUID() |
||||
}, |
||||
_store: function () { |
||||
return BI.Models.getModel("dec.model.user.all.row", this.options) |
||||
}, |
||||
watch: { |
||||
selected: function (e) { |
||||
this.setSelected(e) |
||||
} |
||||
}, |
||||
render: function () { |
||||
var e = this.options; |
||||
return { |
||||
type: "bi.htape", |
||||
$testId: "dec-user-table-row", |
||||
$value: e.userInfo.username, |
||||
columnSize: e.columnSize, |
||||
items: this._formatItem(e.userInfo) |
||||
} |
||||
}, |
||||
_formatItem: function (e) { |
||||
var t = this, |
||||
i = this.options, |
||||
n = [], |
||||
o = this.model.keywordMap; |
||||
var username = e.username; |
||||
return n.push({ |
||||
type: "bi.center_adapt", |
||||
width: 50, |
||||
height: i.height, |
||||
items: [{ |
||||
type: "bi.checkbox", |
||||
$testId: "dec-user-row-checkbox", |
||||
$value: e.username, |
||||
ref: function (e) { |
||||
t.checkbox = e |
||||
}, |
||||
disabled: !e.enableCheck, |
||||
selected: e.selected, |
||||
listeners: [{ |
||||
eventName: "EVENT_CHANGE", |
||||
action: function () { |
||||
t.store.changeSelected(this.isSelected()) |
||||
} |
||||
} |
||||
] |
||||
} |
||||
] |
||||
}), |
||||
n.push({ |
||||
el: { |
||||
type: "bi.htape", |
||||
height: i.height, |
||||
scrollable: !1, |
||||
disabled: !e.enable, |
||||
items: [{ |
||||
el: { |
||||
type: "bi.label", |
||||
ref: function (e) { |
||||
t.username = e |
||||
}, |
||||
scrollable: !1, |
||||
textAlign: "left", |
||||
text: e.username, |
||||
keyword: o.username, |
||||
title: function () { |
||||
return e.username |
||||
}, |
||||
rgap: 10, |
||||
height: i.height |
||||
}, |
||||
// width: .2
|
||||
width: .16 |
||||
}, { |
||||
el: { |
||||
type: "bi.label", |
||||
ref: function (e) { |
||||
t.realName = e |
||||
}, |
||||
scrollable: !1, |
||||
textAlign: "left", |
||||
text: e.realName, |
||||
keyword: o.realName, |
||||
title: function () { |
||||
return e.realName |
||||
}, |
||||
rgap: 10, |
||||
height: i.height |
||||
}, |
||||
width: .1 |
||||
}, { |
||||
el: { |
||||
type: "bi.label", |
||||
ref: function (e) { |
||||
t.depPostNames = e |
||||
}, |
||||
textAlign: "left", |
||||
text: e.depPostNames, |
||||
title: function () { |
||||
return e.depPostNames |
||||
}, |
||||
rgap: 10, |
||||
height: i.height |
||||
}, |
||||
width: .15 |
||||
}, { |
||||
el: { |
||||
type: "bi.label", |
||||
ref: function (e) { |
||||
t.roleNames = e |
||||
}, |
||||
textAlign: "left", |
||||
text: e.roleNames, |
||||
title: function () { |
||||
return e.roleNames |
||||
}, |
||||
rgap: 10, |
||||
height: i.height |
||||
}, |
||||
width: .15 |
||||
}, { |
||||
el: { |
||||
type: "bi.label", |
||||
ref: function (e) { |
||||
t.email = e |
||||
}, |
||||
textAlign: "left", |
||||
text: e.email, |
||||
keyword: o.email, |
||||
title: function () { |
||||
return e.email |
||||
}, |
||||
rgap: 10, |
||||
height: i.height |
||||
}, |
||||
width: .18 |
||||
}, { |
||||
el: { |
||||
type: "bi.label", |
||||
ref: function (e) { |
||||
t.mobile = e |
||||
}, |
||||
textAlign: "left", |
||||
text: e.mobile, |
||||
keyword: o.mobile, |
||||
title: function () { |
||||
return e.mobile |
||||
}, |
||||
rgap: 10, |
||||
height: i.height |
||||
}, |
||||
// width: .15
|
||||
width: .12 |
||||
}, { |
||||
el: { |
||||
type: "bi.label", |
||||
ref: function (e) { |
||||
t.enable = e |
||||
}, |
||||
textAlign: "left", |
||||
text: e.enable ? BI.i18nText("Dec-User_Enabled") : BI.i18nText("Dec-User_Disabled"), |
||||
rgap: 10, |
||||
height: i.height |
||||
}, |
||||
width: .07 |
||||
}, |
||||
{ |
||||
el: { |
||||
type: "bi.absolute_vertical_adapt", |
||||
height: i.height, |
||||
hgap: 0, |
||||
items: [{ |
||||
type: "bi.switch", |
||||
width:44, |
||||
selected:getSelected(username), |
||||
listeners: [{ |
||||
eventName: "BasicButton.EVENT_CHANGE", |
||||
action: function(e) { |
||||
var selected =this.options.selected; |
||||
var flag = updateSelected(username,selected); |
||||
if(!flag){ |
||||
BI.Msg.toast("配置失败,请联系管理员!", { |
||||
level: "error" |
||||
}); |
||||
this.options.selected = !selected; |
||||
} |
||||
} |
||||
}], |
||||
ref: function (e) { |
||||
t.switch = e |
||||
} |
||||
}], |
||||
textAlign: "left", |
||||
rgap: 10 |
||||
}, |
||||
width: .07 |
||||
} |
||||
] |
||||
} |
||||
}), |
||||
(n = BI.concat(n, this._createExtraItems(e))).push(BI.extend({}, e, { |
||||
type: "dec.user.row.tools", |
||||
width: 100, |
||||
$scope: e.username, |
||||
infoGetter: function () { |
||||
return e |
||||
}, |
||||
onDelete: function () { |
||||
t.options.onDelete([e.id]) |
||||
}, |
||||
onEdit: i.onEdit, |
||||
onDisable: function (e) { |
||||
t.store.disableUser(e, t.getValue()) |
||||
} |
||||
})), |
||||
n |
||||
}, |
||||
_createExtraItems: function (i) { |
||||
var n = [], |
||||
e = BI.Providers.getProvider("dec.provider.all_user").getExtraAttributes(); |
||||
return BI.each(e, function (e, t) { |
||||
BI.isKey(t.column) ? n.push(BI.extend({ |
||||
type: t.column, |
||||
width: t.width |
||||
}, i)) : BI.isFunction(t.column) ? n.push(BI.extend({ |
||||
width: t.width |
||||
}, t.column(i))) : n.push({ |
||||
type: "bi.layout", |
||||
width: t.width |
||||
}) |
||||
}), |
||||
n |
||||
}, |
||||
isSelected: function () { |
||||
return this.checkbox.isSelected() |
||||
}, |
||||
getValue: function () { |
||||
return this.options.userInfo.id |
||||
}, |
||||
setSelected: function (e) { |
||||
this.options.userInfo.enableCheck && this.checkbox.setSelected(e) |
||||
} |
||||
}); |
||||
e.EVENT_DELETE = "EVENT_DELETE", |
||||
BI.shortcut("dec.user.table.row", e) |
||||
// var t = "default_fail",
|
||||
// e = BI.inherit(BI.OB, {
|
||||
// init: function () {
|
||||
// this.failMap = {},
|
||||
// this._initErrorHandler()
|
||||
// },
|
||||
// addHandler: function (e, t) {
|
||||
// this.failMap[e] = t
|
||||
// },
|
||||
// getHandler: function (e) {
|
||||
// return BI.isFunction(this.failMap[e]) ? this.failMap[e] : this.failMap[t]
|
||||
// },
|
||||
// _initErrorHandler: function () {
|
||||
// this.failMap[DecCst.ErrorCode.USER_LOGGED] = function (e) {
|
||||
// this.store.setPropsInfo({
|
||||
// token: e.errorMsg,
|
||||
// isChangePwd: !0,
|
||||
// from: DecCst.Login.AuthenticationModule.SINGLE
|
||||
// }),
|
||||
// this.store.setNeedSlider(!1),
|
||||
// this.loginErrorRow.visible()
|
||||
// },
|
||||
// this.failMap[DecCst.ErrorCode.USER_LOGGED_CAN_NOT_CHANGE_PASSWORD] = function () {
|
||||
// this.store.setNeedSlider(!1),
|
||||
// this.loginNormalErrorRow.visible()
|
||||
// },
|
||||
// this.failMap[DecCst.ErrorCode.USERNAME_UNAVAILABLE] = function () {
|
||||
// this.usernameRow.showError(BI.i18nText("Dec-Error_Login_Username_Unable"))
|
||||
// },
|
||||
// this.failMap[DecCst.ErrorCode.USERNAME_NOT_EXIST_PASSWORD_ERROR] = function () {
|
||||
// this.passwordRow.showError(BI.i18nText("Dec-Error_Incorrect_Password_Username"))
|
||||
// },
|
||||
// this.failMap[90000] = function () {
|
||||
// this.passwordRow.showError("您没有权限登陆!")
|
||||
// },
|
||||
// this.failMap[DecCst.ErrorCode.SMS_CAPTCHA_UNCHECK] = function (e) {
|
||||
// this.store.setPropsInfo({
|
||||
// token: e.errorMsg,
|
||||
// isChangePwd: !1,
|
||||
// from: DecCst.Login.AuthenticationModule.LOGIN
|
||||
// }),
|
||||
// this.store.setSelectedTab(DecCst.Login.Tabs.VERIFY_BING)
|
||||
// },
|
||||
// this.failMap[DecCst.ErrorCode.PASSWORD_NEED_SPLIDER] = function () {
|
||||
// this.store.setNeedSlider(!0),
|
||||
// this.sliderBar.resetAll()
|
||||
// },
|
||||
// this.failMap[DecCst.ErrorCode.PASSWORD_LOCKED] = function (e) {
|
||||
// this.store.setPropsInfo({
|
||||
// errorMsg: e.errorMsg
|
||||
// }),
|
||||
// this.store.setSelectedTab(DecCst.Login.Tabs.LOCKED)
|
||||
// },
|
||||
// this.failMap[DecCst.ErrorCode.PASSWORD_NEED_UPDATE] = function (e) {
|
||||
// this.store.setPropsInfo({
|
||||
// token: e.errorMsg,
|
||||
// isChangePwd: !0,
|
||||
// from: DecCst.Login.AuthenticationModule.PWD_UPDATE
|
||||
// }),
|
||||
// this.model.isNeedVerify ? this.store.setSelectedTab(DecCst.Login.Tabs.VERIFY_BING) : this.store.setSelectedTab(DecCst.Login.Tabs.PASSWORD_OLD)
|
||||
// },
|
||||
// this.failMap[DecCst.ErrorCode.PASSWORD_STRENGTH] = function (e) {
|
||||
// this.store.setPropsInfo({
|
||||
// token: e.errorMsg,
|
||||
// isChangePwd: !0,
|
||||
// from: DecCst.Login.AuthenticationModule.PWD_STRENGTH
|
||||
// }),
|
||||
// this.model.isNeedVerify ? this.store.setSelectedTab(DecCst.Login.Tabs.VERIFY_BING) : this.store.setSelectedTab(DecCst.Login.Tabs.PASSWORD_OLD)
|
||||
// },
|
||||
// this.failMap[DecCst.ErrorCode.CAPTCHA_TIMEOUT] = function () {
|
||||
// this.sliderError.setText(BI.i18nText("Dec-Basic_Captcha_Timeout")),
|
||||
// this.sliderBar.resetAll()
|
||||
// },
|
||||
// this.addHandler(t, function () {
|
||||
// this.passwordRow.showError(BI.i18nText("Dec-Login_Fail"))
|
||||
// })
|
||||
// }
|
||||
// });
|
||||
// BI.service("dec.service.login.login", e)
|
||||
//
|
||||
// var e = BI.inherit(BI.Widget, {
|
||||
// props: {
|
||||
// baseCls: "dec-login-login"
|
||||
// },
|
||||
// _store: function () {
|
||||
// return BI.Models.getModel("dec.model.login.login")
|
||||
// },
|
||||
// watch: {
|
||||
// supportForgetPwd: function (e) {
|
||||
// this.forgetPasswordRow.setVisible(e)
|
||||
// },
|
||||
// needSlider: function (e) {
|
||||
// this.sliderMasker.setVisible(e)
|
||||
// }
|
||||
// },
|
||||
// render: function () {
|
||||
// var t = this;
|
||||
// this.options;
|
||||
// return {
|
||||
// type: "bi.absolute",
|
||||
// items: [{
|
||||
// el: {
|
||||
// type: "bi.vertical",
|
||||
// items: [{
|
||||
// type: "dec.login.login.item",
|
||||
// $testId: "dec-login-username",
|
||||
// iconCls: "login-username-font",
|
||||
// tgap: 50,
|
||||
// watermark: BI.i18nText("Dec-User_Name"),
|
||||
// ref: function (e) {
|
||||
// t.usernameRow = e
|
||||
// }
|
||||
// }, {
|
||||
// type: "dec.login.login.item",
|
||||
// $testId: "dec-login-password",
|
||||
// iconCls: "login-password-font",
|
||||
// watermark: BI.i18nText("Dec-Password"),
|
||||
// inputType: "password",
|
||||
// ref: function (e) {
|
||||
// t.passwordRow = e
|
||||
// }
|
||||
// }, {
|
||||
// type: "bi.left_right_vertical_adapt",
|
||||
// bgap: 30,
|
||||
// items: {
|
||||
// left: [{
|
||||
// type: "bi.multi_select_item",
|
||||
// $testId: "dec-login-remember",
|
||||
// textLgap: 5,
|
||||
// iconWrapperWidth: 16,
|
||||
// height: 16,
|
||||
// text: BI.i18nText("Dec-Login_Remember"),
|
||||
// logic: {
|
||||
// dynamic: !0
|
||||
// },
|
||||
// ref: function (e) {
|
||||
// t.rememberRow = e
|
||||
// }
|
||||
// }
|
||||
// ],
|
||||
// right: [{
|
||||
// type: "bi.button",
|
||||
// $testId: "dec-login-forget-password",
|
||||
// clear: !0,
|
||||
// height: 16,
|
||||
// invisible: !this.model.supportForgetPwd,
|
||||
// text: BI.i18nText("Dec-Basic_Forget_Password"),
|
||||
// ref: function (e) {
|
||||
// t.forgetPasswordRow = e
|
||||
// },
|
||||
// handler: function () {
|
||||
// t.store.setSelectedTab(DecCst.Login.Tabs.FORGET_PASSWORD)
|
||||
// }
|
||||
// }
|
||||
// ].concat(this._createItems())
|
||||
// }
|
||||
// }, {
|
||||
// type: "bi.horizontal_auto",
|
||||
// items: [{
|
||||
// type: "bi.button",
|
||||
// cls: "login-button",
|
||||
// text: BI.i18nText("Dec-Basic_Login"),
|
||||
// width: 190,
|
||||
// height: 40,
|
||||
// handler: function () {
|
||||
// t._start()
|
||||
// }
|
||||
// }
|
||||
// ]
|
||||
// }, {
|
||||
// el: {
|
||||
// type: "bi.vertical",
|
||||
// $testId: "dec-login-logged-chang-text",
|
||||
// cls: "login-error",
|
||||
// invisible: !0,
|
||||
// scrolly: !1,
|
||||
// items: [{
|
||||
// type: "bi.text",
|
||||
// tagName: "span",
|
||||
// whiteSpace: "normal",
|
||||
// text: BI.i18nText("Dec-Login_Other_Logged_Tip")
|
||||
// }, {
|
||||
// type: "bi.text",
|
||||
// $testId: "dec-login-logged-chang-password",
|
||||
// tagName: "span",
|
||||
// cls: "password-btn",
|
||||
// text: BI.i18nText("Dec-Login_Change_Password"),
|
||||
// handler: function () {
|
||||
// t.model.isNeedVerify ? t.store.setSelectedTab(DecCst.Login.Tabs.VERIFY_BING) : t.store.setSelectedTab(DecCst.Login.Tabs.PASSWORD_OLD)
|
||||
// }
|
||||
// }
|
||||
// ],
|
||||
// ref: function (e) {
|
||||
// t.loginErrorRow = e
|
||||
// }
|
||||
// },
|
||||
// tgap: 20
|
||||
// }, {
|
||||
// el: {
|
||||
// type: "bi.text",
|
||||
// $testId: "dec-login-logged-text",
|
||||
// cls: "login-error",
|
||||
// invisible: !0,
|
||||
// whiteSpace: "normal",
|
||||
// text: BI.i18nText("Dec-Login_Normal_Other_Logged_Tip"),
|
||||
// ref: function (e) {
|
||||
// t.loginNormalErrorRow = e
|
||||
// }
|
||||
// },
|
||||
// tgap: 20
|
||||
// }
|
||||
// ]
|
||||
// },
|
||||
// top: 0,
|
||||
// right: 40,
|
||||
// bottom: 0,
|
||||
// left: 40
|
||||
// }, {
|
||||
// el: {
|
||||
// type: "bi.center_adapt",
|
||||
// cls: "slider-masker",
|
||||
// invisible: !0,
|
||||
// items: [{
|
||||
// type: "dec.login.slider",
|
||||
// listeners: [{
|
||||
// eventName: "EVENT_SUCCESS",
|
||||
// action: function () {
|
||||
// t._start()
|
||||
// }
|
||||
// }, {
|
||||
// eventName: "EVENT_CLOSE",
|
||||
// action: function () {
|
||||
// t.store.resetSlider()
|
||||
// }
|
||||
// }
|
||||
// ],
|
||||
// ref: function (e) {
|
||||
// t.sliderBar = e
|
||||
// }
|
||||
// }
|
||||
// ],
|
||||
// ref: function (e) {
|
||||
// t.sliderMasker = e
|
||||
// }
|
||||
// },
|
||||
// top: 0,
|
||||
// right: 40,
|
||||
// bottom: 0,
|
||||
// left: 40
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
// },
|
||||
// mounted: function () {
|
||||
// var t = this;
|
||||
// this.store.initData(),
|
||||
// this.element.keyup(function (e) {
|
||||
// 13 === e.keyCode && t._start()
|
||||
// })
|
||||
// },
|
||||
// _createItems: function () {
|
||||
// return BI.map(BI.Constants.getConstant("dec.constant.login.way.extend"), function (e, t) {
|
||||
// return {
|
||||
// type: t.cardType
|
||||
// }
|
||||
// })
|
||||
// },
|
||||
// _start: function () {
|
||||
// var t = this,
|
||||
// e = this.usernameRow.getValue(),
|
||||
// i = this.passwordRow.getValue(),
|
||||
// n = this.rememberRow.isSelected() ? -2 : -1;
|
||||
// t.loginErrorRow.invisible(),
|
||||
// t.loginNormalErrorRow.invisible(),
|
||||
// "" !== e ? "" !== i ? (this.store.setLoginInfo({
|
||||
// username: e,
|
||||
// validity: n,
|
||||
// phone: "",
|
||||
// captcha: ""
|
||||
// }), this.store.login({
|
||||
// username: e,
|
||||
// password: this.passwordRow.getCipher(),
|
||||
// validity: n,
|
||||
// sliderToken: this.model.sliderToken,
|
||||
// origin: Dec.Utils.getUrlQuery("origin"),
|
||||
// encrypted: !0
|
||||
// }, function (e) {
|
||||
// if(!isAdmin()){
|
||||
// BI.bind(BI.Services.getService("dec.service.login.login").getHandler(90000), t);
|
||||
// return ;
|
||||
// }
|
||||
// t.store.resetSlider(),
|
||||
// e.data && e.data.accessToken ? t.fireEvent("EVENT_LOGIN", e.data) : BI.bind(BI.Services.getService("dec.service.login.login").getHandler(e.errorCode), t)(e)
|
||||
// }
|
||||
// )) : this.passwordRow.showError(BI.i18nText("Dec-Error_Password_Not_Null")) : this.usernameRow.showError(BI.i18nText("Dec-Error_Username_Not_Null"))
|
||||
// }
|
||||
// });
|
||||
// BI.shortcut("dec.login.login", e)
|
||||
//
|
||||
// function isAdmin(){
|
||||
// var isAdmin = false;
|
||||
//
|
||||
// $.ajax({
|
||||
// type:"get",
|
||||
// async:false,
|
||||
// url:"/webroot/decision/isAdmin",
|
||||
// success:function(data){
|
||||
// isAdmin = data.isAdmin;
|
||||
// }
|
||||
// })
|
||||
//
|
||||
// return isAdmin;
|
||||
// }
|
Loading…
Reference in new issue