parent
cd50cbf719
commit
208ac577c3
@ -0,0 +1,41 @@
|
||||
package au.com.royalpay.payment.manage.mappers.system;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import cn.yixblog.support.mybatis.autosql.annotations.AutoMapper;
|
||||
import cn.yixblog.support.mybatis.autosql.annotations.AutoSql;
|
||||
import cn.yixblog.support.mybatis.autosql.annotations.SqlType;
|
||||
|
||||
/**
|
||||
* Created by yixian on 2017-02-28.
|
||||
*/
|
||||
@AutoMapper(tablename = "sys_permission_partner_functions", pkName = "func_id")
|
||||
public interface PermissionPartnerFunctionMapper {
|
||||
|
||||
@AutoSql(type = SqlType.INSERT)
|
||||
void save(JSONObject func);
|
||||
|
||||
@AutoSql(type = SqlType.UPDATE)
|
||||
void update(JSONObject func);
|
||||
|
||||
List<JSONObject> listByRoleMask(@Param("mask") int mask);
|
||||
|
||||
List<JSONObject> listAll();
|
||||
|
||||
@AutoSql(type = SqlType.SELECT)
|
||||
List<JSONObject> listByModule(@Param("module") String moduleName);
|
||||
|
||||
@AutoSql(type = SqlType.DELETE)
|
||||
void delete(@Param("func_id") String funcId);
|
||||
|
||||
void clearRolePermission(@Param("mask") int mask);
|
||||
|
||||
void authorizeRole(@Param("mask") int mask, @Param("func_ids") List<String> functions);
|
||||
|
||||
@AutoSql(type = SqlType.SELECT)
|
||||
JSONObject find(@Param("func_id") String funcId);
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package au.com.royalpay.payment.manage.mappers.system;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import cn.yixblog.support.mybatis.autosql.annotations.AutoMapper;
|
||||
import cn.yixblog.support.mybatis.autosql.annotations.AutoSql;
|
||||
import cn.yixblog.support.mybatis.autosql.annotations.SqlType;
|
||||
|
||||
/**
|
||||
* Created by yixian on 2017-02-28.
|
||||
*/
|
||||
@AutoMapper(tablename = "sys_permission_partner_modules", pkName = "module_name")
|
||||
public interface PermissionPartnerModuleMapper {
|
||||
@AutoSql(type = SqlType.INSERT)
|
||||
void save(JSONObject module);
|
||||
|
||||
@AutoSql(type = SqlType.UPDATE)
|
||||
void update(JSONObject module);
|
||||
|
||||
@AutoSql(type = SqlType.DELETE)
|
||||
void delete(@Param("module_name") String moduleName);
|
||||
|
||||
@AutoSql(type = SqlType.SELECT)
|
||||
List<JSONObject> list();
|
||||
|
||||
@AutoSql(type = SqlType.SELECT)
|
||||
JSONObject find(@Param("module_name") String moduleName);
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
package au.com.royalpay.payment.manage.permission.manager.scanner;
|
||||
|
||||
import au.com.royalpay.payment.manage.permission.manager.RequirePartner;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by yixian on 2017-02-28.
|
||||
*/
|
||||
@Component
|
||||
public class PartnerPermissionScanner implements BeanPostProcessor, PermissionPartnerReader {
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
private Map<String, PermissionNode> permissionNodes = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
|
||||
Class<?> clazz = bean.getClass();
|
||||
if (AnnotatedElementUtils.isAnnotated(clazz, Controller.class)) {
|
||||
|
||||
Method[] methods = clazz.getDeclaredMethods();
|
||||
RequestMapping clazzRequestMapping = AnnotatedElementUtils.findMergedAnnotation(clazz, RequestMapping.class);
|
||||
RequirePartner clazzPermission = AnnotatedElementUtils.findMergedAnnotation(clazz, RequirePartner.class);
|
||||
for (Method method : methods) {
|
||||
if (AnnotatedElementUtils.isAnnotated(method, RequestMapping.class)) {
|
||||
RequestMapping methodMapping = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class);
|
||||
RequirePartner methodPermission = AnnotatedElementUtils.findMergedAnnotation(method, RequirePartner.class);
|
||||
|
||||
if (clazzPermission != null || methodPermission != null) {
|
||||
registerPermissionMapping(clazz, method, clazzRequestMapping, clazzPermission, methodMapping, methodPermission);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
|
||||
private void registerPermissionMapping(Class<?> controller, Method method, RequestMapping clazzRequestMapping, RequirePartner clazzPermission, RequestMapping methodMapping, RequirePartner methodPermission) {
|
||||
|
||||
//get request uri and methods
|
||||
PermissionNode node = new PermissionNode(controller.getSimpleName(), method.getName());
|
||||
getRequestInfo(node, clazzRequestMapping, methodMapping);
|
||||
node.setPartnerPermissions(clazzPermission, methodPermission);
|
||||
logger.debug("register permission:" + node.getFuncName() + ":" + node.getRequestId());
|
||||
if (permissionNodes.containsKey(node.getFuncId())) {
|
||||
throw new RuntimeException("Duplicated permission function ID:" + controller.getName() + "." + method.getName());
|
||||
}
|
||||
permissionNodes.put(node.getFuncId(), node);
|
||||
|
||||
}
|
||||
|
||||
private void getRequestInfo(PermissionNode node, RequestMapping clazzRequestMapping, RequestMapping methodMapping) {
|
||||
String uri = "";
|
||||
RequestMethod[] methods = {};
|
||||
if (clazzRequestMapping != null) {
|
||||
if (clazzRequestMapping.value().length > 0) {
|
||||
uri += clazzRequestMapping.value()[0];
|
||||
}
|
||||
methods = clazzRequestMapping.method();
|
||||
}
|
||||
if (!uri.startsWith("/")) {
|
||||
uri = "/" + uri;
|
||||
}
|
||||
if (uri.endsWith("/")) {
|
||||
uri = uri.substring(0, uri.length() - 1);
|
||||
}
|
||||
if (methodMapping.value().length > 0) {
|
||||
String val = methodMapping.value()[0];
|
||||
if (val.startsWith("/")) {
|
||||
val = val.substring(1);
|
||||
}
|
||||
uri += "/" + val;
|
||||
}
|
||||
if (methodMapping.method().length > 0) {
|
||||
methods = methodMapping.method();
|
||||
}
|
||||
node.setUri(uri);
|
||||
node.setMethods(methods);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
return bean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PermissionNode> listFunctions() {
|
||||
return new ArrayList<>(permissionNodes.values());
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package au.com.royalpay.payment.manage.permission.manager.scanner;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by yixian on 2017-02-28.
|
||||
*/
|
||||
public interface PermissionPartnerReader {
|
||||
List<PermissionNode> listFunctions();
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="au.com.royalpay.payment.manage.mappers.system.PermissionPartnerFunctionMapper">
|
||||
<sql id="joinModule">
|
||||
SELECT
|
||||
f.*,
|
||||
m.js_module,
|
||||
m.js_path,
|
||||
m.remark mod_remark
|
||||
FROM sys_permission_partner_functions f
|
||||
LEFT JOIN sys_permission_partner_modules m ON m.module_name = f.module
|
||||
</sql>
|
||||
<update id="clearRolePermission">
|
||||
<![CDATA[
|
||||
UPDATE sys_permission_partner_functions
|
||||
SET role = role & #{mask}
|
||||
]]>
|
||||
</update>
|
||||
<update id="authorizeRole">
|
||||
<![CDATA[
|
||||
UPDATE sys_permission_partner_functions
|
||||
SET role = role | #{mask}
|
||||
WHERE func_id in
|
||||
]]>
|
||||
<foreach collection="func_ids" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</update>
|
||||
<select id="listByRoleMask" resultType="com.alibaba.fastjson.JSONObject">
|
||||
<include refid="joinModule"/>
|
||||
<![CDATA[
|
||||
WHERE f.role & #{mask} >0
|
||||
]]>
|
||||
</select>
|
||||
<select id="listAll" resultType="com.alibaba.fastjson.JSONObject">
|
||||
<include refid="joinModule"/>
|
||||
ORDER BY f.module ASC,f.func_id ASC
|
||||
</select>
|
||||
</mapper>
|
Loading…
Reference in new issue