├── .idea
├── .gitignore
├── .name
├── checkstyle-idea.xml
├── compiler.xml
├── inspectionProfiles
│ └── Project_Default.xml
├── jarRepositories.xml
├── libraries
│ ├── Maven__asm_asm_3_3_1.xml
│ ├── Maven__asm_asm_commons_3_3_1.xml
│ ├── Maven__asm_asm_tree_3_3_1.xml
│ ├── Maven__backport_util_concurrent_backport_util_concurrent_3_1.xml
│ ├── Maven__bsh_bsh_1_3_0.xml
│ ├── Maven__ch_qos_logback_logback_classic_1_2_3.xml
│ ├── Maven__ch_qos_logback_logback_core_1_2_3.xml
│ ├── Maven__classworlds_classworlds_1_1_alpha_2.xml
│ ├── Maven__cn_hutool_hutool_core_5_7_22.xml
│ ├── Maven__com_alibaba_druid_1_2_9.xml
│ ├── Maven__com_alibaba_druid_spring_boot_starter_1_2_9.xml
│ ├── Maven__com_alibaba_fastjson2_fastjson2_2_0_1.xml
│ ├── Maven__com_alibaba_transmittable_thread_local_2_12_6.xml
│ ├── Maven__com_google_code_findbugs_jsr305_3_0_2.xml
│ ├── Maven__com_google_errorprone_error_prone_annotations_2_11_0.xml
│ ├── Maven__com_google_guava_failureaccess_1_0_1.xml
│ ├── Maven__com_google_guava_guava_31_1_jre.xml
│ ├── Maven__com_google_guava_listenablefuture_9999_0_empty_to_avoid_conflict_with_guava.xml
│ ├── Maven__com_google_j2objc_j2objc_annotations_1_3.xml
│ ├── Maven__com_thoughtworks_qdox_qdox_1_12_1.xml
│ ├── Maven__com_zaxxer_HikariCP_3_4_5.xml
│ ├── Maven__commons_beanutils_commons_beanutils_1_7_0.xml
│ ├── Maven__commons_codec_commons_codec_1_15.xml
│ ├── Maven__commons_collections_commons_collections_3_2_1.xml
│ ├── Maven__commons_digester_commons_digester_1_6.xml
│ ├── Maven__commons_lang_commons_lang_2_4.xml
│ ├── Maven__commons_logging_commons_logging_1_0_4.xml
│ ├── Maven__commons_validator_commons_validator_1_2_0.xml
│ ├── Maven__jakarta_annotation_jakarta_annotation_api_1_3_5.xml
│ ├── Maven__javax_annotation_javax_annotation_api_1_3_2.xml
│ ├── Maven__javax_persistence_javax_persistence_api_2_2.xml
│ ├── Maven__javax_servlet_javax_servlet_api_3_1_0.xml
│ ├── Maven__junit_junit_3_8_1.xml
│ ├── Maven__mysql_mysql_connector_java_5_1_49.xml
│ ├── Maven__net_sf_jtidy_jtidy_r938.xml
│ ├── Maven__org_apache_httpcomponents_httpclient_4_5_13.xml
│ ├── Maven__org_apache_httpcomponents_httpcore_4_4_14.xml
│ ├── Maven__org_apache_logging_log4j_log4j_api_2_13_3.xml
│ ├── Maven__org_apache_logging_log4j_log4j_to_slf4j_2_13_3.xml
│ ├── Maven__org_apache_maven_doxia_doxia_core_1_2.xml
│ ├── Maven__org_apache_maven_doxia_doxia_decoration_model_1_2.xml
│ ├── Maven__org_apache_maven_doxia_doxia_logging_api_1_2.xml
│ ├── Maven__org_apache_maven_doxia_doxia_module_fml_1_2.xml
│ ├── Maven__org_apache_maven_doxia_doxia_module_xhtml_1_2.xml
│ ├── Maven__org_apache_maven_doxia_doxia_sink_api_1_2.xml
│ ├── Maven__org_apache_maven_doxia_doxia_site_renderer_1_2.xml
│ ├── Maven__org_apache_maven_maven_artifact_2_0.xml
│ ├── Maven__org_apache_maven_maven_artifact_manager_2_2_1.xml
│ ├── Maven__org_apache_maven_maven_model_2_0.xml
│ ├── Maven__org_apache_maven_maven_plugin_api_2_0.xml
│ ├── Maven__org_apache_maven_maven_plugin_descriptor_2_0.xml
│ ├── Maven__org_apache_maven_maven_plugin_registry_2_2_1.xml
│ ├── Maven__org_apache_maven_maven_profile_2_0.xml
│ ├── Maven__org_apache_maven_maven_project_2_0.xml
│ ├── Maven__org_apache_maven_maven_repository_metadata_2_2_1.xml
│ ├── Maven__org_apache_maven_plugin_tools_maven_plugin_annotations_3_6_1.xml
│ ├── Maven__org_apache_maven_plugin_tools_maven_plugin_tools_annotations_3_2.xml
│ ├── Maven__org_apache_maven_plugin_tools_maven_plugin_tools_api_3_2.xml
│ ├── Maven__org_apache_maven_plugin_tools_maven_plugin_tools_beanshell_3_2.xml
│ ├── Maven__org_apache_maven_plugin_tools_maven_plugin_tools_generators_3_2.xml
│ ├── Maven__org_apache_maven_plugin_tools_maven_plugin_tools_java_3_2.xml
│ ├── Maven__org_apache_maven_plugin_tools_maven_plugin_tools_model_3_2.xml
│ ├── Maven__org_apache_maven_plugins_maven_plugin_plugin_3_2.xml
│ ├── Maven__org_apache_maven_reporting_maven_reporting_api_3_0.xml
│ ├── Maven__org_apache_maven_reporting_maven_reporting_impl_2_1.xml
│ ├── Maven__org_apache_maven_wagon_wagon_provider_api_1_0_beta_6.xml
│ ├── Maven__org_apache_velocity_velocity_1_7.xml
│ ├── Maven__org_aspectj_aspectjweaver_1_9_9_1.xml
│ ├── Maven__org_checkerframework_checker_qual_3_12_0.xml
│ ├── Maven__org_codehaus_plexus_plexus_archiver_2_1_1.xml
│ ├── Maven__org_codehaus_plexus_plexus_component_annotations_1_5_5.xml
│ ├── Maven__org_codehaus_plexus_plexus_container_default_1_0_alpha_8.xml
│ ├── Maven__org_codehaus_plexus_plexus_i18n_1_0_beta_7.xml
│ ├── Maven__org_codehaus_plexus_plexus_io_2_0_3.xml
│ ├── Maven__org_codehaus_plexus_plexus_utils_3_0.xml
│ ├── Maven__org_codehaus_plexus_plexus_velocity_1_1_8.xml
│ ├── Maven__org_mybatis_dynamic_sql_mybatis_dynamic_sql_1_4_0.xml
│ ├── Maven__org_mybatis_mybatis_3_5_9.xml
│ ├── Maven__org_mybatis_mybatis_spring_2_0_7.xml
│ ├── Maven__org_mybatis_spring_boot_mybatis_spring_boot_autoconfigure_2_2_2.xml
│ ├── Maven__org_mybatis_spring_boot_mybatis_spring_boot_starter_2_2_2.xml
│ ├── Maven__org_slf4j_jul_to_slf4j_1_7_30.xml
│ ├── Maven__org_slf4j_slf4j_api_1_7_30.xml
│ ├── Maven__org_springframework_boot_spring_boot_2_4_6.xml
│ ├── Maven__org_springframework_boot_spring_boot_autoconfigure_2_4_6.xml
│ ├── Maven__org_springframework_boot_spring_boot_starter_2_4_6.xml
│ ├── Maven__org_springframework_boot_spring_boot_starter_jdbc_2_4_6.xml
│ ├── Maven__org_springframework_boot_spring_boot_starter_logging_2_4_6.xml
│ ├── Maven__org_springframework_spring_aop_5_3_7.xml
│ ├── Maven__org_springframework_spring_beans_5_3_7.xml
│ ├── Maven__org_springframework_spring_context_5_3_7.xml
│ ├── Maven__org_springframework_spring_core_5_3_7.xml
│ ├── Maven__org_springframework_spring_expression_5_3_7.xml
│ ├── Maven__org_springframework_spring_jcl_5_3_7.xml
│ ├── Maven__org_springframework_spring_jdbc_5_3_7.xml
│ ├── Maven__org_springframework_spring_tx_5_3_7.xml
│ ├── Maven__org_springframework_spring_web_5_3_7.xml
│ ├── Maven__org_yaml_snakeyaml_1_27.xml
│ ├── Maven__oro_oro_2_0_8.xml
│ ├── Maven__xerces_xercesImpl_2_9_1.xml
│ └── Maven__xml_apis_xml_apis_1_0_b2.xml
├── misc.xml
├── modules.xml
├── uiDesigner.xml
└── vcs.xml
├── README.md
├── data-authority-column
├── data-authority-column.iml
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── github
│ │ └── data
│ │ └── authority
│ │ ├── IDatalimitColumn.java
│ │ ├── annotation
│ │ └── DatalimitColumn.java
│ │ ├── aspectj
│ │ ├── AbstractDatalimitColAspectSupport.java
│ │ ├── DatalimitColResourceAspect.java
│ │ └── MethodWrapper.java
│ │ ├── config
│ │ └── DatalimitColumnAutoConfiguration.java
│ │ ├── exception
│ │ └── DatalimitColumnException.java
│ │ └── filter
│ │ └── DataColumnPropertyPreFilter.java
│ └── resources
│ └── META-INF
│ └── spring.factories
├── data-authority-common
├── data-authority-common.iml
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── github
│ └── data
│ └── authority
│ └── util
│ ├── MethodUtil.java
│ └── SimpleTypeRegistryUtil.java
├── data-authority-maven
├── data-authority-maven.iml
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── github
│ └── data
│ └── authority
│ ├── DatalimitColumnMojo.java
│ ├── DatalimitRowMojo.java
│ ├── col
│ ├── dao
│ │ └── DatalimitColDao.java
│ └── model
│ │ ├── DatalimitMetaCol.java
│ │ └── DatalimitMetaColField.java
│ ├── db
│ ├── DBConfig.java
│ └── MyDataSource.java
│ ├── model
│ └── Config.java
│ ├── row
│ ├── DatalimitMetaRow.java
│ └── DatalimitMetaRowField.java
│ └── util
│ ├── ClassLoaderUtil.java
│ ├── ClassUtil.java
│ ├── ReflectionUtil.java
│ └── ScanJarClassUtil.java
├── data-authority-row
├── data-authority-row.iml
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── github
│ │ └── data
│ │ └── authority
│ │ ├── parser
│ │ ├── DruidParseStatementsFactory.java
│ │ ├── ParserColumnInfo.java
│ │ ├── ParserTableInfo.java
│ │ └── SelectParserVisitor.java
│ │ ├── plugins
│ │ └── DataPermissionInterceptor.java
│ │ ├── rule
│ │ ├── DataPermission.java
│ │ ├── DataPermissionHolder.java
│ │ ├── DataPermissionRule.java
│ │ └── ParamFiled.java
│ │ ├── sql
│ │ ├── MysqlSanitiser.java
│ │ ├── SqliSanitiser.java
│ │ └── extra
│ │ │ └── codecs
│ │ │ ├── AbstractCharacterCodec.java
│ │ │ ├── AbstractCodec.java
│ │ │ ├── AbstractPushbackSequence.java
│ │ │ ├── Codec.java
│ │ │ ├── MySQLCodec.java
│ │ │ ├── PushBackSequenceImpl.java
│ │ │ ├── PushbackSequence.java
│ │ │ └── PushbackString.java
│ │ └── util
│ │ ├── DruidParseStatementsUtils.java
│ │ ├── DruidSqlParser.java
│ │ ├── PluginUtils.java
│ │ ├── ReflectionUtils.java
│ │ └── Test.java
│ └── resources
│ └── mybatis.xml
├── data-authority.iml
└── pom.xml
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | github-data-authority
--------------------------------------------------------------------------------
/.idea/checkstyle-idea.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
15 |
16 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__asm_asm_3_3_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__asm_asm_commons_3_3_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__asm_asm_tree_3_3_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__backport_util_concurrent_backport_util_concurrent_3_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__bsh_bsh_1_3_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__ch_qos_logback_logback_classic_1_2_3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__ch_qos_logback_logback_core_1_2_3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__classworlds_classworlds_1_1_alpha_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__cn_hutool_hutool_core_5_7_22.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__com_alibaba_druid_1_2_9.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__com_alibaba_druid_spring_boot_starter_1_2_9.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__com_alibaba_fastjson2_fastjson2_2_0_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__com_alibaba_transmittable_thread_local_2_12_6.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__com_google_code_findbugs_jsr305_3_0_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__com_google_errorprone_error_prone_annotations_2_11_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__com_google_guava_failureaccess_1_0_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__com_google_guava_guava_31_1_jre.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__com_google_guava_listenablefuture_9999_0_empty_to_avoid_conflict_with_guava.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__com_google_j2objc_j2objc_annotations_1_3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__com_thoughtworks_qdox_qdox_1_12_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__com_zaxxer_HikariCP_3_4_5.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__commons_beanutils_commons_beanutils_1_7_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__commons_codec_commons_codec_1_15.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__commons_collections_commons_collections_3_2_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__commons_digester_commons_digester_1_6.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__commons_lang_commons_lang_2_4.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__commons_logging_commons_logging_1_0_4.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__commons_validator_commons_validator_1_2_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__jakarta_annotation_jakarta_annotation_api_1_3_5.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__javax_annotation_javax_annotation_api_1_3_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__javax_persistence_javax_persistence_api_2_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__javax_servlet_javax_servlet_api_3_1_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__junit_junit_3_8_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__mysql_mysql_connector_java_5_1_49.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__net_sf_jtidy_jtidy_r938.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_httpcomponents_httpclient_4_5_13.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_httpcomponents_httpcore_4_4_14.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_logging_log4j_log4j_api_2_13_3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_logging_log4j_log4j_to_slf4j_2_13_3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_maven_doxia_doxia_core_1_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_maven_doxia_doxia_decoration_model_1_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_maven_doxia_doxia_logging_api_1_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_maven_doxia_doxia_module_fml_1_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_maven_doxia_doxia_module_xhtml_1_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_maven_doxia_doxia_sink_api_1_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_maven_doxia_doxia_site_renderer_1_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_maven_maven_artifact_2_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_maven_maven_artifact_manager_2_2_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_maven_maven_model_2_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_maven_maven_plugin_api_2_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_maven_maven_plugin_descriptor_2_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_maven_maven_plugin_registry_2_2_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_maven_maven_profile_2_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_maven_maven_project_2_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_maven_maven_repository_metadata_2_2_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_maven_plugin_tools_maven_plugin_annotations_3_6_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_maven_plugin_tools_maven_plugin_tools_annotations_3_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_maven_plugin_tools_maven_plugin_tools_api_3_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_maven_plugin_tools_maven_plugin_tools_beanshell_3_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_maven_plugin_tools_maven_plugin_tools_generators_3_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_maven_plugin_tools_maven_plugin_tools_java_3_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_maven_plugin_tools_maven_plugin_tools_model_3_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_maven_plugins_maven_plugin_plugin_3_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_maven_reporting_maven_reporting_api_3_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_maven_reporting_maven_reporting_impl_2_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_maven_wagon_wagon_provider_api_1_0_beta_6.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_velocity_velocity_1_7.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_aspectj_aspectjweaver_1_9_9_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_checkerframework_checker_qual_3_12_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_codehaus_plexus_plexus_archiver_2_1_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_codehaus_plexus_plexus_component_annotations_1_5_5.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_codehaus_plexus_plexus_container_default_1_0_alpha_8.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_codehaus_plexus_plexus_i18n_1_0_beta_7.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_codehaus_plexus_plexus_io_2_0_3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_codehaus_plexus_plexus_utils_3_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_codehaus_plexus_plexus_velocity_1_1_8.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_mybatis_dynamic_sql_mybatis_dynamic_sql_1_4_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_mybatis_mybatis_3_5_9.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_mybatis_mybatis_spring_2_0_7.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_mybatis_spring_boot_mybatis_spring_boot_autoconfigure_2_2_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_mybatis_spring_boot_mybatis_spring_boot_starter_2_2_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_slf4j_jul_to_slf4j_1_7_30.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_slf4j_slf4j_api_1_7_30.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_boot_spring_boot_2_4_6.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_boot_spring_boot_autoconfigure_2_4_6.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_2_4_6.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_jdbc_2_4_6.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_logging_2_4_6.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_spring_aop_5_3_7.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_spring_beans_5_3_7.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_spring_context_5_3_7.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_spring_core_5_3_7.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_spring_expression_5_3_7.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_spring_jcl_5_3_7.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_spring_jdbc_5_3_7.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_spring_tx_5_3_7.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_spring_web_5_3_7.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_yaml_snakeyaml_1_27.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__oro_oro_2_0_8.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__xerces_xercesImpl_2_9_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__xml_apis_xml_apis_1_0_b2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # data-authority
2 | 微服务+DDD数据权限。数据权限包含行级权限和列级权限
3 |
--------------------------------------------------------------------------------
/data-authority-column/data-authority-column.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/data-authority-column/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | data-authority
7 | com.github.data.authority
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | data-authority-column
13 |
14 |
15 | 8
16 | 8
17 |
18 |
19 |
20 | data-authority-common
21 | com.github.data.authority
22 |
23 |
24 | org.aspectj
25 | aspectjweaver
26 |
27 |
28 | org.slf4j
29 | slf4j-api
30 | 1.7.30
31 | compile
32 |
33 |
34 | javax.servlet
35 | javax.servlet-api
36 | 3.1.0
37 | compile
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/data-authority-column/src/main/java/com/github/data/authority/IDatalimitColumn.java:
--------------------------------------------------------------------------------
1 | package com.github.data.authority;
2 |
3 | import java.util.List;
4 | import java.util.Objects;
5 | import javax.servlet.http.HttpServletRequest;
6 | import org.springframework.web.context.request.RequestContextHolder;
7 | import org.springframework.web.context.request.ServletRequestAttributes;
8 |
9 | /**
10 | * 查询用户的列级权限
11 | *
12 | * @author chenzhh
13 | */
14 | public interface IDatalimitColumn {
15 | /**
16 | * 根据方法名称查询列级权限
17 | *
18 | * @param method
19 | * @return
20 | */
21 | default List getDatalimitColumnByMethod(String method) {
22 | HttpServletRequest httpServletRequest = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
23 | Objects.requireNonNull(httpServletRequest, "httpServletRequest不能为空");
24 | String applicationId = httpServletRequest.getHeader("yes.req.applicationId");
25 | Objects.requireNonNull(applicationId, "应用Id不能为空");
26 | String tenantId = httpServletRequest.getHeader("yes.req.tenantId");
27 | Objects.requireNonNull(tenantId, "租户Id不能为空");
28 | String userId = httpServletRequest.getHeader("yes.req.userId");
29 | Objects.requireNonNull(userId, "用户Id不能为空");
30 | return getDatalimitColumnByUserId(tenantId,applicationId,userId,method);
31 | }
32 | /**
33 | * 查询用户字段级权限
34 | *
35 | * @param tenantId 租户
36 | * @param applicationId 应用
37 | * @param userId 用户
38 | * @param method 方法
39 | * @return
40 | */
41 | List getDatalimitColumnByUserId(String tenantId, String applicationId, String userId, String method);
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/data-authority-column/src/main/java/com/github/data/authority/annotation/DatalimitColumn.java:
--------------------------------------------------------------------------------
1 | package com.github.data.authority.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Inherited;
5 | import java.lang.annotation.Retention;
6 | import java.lang.annotation.RetentionPolicy;
7 | import java.lang.annotation.Target;
8 |
9 | /**
10 | * 数据列级权限
11 | * @author chenzhh
12 | */
13 | @Target({ElementType.METHOD})
14 | @Inherited
15 | @Retention(RetentionPolicy.RUNTIME)
16 | public @interface DatalimitColumn {
17 | /**
18 | * 返回数据类型
19 | * @return
20 | */
21 | Class> clazz ();
22 |
23 | /**
24 | * 方法说明
25 | * @return
26 | */
27 | String name();
28 | /**
29 | * 方法名称
30 | * @return
31 | */
32 | String method() default "";
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/data-authority-column/src/main/java/com/github/data/authority/aspectj/AbstractDatalimitColAspectSupport.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 1999-2020 Alibaba Group Holding Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.github.data.authority.aspectj;
17 |
18 | import java.lang.reflect.Method;
19 | import org.aspectj.lang.ProceedingJoinPoint;
20 | import org.aspectj.lang.reflect.MethodSignature;
21 | import org.slf4j.Logger;
22 | import org.slf4j.LoggerFactory;
23 |
24 | /**
25 | * 数据列级权限拦截器
26 | *
27 | * @author chenzhh
28 | */
29 | public abstract class AbstractDatalimitColAspectSupport {
30 | /**
31 | *
32 | */
33 | protected static final Logger LOGGER = LoggerFactory.getLogger(DatalimitColResourceAspect.class);
34 |
35 | protected Method resolveMethod(ProceedingJoinPoint joinPoint) {
36 | MethodSignature signature = (MethodSignature) joinPoint.getSignature();
37 | Class> targetClass = joinPoint.getTarget().getClass();
38 |
39 | Method method = getDeclaredMethodFor(targetClass, signature.getName(),
40 | signature.getMethod().getParameterTypes());
41 | if (method == null) {
42 | throw new IllegalStateException("Cannot resolve target method: " + signature.getMethod().getName());
43 | }
44 | return method;
45 | }
46 |
47 | /**
48 | * Get declared method with provided name and parameterTypes in given class and its super classes. All parameters
49 | * should be valid.
50 | *
51 | * @param clazz class where the method is located
52 | * @param name method name
53 | * @param parameterTypes method parameter type list
54 | * @return resolved method, null if not found
55 | */
56 | private Method getDeclaredMethodFor(Class> clazz, String name, Class>... parameterTypes) {
57 | try {
58 | return clazz.getDeclaredMethod(name, parameterTypes);
59 | } catch (NoSuchMethodException e) {
60 | Class> superClass = clazz.getSuperclass();
61 | if (superClass != null) {
62 | return getDeclaredMethodFor(superClass, name, parameterTypes);
63 | }
64 | }
65 | return null;
66 | }
67 | }
--------------------------------------------------------------------------------
/data-authority-column/src/main/java/com/github/data/authority/aspectj/DatalimitColResourceAspect.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 1999-2018 Alibaba Group Holding Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.github.data.authority.aspectj;
17 |
18 | import com.alibaba.fastjson2.JSON;
19 | import com.github.data.authority.IDatalimitColumn;
20 | import com.github.data.authority.annotation.DatalimitColumn;
21 | import com.github.data.authority.exception.DatalimitColumnException;
22 | import com.github.data.authority.filter.DataColumnPropertyPreFilter;
23 | import com.github.data.authority.util.MethodUtil;
24 | import com.github.data.authority.util.SimpleTypeRegistryUtil;
25 | import java.lang.reflect.Method;
26 | import java.util.List;
27 | import java.util.Objects;
28 | import org.aspectj.lang.ProceedingJoinPoint;
29 | import org.aspectj.lang.annotation.Around;
30 | import org.aspectj.lang.annotation.Aspect;
31 | import org.aspectj.lang.annotation.Pointcut;
32 |
33 | /**
34 | * 数据列级权限
35 | *
36 | * @author chenzhh
37 | */
38 | @Aspect
39 | public class DatalimitColResourceAspect extends AbstractDatalimitColAspectSupport {
40 | /**
41 | *
42 | */
43 | private IDatalimitColumn datalimitColumn;
44 |
45 | public DatalimitColResourceAspect(IDatalimitColumn datalimitColumn) {
46 | this.datalimitColumn = datalimitColumn;
47 | }
48 |
49 | @Pointcut("@annotation(com.github.data.authority.annotation.DatalimitColumn)")
50 | public void datalimitColumnAnnotationPointcut() {
51 | }
52 |
53 | @Around("datalimitColumnAnnotationPointcut()")
54 | public Object invokeResourceWithDatalimitColumn(ProceedingJoinPoint pjp) throws Throwable {
55 | Method originMethod = resolveMethod(pjp);
56 | DatalimitColumn annotation = originMethod.getAnnotation(DatalimitColumn.class);
57 | if (Objects.isNull(annotation)) {
58 | throw new IllegalStateException("权限注解【DatalimitColumn】不能为空");
59 | }
60 | try {
61 | Object result = pjp.proceed();
62 | String method = MethodUtil.resolveMethodName(originMethod);
63 | String value = annotation.method();
64 | if(Objects.nonNull(value) && !"".equals(value.trim())){
65 | method = method+"."+value;
66 | }
67 | List columns = this.datalimitColumn.getDatalimitColumnByMethod(method);
68 | Class> ret = result.getClass();
69 | if (Objects.nonNull(ret) && !SimpleTypeRegistryUtil.isSimpleType(ret)) {
70 | DataColumnPropertyPreFilter simplePropertyPreFilter = new DataColumnPropertyPreFilter();
71 | if (Objects.nonNull(columns) && columns.size() > 0) {
72 | simplePropertyPreFilter.getExcludes().addAll(columns);
73 | } else {
74 | LOGGER.error("数据列级权限查询为空,方法为:{}", method);
75 | }
76 | return JSON.parseObject(JSON.toJSONString(result, simplePropertyPreFilter), ret);
77 | }
78 | return result;
79 | } catch (Exception ex) {
80 | throw new DatalimitColumnException("数据列级权限拦截失败",ex);
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/data-authority-column/src/main/java/com/github/data/authority/aspectj/MethodWrapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 1999-2018 Alibaba Group Holding Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.github.data.authority.aspectj;
17 |
18 | import java.lang.reflect.Method;
19 |
20 | /**
21 | * 数据列级权限,来源alibaba
22 | *
23 | * @author chenzhh
24 | */
25 | public class MethodWrapper {
26 |
27 | private final Method method;
28 | private final boolean present;
29 |
30 | private MethodWrapper(Method method, boolean present) {
31 | this.method = method;
32 | this.present = present;
33 | }
34 |
35 | static MethodWrapper wrap(Method method) {
36 | if (method == null) {
37 | return none();
38 | }
39 | return new MethodWrapper(method, true);
40 | }
41 |
42 | static MethodWrapper none() {
43 | return new MethodWrapper(null, false);
44 | }
45 |
46 | Method getMethod() {
47 | return method;
48 | }
49 |
50 | boolean isPresent() {
51 | return present;
52 | }
53 | }
--------------------------------------------------------------------------------
/data-authority-column/src/main/java/com/github/data/authority/config/DatalimitColumnAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.github.data.authority.config;
2 |
3 | import com.github.data.authority.IDatalimitColumn;
4 | import com.github.data.authority.aspectj.DatalimitColResourceAspect;
5 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
6 | import org.springframework.context.annotation.Bean;
7 | import org.springframework.context.annotation.Configuration;
8 |
9 | /**
10 | * @author chenzhh
11 | */
12 | @Configuration
13 | public class DatalimitColumnAutoConfiguration {
14 |
15 | @Bean
16 | @ConditionalOnMissingBean
17 | public DatalimitColResourceAspect datalimitColResourceAspect(IDatalimitColumn datalimitColumn) {
18 | return new DatalimitColResourceAspect(datalimitColumn);
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/data-authority-column/src/main/java/com/github/data/authority/exception/DatalimitColumnException.java:
--------------------------------------------------------------------------------
1 | package com.github.data.authority.exception;
2 |
3 | /**
4 | *
5 | * @author chenzhh
6 | */
7 | public class DatalimitColumnException extends RuntimeException{
8 |
9 | public DatalimitColumnException(String message, Throwable cause) {
10 | super(message, cause);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/data-authority-column/src/main/java/com/github/data/authority/filter/DataColumnPropertyPreFilter.java:
--------------------------------------------------------------------------------
1 | package com.github.data.authority.filter;
2 |
3 | import com.alibaba.fastjson2.JSONWriter;
4 | import com.alibaba.fastjson2.filter.PropertyPreFilter;
5 | import com.google.common.collect.Sets;
6 | import java.util.Set;
7 |
8 | /**
9 | * 改造fastjson源码
10 | * @author chenzhh
11 | */
12 | public class DataColumnPropertyPreFilter implements PropertyPreFilter {
13 | private final Class> clazz;
14 | private final Set includes = Sets.newHashSet();
15 | private final Set excludes = Sets.newHashSet();
16 | private int maxLevel = 0;
17 |
18 | public DataColumnPropertyPreFilter(String... properties) {
19 | this(null, properties);
20 | }
21 |
22 | public DataColumnPropertyPreFilter(Class> clazz, String... properties) {
23 | super();
24 | this.clazz = clazz;
25 | for (String item : properties) {
26 | if (item != null) {
27 | this.includes.add(item);
28 | }
29 | }
30 | }
31 |
32 | /**
33 | * @since 1.2.9
34 | */
35 | public int getMaxLevel() {
36 | return maxLevel;
37 | }
38 |
39 | /**
40 | * @since 1.2.9
41 | */
42 | public void setMaxLevel(int maxLevel) {
43 | this.maxLevel = maxLevel;
44 | }
45 |
46 | public Class> getClazz() {
47 | return clazz;
48 | }
49 |
50 | public Set getIncludes() {
51 | return includes;
52 | }
53 |
54 | public Set getExcludes() {
55 | return excludes;
56 | }
57 |
58 |
59 | @Override public boolean process(JSONWriter writer, Object source, String name) {
60 | if (source == null) {
61 | return true;
62 | }
63 |
64 | if (clazz != null && !clazz.isInstance(source)) {
65 | return true;
66 | }
67 |
68 | if (this.excludes.contains(name)) {
69 | return false;
70 | }
71 | JSONWriter.Context context = writer.getContext();
72 | String prefix = context.toString();
73 | prefix = prefix + "." + name;
74 | //去除开头的$.
75 | prefix = prefix.replaceAll("\\[\\d+\\]", "");
76 | prefix = prefix.replace("$.", "");
77 | if (this.excludes.contains(prefix)) {
78 | return false;
79 | }
80 | return includes.size() == 0 || includes.contains(name);
81 |
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/data-authority-column/src/main/resources/META-INF/spring.factories:
--------------------------------------------------------------------------------
1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.github.data.authority.config.DatalimitColumnAutoConfiguration
--------------------------------------------------------------------------------
/data-authority-common/data-authority-common.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/data-authority-common/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | data-authority
7 | com.github.data.authority
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | data-authority-common
13 |
14 |
15 | 8
16 | 8
17 |
18 |
19 |
--------------------------------------------------------------------------------
/data-authority-common/src/main/java/com/github/data/authority/util/MethodUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 1999-2018 Alibaba Group Holding Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.github.data.authority.util;
17 |
18 | import java.lang.reflect.Method;
19 | import java.util.Map;
20 | import java.util.Objects;
21 | import java.util.concurrent.ConcurrentHashMap;
22 |
23 | /**
24 | * @author chenzhh
25 | */
26 | public final class MethodUtil {
27 |
28 | private static final Map methodNameMap = new ConcurrentHashMap();
29 |
30 | private static final Object LOCK = new Object();
31 |
32 | /**
33 | * Parse and resolve the method name, then cache to the map.
34 | *
35 | * @param method method instance
36 | * @return resolved method name
37 | */
38 | public static String resolveMethodName(Method method) {
39 | if (Objects.isNull(method)) {
40 | throw new IllegalArgumentException("方法名不能为空");
41 | }
42 | String methodName = methodNameMap.get(method);
43 | if (Objects.isNull(methodName)) {
44 | synchronized (LOCK) {
45 | methodName = methodNameMap.get(method);
46 | if (Objects.isNull(methodName)) {
47 | StringBuilder sb = new StringBuilder();
48 |
49 | String className = method.getDeclaringClass().getName();
50 | String name = method.getName();
51 | Class>[] params = method.getParameterTypes();
52 | sb.append(className).append(":").append(name);
53 | sb.append("(");
54 | int paramPos = 0;
55 | for (Class> clazz : params) {
56 | sb.append(clazz.getCanonicalName());
57 | if (++paramPos < params.length) {
58 | sb.append(",");
59 | }
60 | }
61 | sb.append(")");
62 | methodName = sb.toString();
63 | methodNameMap.put(method, methodName);
64 | }
65 | }
66 | }
67 | return methodName;
68 | }
69 |
70 | /**
71 | * For test.
72 | */
73 | static void clearMethodMap() {
74 | methodNameMap.clear();
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/data-authority-common/src/main/java/com/github/data/authority/util/SimpleTypeRegistryUtil.java:
--------------------------------------------------------------------------------
1 | package com.github.data.authority.util;
2 |
3 | import java.math.BigDecimal;
4 | import java.math.BigInteger;
5 | import java.time.LocalDate;
6 | import java.time.LocalDateTime;
7 | import java.util.Date;
8 | import java.util.HashSet;
9 | import java.util.Set;
10 |
11 | /**
12 | * 基本类型
13 | * @author chenzhh
14 | */
15 | public class SimpleTypeRegistryUtil {
16 | private static final Set> SIMPLE_TYPE_SET = new HashSet();
17 |
18 | private SimpleTypeRegistryUtil() {
19 | }
20 |
21 | public static boolean isSimpleType(Class> clazz) {
22 | return SIMPLE_TYPE_SET.contains(clazz);
23 | }
24 |
25 | static {
26 |
27 | SIMPLE_TYPE_SET.add(String.class);
28 | SIMPLE_TYPE_SET.add(String[].class);
29 | SIMPLE_TYPE_SET.add(Byte.class);
30 | SIMPLE_TYPE_SET.add(byte.class);
31 | SIMPLE_TYPE_SET.add(byte[].class);
32 | SIMPLE_TYPE_SET.add(Short.class);
33 | SIMPLE_TYPE_SET.add(short.class);
34 | SIMPLE_TYPE_SET.add(short[].class);
35 | SIMPLE_TYPE_SET.add(Character.class);
36 | SIMPLE_TYPE_SET.add(char.class);
37 | SIMPLE_TYPE_SET.add(char[].class);
38 | SIMPLE_TYPE_SET.add(Integer.class);
39 | SIMPLE_TYPE_SET.add(Integer[].class);
40 | SIMPLE_TYPE_SET.add(int.class);
41 | SIMPLE_TYPE_SET.add(int[].class);
42 | SIMPLE_TYPE_SET.add(Long.class);
43 | SIMPLE_TYPE_SET.add(Long[].class);
44 | SIMPLE_TYPE_SET.add(long.class);
45 | SIMPLE_TYPE_SET.add(long[].class);
46 | SIMPLE_TYPE_SET.add(Float.class);
47 | SIMPLE_TYPE_SET.add(Float[].class);
48 | SIMPLE_TYPE_SET.add(float.class);
49 | SIMPLE_TYPE_SET.add(float[].class);
50 | SIMPLE_TYPE_SET.add(Double.class);
51 | SIMPLE_TYPE_SET.add(Double[].class);
52 | SIMPLE_TYPE_SET.add(double.class);
53 | SIMPLE_TYPE_SET.add(double[].class);
54 | SIMPLE_TYPE_SET.add(Boolean.class);
55 | SIMPLE_TYPE_SET.add(Boolean[].class);
56 | SIMPLE_TYPE_SET.add(boolean.class);
57 | SIMPLE_TYPE_SET.add(boolean[].class);
58 | SIMPLE_TYPE_SET.add(Date.class);
59 | SIMPLE_TYPE_SET.add(LocalDate.class);
60 | SIMPLE_TYPE_SET.add(LocalDateTime.class);
61 | SIMPLE_TYPE_SET.add(java.sql.Date.class);
62 | SIMPLE_TYPE_SET.add(Class.class);
63 | SIMPLE_TYPE_SET.add(BigInteger.class);
64 | SIMPLE_TYPE_SET.add(BigDecimal.class);
65 | }
66 | }
67 |
68 |
--------------------------------------------------------------------------------
/data-authority-maven/pom.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 | data-authority
5 | com.github.data.authority
6 | 1.0-SNAPSHOT
7 |
8 | 4.0.0
9 | data-authority-maven
10 | maven-plugin
11 | data-authority-maven Maven Mojo
12 | http://maven.apache.org
13 |
14 |
15 | org.apache.maven.plugin-tools
16 | maven-plugin-annotations
17 | 3.6.1
18 |
19 |
20 | org.apache.maven.plugins
21 | maven-plugin-plugin
22 | 3.2
23 |
24 |
25 | org.apache.maven
26 | maven-plugin-api
27 | 2.0
28 |
29 |
30 | org.apache.maven
31 | maven-plugin-descriptor
32 | 2.0
33 |
34 |
35 | cn.hutool
36 | hutool-core
37 | 5.7.22
38 |
39 |
40 | org.apache.maven
41 | maven-project
42 | 2.0
43 |
44 |
45 | org.apache.maven
46 | maven-model
47 | 2.0
48 |
49 |
50 | org.apache.maven
51 | maven-artifact
52 | 2.0
53 |
54 |
55 | junit
56 | junit
57 | 3.8.1
58 | test
59 |
60 |
61 | org.springframework
62 | spring-core
63 |
64 |
65 | com.alibaba
66 | druid-spring-boot-starter
67 |
68 |
69 | mysql
70 | mysql-connector-java
71 | 5.1.49
72 |
73 |
74 | javax.servlet
75 | javax.servlet-api
76 | 3.1.0
77 | compile
78 |
79 |
80 | javax.persistence
81 | javax.persistence-api
82 |
83 |
84 | com.github.data.authority
85 | data-authority-row
86 |
87 |
88 | com.github.data.authority
89 | data-authority-column
90 |
91 |
92 |
93 |
94 |
95 |
96 | org.apache.maven.plugins
97 | maven-plugin-plugin
98 | 3.5
99 |
100 |
101 |
102 |
103 |
104 |
105 |
--------------------------------------------------------------------------------
/data-authority-maven/src/main/java/com/github/data/authority/DatalimitColumnMojo.java:
--------------------------------------------------------------------------------
1 | package com.github.data.authority;
2 |
3 | /*
4 | * Copyright 2001-2005 The Apache Software Foundation.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import com.github.data.authority.annotation.DatalimitColumn;
20 | import com.github.data.authority.db.DBConfig;
21 | import com.github.data.authority.model.Config;
22 | import com.github.data.authority.util.ClassUtil;
23 | import com.github.data.authority.util.ReflectionUtil;
24 | import com.github.data.authority.util.SimpleTypeRegistryUtil;
25 | import com.google.common.collect.Sets;
26 | import java.io.File;
27 | import java.lang.reflect.Field;
28 | import java.lang.reflect.Method;
29 | import java.lang.reflect.ParameterizedType;
30 | import java.lang.reflect.Type;
31 | import java.util.List;
32 | import java.util.Objects;
33 | import java.util.Set;
34 | import java.util.StringJoiner;
35 | import java.util.stream.Collectors;
36 | import org.apache.maven.artifact.Artifact;
37 | import org.apache.maven.plugin.AbstractMojo;
38 | import org.apache.maven.plugin.MojoExecutionException;
39 | import org.apache.maven.plugin.MojoFailureException;
40 | import org.apache.maven.plugins.annotations.LifecyclePhase;
41 | import org.apache.maven.plugins.annotations.Mojo;
42 | import org.apache.maven.plugins.annotations.Parameter;
43 | import org.apache.maven.plugins.annotations.ResolutionScope;
44 | import org.apache.maven.project.MavenProject;
45 | import org.springframework.util.CollectionUtils;
46 | import org.springframework.util.ReflectionUtils;
47 |
48 | /**
49 | * 行级权限
50 | *
51 | * @author chenzhh
52 | */
53 | @Mojo(name = "datalimit-column",
54 | defaultPhase = LifecyclePhase.COMPILE,
55 | threadSafe = true,
56 | requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME,
57 | requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME
58 | )
59 | public class DatalimitColumnMojo extends AbstractMojo {
60 | @Parameter(property = "project", required = true, readonly = true)
61 | private MavenProject mavenProject;
62 | /**
63 | *
64 | */
65 | @Parameter(defaultValue = "${project.compileClasspathElements}", required = true, readonly = true)
66 | private List compileClasspathElements;
67 | /**
68 | *
69 | */
70 | private File outputDirectory;
71 | /**
72 | *
73 | */
74 | @Parameter(readonly = true)
75 | private DBConfig dbConfig;
76 | /**
77 | *
78 | */
79 | @Parameter(readonly = true)
80 | private Config config;
81 | /**
82 | * 依赖包地址
83 | */
84 | private Set classpathElements = Sets.newHashSet();
85 |
86 | @Override
87 | public void execute() throws MojoExecutionException, MojoFailureException {
88 | Set artifacts = this.mavenProject.getArtifacts();
89 | for (Artifact artifact : artifacts) {
90 | classpathElements.add(artifact.getFile().getAbsoluteFile().toString());
91 | }
92 | Set compileClasspath = compileClasspathElements.stream().filter(path -> {
93 | return new File(path).isDirectory();
94 | }).collect(Collectors.toSet());
95 | classpathElements.addAll(compileClasspath);
96 |
97 | List> classes = ClassUtil.getClassAll(this.classpathElements, config.getPackages(), getLog());
98 | //注解判断
99 | if (!CollectionUtils.isEmpty(classes)) {
100 | for (Class> clazz : classes) {
101 | Method[] methods = ReflectionUtils.getDeclaredMethods(clazz);
102 | if (Objects.nonNull(methods) && methods.length > 0) {
103 | for (Method method : methods) {
104 | //是否数据列级权限注解
105 | if (method.isAnnotationPresent(DatalimitColumn.class)) {
106 | StringJoiner methodName = new StringJoiner("");
107 | methodName.add(clazz.getName()).add(".").add(method.getName());
108 | DatalimitColumn datalimitColumn = method.getAnnotation(DatalimitColumn.class);
109 | if (Objects.nonNull(datalimitColumn)) {
110 | //方法名称
111 | String annotation_method = datalimitColumn.method();
112 | if (Objects.nonNull(annotation_method) && !"".contains(annotation_method.trim())) {
113 | methodName.add(clazz.getName()).add(".").add(method.getName()).add(".").add(annotation_method);
114 | }
115 | //获取对象字段
116 | Set result = Sets.newHashSet();
117 | ReflectionUtil.field(null, result, datalimitColumn.clazz());
118 | getLog().info(methodName.toString());
119 | //保存数据库
120 |
121 | }
122 | }
123 | }
124 | }
125 | }
126 |
127 | }
128 |
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/data-authority-maven/src/main/java/com/github/data/authority/col/model/DatalimitMetaCol.java:
--------------------------------------------------------------------------------
1 | package com.github.data.authority.col.model;
2 |
3 | import java.time.LocalDateTime;
4 | import java.util.List;
5 |
6 | /**
7 | * @author chenzhh
8 | */
9 | public class DatalimitMetaCol {
10 | private Long id;
11 | private String service;
12 | private String name;
13 | private LocalDateTime create_time;
14 | private String create_by;
15 | private LocalDateTime update_time;
16 | private String update_by;
17 | private Integer version;
18 | private Integer dr;
19 | private Integer enable;
20 | private List fields;
21 |
22 | public Long getId() {
23 | return id;
24 | }
25 |
26 | public void setId(Long id) {
27 | this.id = id;
28 | }
29 |
30 | public String getService() {
31 | return service;
32 | }
33 |
34 | public void setService(String service) {
35 | this.service = service;
36 | }
37 |
38 | public String getName() {
39 | return name;
40 | }
41 |
42 | public void setName(String name) {
43 | this.name = name;
44 | }
45 |
46 | public LocalDateTime getCreate_time() {
47 | return create_time;
48 | }
49 |
50 | public void setCreate_time(LocalDateTime create_time) {
51 | this.create_time = create_time;
52 | }
53 |
54 | public String getCreate_by() {
55 | return create_by;
56 | }
57 |
58 | public void setCreate_by(String create_by) {
59 | this.create_by = create_by;
60 | }
61 |
62 | public LocalDateTime getUpdate_time() {
63 | return update_time;
64 | }
65 |
66 | public void setUpdate_time(LocalDateTime update_time) {
67 | this.update_time = update_time;
68 | }
69 |
70 | public String getUpdate_by() {
71 | return update_by;
72 | }
73 |
74 | public void setUpdate_by(String update_by) {
75 | this.update_by = update_by;
76 | }
77 |
78 | public Integer getVersion() {
79 | return version;
80 | }
81 |
82 | public void setVersion(Integer version) {
83 | this.version = version;
84 | }
85 |
86 | public Integer getDr() {
87 | return dr;
88 | }
89 |
90 | public void setDr(Integer dr) {
91 | this.dr = dr;
92 | }
93 |
94 | public Integer getEnable() {
95 | return enable;
96 | }
97 |
98 | public void setEnable(Integer enable) {
99 | this.enable = enable;
100 | }
101 |
102 | public List getFields() {
103 | return fields;
104 | }
105 |
106 | public void setFields(List fields) {
107 | this.fields = fields;
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/data-authority-maven/src/main/java/com/github/data/authority/col/model/DatalimitMetaColField.java:
--------------------------------------------------------------------------------
1 | package com.github.data.authority.col.model;
2 |
3 | import java.time.LocalDateTime;
4 |
5 | /**
6 | * @author chenzhh
7 | */
8 | public class DatalimitMetaColField {
9 | private Long id;
10 | private String fieldName;
11 | private String name;
12 | private String metaId;
13 | private LocalDateTime create_time;
14 | private String create_by;
15 | private LocalDateTime update_time;
16 | private String update_by;
17 | private Integer version;
18 | private Integer dr;
19 | private Integer enable;
20 |
21 | public Long getId() {
22 | return id;
23 | }
24 |
25 | public void setId(Long id) {
26 | this.id = id;
27 | }
28 |
29 | public String getFieldName() {
30 | return fieldName;
31 | }
32 |
33 | public void setFieldName(String fieldName) {
34 | this.fieldName = fieldName;
35 | }
36 |
37 | public String getName() {
38 | return name;
39 | }
40 |
41 | public void setName(String name) {
42 | this.name = name;
43 | }
44 |
45 | public String getMetaId() {
46 | return metaId;
47 | }
48 |
49 | public void setMetaId(String metaId) {
50 | this.metaId = metaId;
51 | }
52 |
53 | public LocalDateTime getCreate_time() {
54 | return create_time;
55 | }
56 |
57 | public void setCreate_time(LocalDateTime create_time) {
58 | this.create_time = create_time;
59 | }
60 |
61 | public String getCreate_by() {
62 | return create_by;
63 | }
64 |
65 | public void setCreate_by(String create_by) {
66 | this.create_by = create_by;
67 | }
68 |
69 | public LocalDateTime getUpdate_time() {
70 | return update_time;
71 | }
72 |
73 | public void setUpdate_time(LocalDateTime update_time) {
74 | this.update_time = update_time;
75 | }
76 |
77 | public String getUpdate_by() {
78 | return update_by;
79 | }
80 |
81 | public void setUpdate_by(String update_by) {
82 | this.update_by = update_by;
83 | }
84 |
85 | public Integer getVersion() {
86 | return version;
87 | }
88 |
89 | public void setVersion(Integer version) {
90 | this.version = version;
91 | }
92 |
93 | public Integer getDr() {
94 | return dr;
95 | }
96 |
97 | public void setDr(Integer dr) {
98 | this.dr = dr;
99 | }
100 |
101 | public Integer getEnable() {
102 | return enable;
103 | }
104 |
105 | public void setEnable(Integer enable) {
106 | this.enable = enable;
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/data-authority-maven/src/main/java/com/github/data/authority/db/DBConfig.java:
--------------------------------------------------------------------------------
1 | package com.github.data.authority.db;
2 |
3 | /**
4 | * 数据库连接信息
5 | *
6 | * @author chenzhh
7 | */
8 | public class DBConfig {
9 | /**
10 | * 驱动
11 | */
12 | private String driverClass;
13 | /**
14 | * 地址
15 | */
16 | private String url;
17 | /**
18 | * 用户名称
19 | */
20 | private String username;
21 | /**
22 | * 密码
23 | */
24 | private String password;
25 |
26 | private String useSSL;
27 |
28 | public String getDriverClass() {
29 | return driverClass;
30 | }
31 |
32 | public void setDriverClass(String driverClass) {
33 | this.driverClass = driverClass;
34 | }
35 |
36 | public String getUrl() {
37 | return url;
38 | }
39 |
40 | public void setUrl(String url) {
41 | this.url = url;
42 | }
43 |
44 | public String getUsername() {
45 | return username;
46 | }
47 |
48 | public void setUsername(String username) {
49 | this.username = username;
50 | }
51 |
52 | public String getPassword() {
53 | return password;
54 | }
55 |
56 | public void setPassword(String password) {
57 | this.password = password;
58 | }
59 |
60 | public String getUseSSL() {
61 | return useSSL;
62 | }
63 |
64 | public void setUseSSL(String useSSL) {
65 | this.useSSL = useSSL;
66 | }
67 |
68 | @Override public String toString() {
69 | return "DBConfig{" +
70 | "driverClass='" + driverClass + '\'' +
71 | ", url='" + url + '\'' +
72 | ", username='" + username + '\'' +
73 | ", password='" + password + '\'' +
74 | ", useSSL='" + useSSL + '\'' +
75 | '}';
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/data-authority-maven/src/main/java/com/github/data/authority/db/MyDataSource.java:
--------------------------------------------------------------------------------
1 | package com.github.data.authority.db;
2 |
3 | import com.alibaba.druid.pool.DruidDataSource;
4 | import java.sql.Connection;
5 | import java.sql.PreparedStatement;
6 | import java.sql.ResultSet;
7 | import java.sql.SQLException;
8 | import java.util.Objects;
9 |
10 | /**
11 | * 数据库连接
12 | *
13 | * @author chenzhh
14 | */
15 | public final class MyDataSource {
16 | /**
17 | * @param config
18 | * @return
19 | */
20 | public static Connection getConnection(DBConfig config) {
21 | DruidDataSource dataSource = new DruidDataSource();
22 | dataSource.setDriverClassName(config.getDriverClass()+"&"+config.getUseSSL());
23 | dataSource.setUrl(config.getUrl());
24 | dataSource.setUsername(config.getUsername());
25 | dataSource.setPassword(config.getPassword());
26 | try {
27 | return dataSource.getConnection().getConnection();
28 | } catch (SQLException ex) {
29 | throw new RuntimeException("数据库连接异常", ex);
30 | }
31 |
32 | }
33 |
34 | public static void close(ResultSet resultSet, PreparedStatement statement, Connection conn) {
35 | try {
36 | if (Objects.nonNull(resultSet)) {
37 | resultSet.close();
38 | }
39 | if (Objects.nonNull(statement)) {
40 | statement.execute();
41 | }
42 | if (Objects.nonNull(conn)) {
43 | conn.close();
44 | }
45 | } catch (SQLException throwables) {
46 | throwables.printStackTrace();
47 | }
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/data-authority-maven/src/main/java/com/github/data/authority/model/Config.java:
--------------------------------------------------------------------------------
1 | package com.github.data.authority.model;
2 |
3 | /**
4 | * 配置信息
5 | * @author chenzhh
6 | */
7 | public class Config {
8 | /**
9 | * 模块名称
10 | */
11 | private String module;
12 | /**
13 | * 解析包名,多个逗号分隔
14 | */
15 | private String packages;
16 | /**
17 | * 后缀名称,多个逗号分隔
18 | */
19 | private String suffix;
20 | /**
21 | * 包含方法名,多个逗号分隔
22 | */
23 | private String methods;
24 |
25 | public String getModule() {
26 | return module;
27 | }
28 |
29 | public void setModule(String module) {
30 | this.module = module;
31 | }
32 |
33 | public String getPackages() {
34 | return packages;
35 | }
36 |
37 | public void setPackages(String packages) {
38 | this.packages = packages;
39 | }
40 |
41 | public String getSuffix() {
42 | return suffix;
43 | }
44 |
45 | public void setSuffix(String suffix) {
46 | this.suffix = suffix;
47 | }
48 |
49 | public String getMethods() {
50 | return methods;
51 | }
52 |
53 | public void setMethods(String methods) {
54 | this.methods = methods;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/data-authority-maven/src/main/java/com/github/data/authority/row/DatalimitMetaRow.java:
--------------------------------------------------------------------------------
1 | package com.github.data.authority.row;
2 |
3 | import com.github.data.authority.col.model.DatalimitMetaColField;
4 | import java.time.LocalDateTime;
5 | import java.util.List;
6 |
7 | /**
8 | * @author chenzhh
9 | */
10 | public class DatalimitMetaRow {
11 | private Long id;
12 | private String module;
13 | private String mapper;
14 | private String name;
15 | private LocalDateTime create_time;
16 | private String create_by;
17 | private LocalDateTime update_time;
18 | private String update_by;
19 | private Integer version;
20 | private Integer dr;
21 | private Integer enable;
22 | private List fields;
23 |
24 | @Override public String toString() {
25 | return "DatalimitMetaRow{" +
26 | "id=" + id +
27 | ", module='" + module + '\'' +
28 | ", mapper='" + mapper + '\'' +
29 | ", name='" + name + '\'' +
30 | ", create_time=" + create_time +
31 | ", create_by='" + create_by + '\'' +
32 | ", update_time=" + update_time +
33 | ", update_by='" + update_by + '\'' +
34 | ", version=" + version +
35 | ", dr=" + dr +
36 | ", enable=" + enable +
37 | ", fields=" + fields +
38 | '}';
39 | }
40 |
41 | public Long getId() {
42 | return id;
43 | }
44 |
45 | public void setId(Long id) {
46 | this.id = id;
47 | }
48 |
49 | public String getModule() {
50 | return module;
51 | }
52 |
53 | public void setModule(String module) {
54 | this.module = module;
55 | }
56 |
57 | public String getMapper() {
58 | return mapper;
59 | }
60 |
61 | public void setMapper(String mapper) {
62 | this.mapper = mapper;
63 | }
64 |
65 | public String getName() {
66 | return name;
67 | }
68 |
69 | public void setName(String name) {
70 | this.name = name;
71 | }
72 |
73 | public LocalDateTime getCreate_time() {
74 | return create_time;
75 | }
76 |
77 | public void setCreate_time(LocalDateTime create_time) {
78 | this.create_time = create_time;
79 | }
80 |
81 | public String getCreate_by() {
82 | return create_by;
83 | }
84 |
85 | public void setCreate_by(String create_by) {
86 | this.create_by = create_by;
87 | }
88 |
89 | public LocalDateTime getUpdate_time() {
90 | return update_time;
91 | }
92 |
93 | public void setUpdate_time(LocalDateTime update_time) {
94 | this.update_time = update_time;
95 | }
96 |
97 | public String getUpdate_by() {
98 | return update_by;
99 | }
100 |
101 | public void setUpdate_by(String update_by) {
102 | this.update_by = update_by;
103 | }
104 |
105 | public Integer getVersion() {
106 | return version;
107 | }
108 |
109 | public void setVersion(Integer version) {
110 | this.version = version;
111 | }
112 |
113 | public Integer getDr() {
114 | return dr;
115 | }
116 |
117 | public void setDr(Integer dr) {
118 | this.dr = dr;
119 | }
120 |
121 | public Integer getEnable() {
122 | return enable;
123 | }
124 |
125 | public void setEnable(Integer enable) {
126 | this.enable = enable;
127 | }
128 |
129 | public List getFields() {
130 | return fields;
131 | }
132 |
133 | public void setFields(List fields) {
134 | this.fields = fields;
135 | }
136 | }
137 |
--------------------------------------------------------------------------------
/data-authority-maven/src/main/java/com/github/data/authority/row/DatalimitMetaRowField.java:
--------------------------------------------------------------------------------
1 | package com.github.data.authority.row;
2 |
3 | import java.time.LocalDateTime;
4 |
5 | /**
6 | * @author chenzhh
7 | */
8 | public class DatalimitMetaRowField {
9 | private Long id;
10 | private String tableColumn;
11 | private String tableName;
12 | private String fieldName;
13 | private String name;
14 | private String metaId;
15 | private LocalDateTime create_time;
16 | private String create_by;
17 | private LocalDateTime update_time;
18 | private String update_by;
19 | private Integer version;
20 | private Integer dr;
21 | private Integer enable;
22 |
23 | public Long getId() {
24 | return id;
25 | }
26 |
27 | public void setId(Long id) {
28 | this.id = id;
29 | }
30 |
31 | public String getTableColumn() {
32 | return tableColumn;
33 | }
34 |
35 | public void setTableColumn(String tableColumn) {
36 | this.tableColumn = tableColumn;
37 | }
38 |
39 | public String getTableName() {
40 | return tableName;
41 | }
42 |
43 | public void setTableName(String tableName) {
44 | this.tableName = tableName;
45 | }
46 |
47 | public String getFieldName() {
48 | return fieldName;
49 | }
50 |
51 | public void setFieldName(String fieldName) {
52 | this.fieldName = fieldName;
53 | }
54 |
55 | public String getName() {
56 | return name;
57 | }
58 |
59 | public void setName(String name) {
60 | this.name = name;
61 | }
62 |
63 | public String getMetaId() {
64 | return metaId;
65 | }
66 |
67 | public void setMetaId(String metaId) {
68 | this.metaId = metaId;
69 | }
70 |
71 | public LocalDateTime getCreate_time() {
72 | return create_time;
73 | }
74 |
75 | public void setCreate_time(LocalDateTime create_time) {
76 | this.create_time = create_time;
77 | }
78 |
79 | public String getCreate_by() {
80 | return create_by;
81 | }
82 |
83 | public void setCreate_by(String create_by) {
84 | this.create_by = create_by;
85 | }
86 |
87 | public LocalDateTime getUpdate_time() {
88 | return update_time;
89 | }
90 |
91 | public void setUpdate_time(LocalDateTime update_time) {
92 | this.update_time = update_time;
93 | }
94 |
95 | public String getUpdate_by() {
96 | return update_by;
97 | }
98 |
99 | public void setUpdate_by(String update_by) {
100 | this.update_by = update_by;
101 | }
102 |
103 | public Integer getVersion() {
104 | return version;
105 | }
106 |
107 | public void setVersion(Integer version) {
108 | this.version = version;
109 | }
110 |
111 | public Integer getDr() {
112 | return dr;
113 | }
114 |
115 | public void setDr(Integer dr) {
116 | this.dr = dr;
117 | }
118 |
119 | public Integer getEnable() {
120 | return enable;
121 | }
122 |
123 | public void setEnable(Integer enable) {
124 | this.enable = enable;
125 | }
126 |
127 | @Override public String toString() {
128 | return "DatalimitMetaRowField{" +
129 | "id=" + id +
130 | ", tableColumn='" + tableColumn + '\'' +
131 | ", tableName='" + tableName + '\'' +
132 | ", fieldName='" + fieldName + '\'' +
133 | ", name='" + name + '\'' +
134 | ", metaId='" + metaId + '\'' +
135 | ", create_time=" + create_time +
136 | ", create_by='" + create_by + '\'' +
137 | ", update_time=" + update_time +
138 | ", update_by='" + update_by + '\'' +
139 | ", version=" + version +
140 | ", dr=" + dr +
141 | ", enable=" + enable +
142 | '}';
143 | }
144 | }
145 |
--------------------------------------------------------------------------------
/data-authority-maven/src/main/java/com/github/data/authority/util/ClassLoaderUtil.java:
--------------------------------------------------------------------------------
1 | package com.github.data.authority.util;
2 |
3 | import com.google.common.collect.Sets;
4 | import java.io.File;
5 | import java.net.MalformedURLException;
6 | import java.net.URL;
7 | import java.net.URLClassLoader;
8 | import java.util.Objects;
9 | import java.util.Set;
10 | import org.apache.maven.plugin.logging.Log;
11 | import org.springframework.util.ClassUtils;
12 |
13 | /**
14 | * @author chenzhh
15 | */
16 | public class ClassLoaderUtil {
17 | /**
18 | * @param compileClasspaths
19 | * @param log
20 | * @return
21 | */
22 | public static URLClassLoader addURLClassLoader(Set compileClasspaths, Log log) {
23 | Set urls = Sets.newHashSet();
24 | try {
25 | for (String classpath : compileClasspaths) {
26 | urls.add(new File(classpath).toURI().toURL());
27 | }
28 | } catch (MalformedURLException e) {
29 | log.warn("加载url异常", e);
30 | e.printStackTrace();
31 | }
32 | URLClassLoader classLoader = new URLClassLoader(urls.toArray(new URL[] {}), ClassUtils.getDefaultClassLoader());
33 | Objects.requireNonNull(classLoader, "获取类加载器失败");
34 | return classLoader;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/data-authority-maven/src/main/java/com/github/data/authority/util/ClassUtil.java:
--------------------------------------------------------------------------------
1 | package com.github.data.authority.util;
2 |
3 | import com.google.common.collect.Lists;
4 | import java.io.File;
5 | import java.net.URLClassLoader;
6 | import java.util.List;
7 | import java.util.Objects;
8 | import java.util.Set;
9 | import java.util.stream.Collectors;
10 | import org.apache.maven.plugin.logging.Log;
11 | import org.springframework.util.ClassUtils;
12 | import org.springframework.util.CollectionUtils;
13 |
14 | /**
15 | * 处理calss
16 | *
17 | * @author chenzhh
18 | */
19 | public final class ClassUtil {
20 | /**
21 | *
22 | * @param classpathElements
23 | * @param log
24 | * @return
25 | */
26 | public static List> getClassAll(Set classpathElements,String packages, Log log){
27 | URLClassLoader urlClassLoader = ClassLoaderUtil.addURLClassLoader(classpathElements, log);
28 | Objects.requireNonNull(urlClassLoader,"类加载器失败");
29 | return getClassAll(classpathElements,urlClassLoader,packages,log);
30 | }
31 | /**
32 | * @param classpathElements
33 | * @param classLoader
34 | * @param log
35 | * @return
36 | */
37 | private static List> getClassAll(Set classpathElements,
38 | ClassLoader classLoader,String packages, Log log) {
39 | List> clazzs = Lists.newArrayList();
40 | List> classes = classpathElements.stream().filter(classpath -> {
41 | return new File(classpath).isDirectory();
42 | }).flatMap((classpath) -> {
43 | return getClass(clazzs,new File(classpath), classLoader, log).stream();
44 | }).collect(Collectors.toList());
45 | Set> classSet = ScanJarClassUtil.getScanJarClass(classpathElements, classLoader,packages, log);
46 | if (!CollectionUtils.isEmpty(classSet)) {
47 | clazzs.addAll(classSet);
48 | }
49 | return clazzs;
50 | }
51 |
52 | /**
53 | * @param file
54 | * @param classLoader
55 | * @param log
56 | * @return
57 | */
58 | private static List> getClass(List> clazzs,File file, ClassLoader classLoader, Log log) {
59 | //递归
60 | if (Objects.nonNull(file) && file.exists() && file.isDirectory()) {
61 | File[] files = file.listFiles();
62 | if (Objects.nonNull(files) && files.length > 0) {
63 | for (File f : files) {
64 | if (f.isDirectory()) {
65 | getClass(clazzs,f, classLoader, log);
66 | } else if (f.isFile() && f.getName().endsWith(".class")) {
67 | String absolutePath = f.getAbsolutePath();
68 | absolutePath = absolutePath.substring(absolutePath.indexOf("classes") + 8, absolutePath.length() - ".class".length());
69 | absolutePath = absolutePath.replaceAll("[/|\\\\]", ".");
70 | try {
71 | clazzs.add(classLoader.loadClass(absolutePath));
72 | } catch (ClassNotFoundException e) {
73 | log.info("加载类异常" + f.getAbsolutePath(), e);
74 | throw new RuntimeException("加载类异常", e);
75 | }
76 | }
77 | }
78 | }
79 | }
80 | return clazzs;
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/data-authority-maven/src/main/java/com/github/data/authority/util/ReflectionUtil.java:
--------------------------------------------------------------------------------
1 | package com.github.data.authority.util;
2 |
3 | import com.google.common.collect.Lists;
4 | import java.lang.reflect.Field;
5 | import java.lang.reflect.Modifier;
6 | import java.lang.reflect.ParameterizedType;
7 | import java.lang.reflect.Type;
8 | import java.util.List;
9 | import java.util.Map;
10 | import java.util.Objects;
11 | import java.util.Set;
12 |
13 | /**
14 | * 反射获取所有字段
15 | *
16 | * @author chenzhh
17 | */
18 | public final class ReflectionUtil {
19 | /**
20 | * @param clazz
21 | * @return
22 | */
23 | public final static List fieldList(Class> clazz) {
24 | List list = Lists.newArrayList();
25 | while (Objects.nonNull(clazz)) {
26 | list.addAll(Lists.newArrayList(clazz.getDeclaredFields()));
27 | clazz = clazz.getSuperclass();
28 | }
29 | list.removeIf(field -> Modifier.isStatic(field.getModifiers()));
30 | return list;
31 | }
32 |
33 | /**
34 | * @param clazz
35 | * @return
36 | */
37 | public final static void field(String prefix, Set result, Class> clazz) {
38 | List fields = ReflectionUtil.fieldList(clazz);
39 | if (!org.springframework.util.CollectionUtils.isEmpty(fields)) {
40 | for (Field field : fields) {
41 | if (SimpleTypeRegistryUtil.isSimpleType(field.getType())) {
42 | if (Objects.nonNull(prefix)) {
43 | result.add(prefix + "." + field.getName());
44 | } else {
45 | result.add(field.getName());
46 | }
47 | } else if (field.getType() == List.class || field.getType() == Map.class || field.getType() == Set.class) {
48 | Type type = field.getGenericType();
49 | if (type instanceof ParameterizedType) {
50 | Class> parameterizedType = (Class>) ((ParameterizedType) type).getActualTypeArguments()[0];
51 | if (SimpleTypeRegistryUtil.isSimpleType(parameterizedType)) {
52 | if (Objects.nonNull(prefix)) {
53 | result.add(prefix + "." + field.getName());
54 | }else{
55 | result.add(field.getName());
56 | }
57 |
58 | } else {
59 | if (clazz == parameterizedType) {
60 | List parameterfields = ReflectionUtil.fieldList(parameterizedType);
61 | for (Field parameterfield : parameterfields) {
62 | if (SimpleTypeRegistryUtil.isSimpleType(parameterfield.getType())) {
63 | result.add(field.getName() + "." + parameterfield.getName());
64 | }
65 | }
66 | } else {
67 | if (Objects.nonNull(prefix)) {
68 | field(prefix+"."+field.getName(), result, parameterizedType);
69 | }else{
70 | field(field.getName(), result, parameterizedType);
71 | }
72 |
73 | }
74 | }
75 | }
76 | } else {
77 | if (clazz == field.getType()) {
78 | List parameterfields = ReflectionUtil.fieldList(field.getType());
79 | for (Field parameterfield : parameterfields) {
80 | if (SimpleTypeRegistryUtil.isSimpleType(parameterfield.getType())) {
81 | if (Objects.nonNull(prefix)) {
82 | result.add(prefix+"."+field.getName() + "." + parameterfield.getName());
83 | }else{
84 | result.add(field.getName() + "." + parameterfield.getName());
85 | }
86 |
87 | }
88 | }
89 | } else {
90 | if (Objects.nonNull(prefix)) {
91 | field(prefix+"."+field.getName(), result, field.getType());
92 | }else{
93 | field(field.getName(), result, field.getType());
94 | }
95 |
96 | }
97 |
98 | }
99 | }
100 | }
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/data-authority-maven/src/main/java/com/github/data/authority/util/ScanJarClassUtil.java:
--------------------------------------------------------------------------------
1 | package com.github.data.authority.util;
2 |
3 | import com.google.common.collect.Lists;
4 | import com.google.common.collect.Sets;
5 | import java.io.IOException;
6 | import java.util.Enumeration;
7 | import java.util.List;
8 | import java.util.Set;
9 | import java.util.jar.JarEntry;
10 | import java.util.jar.JarFile;
11 | import org.apache.maven.plugin.logging.Log;
12 |
13 | /**
14 | * 获取jar包的class
15 | *
16 | * @author chenzhh
17 | */
18 | public class ScanJarClassUtil {
19 | /**
20 | * @param compileClasspaths
21 | * @param classLoader
22 | * @param log
23 | * @return
24 | */
25 | public static Set> getScanJarClass(Set compileClasspaths, ClassLoader classLoader,String packages , Log log) {
26 | Set> result = Sets.newHashSet();
27 | List list = Lists.newArrayList(packages);
28 | for (String path : compileClasspaths) {
29 | try {
30 | for(String pack : list){
31 | if (path.contains(pack) && path.endsWith(".jar")) {
32 | JarFile jarFile = new JarFile(path);
33 | Enumeration enumeration = jarFile.entries();
34 | while (enumeration.hasMoreElements()) {
35 | String name = enumeration.nextElement().getName();
36 | if (name.endsWith(".class")) {
37 | String clazz = name.substring(0, name.lastIndexOf(".")).replace("/", ".");
38 | result.add(classLoader.loadClass(clazz));
39 | }
40 | }
41 | }
42 | }
43 | } catch (IOException | ClassNotFoundException e) {
44 | log.info("读取" + path + "jar包的class异常", e);
45 | e.printStackTrace();
46 | }
47 | }
48 | return result;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/data-authority-row/data-authority-row.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/data-authority-row/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | data-authority
7 | com.github.data.authority
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | data-authority-row
13 |
14 |
15 | 8
16 | 8
17 |
18 |
19 |
20 | com.alibaba.fastjson2
21 | fastjson2
22 |
23 |
24 | com.google.guava
25 | guava
26 |
27 |
28 | org.springframework
29 | spring-core
30 |
31 |
32 | com.alibaba
33 | druid-spring-boot-starter
34 |
35 |
36 | org.mybatis.dynamic-sql
37 | mybatis-dynamic-sql
38 |
39 |
40 | org.mybatis.spring.boot
41 | mybatis-spring-boot-starter
42 |
43 |
44 | com.alibaba
45 | transmittable-thread-local
46 |
47 |
48 | data-authority-common
49 | com.github.data.authority
50 |
51 |
52 |
--------------------------------------------------------------------------------
/data-authority-row/src/main/java/com/github/data/authority/parser/DruidParseStatementsFactory.java:
--------------------------------------------------------------------------------
1 | package com.github.data.authority.parser;
2 |
3 | import com.alibaba.druid.DbType;
4 | import com.alibaba.druid.sql.SQLUtils;
5 | import com.alibaba.druid.sql.ast.SQLStatement;
6 | import java.util.List;
7 | import java.util.Map;
8 | import java.util.Objects;
9 |
10 | /**
11 | * @author chenzhh
12 | */
13 | public final class DruidParseStatementsFactory {
14 | /**
15 | * 动态添加条件
16 | *
17 | * @param sql sql语句
18 | * @return
19 | */
20 | public static String parseStatements(String sql, Map> parserColumnInfos) {
21 | List sqlStatements = SQLUtils.parseStatements(sql, DbType.mysql);
22 | if (Objects.isNull(sqlStatements) || sqlStatements.size() == 0) {
23 | return null;
24 | }
25 | for (SQLStatement sqlStatement : sqlStatements) {
26 |
27 | SelectParserVisitor parserVisitor = new SelectParserVisitor(parserColumnInfos);
28 | sqlStatement.accept(parserVisitor);
29 | return sqlStatement.toString();
30 | }
31 | return null;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/data-authority-row/src/main/java/com/github/data/authority/parser/ParserColumnInfo.java:
--------------------------------------------------------------------------------
1 | package com.github.data.authority.parser;
2 |
3 | /**
4 | * 列信息
5 | * @author chenzhh
6 | */
7 | public class ParserColumnInfo {
8 | /**
9 | * 表名
10 | */
11 | private String table;
12 | /**
13 | * 规则字段
14 | */
15 | private String column;
16 |
17 | /**
18 | * 规则字段
19 | */
20 | private String operator;
21 |
22 | public String getTable() {
23 | return table;
24 | }
25 |
26 | public void setTable(String table) {
27 | this.table = table;
28 | }
29 |
30 | public String getColumn() {
31 | return column;
32 | }
33 |
34 | public void setColumn(String column) {
35 | this.column = column;
36 | }
37 |
38 | public String getOperator() {
39 | return operator;
40 | }
41 |
42 | public void setOperator(String operator) {
43 | this.operator = operator;
44 | }
45 |
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/data-authority-row/src/main/java/com/github/data/authority/parser/ParserTableInfo.java:
--------------------------------------------------------------------------------
1 | package com.github.data.authority.parser;
2 |
3 | /**
4 | * 表信息
5 | * @author chenzhh
6 | */
7 | public class ParserTableInfo {
8 | /**
9 | * 表的别名
10 | */
11 | private String alias;
12 | /**
13 | * 表名
14 | */
15 | private String tableName;
16 | /**
17 | * 列名
18 | */
19 | private String columnName;
20 |
21 | public ParserTableInfo(String alias, String tableName) {
22 | this.alias = alias;
23 | this.tableName = tableName;
24 | }
25 |
26 | public String getAlias() {
27 | return alias;
28 | }
29 |
30 | public void setAlias(String alias) {
31 | this.alias = alias;
32 | }
33 |
34 | public String getTableName() {
35 | return tableName;
36 | }
37 |
38 | public void setTableName(String tableName) {
39 | this.tableName = tableName;
40 | }
41 |
42 | public String getColumnName() {
43 | return columnName;
44 | }
45 |
46 | public void setColumnName(String columnName) {
47 | this.columnName = columnName;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/data-authority-row/src/main/java/com/github/data/authority/rule/DataPermission.java:
--------------------------------------------------------------------------------
1 | package com.github.data.authority.rule;
2 |
3 | import com.google.common.collect.Lists;
4 | import com.google.common.collect.Maps;
5 | import java.util.List;
6 | import java.util.Map;
7 |
8 | /**
9 | * 权限信息
10 | *
11 | * @author chenzhh
12 | */
13 | public class DataPermission {
14 | /**
15 | *设置数据权限
16 | */
17 | private Map> dataPermissionRule = Maps.newConcurrentMap();
18 |
19 |
20 | public void setDataPermissionRule(
21 | Map> dataPermissionRule) {
22 | this.dataPermissionRule = dataPermissionRule;
23 | }
24 |
25 | /**
26 | * 根据mapper查询权限
27 | * @param mapperId
28 | * @return
29 | */
30 | public List getDataPermissionRuleByMapperId(String mapperId){
31 | if(dataPermissionRule.containsKey(mapperId)){
32 | return dataPermissionRule.get(mapperId);
33 | }
34 | return Lists.newArrayList();
35 | }
36 |
37 | @Override public String toString() {
38 | return "DataPermission{" +
39 | "dataPermissionRule=" + dataPermissionRule +
40 | '}';
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/data-authority-row/src/main/java/com/github/data/authority/rule/DataPermissionHolder.java:
--------------------------------------------------------------------------------
1 | package com.github.data.authority.rule;
2 |
3 | import com.alibaba.ttl.TransmittableThreadLocal;
4 |
5 | /**
6 | * 当前登录用户信息
7 | * @author chenzhh
8 | */
9 | public final class DataPermissionHolder {
10 | /**
11 | * 获取当前用户信息
12 | */
13 | private static final TransmittableThreadLocal currentUser = new TransmittableThreadLocal();
14 |
15 |
16 | public final static void setCurrentUser(DataPermission dataPermission){
17 | currentUser.set(dataPermission);
18 | }
19 |
20 | public final static DataPermission getCurrentUser(){
21 | return currentUser.get();
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/data-authority-row/src/main/java/com/github/data/authority/rule/DataPermissionRule.java:
--------------------------------------------------------------------------------
1 | package com.github.data.authority.rule;
2 |
3 | /**
4 | * 数据权限规则
5 | *
6 | * @author chenzhh
7 | */
8 | public class DataPermissionRule {
9 | /**
10 | * 表名
11 | */
12 | private String table;
13 | /**
14 | * 规则字段
15 | */
16 | private String column;
17 |
18 | /**
19 | * 规则字段
20 | */
21 | private String operator;
22 | /**
23 | * 规则值
24 | */
25 | private String attribute;
26 |
27 | public String getColumn() {
28 | return column;
29 | }
30 |
31 | public void setColumn(String column) {
32 | this.column = column;
33 | }
34 |
35 | public String getOperator() {
36 | return operator;
37 | }
38 |
39 | public void setOperator(String operator) {
40 | this.operator = operator;
41 | }
42 |
43 | public String getAttribute() {
44 | return attribute;
45 | }
46 |
47 | public void setAttribute(String attribute) {
48 | this.attribute = attribute;
49 | }
50 |
51 | public String getTable() {
52 | return table;
53 | }
54 |
55 | public void setTable(String table) {
56 | this.table = table;
57 | }
58 |
59 | @Override public String toString() {
60 | return "DataPermissionRule{" +
61 | "table='" + table + '\'' +
62 | ", column='" + column + '\'' +
63 | ", operator='" + operator + '\'' +
64 | ", attribute='" + attribute + '\'' +
65 | '}';
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/data-authority-row/src/main/java/com/github/data/authority/rule/ParamFiled.java:
--------------------------------------------------------------------------------
1 | package com.github.data.authority.rule;
2 |
3 | import java.util.Objects;
4 |
5 | /**
6 | * 参数字段
7 | *
8 | * @author chenzhh
9 | */
10 | public class ParamFiled {
11 | /**
12 | * 字段名称
13 | */
14 | private String name;
15 | /**
16 | * 参数长度大于0 标识集合
17 | */
18 | private Object value;
19 |
20 | public String getName() {
21 | return name;
22 | }
23 |
24 | public void setName(String name) {
25 | this.name = name;
26 | }
27 |
28 | public Object getValue() {
29 | return value;
30 | }
31 |
32 |
33 |
34 | public void setValue(Object value) {
35 | this.value = value;
36 | }
37 | @Override public String toString() {
38 | return "ParamFiled{" +
39 | "name='" + name + '\'' +
40 | ", value=" + value +
41 | '}';
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/data-authority-row/src/main/java/com/github/data/authority/sql/MysqlSanitiser.java:
--------------------------------------------------------------------------------
1 | /**
2 | * MOMOSEC Security SDK(MSS)
3 | *
4 | * This file is part of the Open MSS Project
5 | *
6 | * Copyright (c) 2019 - V0ld1ron
7 | *
8 | * The MSS is published by V0ld1ron under the BSD license. You should read and accept the
9 | * LICENSE before you use, modify, and/or redistribute this software.
10 | *
11 | * @author V0ld1ron (projectone .at. immomo.com)
12 | * @created 2019
13 | */
14 | package com.github.data.authority.sql;
15 |
16 | import com.github.data.authority.sql.extra.codecs.Codec;
17 | import com.github.data.authority.sql.extra.codecs.MySQLCodec;
18 |
19 | /**
20 | * @program: java安全编码实践
21 | *
22 | * @description: Mysql数据库sql语句过滤方法
23 | *
24 | * @author: V0ld1ron
25 | *
26 | **/
27 | public class MysqlSanitiser extends SqliSanitiser {
28 | private static MysqlSanitiser instance = null;
29 | Codec mysqlEncoder = null;
30 |
31 | public MysqlSanitiser(){
32 | mysqlEncoder = MySQLCodec.getInstance();
33 | }
34 |
35 | public static MysqlSanitiser getInstance() {
36 | if (null == instance) {
37 | synchronized (MysqlSanitiser.class) {
38 | if (null == instance) {
39 | instance = new MysqlSanitiser();
40 | }
41 | }
42 | }
43 | return instance;
44 | }
45 |
46 | /**
47 | * @Description: 过滤Mysql sql语句中的特殊字符,暂不支持数据库采用gbk编码
48 | * @Param: desc 反序列化的类
49 | * @return: Class 类对象
50 | */
51 | public String mysqlSanitise(String input){
52 | return super.sqlSanitise(mysqlEncoder, input);
53 | }
54 |
55 | /**
56 | * @Description: 过滤表名、列名的特殊字符,暂不支持数据库采用gbk编码
57 | * @Param: codec 数据库类型
58 | * @return: String 过滤后语句
59 | */
60 | public String mysqlSanitise(String input, boolean isColumn){
61 | return super.sqlSanitise(mysqlEncoder, input, isColumn);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/data-authority-row/src/main/java/com/github/data/authority/sql/SqliSanitiser.java:
--------------------------------------------------------------------------------
1 | package com.github.data.authority.sql;
2 |
3 | import com.github.data.authority.sql.extra.codecs.Codec;
4 |
5 | /**
6 | * 防止sql 注入
7 | * @author chenzhh
8 | */
9 | public class SqliSanitiser {
10 | private final static char[] SAFE_SQL_CHAR = {' '};
11 | private final static char[] SAFE_SQL_CHAR_COLUMN = {' ', '_', '$'};
12 |
13 | public SqliSanitiser(){
14 |
15 | }
16 |
17 | /**
18 | * @Description: 过滤sql语句中的特殊字符,暂不支持数据库采用gbk编码
19 | * @Param: desc 反序列化的类
20 | * @return: Class 类对象
21 | */
22 | protected String sqlSanitise(Codec codec, String input) {
23 | if (null == input) {
24 | return null;
25 | }
26 | return codec.encode(SAFE_SQL_CHAR, input);
27 | }
28 |
29 | /**
30 | * @Description: 过滤表名、列名的特殊字符,暂不支持数据库采用gbk编码
31 | * @Param: codec 数据库类型
32 | * @return: String 过滤后语句
33 | */
34 | protected String sqlSanitise(Codec codec, String input, boolean isColumn) {
35 | if (null == input) {
36 | return null;
37 | }
38 | if (isColumn) {
39 | return codec.encode(SAFE_SQL_CHAR_COLUMN, input);
40 | } else {
41 | return codec.encode(SAFE_SQL_CHAR, input);
42 | }
43 | }
44 | }
45 |
46 |
--------------------------------------------------------------------------------
/data-authority-row/src/main/java/com/github/data/authority/sql/extra/codecs/AbstractCharacterCodec.java:
--------------------------------------------------------------------------------
1 | /**
2 | * OWASP Enterprise Security API (ESAPI)
3 | *
4 | * This file is part of the Open Web Application Security Project (OWASP)
5 | * Enterprise Security API (ESAPI) project. For details, please see
6 | * http://www.owasp.org/index.php/ESAPI.
7 | *
8 | * Copyright (c) 2017 - The OWASP Foundation
9 | *
10 | * The ESAPI is published by OWASP under the BSD license. You should read and accept the
11 | * LICENSE before you use, modify, and/or redistribute this software.
12 | *
13 | * @author Matt Seil (mseil .at. owasp.org)
14 | * @created 2017
15 | *
16 | * @author Jeff Williams (jeff.williams .at. aspectsecurity.com) Aspect Security
18 | * @created 2007
19 | */
20 |
21 | package com.github.data.authority.sql.extra.codecs;
22 |
23 | /**
24 | *
25 | * This abstract Impl is broken off from the original {@code Codec} class and
26 | * provides the {@code Character} parsing logic that has been with ESAPI from the beginning.
27 | *
28 | */
29 | public abstract class AbstractCharacterCodec extends AbstractCodec {
30 | /* (non-Javadoc)
31 | * @see org.owasp.esapi.codecs.Codec#decode(java.lang.String)
32 | */
33 | @Override
34 | public String decode(String input) {
35 | StringBuilder sb = new StringBuilder();
36 | PushbackSequence pbs = new PushbackString(input);
37 | while (pbs.hasNext()) {
38 | Character c = decodeCharacter(pbs);
39 | if (c != null) {
40 | sb.append(c);
41 | } else {
42 | sb.append(pbs.next());
43 | }
44 | }
45 | return sb.toString();
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/data-authority-row/src/main/java/com/github/data/authority/sql/extra/codecs/AbstractPushbackSequence.java:
--------------------------------------------------------------------------------
1 | /**
2 | * OWASP Enterprise Security API (ESAPI)
3 | *
4 | * This file is part of the Open Web Application Security Project (OWASP)
5 | * Enterprise Security API (ESAPI) project. For details, please see
6 | * http://www.owasp.org/index.php/ESAPI.
7 | *
8 | * Copyright (c) 2017 - The OWASP Foundation
9 | *
10 | * The ESAPI is published by OWASP under the BSD license. You should read and accept the
11 | * LICENSE before you use, modify, and/or redistribute this software.
12 | *
13 | * @author Matt Seil (mseil .at. owasp.org)
14 | * @created 2017
15 | *
16 | */
17 |
18 | package com.github.data.authority.sql.extra.codecs;
19 |
20 | /**
21 | *
22 | * This Abstract class provides the generic logic for using a {@code PushbackSequence}
23 | * in regards to iterating strings. The final Impl is intended for the user to supply
24 | * a type {@code T} such that the pushback interface can be utilized for sequences
25 | * of type {@code T}. Presently this generic class is limited by the fact that
26 | * @{code input} is a {@code String}.
27 | *
28 | * @author Matt Seil
29 | *
30 | * @param
31 | */
32 | public abstract class AbstractPushbackSequence implements PushbackSequence {
33 | protected String input;
34 | protected T pushback;
35 | protected T temp;
36 | protected int index = 0;
37 | protected int mark = 0;
38 |
39 | public AbstractPushbackSequence(String input) {
40 | this.input = input;
41 | }
42 |
43 | /**
44 | * @param c
45 | */
46 | @Override
47 | public void pushback(T c) {
48 | pushback = c;
49 | }
50 |
51 | /**
52 | * Get the current index of the PushbackString. Typically used in error
53 | * messages.
54 | *
55 | * @return The current index of the PushbackString.
56 | */
57 | @Override
58 | public int index() {
59 | return index;
60 | }
61 |
62 | /**
63 | * @return
64 | */
65 | @Override
66 | public boolean hasNext() {
67 | if (pushback != null) {
68 | return true;
69 | }
70 | if (input == null) {
71 | return false;
72 | }
73 | if (input.length() == 0) {
74 | return false;
75 | }
76 | if (index >= input.length()) {
77 | return false;
78 | }
79 | return true;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/data-authority-row/src/main/java/com/github/data/authority/sql/extra/codecs/Codec.java:
--------------------------------------------------------------------------------
1 | /**
2 | * OWASP Enterprise Security API (ESAPI)
3 | *
4 | * This file is part of the Open Web Application Security Project (OWASP)
5 | * Enterprise Security API (ESAPI) project. For details, please see
6 | * http://www.owasp.org/index.php/ESAPI.
7 | *
8 | * Copyright (c) 2007 - The OWASP Foundation
9 | *
10 | * The ESAPI is published by OWASP under the BSD license. You should read and accept the
11 | * LICENSE before you use, modify, and/or redistribute this software.
12 | *
13 | * @author Jeff Williams Aspect Security
14 | * @created 2007
15 | */
16 | package com.github.data.authority.sql.extra.codecs;
17 |
18 | /**
19 | * The Codec interface defines a set of methods for encoding and decoding application level encoding schemes,
20 | * such as HTML entity encoding and percent encoding (aka URL encoding). Codecs are used in output encoding
21 | * and canonicalization. The design of these codecs allows for character-by-character decoding, which is
22 | * necessary to detect double-encoding and the use of multiple encoding schemes, both of which are techniques
23 | * used by attackers to bypass validation and bury encoded attacks in data.
24 | *
25 | * @author Jeff Williams (jeff.williams .at. aspectsecurity.com) Aspect Security
27 | * @since June 1, 2007
28 | *
29 | * @author Matt Seil (mseil .at. owasp.org)
30 | * @since June 1, 2017
31 | * @see org.owasp.esapi.Encoder
32 | */
33 | public interface Codec {
34 | /**
35 | * Encode a String so that it can be safely used in a specific context.
36 | *
37 | * @param immune
38 | * @param input
39 | * the String to encode
40 | * @return the encoded String
41 | */
42 | public String encode(char[] immune, String input);
43 |
44 | /**
45 | * Default implementation that should be overridden in specific codecs.
46 | *
47 | * @param immune
48 | * array of chars to NOT encode. Use with caution.
49 | * @param c
50 | * the Character to encode
51 | * @return
52 | * the encoded Character
53 | */
54 | public String encodeCharacter( char[] immune, Character c );
55 |
56 | /**
57 | * Default codepoint implementation that should be overridden in specific codecs.
58 | *
59 | * @param immune
60 | * @param codePoint
61 | * the integer to encode
62 | * @return
63 | * the encoded Character
64 | */
65 | public String encodeCharacter( char[] immune, int codePoint );
66 |
67 | /**
68 | * Decode a String that was encoded using the encode method in this Class
69 | *
70 | * @param input
71 | * the String to decode
72 | * @return
73 | * the decoded String
74 | */
75 | public String decode(String input);
76 |
77 | /**
78 | * Returns the decoded version of the next character from the input string and advances the
79 | * current character in the PushbackSequence. If the current character is not encoded, this
80 | * method MUST reset the PushbackString.
81 | *
82 | * @param input the Character to decode
83 | *
84 | * @return the decoded Character
85 | */
86 | public T decodeCharacter( PushbackSequence input );
87 |
88 | /**
89 | * Lookup the hex value of any character that is not alphanumeric.
90 | * @param c The character to lookup.
91 | * @return, return null if alphanumeric or the character code
92 | * in hex.
93 | */
94 | public String getHexForNonAlphanumeric(char c);
95 |
96 | /**
97 | * Lookup the hex value of any character that is not alphanumeric.
98 | * @param c The character to lookup.
99 | * @return, return null if alphanumeric or the character code
100 | * in hex.
101 | */
102 | public String getHexForNonAlphanumeric(int c);
103 |
104 | public String toOctal(char c);
105 |
106 | public String toHex(char c);
107 |
108 | public String toHex(int c);
109 |
110 | /**
111 | * Utility to search a char[] for a specific char.
112 | *
113 | * @param c
114 | * @param array
115 | * @return
116 | */
117 | public boolean containsCharacter( char c, char[] array );
118 |
119 | }
--------------------------------------------------------------------------------
/data-authority-row/src/main/java/com/github/data/authority/sql/extra/codecs/PushBackSequenceImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.data.authority.sql.extra.codecs;
2 |
3 |
4 | /**
5 | * The pushback string is used by Codecs to allow them to push decoded characters back onto a string
6 | * for further decoding. This is necessary to detect double-encoding.
7 | *
8 | * @author Jeff Williams (jeff.williams .at. aspectsecurity.com) Aspect Security
10 | * @since June 1, 2007
11 | * @see org.owasp.esapi.Encoder
12 | */
13 | public class PushBackSequenceImpl extends AbstractPushbackSequence{
14 | /**
15 | * @param input
16 | */
17 | public PushBackSequenceImpl(String input) {
18 | super(input);
19 | }
20 |
21 | /**
22 | * Returns true if the parameter character is a hexidecimal digit 0 through 9, a through f, or A through F.
23 | *
24 | * @param c
25 | * @return
26 | */
27 | public static boolean isHexDigit(Integer c) {
28 | if (c == null) {
29 | return false;
30 | }
31 | Integer ch = Integer.valueOf(c);
32 | return (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F');
33 | }
34 |
35 | /**
36 | * Returns true if the parameter character is an octal digit 0 through 7.
37 | *
38 | * @param c
39 | * @return
40 | */
41 | public static boolean isOctalDigit(Integer c) {
42 | if (c == null) {
43 | return false;
44 | }
45 | Integer ch = Integer.valueOf(c);
46 | return ch >= '0' && ch <= '7';
47 | }
48 |
49 | /**
50 | * @return
51 | */
52 | @Override
53 | public Integer next() {
54 | if (pushback != null) {
55 | Integer save = pushback;
56 | pushback = null;
57 | return save;
58 | }
59 | if (input == null) {
60 | return null;
61 | }
62 | if (input.length() == 0) {
63 | return null;
64 | }
65 | if (index >= input.length()) {
66 | return null;
67 | }
68 | final Integer point = input.codePointAt(index);
69 | index += Character.charCount(point);
70 | return point;
71 | }
72 |
73 | /**
74 | * @return
75 | */
76 | @Override
77 | public Integer nextHex() {
78 | Integer c = next();
79 | if (c == null) {
80 | return null;
81 | }
82 | if (isHexDigit(c)) {
83 | return c;
84 | }
85 | return null;
86 | }
87 |
88 | /**
89 | * @return
90 | */
91 | @Override
92 | public Integer nextOctal() {
93 | Integer c = next();
94 | if (c == null) {
95 | return null;
96 | }
97 | if (isOctalDigit(c)) {
98 | return c;
99 | }
100 | return null;
101 | }
102 |
103 | /**
104 | * Return the next codePoint without affecting the current index.
105 | *
106 | * @return
107 | */
108 | @Override
109 | public Integer peek() {
110 | if (pushback != null) {
111 | return pushback;
112 | }
113 | if (input == null) {
114 | return null;
115 | }
116 | if (input.length() == 0) {
117 | return null;
118 | }
119 | if (index >= input.length()) {
120 | return null;
121 | }
122 | return input.codePointAt(index);
123 | }
124 |
125 | /**
126 | * Test to see if the next codePoint is a particular value without affecting the current index.
127 | *
128 | * @param c
129 | * @return
130 | */
131 | @Override
132 | public boolean peek(Integer c) {
133 | if (pushback != null && pushback.intValue() == c) {
134 | return true;
135 | }
136 | if (input == null) {
137 | return false;
138 | }
139 | if (input.length() == 0) {
140 | return false;
141 | }
142 | if (index >= input.length()) {
143 | return false;
144 | }
145 | return input.codePointAt(index) == c;
146 | }
147 |
148 | /**
149 | *
150 | */
151 | @Override
152 | public void mark() {
153 | temp = pushback;
154 | mark = index;
155 | }
156 |
157 | /**
158 | *
159 | */
160 | @Override
161 | public void reset() {
162 | pushback = temp;
163 | index = mark;
164 | }
165 |
166 | /**
167 | * @return
168 | */
169 | @Override
170 | public String remainder() {
171 | String output = input.substring(index);
172 | if (pushback != null) {
173 | output = pushback + output;
174 | }
175 | return output;
176 | }
177 |
178 | }
179 |
180 |
--------------------------------------------------------------------------------
/data-authority-row/src/main/java/com/github/data/authority/sql/extra/codecs/PushbackSequence.java:
--------------------------------------------------------------------------------
1 | /**
2 | * OWASP Enterprise Security API (ESAPI)
3 | *
4 | * This file is part of the Open Web Application Security Project (OWASP)
5 | * Enterprise Security API (ESAPI) project. For details, please see
6 | * http://www.owasp.org/index.php/ESAPI.
7 | *
8 | * Copyright (c) 2017 - The OWASP Foundation
9 | *
10 | * The ESAPI is published by OWASP under the BSD license. You should read and accept the
11 | * LICENSE before you use, modify, and/or redistribute this software.
12 | *
13 | * @author Matt Seil (mseil .at. owasp.org)
14 | * @created 2017
15 | *
16 | */
17 | package com.github.data.authority.sql.extra.codecs;;
18 |
19 | public interface PushbackSequence {
20 |
21 | /**
22 | * @param c
23 | */
24 | void pushback(T c);
25 |
26 | /**
27 | * Get the current index of the PushbackString. Typically used in error messages.
28 | *
29 | * @return The current index of the PushbackSequence.
30 | */
31 | int index();
32 |
33 | /**
34 | * @return
35 | */
36 | boolean hasNext();
37 |
38 | /**
39 | * @return
40 | */
41 | T next();
42 |
43 | /**
44 | * @return
45 | */
46 | T nextHex();
47 |
48 | /**
49 | * @return
50 | */
51 | T nextOctal();
52 |
53 | /**
54 | * Return the next character without affecting the current index.
55 | *
56 | * @return
57 | */
58 | T peek();
59 |
60 | /**
61 | * Test to see if the next character is a particular value without affecting the current index.
62 | *
63 | * @param c
64 | * @return
65 | */
66 | boolean peek(T c);
67 |
68 | /**
69 | *
70 | */
71 | void mark();
72 |
73 | /**
74 | *
75 | */
76 | void reset();
77 |
78 | /**
79 | * Not at all sure what this method is intended to do. There
80 | * is a line in HTMLEntityCodec that said calling this method
81 | * is a "kludge around PushbackString..."
82 | *
83 | * @return
84 | */
85 | String remainder();
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/data-authority-row/src/main/java/com/github/data/authority/util/PluginUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2011-2022, baomidou (jobob@qq.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.github.data.authority.util;
17 |
18 | import java.lang.reflect.Proxy;
19 | import java.util.ArrayList;
20 | import java.util.Collections;
21 | import java.util.List;
22 | import java.util.Map;
23 | import org.apache.ibatis.executor.Executor;
24 | import org.apache.ibatis.executor.parameter.ParameterHandler;
25 | import org.apache.ibatis.executor.statement.StatementHandler;
26 | import org.apache.ibatis.mapping.BoundSql;
27 | import org.apache.ibatis.mapping.MappedStatement;
28 | import org.apache.ibatis.mapping.ParameterMapping;
29 | import org.apache.ibatis.reflection.MetaObject;
30 | import org.apache.ibatis.reflection.SystemMetaObject;
31 | import org.apache.ibatis.session.Configuration;
32 |
33 | /**
34 | * 插件工具类 参照 mybatis-plus
35 | *
36 | * @author TaoYu , hubin
37 | * @since 2017-06-20
38 | */
39 | public abstract class PluginUtils {
40 | public static final String DELEGATE_BOUNDSQL_SQL = "delegate.boundSql.sql";
41 |
42 | /**
43 | * 获得真正的处理对象,可能多层代理.
44 | */
45 | public static T realTarget(Object target) {
46 | if (Proxy.isProxyClass(target.getClass())) {
47 | MetaObject metaObject = SystemMetaObject.forObject(target);
48 | return realTarget(metaObject.getValue("h.target"));
49 | }
50 | return (T) target;
51 | }
52 |
53 | /**
54 | * 给 BoundSql 设置 additionalParameters
55 | *
56 | * @param boundSql BoundSql
57 | * @param additionalParameters additionalParameters
58 | */
59 | public static void setAdditionalParameter(BoundSql boundSql, Map additionalParameters) {
60 | additionalParameters.forEach(boundSql::setAdditionalParameter);
61 | }
62 |
63 | public static MybatisBoundSql mybatisBoundSql(BoundSql boundSql) {
64 | return new MybatisBoundSql(boundSql);
65 | }
66 |
67 | public static MybatisStatementHandler mybatisStatementHandler(StatementHandler statementHandler) {
68 | statementHandler = realTarget(statementHandler);
69 | MetaObject object = SystemMetaObject.forObject(statementHandler);
70 | return new MybatisStatementHandler(SystemMetaObject.forObject(object.getValue("delegate")));
71 | }
72 |
73 | /**
74 | * {@link org.apache.ibatis.executor.statement.BaseStatementHandler}
75 | */
76 | public static class MybatisStatementHandler {
77 | private final MetaObject statementHandler;
78 |
79 | MybatisStatementHandler(MetaObject statementHandler) {
80 | this.statementHandler = statementHandler;
81 | }
82 |
83 | public ParameterHandler parameterHandler() {
84 | return get("parameterHandler");
85 | }
86 |
87 | public MappedStatement mappedStatement() {
88 | return get("mappedStatement");
89 | }
90 |
91 | public Executor executor() {
92 | return get("executor");
93 | }
94 |
95 | public MybatisBoundSql mybatisBoundSql() {
96 | return new MybatisBoundSql(boundSql());
97 | }
98 |
99 | public BoundSql boundSql() {
100 | return get("boundSql");
101 | }
102 |
103 | public Configuration configuration() {
104 | return get("configuration");
105 | }
106 |
107 | @SuppressWarnings("unchecked")
108 | private T get(String property) {
109 | return (T) statementHandler.getValue(property);
110 | }
111 | }
112 |
113 | /**
114 | * {@link BoundSql}
115 | */
116 | public static class MybatisBoundSql {
117 | private final MetaObject boundSql;
118 | private final BoundSql delegate;
119 |
120 | MybatisBoundSql(BoundSql boundSql) {
121 | this.delegate = boundSql;
122 | this.boundSql = SystemMetaObject.forObject(boundSql);
123 | }
124 |
125 | public String sql() {
126 | return delegate.getSql();
127 | }
128 |
129 | public void sql(String sql) {
130 | boundSql.setValue("sql", sql);
131 | }
132 |
133 | public List parameterMappings() {
134 | List parameterMappings = delegate.getParameterMappings();
135 | return new ArrayList<>(parameterMappings);
136 | }
137 |
138 | public void parameterMappings(List parameterMappings) {
139 | boundSql.setValue("parameterMappings", Collections.unmodifiableList(parameterMappings));
140 | }
141 |
142 | public Object parameterObject() {
143 | return get("parameterObject");
144 | }
145 |
146 | public Map additionalParameters() {
147 | return get("additionalParameters");
148 | }
149 |
150 | private T get(String property) {
151 | return (T) boundSql.getValue(property);
152 | }
153 | }
154 | }
155 |
--------------------------------------------------------------------------------
/data-authority-row/src/main/java/com/github/data/authority/util/ReflectionUtils.java:
--------------------------------------------------------------------------------
1 | package com.github.data.authority.util;
2 |
3 | import com.github.data.authority.rule.ParamFiled;
4 | import com.google.common.collect.Lists;
5 | import java.lang.reflect.Field;
6 | import java.lang.reflect.Method;
7 | import java.util.List;
8 | import java.util.Map;
9 | import java.util.Objects;
10 |
11 | /**
12 | * 反射工具类
13 | *
14 | * @author chenzhh
15 | */
16 | public final class ReflectionUtils {
17 |
18 | private ReflectionUtils() {
19 | }
20 |
21 | /**
22 | * 获取参数值
23 | *
24 | * @param o
25 | * @return
26 | */
27 | public static List getParamFiled(Object o) {
28 | List list = Lists.newArrayList();
29 | if (o instanceof Map) {
30 | Map paramMap = (Map) o;
31 | for (String param : paramMap.keySet()) {
32 | if (!param.startsWith("param")) {
33 | ParamFiled filed = new ParamFiled();
34 | filed.setName(param);
35 | filed.setValue(paramMap.get(param));
36 | list.add(filed);
37 | }
38 | }
39 | } else {
40 | Field[] fields = o.getClass().getDeclaredFields();
41 | for (int i = 0; i < fields.length; i++) {
42 | Object value = getFieldValueByName(fields[i].getName(), o);
43 | if (Objects.nonNull(value) && !"".equals(value) && !"null".equals(value)) {
44 | ParamFiled filed = new ParamFiled();
45 | filed.setName(fields[i].getName());
46 | filed.setValue(value);
47 | list.add(filed);
48 | }
49 |
50 | }
51 | }
52 | return list;
53 | }
54 |
55 | /**
56 | * 根据属性名获取属性值
57 | */
58 | private final static Object getFieldValueByName(String fieldName, Object o) {
59 | try {
60 | String firstLetter = fieldName.substring(0, 1).toUpperCase();
61 | String getter = "get" + firstLetter + fieldName.substring(1);
62 | Method method = o.getClass().getMethod(getter, new Class[] {});
63 | Object value = method.invoke(o, new Object[] {});
64 | return value;
65 | } catch (Exception e) {
66 | return null;
67 | }
68 |
69 | }
70 |
71 | // private final static void paramFiled(Class> clazz, Object value, ParamFiled filed) {
72 | // if (clazz == List.class) {
73 | // List list = (List) value;
74 | // filed.setLen(list.size());
75 | // } else if (clazz == Set.class) {
76 | // Set set = (Set) value;
77 | // filed.setLen(set.size());
78 | // } else if (clazz == Map.class) {
79 | // Map map = (Map) value;
80 | // filed.setLen(map.size());
81 | // } else {
82 | // filed.setLen(0);
83 | // }
84 | // }
85 | }
86 |
--------------------------------------------------------------------------------
/data-authority-row/src/main/java/com/github/data/authority/util/Test.java:
--------------------------------------------------------------------------------
1 | package com.github.data.authority.util;
2 |
3 | import com.github.data.authority.parser.DruidParseStatementsFactory;
4 | import com.github.data.authority.parser.ParserColumnInfo;
5 | import com.google.common.collect.Lists;
6 | import com.google.common.collect.Maps;
7 | import java.util.List;
8 | import java.util.Map;
9 |
10 | public class Test {
11 | static String sql = "select * from test left join test1 on 1 = 1 where name = 'maple';";
12 | static String sql5 = "select * from test a left join test1 b on a.id = b.id where a.name = 'maple';";
13 | static String sql2 = "select * from (select * from test a left join test1 b on 1 = 1 where name = 'maple') x where x" +
14 | ".sex = 'man';";
15 | static String sql3 = "select * from (select * from test a left join test1 b on 1 = 1 and a.is_delete is false where " +
16 | "name = 'maple') x where x.sex = 'man' and x.is_delete is false;";
17 | static String sql4 = "select * from (select * from test a left join test1 b on 1 = 1 and a.is_delete is false where " +
18 | "name = 'maple') x where x.sex = 'man' and x.is_delete is false " +
19 | "union all select * from (select * from test a left join test1 b on 1 = 1 and a.is_delete is false " +
20 | "where name = 'maple') x where x.sex = 'woman' and x.is_delete is false;";
21 |
22 | static String sql6 = "select * from test x where x.sex = 'woman'";
23 | static String sql7 = "select * from test x where x.sex = 'woman' union select * from test x where x.sex = '111'";
24 | static String sql8 = "select * from test x where exists(select id from test1 a where a.id = x.id) and x.id=1";
25 | static String sql9="select * from (select a.approve_no as approveNo,\n" +
26 | " a.id as id,\n" +
27 | " a.create_time as applyTime,\n" +
28 | " a.quota_type as quotaType,\n" +
29 | " a.apply_person as applyPerson,\n" +
30 | " a.remark as remark,\n" +
31 | " a.approve_result as approveResult,\n" +
32 | "\n" +
33 | " a.credit_apply_status as creditApplyStatus,\n" +
34 | " group_concat(d.credit_entity_name) as creditEntityNames\n" +
35 | " from cr_credit_apply as a\n" +
36 | " left join cr_credit_apply_detail d on a.id = d.credit_apply_id\n" +
37 | " \n" +
38 | " group by a.id )as dd order by dd.applyTime desc";
39 |
40 | static String getSql10="select a.approve_no as approveNo,\n" +
41 | " a.id as id,\n" +
42 | " a.create_time as applyTime,\n" +
43 | " a.quota_type as quotaType,\n" +
44 | " a.apply_person as applyPerson,\n" +
45 | " a.remark as remark,\n" +
46 | " a.approve_result as approveResult,\n" +
47 | "\n" +
48 | " a.credit_apply_status as creditApplyStatus,\n" +
49 | " group_concat(d.credit_entity_name) as creditEntityNames\n" +
50 | " from cr_credit_apply as a\n" +
51 | " left join cr_credit_apply_detail d on a.id = d.credit_apply_id\n" +
52 | " \n" +
53 | " group by a.id";
54 | static List list = Lists.newArrayList("1", "2");
55 |
56 | public static void main(String[] args) {
57 | Map> list = Maps.newHashMap();
58 |
59 | List parserColumnInfos = Lists.newArrayList();
60 | ParserColumnInfo parserColumnInfo = new ParserColumnInfo();
61 | parserColumnInfo.setTable("test");
62 | parserColumnInfo.setColumn("organization_id in(?)");
63 | parserColumnInfo.setOperator("0");
64 | parserColumnInfos.add(parserColumnInfo);
65 |
66 | list.put("test", parserColumnInfos);
67 | String result = DruidParseStatementsFactory.parseStatements(sql7, list);
68 | System.out.println(result);
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/data-authority-row/src/main/resources/mybatis.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/data-authority.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 | com.github.data.authority
7 | data-authority
8 | 1.0-SNAPSHOT
9 |
10 | data-authority-maven
11 | data-authority-column
12 | data-authority-common
13 | data-authority-row
14 |
15 | pom
16 |
17 |
18 | 8
19 | 8
20 | 2.4.6
21 | 1.2.9
22 | 2.2.2
23 | 1.4.0
24 | 2.12.6
25 | 1.9.9.1
26 | 2.0.1
27 | 31.1-jre
28 |
29 |
30 |
31 |
32 | com.github.data.authority
33 | data-authority-row
34 | ${project.version}
35 |
36 |
37 | com.github.data.authority
38 | data-authority-column
39 | ${project.version}
40 |
41 |
42 | data-authority-common
43 | com.github.data.authority
44 | ${project.version}
45 |
46 |
47 |
48 | org.springframework.boot
49 | spring-boot-dependencies
50 | ${spring-boot.version}
51 | pom
52 | import
53 |
54 |
55 | com.alibaba
56 | druid-spring-boot-starter
57 | ${druid.version}
58 |
59 |
60 | org.mybatis.dynamic-sql
61 | mybatis-dynamic-sql
62 | ${mybatis-dynamic.version}
63 |
64 |
65 | org.mybatis.spring.boot
66 | mybatis-spring-boot-starter
67 | ${mybatis.version}
68 |
69 |
70 | com.alibaba
71 | transmittable-thread-local
72 | ${transmittable.version}
73 |
74 |
75 | org.aspectj
76 | aspectjweaver
77 | ${aspectjweaver.versin}
78 |
79 |
80 | com.alibaba.fastjson2
81 | fastjson2
82 | ${fastjson2.version}
83 |
84 |
85 | com.google.guava
86 | guava
87 | ${guava.version}
88 |
89 |
90 |
91 |
92 |
93 | org.springframework.boot
94 | spring-boot-autoconfigure
95 |
96 |
97 | org.springframework
98 | spring-web
99 |
100 |
101 | org.springframework
102 | spring-context
103 |
104 |
105 | com.alibaba.fastjson2
106 | fastjson2
107 |
108 |
109 | com.google.guava
110 | guava
111 |
112 |
113 |
--------------------------------------------------------------------------------