24 changed files with 1059 additions and 1 deletions
Binary file not shown.
Binary file not shown.
@ -1,3 +1,6 @@
|
||||
# open-JSD-9046 |
||||
|
||||
JSD-9046 用户自行申请报表访问权限+领导审批 |
||||
JSD-9046 用户自行申请报表访问权限+领导审批\ |
||||
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ |
||||
仅作为开发者学习参考使用!禁止用于任何商业用途!\ |
||||
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系hugh处理。 |
@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
||||
<plugin> |
||||
<id>com.fr.plugin.xxxx.xxxx.auth</id> |
||||
<main-package>com.fr.plugin.xxxx.xxxx.auth</main-package> |
||||
<name><![CDATA[权限管理]]></name> |
||||
<active>yes</active> |
||||
<version>1.8</version> |
||||
<env-version>10.0</env-version> |
||||
<jartime>2018-07-31</jartime> |
||||
<vendor>fr.open</vendor> |
||||
<description><![CDATA[权限管理]]></description> |
||||
<change-notes><![CDATA[ |
||||
[2021-11-29]【1.0】初始化插件。<br/> |
||||
[2021-12-01]【1.1】增加角色清理功能。<br/> |
||||
[2021-12-09]【1.2】授权修改。<br/> |
||||
[2021-12-10]【1.3】修改数据更新问题。<br/> |
||||
[2021-12-10]【1.4】权限收回处理。<br/> |
||||
[2021-12-10]【1.5】角色更新处理。<br/> |
||||
[2021-12-13]【1.6】组织树排序修改。<br/> |
||||
[2021-12-14]【1.7】权限继承。<br/> |
||||
[2021-12-16]【1.8】修改收回方式逻辑。<br/> |
||||
]]></change-notes> |
||||
<lifecycle-monitor class="com.fr.plugin.xxxx.xxxx.auth.PluginLifecycleMonitor"/> |
||||
<extra-decision> |
||||
<WebResourceProvider class="com.fr.plugin.xxxx.xxxx.auth.js.FunctionJSProvider"/> |
||||
<HttpHandlerProvider class="com.fr.plugin.xxxx.xxxx.auth.handler.HRGT"/> |
||||
<URLAliasProvider class="com.fr.plugin.xxxx.xxxx.auth.handler.URGT"/> |
||||
<GlobalRequestFilterProvider class="com.fr.plugin.xxxx.xxxx.auth.GlobalFilter"/> |
||||
</extra-decision> |
||||
<extra-core> |
||||
<FunctionDefineProvider class="com.fr.plugin.xxxx.xxxx.auth.fun.AuthExpireFun" name="authExpire" description="超期权限释放。"/> |
||||
<FunctionDefineProvider class="com.fr.plugin.xxxx.xxxx.auth.fun.RoleExpireFun" name="roleExpire" description="角色权限释放。"/> |
||||
<DBAccessProvider class="com.fr.plugin.xxxx.xxxx.auth.AuthDBAccessProvider"/> |
||||
<JavaScriptFileHandler class="com.fr.plugin.xxxx.xxxx.auth.js.FunctionJSProvider"/> |
||||
</extra-core> |
||||
<function-recorder class="com.fr.plugin.xxxx.xxxx.auth.GlobalFilter"/> |
||||
</plugin> |
@ -0,0 +1,56 @@
|
||||
package com.fr.plugin.xxxx.xxxx.auth; |
||||
|
||||
import com.fr.db.fun.impl.AbstractDBAccessProvider; |
||||
import com.fr.plugin.xxxx.xxxx.auth.dao.AuthDao; |
||||
import com.fr.plugin.xxxx.xxxx.auth.dao.RoleConfigDao; |
||||
import com.fr.plugin.xxxx.xxxx.auth.entity.AuthConfigEntity; |
||||
import com.fr.plugin.xxxx.xxxx.auth.entity.RoleConfigEntity; |
||||
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/11/29 |
||||
**/ |
||||
public class AuthDBAccessProvider 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 AuthConfigEntity.class; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends BaseDAO> getDAOClass() { |
||||
return AuthDao.class; |
||||
} |
||||
}, |
||||
new DAOProvider() { |
||||
@Override |
||||
public Class getEntityClass() { |
||||
return RoleConfigEntity.class; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends BaseDAO> getDAOClass() { |
||||
return RoleConfigDao.class; |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
|
||||
@Override |
||||
public void onDBAvailable(DBAccessor dbAccessor) { |
||||
AuthDBAccessProvider.dbAccessor = dbAccessor; |
||||
} |
||||
} |
@ -0,0 +1,12 @@
|
||||
package com.fr.plugin.xxxx.xxxx.auth; |
||||
|
||||
/** |
||||
* @author fr.open |
||||
* @date 2020/11/27 |
||||
*/ |
||||
public class Constants { |
||||
public static final String PLUGIN_ID = "com.fr.plugin.xxxx.xxxx.menu"; |
||||
|
||||
|
||||
public static final String PLUGIN_NAME = "权限管理"; |
||||
} |
@ -0,0 +1,128 @@
|
||||
package com.fr.plugin.xxxx.xxxx.auth; |
||||
|
||||
import com.fr.decision.authority.AuthorityContext; |
||||
import com.fr.decision.authority.data.Department; |
||||
import com.fr.decision.fun.impl.AbstractGlobalRequestFilterProvider; |
||||
import com.fr.decision.webservice.v10.config.ConfigService; |
||||
import com.fr.intelli.record.Focus; |
||||
import com.fr.intelli.record.Original; |
||||
import com.fr.json.JSONArray; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.plugin.context.PluginContexts; |
||||
import com.fr.plugin.xxxx.xxxx.auth.config.AuthConfig; |
||||
import com.fr.plugin.xxxx.xxxx.auth.utils.LogUtils; |
||||
import com.fr.plugin.transform.FunctionRecorder; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.stable.fun.Authorize; |
||||
|
||||
import javax.servlet.FilterChain; |
||||
import javax.servlet.ServletException; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.IOException; |
||||
import java.nio.charset.StandardCharsets; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
import java.util.regex.Matcher; |
||||
import java.util.regex.Pattern; |
||||
|
||||
/** |
||||
* @Author fr.open |
||||
* @Date 2021/10/29 |
||||
* @Description |
||||
**/ |
||||
@FunctionRecorder |
||||
@Authorize(callSignKey = Constants.PLUGIN_ID) |
||||
@EnableMetrics |
||||
public class GlobalFilter extends AbstractGlobalRequestFilterProvider { |
||||
|
||||
private static final Pattern pattern = Pattern.compile("[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}"); |
||||
|
||||
|
||||
@Override |
||||
public String filterName() { |
||||
return "global"; |
||||
} |
||||
|
||||
@Override |
||||
@Focus(id = Constants.PLUGIN_ID, text = Constants.PLUGIN_NAME, source = Original.PLUGIN) |
||||
public String[] urlPatterns() { |
||||
if (PluginContexts.currentContext().isAvailable()) { |
||||
String servletPathName = "decision"; |
||||
try { |
||||
servletPathName = ConfigService.getInstance().getBasicParam().getServletPathName(); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
} |
||||
return new String[]{ |
||||
"/" + servletPathName + "/v10/departments/*", |
||||
|
||||
}; |
||||
} else { |
||||
return new String[0]; |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain filterChain) { |
||||
try { |
||||
ResponseWrapperImpl responseWrapper = new ResponseWrapperImpl(res); |
||||
filterChain.doFilter(req, responseWrapper); |
||||
String deptId = getId(req); |
||||
if(StringUtils.isBlank(deptId)){ |
||||
res.getOutputStream().write(responseWrapper.getDataStream()); |
||||
return; |
||||
} |
||||
Department department = AuthorityContext.getInstance().getDepartmentController().getById(deptId); |
||||
if(department == null || !StringUtils.equals(department.getName(),AuthConfig.getInstance().getRootDept())){ |
||||
res.getOutputStream().write(responseWrapper.getDataStream()); |
||||
return; |
||||
} |
||||
byte[] dataStream = responseWrapper.getDataStream(); |
||||
JSONObject object = new JSONObject(new String(dataStream)); |
||||
JSONArray sorted = new JSONArray(); |
||||
Map<String, JSONObject> deptMap = new HashMap<>(); |
||||
for (int i = 0; i < object.getJSONArray("data").size(); i++) { |
||||
JSONObject data = object.getJSONArray("data").getJSONObject(i); |
||||
String text = data.getString("text"); |
||||
deptMap.put(text, data); |
||||
} |
||||
String deptSort = AuthConfig.getInstance().getDeptSort(); |
||||
LogUtils.debug4plugin("get deptSort is {}", deptSort); |
||||
if (StringUtils.isNotBlank(deptSort)) { |
||||
String[] split = deptSort.split(","); |
||||
for (int i = 0; i < split.length; i++) { |
||||
String dept = split[i]; |
||||
JSONObject getObj = deptMap.get(dept); |
||||
if (getObj != null) { |
||||
sorted.add(getObj); |
||||
deptMap.remove(dept); |
||||
} |
||||
} |
||||
} |
||||
sorted.addAll(new JSONArray(deptMap.values())); |
||||
LogUtils.debug4plugin("sort dept result is {}", sorted); |
||||
object.put("data", sorted); |
||||
res.getOutputStream().write(object.toString().getBytes(StandardCharsets.UTF_8)); |
||||
} catch (IOException e) { |
||||
LogUtils.debug4plugin(e.getMessage(),e); |
||||
} catch (ServletException e) { |
||||
LogUtils.debug4plugin(e.getMessage(),e); |
||||
} catch (Exception e) { |
||||
LogUtils.debug4plugin(e.getMessage(),e); |
||||
} |
||||
} |
||||
|
||||
private String getId(HttpServletRequest req) { |
||||
Matcher matcher = pattern.matcher(req.getRequestURI()); |
||||
boolean b = matcher.find(); |
||||
if(b){ |
||||
return matcher.group(); |
||||
} |
||||
return StringUtils.EMPTY; |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,22 @@
|
||||
package com.fr.plugin.xxxx.xxxx.auth; |
||||
|
||||
import com.fr.plugin.context.PluginContext; |
||||
import com.fr.plugin.xxxx.xxxx.auth.config.AuthConfig; |
||||
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor; |
||||
|
||||
/** |
||||
* @Author fr.open |
||||
* @Date 2021/11/27 |
||||
* @Description |
||||
**/ |
||||
public class PluginLifecycleMonitor extends AbstractPluginLifecycleMonitor { |
||||
@Override |
||||
public void afterRun(PluginContext pluginContext) { |
||||
AuthConfig.getInstance(); |
||||
} |
||||
|
||||
@Override |
||||
public void beforeStop(PluginContext pluginContext) { |
||||
|
||||
} |
||||
} |
@ -0,0 +1,84 @@
|
||||
package com.fr.plugin.xxxx.xxxx.auth; |
||||
|
||||
import javax.servlet.ServletOutputStream; |
||||
import javax.servlet.WriteListener; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import javax.servlet.http.HttpServletResponseWrapper; |
||||
import java.io.ByteArrayOutputStream; |
||||
import java.io.DataOutputStream; |
||||
import java.io.IOException; |
||||
import java.io.OutputStream; |
||||
|
||||
|
||||
/** |
||||
* @author fr.open |
||||
* @Date 2021/8/1 |
||||
*/ |
||||
public class ResponseWrapperImpl extends HttpServletResponseWrapper { |
||||
ByteArrayOutputStream output; |
||||
FilterServletOutputStream filterOutput; |
||||
|
||||
public ResponseWrapperImpl(HttpServletResponse response) { |
||||
super(response); |
||||
output = new ByteArrayOutputStream(); |
||||
} |
||||
|
||||
@Override |
||||
public ServletOutputStream getOutputStream() throws IOException { |
||||
if (filterOutput == null) { |
||||
filterOutput = new FilterServletOutputStream(output); |
||||
} |
||||
return filterOutput; |
||||
} |
||||
|
||||
public void setContent(ByteArrayOutputStream output){ |
||||
this.output = output; |
||||
this.filterOutput = null; |
||||
} |
||||
|
||||
public void clear(){ |
||||
output = new ByteArrayOutputStream(); |
||||
filterOutput = new FilterServletOutputStream(output); |
||||
} |
||||
public ByteArrayOutputStream getOut(){ |
||||
return output; |
||||
} |
||||
|
||||
public byte[] getDataStream() { |
||||
return output.toByteArray(); |
||||
} |
||||
|
||||
class FilterServletOutputStream extends ServletOutputStream { |
||||
DataOutputStream output; |
||||
|
||||
public FilterServletOutputStream(OutputStream output) { |
||||
this.output = new DataOutputStream(output); |
||||
} |
||||
|
||||
@Override |
||||
public void write(int arg0) throws IOException { |
||||
output.write(arg0); |
||||
} |
||||
|
||||
@Override |
||||
public void write(byte[] arg0, int arg1, int arg2) throws IOException { |
||||
output.write(arg0, arg1, arg2); |
||||
} |
||||
|
||||
@Override |
||||
public void write(byte[] arg0) throws IOException { |
||||
output.write(arg0); |
||||
System.out.printf(""); |
||||
} |
||||
|
||||
@Override |
||||
public boolean isReady() { |
||||
return false; |
||||
} |
||||
|
||||
@Override |
||||
public void setWriteListener(WriteListener writeListener) { |
||||
|
||||
} |
||||
} |
||||
} |
@ -0,0 +1,46 @@
|
||||
package com.fr.plugin.xxxx.xxxx.auth.action; |
||||
|
||||
import com.fr.plugin.xxxx.xxxx.auth.AuthDBAccessProvider; |
||||
import com.fr.plugin.xxxx.xxxx.auth.dao.AuthDao; |
||||
import com.fr.plugin.xxxx.xxxx.auth.entity.AuthConfigEntity; |
||||
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.HashMap; |
||||
import java.util.HashSet; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @Author fr.open |
||||
* @Date 2021/11/29 |
||||
* @Description |
||||
**/ |
||||
public class AuthConfigService { |
||||
|
||||
public static List<AuthConfigEntity> getUnFinish() throws Exception { |
||||
return AuthDBAccessProvider.getDbAccessor().runDMLAction(new DBAction<List<AuthConfigEntity>>() { |
||||
@Override |
||||
public List<AuthConfigEntity> run(DAOContext daoContext) throws Exception { |
||||
return daoContext.getDAO(AuthDao.class).find(QueryFactory.create().addRestriction(RestrictionFactory.eq("state", 0))); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
public static void updateState(List<String> updates) throws Exception { |
||||
if (updates == null || updates.isEmpty()) { |
||||
return; |
||||
} |
||||
AuthDBAccessProvider.getDbAccessor().runDMLAction(new DBAction() { |
||||
@Override |
||||
public Object run(DAOContext daoContext) throws Exception { |
||||
Map<String, Object> data = new HashMap<>(); |
||||
data.put("state", 1); |
||||
daoContext.getDAO(AuthDao.class).update(data, QueryFactory.create().addRestriction(RestrictionFactory.in("id", new HashSet<>(updates)))); |
||||
return null; |
||||
} |
||||
}); |
||||
} |
||||
} |
@ -0,0 +1,44 @@
|
||||
package com.fr.plugin.xxxx.xxxx.auth.action; |
||||
|
||||
import com.fr.plugin.xxxx.xxxx.auth.AuthDBAccessProvider; |
||||
import com.fr.plugin.xxxx.xxxx.auth.dao.RoleConfigDao; |
||||
import com.fr.plugin.xxxx.xxxx.auth.entity.RoleConfigEntity; |
||||
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.HashMap; |
||||
import java.util.HashSet; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @Author fr.open |
||||
* @Date 2021/11/29 |
||||
* @Description |
||||
**/ |
||||
public class RoleConfigService { |
||||
|
||||
public static List<RoleConfigEntity> getUnFinish() throws Exception { |
||||
return AuthDBAccessProvider.getDbAccessor().runDMLAction(new DBAction<List<RoleConfigEntity>>() { |
||||
@Override |
||||
public List<RoleConfigEntity> run(DAOContext daoContext) throws Exception { |
||||
List<RoleConfigEntity> state = daoContext.getDAO(RoleConfigDao.class).find(QueryFactory.create().addRestriction(RestrictionFactory.eq("state", 0))); |
||||
return state; |
||||
} |
||||
}); |
||||
} |
||||
|
||||
public static void updateState(List<String> updates) throws Exception { |
||||
AuthDBAccessProvider.getDbAccessor().runDMLAction(new DBAction() { |
||||
@Override |
||||
public Object run(DAOContext daoContext) throws Exception { |
||||
Map<String, Object> data = new HashMap<>(); |
||||
data.put("state", 1); |
||||
daoContext.getDAO(RoleConfigDao.class).update(data, QueryFactory.create().addRestriction(RestrictionFactory.in("id", new HashSet<>(updates)))); |
||||
return null; |
||||
} |
||||
}); |
||||
} |
||||
} |
@ -0,0 +1,83 @@
|
||||
package com.fr.plugin.xxxx.xxxx.auth.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.plugin.xxxx.xxxx.auth.Constants; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
|
||||
|
||||
/** |
||||
* @author fr.open |
||||
* @date 2020/11/27 |
||||
*/ |
||||
@Visualization(category = "权限管理配置") |
||||
@EnableMetrics |
||||
public class AuthConfig extends DefaultConfiguration { |
||||
|
||||
private static volatile AuthConfig config = null; |
||||
|
||||
@Focus(id = Constants.PLUGIN_ID, text = Constants.PLUGIN_NAME, source = Original.PLUGIN) |
||||
public static AuthConfig getInstance() { |
||||
if (config == null) { |
||||
config = ConfigContext.getConfigInstance(AuthConfig.class); |
||||
} |
||||
return config; |
||||
} |
||||
|
||||
@Identifier(value = "debugSwitch", name = "插件调试开关", description = "日志调试模式", status = Status.SHOW) |
||||
private Conf<Boolean> debugSwitch = Holders.simple(true); |
||||
|
||||
public Boolean getDebugSwitch() { |
||||
return debugSwitch.get(); |
||||
} |
||||
|
||||
public void setDebugSwitch(Boolean debugSwitch) { |
||||
this.debugSwitch.set(debugSwitch); |
||||
} |
||||
|
||||
@Identifier(value = "authUser", name = "接口授权用户", description = "接口授权用户名称", status = Status.SHOW) |
||||
private Conf<String> authUser = Holders.simple(""); |
||||
|
||||
public String getAuthUser() { |
||||
return authUser.get(); |
||||
} |
||||
|
||||
public void setAuthUser(String api_process) { |
||||
this.authUser.set(api_process); |
||||
} |
||||
|
||||
@Identifier(value = "deptSort", name = "部门排序", description = "部门排序", status = Status.SHOW) |
||||
private Conf<String> deptSort = Holders.simple(""); |
||||
|
||||
public String getDeptSort() { |
||||
return deptSort.get(); |
||||
} |
||||
|
||||
public void setDeptSort(String api_process) { |
||||
this.deptSort.set(api_process); |
||||
} |
||||
|
||||
@Identifier(value = "rootDept", name = "排序部门名称", description = "需要排序的部门名称", status = Status.SHOW) |
||||
private Conf<String> rootDept = Holders.simple(""); |
||||
|
||||
public String getRootDept() { |
||||
return rootDept.get(); |
||||
} |
||||
|
||||
public void setRootDept(String rootDept) { |
||||
this.rootDept.set(rootDept); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public Object clone() throws CloneNotSupportedException { |
||||
AuthConfig cloned = (AuthConfig) super.clone(); |
||||
|
||||
return cloned; |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,21 @@
|
||||
package com.fr.plugin.xxxx.xxxx.auth.dao; |
||||
|
||||
import com.fr.plugin.xxxx.xxxx.auth.entity.AuthConfigEntity; |
||||
import com.fr.stable.db.dao.BaseDAO; |
||||
import com.fr.stable.db.session.DAOSession; |
||||
|
||||
/** |
||||
* @Author fr.open |
||||
* @Date 2021/11/29 |
||||
* @Description |
||||
**/ |
||||
public class AuthDao extends BaseDAO<AuthConfigEntity> { |
||||
public AuthDao(DAOSession daoSession) { |
||||
super(daoSession); |
||||
} |
||||
|
||||
@Override |
||||
protected Class<AuthConfigEntity> getEntityClass() { |
||||
return AuthConfigEntity.class; |
||||
} |
||||
} |
@ -0,0 +1,21 @@
|
||||
package com.fr.plugin.xxxx.xxxx.auth.dao; |
||||
|
||||
import com.fr.plugin.xxxx.xxxx.auth.entity.RoleConfigEntity; |
||||
import com.fr.stable.db.dao.BaseDAO; |
||||
import com.fr.stable.db.session.DAOSession; |
||||
|
||||
/** |
||||
* @Author fr.open |
||||
* @Date 2021/12/2 |
||||
* @Description |
||||
**/ |
||||
public class RoleConfigDao extends BaseDAO<RoleConfigEntity> { |
||||
public RoleConfigDao(DAOSession daoSession) { |
||||
super(daoSession); |
||||
} |
||||
|
||||
@Override |
||||
protected Class<RoleConfigEntity> getEntityClass() { |
||||
return RoleConfigEntity.class; |
||||
} |
||||
} |
@ -0,0 +1,62 @@
|
||||
package com.fr.plugin.xxxx.xxxx.auth.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; |
||||
|
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* @Author fr.open |
||||
* @Date 2021/11/29 |
||||
* @Description |
||||
**/ |
||||
@Entity |
||||
@Table(name = "plugin_auth_config") |
||||
public class AuthConfigEntity extends BaseEntity { |
||||
|
||||
@Column(name = "user_id") |
||||
private String userId; |
||||
@Column(name = "entity_id") |
||||
private String entityId; |
||||
@Column(name = "expire") |
||||
private Date expire; |
||||
@Column(name = "state") |
||||
private int state; |
||||
|
||||
public AuthConfigEntity() { |
||||
} |
||||
|
||||
public int getState() { |
||||
return state; |
||||
} |
||||
|
||||
public void setState(int state) { |
||||
this.state = state; |
||||
} |
||||
|
||||
public String getUserId() { |
||||
return userId; |
||||
} |
||||
|
||||
public void setUserId(String userId) { |
||||
this.userId = userId; |
||||
} |
||||
|
||||
public String getEntityId() { |
||||
return entityId; |
||||
} |
||||
|
||||
public void setEntityId(String entityId) { |
||||
this.entityId = entityId; |
||||
} |
||||
|
||||
public Date getExpire() { |
||||
return expire; |
||||
} |
||||
|
||||
public void setExpire(Date expire) { |
||||
this.expire = expire; |
||||
} |
||||
} |
@ -0,0 +1,52 @@
|
||||
package com.fr.plugin.xxxx.xxxx.auth.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/12/2 |
||||
* @Description |
||||
**/ |
||||
@Entity |
||||
@Table(name = "plugin_role_config") |
||||
public class RoleConfigEntity extends BaseEntity { |
||||
|
||||
@Column(name = "user_id") |
||||
private String userId; |
||||
|
||||
@Column(name = "role_id") |
||||
private String roleId; |
||||
|
||||
@Column(name = "state") |
||||
private int state; |
||||
|
||||
public RoleConfigEntity() { |
||||
} |
||||
|
||||
public String getUserId() { |
||||
return userId; |
||||
} |
||||
|
||||
public void setUserId(String userId) { |
||||
this.userId = userId; |
||||
} |
||||
|
||||
public String getRoleId() { |
||||
return roleId; |
||||
} |
||||
|
||||
public void setRoleId(String roleId) { |
||||
this.roleId = roleId; |
||||
} |
||||
|
||||
public int getState() { |
||||
return state; |
||||
} |
||||
|
||||
public void setState(int state) { |
||||
this.state = state; |
||||
} |
||||
} |
@ -0,0 +1,54 @@
|
||||
package com.fr.plugin.xxxx.xxxx.auth.fun; |
||||
|
||||
import com.fr.decision.webservice.bean.authority.PrivilegeOperator; |
||||
import com.fr.decision.webservice.v10.authority.AuthorityService; |
||||
import com.fr.plugin.xxxx.xxxx.auth.action.AuthConfigService; |
||||
import com.fr.plugin.xxxx.xxxx.auth.entity.AuthConfigEntity; |
||||
import com.fr.plugin.xxxx.xxxx.auth.utils.LogUtils; |
||||
import com.fr.script.AbstractFunction; |
||||
import com.fr.stable.exception.FormulaException; |
||||
import com.fr.third.guava.collect.Sets; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @Author fr.open |
||||
* @Date 2021/11/29 |
||||
* @Description |
||||
**/ |
||||
public class AuthExpireFun extends AbstractFunction { |
||||
@Override |
||||
public Object run(Object[] objects) throws FormulaException { |
||||
List<String> updates = new ArrayList<>(); |
||||
try { |
||||
List<AuthConfigEntity> unFinish = AuthConfigService.getUnFinish(); |
||||
for (AuthConfigEntity config : unFinish) { |
||||
if (config.getExpire() == null || config.getExpire().getTime() < System.currentTimeMillis()) { |
||||
if (extracted(config)) { |
||||
updates.add(config.getId()); |
||||
} |
||||
} |
||||
} |
||||
AuthConfigService.updateState(updates); |
||||
LogUtils.debug("移除用户数量{}", updates.size()); |
||||
} catch (Exception e) { |
||||
LogUtils.error(e.getMessage(), e); |
||||
} |
||||
return updates.size(); |
||||
} |
||||
|
||||
private boolean extracted(AuthConfigEntity config) { |
||||
try { |
||||
PrivilegeOperator operator = new PrivilegeOperator("user", config.getUserId(), config.getEntityId(), ""); |
||||
operator.setPrivilegeTypes(Sets.newHashSet(new Integer[]{1, 3})); |
||||
AuthorityService.getInstance().authorityRecovery(operator); |
||||
LogUtils.debug("重置用户{}的权限", config.getUserId()); |
||||
} catch (Exception e) { |
||||
LogUtils.debug("重置用户{}失败", config.getUserId()); |
||||
LogUtils.error(e.getMessage(), e); |
||||
return false; |
||||
} |
||||
return true; |
||||
} |
||||
} |
@ -0,0 +1,48 @@
|
||||
package com.fr.plugin.xxxx.xxxx.auth.fun; |
||||
|
||||
import com.fr.decision.authority.AuthorityContext; |
||||
import com.fr.plugin.xxxx.xxxx.auth.action.RoleConfigService; |
||||
import com.fr.plugin.xxxx.xxxx.auth.entity.RoleConfigEntity; |
||||
import com.fr.plugin.xxxx.xxxx.auth.utils.LogUtils; |
||||
import com.fr.script.AbstractFunction; |
||||
import com.fr.stable.exception.FormulaException; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @Author fr.open |
||||
* @Date 2021/11/29 |
||||
* @Description |
||||
**/ |
||||
public class RoleExpireFun extends AbstractFunction { |
||||
@Override |
||||
public Object run(Object[] objects) throws FormulaException { |
||||
List<String> updates = new ArrayList<>(); |
||||
try { |
||||
List<RoleConfigEntity> unFinish = RoleConfigService.getUnFinish(); |
||||
for (RoleConfigEntity config : unFinish) { |
||||
if (extracted(config)) { |
||||
updates.add(config.getId()); |
||||
} |
||||
} |
||||
RoleConfigService.updateState(updates); |
||||
LogUtils.debug("移除角色数量{}", updates.size()); |
||||
} catch (Exception e) { |
||||
LogUtils.error(e.getMessage(), e); |
||||
} |
||||
return updates.size(); |
||||
} |
||||
|
||||
private boolean extracted(RoleConfigEntity config) { |
||||
try { |
||||
AuthorityContext.getInstance().getUserController().removeUserFromCustomRole(config.getUserId(), config.getRoleId()); |
||||
LogUtils.debug("移除用户{}的{}角色权限", config.getUserId(), config.getUserId()); |
||||
} catch (Exception e) { |
||||
LogUtils.error("移除用户{}的{}角色权限失败", config.getUserId(), config.getUserId()); |
||||
LogUtils.error(e.getMessage(), e); |
||||
return false; |
||||
} |
||||
return true; |
||||
} |
||||
} |
@ -0,0 +1,85 @@
|
||||
package com.fr.plugin.xxxx.xxxx.auth.handler; |
||||
|
||||
import com.fr.decision.authority.data.User; |
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
import com.fr.decision.webservice.Response; |
||||
import com.fr.decision.webservice.bean.authority.PrivilegeBean; |
||||
import com.fr.decision.webservice.bean.authority.PrivilegeDetailBean; |
||||
import com.fr.decision.webservice.bean.authority.UpdatePrivilegeResult; |
||||
import com.fr.decision.webservice.v10.authority.AuthorityService; |
||||
import com.fr.decision.webservice.v10.user.UserService; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.plugin.xxxx.xxxx.auth.config.AuthConfig; |
||||
import com.fr.plugin.xxxx.xxxx.auth.utils.LogUtils; |
||||
import com.fr.stable.StringUtils; |
||||
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.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.stream.Stream; |
||||
|
||||
/** |
||||
* @Author fr.open |
||||
* @Date 2021/11/27 |
||||
* @Description |
||||
**/ |
||||
public class AuthHandler extends BaseHttpHandler { |
||||
@Override |
||||
public RequestMethod getMethod() { |
||||
return RequestMethod.GET; |
||||
} |
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return "/auth"; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPublic() { |
||||
return false; |
||||
} |
||||
|
||||
@Override |
||||
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception { |
||||
String userId = WebUtils.getHTTPRequestParameter(req, "userId"); |
||||
if (StringUtils.isBlank(userId)) { |
||||
WebUtils.printAsJSON(res, JSONObject.mapFrom(Response.error("userId_not_null", "userId不能为空"))); |
||||
return; |
||||
} |
||||
String entryId = WebUtils.getHTTPRequestParameter(req, "entryId"); |
||||
if (StringUtils.isBlank(entryId)) { |
||||
WebUtils.printAsJSON(res, JSONObject.mapFrom(Response.error("entryId_not_null", "entryId不能为空"))); |
||||
return; |
||||
} |
||||
String currentUserId = UserService.getInstance().getCurrentUserId(req); |
||||
if (StringUtils.isBlank(currentUserId)) { |
||||
WebUtils.printAsJSON(res, JSONObject.mapFrom(Response.error("auth_user_unLogin", "未获取到授权用户"))); |
||||
return; |
||||
} |
||||
User user = UserService.getInstance().getUserByUserId(currentUserId); |
||||
if (!Stream.of(AuthConfig.getInstance().getAuthUser().split(",")).anyMatch(user.getUserName()::equals)) { |
||||
WebUtils.printAsJSON(res, JSONObject.mapFrom(Response.error("auth_user_notAuth", "当前用户无授权权限"))); |
||||
return; |
||||
} |
||||
|
||||
PrivilegeBean privilegeBean = new PrivilegeBean(); |
||||
privilegeBean.setId(entryId); |
||||
List<PrivilegeDetailBean> updateList = new ArrayList<>(); |
||||
updateList.add(new PrivilegeDetailBean(1, 2)); |
||||
privilegeBean.setValues(updateList.toArray(updateList.toArray(new PrivilegeDetailBean[0]))); |
||||
UpdatePrivilegeResult result = AuthorityService.getInstance().updateAuthorityEntityByCarrier( |
||||
currentUserId, |
||||
"user", |
||||
userId, |
||||
privilegeBean, |
||||
"" |
||||
); |
||||
LogUtils.debug4plugin("auth res is {}",result); |
||||
WebUtils.printAsJSON(res, JSONObject.mapFrom(Response.success())); |
||||
return; |
||||
|
||||
} |
||||
} |
@ -0,0 +1,18 @@
|
||||
package com.fr.plugin.xxxx.xxxx.auth.handler; |
||||
|
||||
import com.fr.decision.fun.HttpHandler; |
||||
import com.fr.decision.fun.impl.AbstractHttpHandlerProvider; |
||||
|
||||
/** |
||||
* @Author fr.open |
||||
* @Date 2021/11/27 |
||||
* @Description |
||||
**/ |
||||
public class HRGT extends AbstractHttpHandlerProvider { |
||||
@Override |
||||
public HttpHandler[] registerHandlers() { |
||||
return new HttpHandler[]{ |
||||
new AuthHandler(), |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,19 @@
|
||||
package com.fr.plugin.xxxx.xxxx.auth.handler; |
||||
|
||||
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 |
||||
* @Date 2021/11/27 |
||||
* @Description |
||||
**/ |
||||
public class URGT extends AbstractURLAliasProvider { |
||||
@Override |
||||
public URLAlias[] registerAlias() { |
||||
return new URLAlias[]{ |
||||
URLAliasFactory.createPluginAlias("/auth", "/auth", false), |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,21 @@
|
||||
package com.fr.plugin.xxxx.xxxx.auth.js; |
||||
|
||||
import com.fr.stable.fun.impl.AbstractJavaScriptFileHandler; |
||||
|
||||
/** |
||||
* @author fr.open |
||||
* @date 2020/11/27 |
||||
*/ |
||||
public class FunctionJSProvider extends AbstractJavaScriptFileHandler { |
||||
@Override |
||||
public String[] pathsForFiles() { |
||||
return new String[]{ |
||||
"/com/fr/plugin/xxxx/xxxx/auth/function.js" |
||||
}; |
||||
} |
||||
|
||||
@Override |
||||
public String encode() { |
||||
return "UTF-8"; |
||||
} |
||||
} |
@ -0,0 +1,118 @@
|
||||
package com.fr.plugin.xxxx.xxxx.auth.utils; |
||||
|
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.log.FineLoggerProvider; |
||||
import com.fr.plugin.context.PluginContexts; |
||||
import com.fr.plugin.xxxx.xxxx.auth.Constants; |
||||
import com.fr.plugin.xxxx.xxxx.auth.config.AuthConfig; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
public final class LogUtils { |
||||
private static final String DEBUG_PREFIX = "[插件调试] "; |
||||
private static String LOG_PREFIX = "["+ Constants.PLUGIN_NAME+"] "; |
||||
private static final String PLUGIN_VERSION; |
||||
|
||||
private static final FineLoggerProvider LOGGER = FineLoggerFactory.getLogger(); |
||||
|
||||
static { |
||||
String version = PluginContexts.currentContext().getMarker().getVersion(); |
||||
if (StringUtils.isNotBlank(version)) { |
||||
PLUGIN_VERSION = "[v" + version + "] "; |
||||
} else { |
||||
PLUGIN_VERSION = "[unknown version] "; |
||||
} |
||||
|
||||
LOG_PREFIX = LOG_PREFIX + PLUGIN_VERSION; |
||||
} |
||||
|
||||
public static void setPrefix(String prefix) { |
||||
if (prefix != null) { |
||||
LOG_PREFIX = prefix; |
||||
} |
||||
} |
||||
|
||||
public static boolean isDebugEnabled() { |
||||
return LOGGER.isDebugEnabled(); |
||||
} |
||||
|
||||
public static void debug(String s) { |
||||
LOGGER.debug(LOG_PREFIX + s); |
||||
} |
||||
|
||||
public static void debug(String s, Object... objects) { |
||||
LOGGER.debug(LOG_PREFIX + s, objects); |
||||
} |
||||
|
||||
public static void debug(String s, Throwable throwable) { |
||||
LOGGER.debug(LOG_PREFIX + s, throwable); |
||||
} |
||||
|
||||
public static void debug4plugin(String s) { |
||||
if (AuthConfig.getInstance().getDebugSwitch()) { |
||||
LOGGER.error(DEBUG_PREFIX + LOG_PREFIX + s); |
||||
} else { |
||||
LOGGER.debug(LOG_PREFIX + s); |
||||
} |
||||
} |
||||
|
||||
public static void debug4plugin(String s, Object... objects) { |
||||
if (AuthConfig.getInstance().getDebugSwitch()) { |
||||
LOGGER.error(DEBUG_PREFIX + LOG_PREFIX + s, objects); |
||||
} else { |
||||
LOGGER.debug(LOG_PREFIX + s, objects); |
||||
} |
||||
} |
||||
|
||||
public static void debug4plugin(String s, Throwable throwable) { |
||||
if (AuthConfig.getInstance().getDebugSwitch()) { |
||||
LOGGER.error(DEBUG_PREFIX + LOG_PREFIX + s, throwable); |
||||
} else { |
||||
LOGGER.debug(LOG_PREFIX + s, throwable); |
||||
} |
||||
} |
||||
|
||||
|
||||
public static boolean isInfoEnabled() { |
||||
return LOGGER.isInfoEnabled(); |
||||
} |
||||
|
||||
public static void info(String s) { |
||||
LOGGER.info(LOG_PREFIX + s); |
||||
} |
||||
|
||||
public static void info(String s, Object... objects) { |
||||
LOGGER.info(LOG_PREFIX + s, objects); |
||||
} |
||||
|
||||
public static void warn(String s) { |
||||
LOGGER.warn(LOG_PREFIX + s); |
||||
} |
||||
|
||||
public static void warn(String s, Object... objects) { |
||||
LOGGER.warn(LOG_PREFIX + s, objects); |
||||
} |
||||
|
||||
public static void warn(String s, Throwable throwable) { |
||||
LOGGER.warn(LOG_PREFIX + s, throwable); |
||||
} |
||||
|
||||
public static void warn(Throwable throwable, String s, Object... objects) { |
||||
LOGGER.warn(throwable, LOG_PREFIX + s, objects); |
||||
} |
||||
|
||||
public static void error(String s) { |
||||
LOGGER.error(LOG_PREFIX + s); |
||||
} |
||||
|
||||
public static void error(String s, Object... objects) { |
||||
LOGGER.error(LOG_PREFIX + s, objects); |
||||
} |
||||
|
||||
public static void error(String s, Throwable throwable) { |
||||
LOGGER.error(LOG_PREFIX + s, throwable); |
||||
} |
||||
|
||||
public static void error(Throwable throwable, String s, Object... objects) { |
||||
LOGGER.error(throwable, LOG_PREFIX + s, objects); |
||||
} |
||||
} |
@ -0,0 +1,24 @@
|
||||
$.extend(FR, { |
||||
updateAuthorityEntity: function (userId, entryId) { |
||||
if (FR.isEmpty(userId)) { |
||||
FR.Msg.alert("", "userId不能为空"); |
||||
return; |
||||
} |
||||
if (FR.isEmpty(entryId)) { |
||||
FR.Msg.alert("", "entryId不能为空"); |
||||
return; |
||||
} |
||||
FR.ajax({ |
||||
url:FR.fineServletURL + "/url/auth?userId=" + userId + "&entryId=" + entryId, |
||||
timeout: 10000, |
||||
success:function(data){ |
||||
var res = FR.jsonDecode(data); |
||||
if (FR.equals(res.data, "success")) { |
||||
FR.Msg.toast("授权成功"); |
||||
} else { |
||||
FR.Msg.alert("", res.errorMsg); |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
}); |
Loading…
Reference in new issue