初始化
This commit is contained in:
commit
58f358e038
|
@ -0,0 +1,38 @@
|
||||||
|
target/
|
||||||
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
!**/src/main/**/target/
|
||||||
|
!**/src/test/**/target/
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea/modules.xml
|
||||||
|
.idea/jarRepositories.xml
|
||||||
|
.idea/compiler.xml
|
||||||
|
.idea/libraries/
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
|
### Eclipse ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
build/
|
||||||
|
!**/src/main/**/build/
|
||||||
|
!**/src/test/**/build/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
### Mac OS ###
|
||||||
|
.DS_Store
|
|
@ -0,0 +1,8 @@
|
||||||
|
# 默认忽略的文件
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# 基于编辑器的 HTTP 客户端请求
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||||
|
<data-source source="LOCAL" name="hst" uuid="7e37209f-9aa5-451d-ae36-475b21bebef6">
|
||||||
|
<driver-ref>mysql.8</driver-ref>
|
||||||
|
<synchronize>true</synchronize>
|
||||||
|
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
|
||||||
|
<jdbc-url>jdbc:mysql://localhost:3306</jdbc-url>
|
||||||
|
<jdbc-additional-properties>
|
||||||
|
<property name="com.intellij.clouds.kubernetes.db.host.port" />
|
||||||
|
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
|
||||||
|
<property name="com.intellij.clouds.kubernetes.db.container.port" />
|
||||||
|
</jdbc-additional-properties>
|
||||||
|
<working-dir>$ProjectFileDir$</working-dir>
|
||||||
|
</data-source>
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="file://$PROJECT_DIR$/hoe-admin/admin-api/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/hoe-admin/admin-boot/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/hoe-admin/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/hoe-admin/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/hoe-auth/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/hoe-common/common-base/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/hoe-common/common-base/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/hoe-common/common-mybatis-plus/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/hoe-common/common-redis/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/hoe-common/common-redis/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/hoe-common/common-web/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/hoe-common/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/hoe-common/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/hoe-gateway/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/hoe-order/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="MavenProjectsManager">
|
||||||
|
<option name="originalFiles">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/pom.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
<option name="ignoredFiles">
|
||||||
|
<set>
|
||||||
|
<option value="$PROJECT_DIR$/hoe-admin/admin-api/pom.xml" />
|
||||||
|
<option value="$PROJECT_DIR$/hoe-common/common-redis/pom.xml" />
|
||||||
|
</set>
|
||||||
|
</option>
|
||||||
|
<option name="workspaceImportForciblyTurnedOn" value="true" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,87 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="TemplatesSettings">
|
||||||
|
<option name="templateConfigs">
|
||||||
|
<TemplateContext>
|
||||||
|
<option name="generateConfig">
|
||||||
|
<GenerateConfig>
|
||||||
|
<option name="annotationType" value="MYBATIS_PLUS3" />
|
||||||
|
<option name="basePackage" value="generator" />
|
||||||
|
<option name="basePath" value="src/main/java" />
|
||||||
|
<option name="classNameStrategy" value="camel" />
|
||||||
|
<option name="encoding" value="UTF-8" />
|
||||||
|
<option name="extraClassSuffix" value="" />
|
||||||
|
<option name="ignoreFieldPrefix" value="" />
|
||||||
|
<option name="ignoreFieldSuffix" value="" />
|
||||||
|
<option name="ignoreTablePrefix" value="" />
|
||||||
|
<option name="ignoreTableSuffix" value="" />
|
||||||
|
<option name="moduleName" value="hoe-auth" />
|
||||||
|
<option name="modulePath" value="$PROJECT_DIR$" />
|
||||||
|
<option name="moduleUIInfoList">
|
||||||
|
<list>
|
||||||
|
<ModuleInfoGo>
|
||||||
|
<option name="basePath" value="${domain.basePath}" />
|
||||||
|
<option name="configFileName" value="mapperInterface.ftl" />
|
||||||
|
<option name="configName" value="mapperInterface" />
|
||||||
|
<option name="encoding" value="${domain.encoding}" />
|
||||||
|
<option name="fileName" value="${domain.fileName}Mapper" />
|
||||||
|
<option name="fileNameWithSuffix" value="${domain.fileName}Mapper.java" />
|
||||||
|
<option name="modulePath" value="$PROJECT_DIR$" />
|
||||||
|
<option name="packageName" value="${domain.basePackage}.mapper" />
|
||||||
|
</ModuleInfoGo>
|
||||||
|
<ModuleInfoGo>
|
||||||
|
<option name="basePath" value="src/main/resources" />
|
||||||
|
<option name="configFileName" value="mapperXml.ftl" />
|
||||||
|
<option name="configName" value="mapperXml" />
|
||||||
|
<option name="encoding" value="${domain.encoding}" />
|
||||||
|
<option name="fileName" value="${domain.fileName}Mapper" />
|
||||||
|
<option name="fileNameWithSuffix" value="${domain.fileName}Mapper.xml" />
|
||||||
|
<option name="modulePath" value="$PROJECT_DIR$" />
|
||||||
|
<option name="packageName" value="mapper" />
|
||||||
|
</ModuleInfoGo>
|
||||||
|
<ModuleInfoGo>
|
||||||
|
<option name="basePath" value="${domain.basePath}" />
|
||||||
|
<option name="configFileName" value="serviceImpl.ftl" />
|
||||||
|
<option name="configName" value="serviceImpl" />
|
||||||
|
<option name="encoding" value="${domain.encoding}" />
|
||||||
|
<option name="fileName" value="${domain.fileName}ServiceImpl" />
|
||||||
|
<option name="fileNameWithSuffix" value="${domain.fileName}ServiceImpl.java" />
|
||||||
|
<option name="modulePath" value="$PROJECT_DIR$" />
|
||||||
|
<option name="packageName" value="${domain.basePackage}.service.impl" />
|
||||||
|
</ModuleInfoGo>
|
||||||
|
<ModuleInfoGo>
|
||||||
|
<option name="basePath" value="${domain.basePath}" />
|
||||||
|
<option name="configFileName" value="serviceInterface.ftl" />
|
||||||
|
<option name="configName" value="serviceInterface" />
|
||||||
|
<option name="encoding" value="${domain.encoding}" />
|
||||||
|
<option name="fileName" value="${domain.fileName}Service" />
|
||||||
|
<option name="fileNameWithSuffix" value="${domain.fileName}Service.java" />
|
||||||
|
<option name="modulePath" value="$PROJECT_DIR$" />
|
||||||
|
<option name="packageName" value="${domain.basePackage}.service" />
|
||||||
|
</ModuleInfoGo>
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
<option name="needToStringHashcodeEquals" value="true" />
|
||||||
|
<option name="needsComment" value="true" />
|
||||||
|
<option name="needsModel" value="true" />
|
||||||
|
<option name="relativePackage" value="domain" />
|
||||||
|
<option name="superClass" value="" />
|
||||||
|
<option name="tableUIInfoList">
|
||||||
|
<list>
|
||||||
|
<TableUIInfo>
|
||||||
|
<option name="className" value="OauthClientDetails" />
|
||||||
|
<option name="tableName" value="oauth_client_details" />
|
||||||
|
</TableUIInfo>
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
<option name="templatesName" value="mybatis-plus3" />
|
||||||
|
<option name="useLombokPlugin" value="true" />
|
||||||
|
</GenerateConfig>
|
||||||
|
</option>
|
||||||
|
<option name="moduleName" value="hoe-auth" />
|
||||||
|
<option name="projectPath" value="$PROJECT_DIR$" />
|
||||||
|
<option name="templateName" value="mybatis-plus3" />
|
||||||
|
</TemplateContext>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,124 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Palette2">
|
||||||
|
<group name="Swing">
|
||||||
|
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Button" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="RadioButton" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="CheckBox" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Label" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||||
|
<preferred-size width="-1" height="20" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
</group>
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,94 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.recovery</groupId>
|
||||||
|
<artifactId>hoe-admin</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>admin-boot</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<!-- 配置读取 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 单元测试 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Spring Cloud & Alibaba -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 注册中心 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 配置中心 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- JWT库 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.nimbusds</groupId>
|
||||||
|
<artifactId>nimbus-jose-jwt</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.recovery</groupId>
|
||||||
|
<artifactId>common-redis</artifactId>
|
||||||
|
<version>${hoe-version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.recovery</groupId>
|
||||||
|
<artifactId>common-mybatis-plus</artifactId>
|
||||||
|
<version>${hoe-version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.recovery</groupId>
|
||||||
|
<artifactId>common-web</artifactId>
|
||||||
|
<version>${hoe-version}</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- <dependency>-->
|
||||||
|
<!-- <groupId>org.springframework</groupId>-->
|
||||||
|
<!-- <artifactId>spring-webmvc</artifactId>-->
|
||||||
|
<!-- </dependency>-->
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.spotify</groupId>
|
||||||
|
<artifactId>docker-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.recovery.admin.boot;
|
||||||
|
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
@EnableDiscoveryClient
|
||||||
|
@RefreshScope
|
||||||
|
@EnableFeignClients
|
||||||
|
@ComponentScan(basePackages = {"com.recovery.admin.boot","com.recovery.common.base"})
|
||||||
|
@MapperScan("com.recovery.admin.boot.mapper")
|
||||||
|
public class AdminApp {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(AdminApp.class, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,81 @@
|
||||||
|
package com.recovery.admin.boot.aspect;
|
||||||
|
|
||||||
|
|
||||||
|
import com.recovery.common.base.util.HspHostUtil;
|
||||||
|
|
||||||
|
import com.recovery.common.base.utils.RedisUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import com.recovery.common.base.ds.*;
|
||||||
|
|
||||||
|
import org.aspectj.lang.JoinPoint;
|
||||||
|
import org.aspectj.lang.annotation.After;
|
||||||
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
import org.aspectj.lang.annotation.Before;
|
||||||
|
import org.aspectj.lang.annotation.Pointcut;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.core.annotation.Order;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Web层日志切面
|
||||||
|
*
|
||||||
|
* @author RyanWang
|
||||||
|
* @version 1.0.0
|
||||||
|
* @date 16/5/17 上午10:42.
|
||||||
|
*/
|
||||||
|
@Aspect
|
||||||
|
@Order(0)
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class WebLogAspect {
|
||||||
|
@Resource
|
||||||
|
private StringRedisTemplate stringRedisTemplate;
|
||||||
|
//
|
||||||
|
@Pointcut("execution(public * com.recovery.admin.boot.controller..*.*(..)) || execution(public * com.recovery.admin.boot.rest.*.*(..))")
|
||||||
|
public void webLog(){}
|
||||||
|
|
||||||
|
@Before("webLog()")
|
||||||
|
public void doBefore(JoinPoint joinPoint) throws Throwable {
|
||||||
|
|
||||||
|
// 接收到请求,记录请求内容
|
||||||
|
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||||
|
//获取请求的域名
|
||||||
|
HttpServletRequest request = attributes.getRequest();
|
||||||
|
// 根据域名获取网站信息
|
||||||
|
StringBuffer urlBuf = request.getRequestURL();
|
||||||
|
URL url = new URL(urlBuf.toString());
|
||||||
|
String path = url.getPath();
|
||||||
|
HttpServletResponse response = (HttpServletResponse)attributes.getResponse();
|
||||||
|
String hospitalHost = request.getHeader("hospitalHost");
|
||||||
|
// if(StringUtils.isEmpty(hospitalHost)){
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
//切割获取访问目标模块
|
||||||
|
String[] split = path.split("/");
|
||||||
|
String module = split[0];
|
||||||
|
System.out.println(RedisUtils.getDBInfoByHostAndModule(stringRedisTemplate,hospitalHost,"admin"));
|
||||||
|
//根据域名和请求的模块名查询目标数据库
|
||||||
|
HttpSession session = request.getSession();
|
||||||
|
/**
|
||||||
|
* 切换为动态数据源实例
|
||||||
|
*/
|
||||||
|
HspHostUtil.switchDB(hospitalHost,"admin",stringRedisTemplate);
|
||||||
|
|
||||||
|
}
|
||||||
|
//执行完切面后,将线程共享中的数据源名称清空
|
||||||
|
@After("webLog()")
|
||||||
|
public void after(JoinPoint joinPoint){
|
||||||
|
DataSourceContextHolder.clearDBType();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.recovery.admin.boot.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.cors.CorsConfiguration;
|
||||||
|
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||||
|
import org.springframework.web.filter.CorsFilter;
|
||||||
|
|
||||||
|
//跨越请求配置类
|
||||||
|
@Configuration
|
||||||
|
public class CorsConfig {
|
||||||
|
|
||||||
|
private CorsConfiguration buildConfig() {
|
||||||
|
CorsConfiguration corsConfiguration = new CorsConfiguration();
|
||||||
|
// 你需要跨域的地址 注意这里的 127.0.0.1 != localhost
|
||||||
|
// * 表示对所有的地址都可以访问
|
||||||
|
corsConfiguration.addAllowedOrigin("*"); // 1
|
||||||
|
// 跨域的请求头
|
||||||
|
corsConfiguration.addAllowedHeader("*"); // 2
|
||||||
|
// 跨域的请求方法
|
||||||
|
corsConfiguration.addAllowedMethod("*"); // 3
|
||||||
|
//加上了这一句,大致意思是可以携带 cookie
|
||||||
|
//最终的结果是可以 在跨域请求的时候获取同一个 session
|
||||||
|
corsConfiguration.setAllowCredentials(true);
|
||||||
|
return corsConfiguration;
|
||||||
|
}
|
||||||
|
@Bean
|
||||||
|
public CorsFilter corsFilter() {
|
||||||
|
|
||||||
|
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||||
|
//配置 可以访问的地址
|
||||||
|
source.registerCorsConfiguration("/**", buildConfig());
|
||||||
|
return new CorsFilter(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.recovery.admin.boot.config;
|
||||||
|
|
||||||
|
|
||||||
|
import com.recovery.admin.boot.interceptor.JwtInterceptor;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class InterceptConfig implements WebMvcConfigurer {
|
||||||
|
@Override
|
||||||
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
|
//添加拦截器
|
||||||
|
registry.addInterceptor(new JwtInterceptor())
|
||||||
|
//拦截的路径 需要进行token验证的路径
|
||||||
|
.addPathPatterns("/**")
|
||||||
|
//放行的路径
|
||||||
|
.excludePathPatterns("/api/rest/users/getUserByUsername")
|
||||||
|
.excludePathPatterns("/api/user/sendMsg")
|
||||||
|
.excludePathPatterns("/api/user/loginPhone")
|
||||||
|
//放行swagger 测试验证
|
||||||
|
.excludePathPatterns("/api/user/get");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,96 @@
|
||||||
|
package com.recovery.admin.boot.config.ds;
|
||||||
|
|
||||||
|
import com.alibaba.druid.pool.DruidDataSource;
|
||||||
|
|
||||||
|
import com.recovery.common.base.ds.DynamicDataSource;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.ibatis.session.SqlSessionFactory;
|
||||||
|
import org.mybatis.spring.SqlSessionFactoryBean;
|
||||||
|
import org.mybatis.spring.SqlSessionTemplate;
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Primary;
|
||||||
|
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||||
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by YHYR on 2017-12-25
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Configuration
|
||||||
|
@MapperScan(basePackages = DataSourceConfig.PACKAGE, sqlSessionFactoryRef = "commonSqlSessionFactory")
|
||||||
|
public class DataSourceConfig {
|
||||||
|
|
||||||
|
// 精确到模块目录,以便跟其他数据源隔离
|
||||||
|
static final String PACKAGE = "com.recovery.admin.boot.mapper";
|
||||||
|
static final String MAPPER_LOCATION = "classpath:mapper/*.xml";
|
||||||
|
|
||||||
|
@Value("${master.datasource.url}")
|
||||||
|
private String masterDBUrl;
|
||||||
|
|
||||||
|
@Value("${master.datasource.username}")
|
||||||
|
private String masterDBUser;
|
||||||
|
|
||||||
|
@Value("${master.datasource.password}")
|
||||||
|
private String masterDBPassword;
|
||||||
|
|
||||||
|
@Value("${master.datasource.driverClassName}")
|
||||||
|
private String masterDBDreiverName;
|
||||||
|
|
||||||
|
|
||||||
|
@Bean(name = "commonDataSource")
|
||||||
|
@Primary
|
||||||
|
public DynamicDataSource dynamicDataSource(){
|
||||||
|
DynamicDataSource dynamicDataSource = DynamicDataSource.getInstance();
|
||||||
|
|
||||||
|
DruidDataSource masterDataSource = new DruidDataSource();
|
||||||
|
try {
|
||||||
|
masterDataSource.setUrl(masterDBUrl);
|
||||||
|
masterDataSource.setUsername(masterDBUser);
|
||||||
|
masterDataSource.setPassword(masterDBPassword);
|
||||||
|
masterDataSource.setDriverClassName(masterDBDreiverName);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<Object,Object> map = new HashMap<>();
|
||||||
|
map.put("master", masterDataSource);
|
||||||
|
dynamicDataSource.setTargetDataSources(map);
|
||||||
|
|
||||||
|
return dynamicDataSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = "commonSqlSessionFactory")
|
||||||
|
@Primary
|
||||||
|
public SqlSessionFactory sqlSessionFactory(
|
||||||
|
@Qualifier("commonDataSource") DataSource dynamicDataSource)
|
||||||
|
throws Exception {
|
||||||
|
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
|
||||||
|
bean.setDataSource(dynamicDataSource);
|
||||||
|
bean.setMapperLocations(new PathMatchingResourcePatternResolver()
|
||||||
|
.getResources(DataSourceConfig.MAPPER_LOCATION));
|
||||||
|
return bean.getObject();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = "commonTransactionManager")
|
||||||
|
@Primary
|
||||||
|
public DataSourceTransactionManager commonTransactionManager() {
|
||||||
|
return new DataSourceTransactionManager(dynamicDataSource());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Bean(name = "commonSqlSessionTemplate")
|
||||||
|
public SqlSessionTemplate sqlSessionTemplate(
|
||||||
|
@Qualifier("commonSqlSessionFactory") SqlSessionFactory sqlSessionFactory)
|
||||||
|
throws Exception {
|
||||||
|
return new SqlSessionTemplate(sqlSessionFactory);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
package com.recovery.admin.boot.config.ds;
|
||||||
|
|
||||||
|
import com.alibaba.druid.pool.DruidDataSource;
|
||||||
|
import org.apache.ibatis.session.SqlSessionFactory;
|
||||||
|
import org.mybatis.spring.SqlSessionFactoryBean;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||||
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
//@Configuration
|
||||||
|
//// 扫描 Mapper 接口并容器管理
|
||||||
|
//@MapperScan(basePackages = TeachingDataSourceConfig.PACKAGE, sqlSessionFactoryRef = "teachingSqlSessionFactory")
|
||||||
|
public class TeachingDataSourceConfig {
|
||||||
|
// 精确到 course 目录,以便跟其他数据源隔离
|
||||||
|
static final String PACKAGE = "com.recovery.admin.boot.mapper";
|
||||||
|
static final String MAPPER_LOCATION = "classpath:mapper/*.xml";
|
||||||
|
|
||||||
|
@Value("${admin.datasource.url}")
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
@Value("${admin.datasource.username}")
|
||||||
|
private String user;
|
||||||
|
|
||||||
|
@Value("${admin.datasource.password}")
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
@Value("${admin.datasource.driverClassName}")
|
||||||
|
private String driverClass;
|
||||||
|
|
||||||
|
@Bean(name = "adminDataSource")
|
||||||
|
public DataSource cpdDataSource() {
|
||||||
|
DruidDataSource dataSource = new DruidDataSource();
|
||||||
|
dataSource.setDriverClassName(driverClass);
|
||||||
|
dataSource.setUrl(url);
|
||||||
|
dataSource.setUsername(user);
|
||||||
|
dataSource.setPassword(password);
|
||||||
|
return dataSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = "adminTransactionManager")
|
||||||
|
public DataSourceTransactionManager courseTransactionManager() {
|
||||||
|
return new DataSourceTransactionManager(cpdDataSource());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = "adminSqlSessionFactory")
|
||||||
|
public SqlSessionFactory cpdSqlSessionFactory(@Qualifier("adminDataSource") DataSource cpdDataSource)
|
||||||
|
throws Exception {
|
||||||
|
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
|
||||||
|
sessionFactory.setDataSource(cpdDataSource);
|
||||||
|
sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver()
|
||||||
|
.getResources(TeachingDataSourceConfig.MAPPER_LOCATION));
|
||||||
|
return sessionFactory.getObject();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.recovery.admin.boot.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.lang.Assert;
|
||||||
|
|
||||||
|
import com.recovery.admin.boot.entity.SysOauthClient;
|
||||||
|
import com.recovery.admin.boot.service.ISysOauthClientService;
|
||||||
|
|
||||||
|
import com.recovery.common.base.dto.OAuth2ClientDTO;
|
||||||
|
import com.recovery.common.base.result.ApiResult;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
@RequestMapping("/api/oauth-clients")
|
||||||
|
@Slf4j
|
||||||
|
@AllArgsConstructor
|
||||||
|
@RestController
|
||||||
|
public class OauthClientController {
|
||||||
|
private ISysOauthClientService iSysOauthClientService;
|
||||||
|
|
||||||
|
@GetMapping("/getOAuth2ClientById")
|
||||||
|
public ApiResult<OAuth2ClientDTO> getOAuth2ClientById(@RequestParam String clientId) {
|
||||||
|
SysOauthClient client = iSysOauthClientService.getById(clientId);
|
||||||
|
Assert.notNull(client, "OAuth2 客户端不存在");
|
||||||
|
OAuth2ClientDTO oAuth2ClientDTO = new OAuth2ClientDTO();
|
||||||
|
BeanUtil.copyProperties(client, oAuth2ClientDTO);
|
||||||
|
return ApiResult.ok(oAuth2ClientDTO);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
package com.recovery.admin.boot.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import com.recovery.admin.boot.service.IMemberUserService;
|
||||||
|
import com.recovery.admin.boot.service.ISysUserService;
|
||||||
|
|
||||||
|
import com.recovery.common.base.dto.MemberUserAuthDTO;
|
||||||
|
import com.recovery.common.base.dto.UserAuthDTO;
|
||||||
|
import com.recovery.common.base.enums.PasswordEncoderTypeEnum;
|
||||||
|
import com.recovery.common.base.result.ApiResult;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/v1/users")
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class UserController {
|
||||||
|
|
||||||
|
private final ISysUserService iSysUserService;
|
||||||
|
|
||||||
|
private final IMemberUserService memberUserService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户信息
|
||||||
|
*/
|
||||||
|
@GetMapping("/username")
|
||||||
|
public ApiResult<UserAuthDTO> getUserByUsername(@RequestParam String username) {
|
||||||
|
UserAuthDTO user = iSysUserService.getByUsername(username);
|
||||||
|
return ApiResult.ok(user);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取会员用户信息
|
||||||
|
*/
|
||||||
|
@GetMapping("/member/username/{username}")
|
||||||
|
public ApiResult<MemberUserAuthDTO> getMemberUserByUsername(@PathVariable String username) {
|
||||||
|
log.info("获取member user info。。。");
|
||||||
|
MemberUserAuthDTO user = memberUserService.getByUsername(username);
|
||||||
|
return ApiResult.ok(user);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
package com.recovery.admin.boot.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import com.recovery.admin.boot.service.ISysUserService;
|
||||||
|
import com.recovery.common.base.dto.UserAuthDTO;
|
||||||
|
import com.recovery.common.base.result.ApiResult;
|
||||||
|
import com.recovery.common.base.util.HspHostUtil;
|
||||||
|
import com.recovery.common.base.util.RedisUtil;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/v1/test")
|
||||||
|
@Slf4j
|
||||||
|
public class testController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
ISysUserService iSysUserService;
|
||||||
|
@Resource
|
||||||
|
RedisUtil redisUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cs
|
||||||
|
*/
|
||||||
|
@GetMapping("/cs")
|
||||||
|
public ApiResult<UserAuthDTO> cs(@RequestParam String name, HttpServletRequest request) {
|
||||||
|
UserAuthDTO authDTO = iSysUserService.getByUsername(name);
|
||||||
|
log.info("测试库:"+authDTO.getStatus());
|
||||||
|
log.info(redisUtil.get("123").toString());
|
||||||
|
return ApiResult.ok(authDTO);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
package com.recovery.admin.boot.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class MemberUser {
|
||||||
|
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
private String nickname;
|
||||||
|
|
||||||
|
private String mobile;
|
||||||
|
|
||||||
|
private Integer gender;
|
||||||
|
|
||||||
|
private String avatar;
|
||||||
|
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
@TableLogic(value = "0", delval = "1")
|
||||||
|
private Integer deleted;
|
||||||
|
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<Long> roleIds;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String roleNames;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<String> roles;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
package com.recovery.admin.boot.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class SysOauthClient {
|
||||||
|
|
||||||
|
@TableId(type = IdType.INPUT)
|
||||||
|
/**
|
||||||
|
* 客户端ID
|
||||||
|
*/
|
||||||
|
private String clientId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客户端密钥
|
||||||
|
*/
|
||||||
|
private String clientSecret;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 资源id列表
|
||||||
|
*/
|
||||||
|
private String resourceIds;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 资源id列表
|
||||||
|
*/
|
||||||
|
private String scope;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 资源id列表
|
||||||
|
*/
|
||||||
|
private String authorizedGrantTypes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 回调地址
|
||||||
|
*/
|
||||||
|
private String webServerRedirectUri;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 权限列表
|
||||||
|
*/
|
||||||
|
private String authorities;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 认证令牌时效
|
||||||
|
*/
|
||||||
|
private Integer accessTokenValidity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 刷新认证令牌时效
|
||||||
|
*/
|
||||||
|
private Integer refreshTokenValidity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扩展信息
|
||||||
|
*/
|
||||||
|
private String additionalInformation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否自动放行
|
||||||
|
*/
|
||||||
|
private String autoapprove;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.recovery.admin.boot.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class SysPermission {
|
||||||
|
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private Long menuId;
|
||||||
|
|
||||||
|
private String urlPerm;
|
||||||
|
|
||||||
|
// 有权限的角色编号集合
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<String> roles;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
package com.recovery.admin.boot.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class User {
|
||||||
|
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
private String nickname;
|
||||||
|
|
||||||
|
private String mobile;
|
||||||
|
|
||||||
|
private Integer gender;
|
||||||
|
|
||||||
|
private String avatar;
|
||||||
|
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
@TableLogic(value = "0", delval = "1")
|
||||||
|
private Integer deleted;
|
||||||
|
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<Long> roleIds;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String roleNames;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<String> roles;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.recovery.admin.boot.exception;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import com.recovery.common.base.result.IResultCode;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义异常类
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class BusinessException extends RuntimeException{
|
||||||
|
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
private String msg;
|
||||||
|
|
||||||
|
|
||||||
|
public BusinessException(IResultCode apiCode) {
|
||||||
|
super(apiCode.getMsg());
|
||||||
|
this.code = apiCode.getCode();
|
||||||
|
this.msg = apiCode.getMsg();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BusinessException(String code, String message) {
|
||||||
|
super(code+":"+message);
|
||||||
|
this.code = code;
|
||||||
|
this.msg = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BusinessException(String message) {
|
||||||
|
super("5001"+":"+message);
|
||||||
|
this.code = "5001";
|
||||||
|
this.msg = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.recovery.admin.boot.exception;
|
||||||
|
|
||||||
|
|
||||||
|
import com.recovery.common.base.result.ApiResult;
|
||||||
|
import com.recovery.common.base.result.ResultCode;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 全局异常处理
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestControllerAdvice
|
||||||
|
public class GlobalExceptionHandler {
|
||||||
|
|
||||||
|
//自定义异常
|
||||||
|
@ExceptionHandler(BusinessException.class)
|
||||||
|
public ApiResult systemExceptionHandler(BusinessException e) {
|
||||||
|
log.error("BusinessException全局异常:{}",e);
|
||||||
|
return ApiResult.failed(e.getCode(), e.getMsg());
|
||||||
|
}
|
||||||
|
|
||||||
|
//系统异常
|
||||||
|
@ExceptionHandler(Exception.class)
|
||||||
|
public ApiResult exceptionHandler(Exception e) {
|
||||||
|
log.error("Exception全局异常:{}",e);
|
||||||
|
return ApiResult.failed(ResultCode.SYSTEM_EXECUTION_ERROR.getCode(), e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
//Security
|
||||||
|
// @ExceptionHandler(value = AccessDeniedException.class)
|
||||||
|
// public void accessDeniedException(AccessDeniedException e) {
|
||||||
|
// throw e;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,133 @@
|
||||||
|
package com.recovery.admin.boot.filter;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
|
||||||
|
import javax.servlet.ReadListener;
|
||||||
|
import javax.servlet.ServletInputStream;
|
||||||
|
import javax.servlet.ServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletRequestWrapper;
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
public class RequestWrapper extends HttpServletRequestWrapper {
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(RequestWrapper.class);
|
||||||
|
private final byte[] body;
|
||||||
|
|
||||||
|
public RequestWrapper(HttpServletRequest request) {
|
||||||
|
super(request);
|
||||||
|
String sessionStream = getBodyString(request);
|
||||||
|
body = sessionStream.getBytes(StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBodyString() {
|
||||||
|
return new String(body, StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @date: 2023/2/6 12:46
|
||||||
|
* @author: zhouzhaodong
|
||||||
|
* @description: 获取请求Body
|
||||||
|
*/
|
||||||
|
public String getBodyString(final ServletRequest request) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
InputStream inputStream = null;
|
||||||
|
BufferedReader reader = null;
|
||||||
|
try {
|
||||||
|
inputStream = cloneInputStream(request.getInputStream());
|
||||||
|
reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
|
||||||
|
String line = "";
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
sb.append(line);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (inputStream != null) {
|
||||||
|
try {
|
||||||
|
inputStream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (reader != null) {
|
||||||
|
try {
|
||||||
|
reader.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 接收到请求,记录请求内容
|
||||||
|
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||||
|
//获取请求的域名
|
||||||
|
HttpServletRequest req = attributes.getRequest();
|
||||||
|
// 根据域名获取网站信息
|
||||||
|
StringBuffer urlBuf = req.getRequestURL();
|
||||||
|
try {
|
||||||
|
logger.info("获取请求地址:" + new URL(urlBuf.toString()).getPath());
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
logger.info("获取body请求参数:" + sb);
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @date: 2023/2/6 12:46
|
||||||
|
* @author: zhouzhaodong
|
||||||
|
* @description: 复制输入流
|
||||||
|
*/
|
||||||
|
public InputStream cloneInputStream(ServletInputStream inputStream) {
|
||||||
|
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int len;
|
||||||
|
try {
|
||||||
|
while ((len = inputStream.read(buffer)) > -1) {
|
||||||
|
byteArrayOutputStream.write(buffer, 0, len);
|
||||||
|
}
|
||||||
|
byteArrayOutputStream.flush();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BufferedReader getReader() {
|
||||||
|
return new BufferedReader(new InputStreamReader(getInputStream()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ServletInputStream getInputStream() {
|
||||||
|
|
||||||
|
final ByteArrayInputStream bais = new ByteArrayInputStream(body);
|
||||||
|
return new ServletInputStream() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int read() {
|
||||||
|
return bais.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isFinished() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isReady() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setReadListener(ReadListener readListener) {
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,85 @@
|
||||||
|
package com.recovery.admin.boot.interceptor;
|
||||||
|
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.auth0.jwt.interfaces.DecodedJWT;
|
||||||
|
|
||||||
|
import com.recovery.admin.boot.exception.BusinessException;
|
||||||
|
import com.recovery.admin.boot.filter.RequestWrapper;
|
||||||
|
import com.recovery.common.base.constant.Constants;
|
||||||
|
import com.recovery.common.base.result.ResultCode;
|
||||||
|
import com.recovery.common.base.utils.JwtUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class JwtInterceptor implements HandlerInterceptor {
|
||||||
|
@Override
|
||||||
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||||
|
HashMap<String, String> map=new HashMap<>();
|
||||||
|
//获取请求参数
|
||||||
|
RequestWrapper requestWrapper = new RequestWrapper(request);
|
||||||
|
//这里getBodyString()方法无参数
|
||||||
|
log.info("RequestBody: {}", requestWrapper.getBodyString());
|
||||||
|
//从http请求头获取token
|
||||||
|
|
||||||
|
String token = requestWrapper.getHeader(Constants.LOGIN_USRE_TOKEN);
|
||||||
|
if (StringUtils.isEmpty(token)) {
|
||||||
|
throw new BusinessException(ResultCode.TOKEN_INVALID_OR_EXPIRED);
|
||||||
|
}
|
||||||
|
//把变量放在request请求域中,仅可以被这次请求,即同一个requerst使用
|
||||||
|
request.setAttribute(Constants.LOGIN_USRE_TOKEN,token);
|
||||||
|
try {
|
||||||
|
//如果验证成功放行请求
|
||||||
|
DecodedJWT verify = JwtUtils.verifyToken(token);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
throw new BusinessException(ResultCode.TOKEN_INVALID_OR_EXPIRED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @date: 2023/2/6 12:46
|
||||||
|
* @author: zhouzhaodong
|
||||||
|
* @description: 访问控制器方法后执行
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
|
||||||
|
log.info(new Date() + "--postHandle:" + request.getRequestURL());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @date: 2023/2/6 12:46
|
||||||
|
* @author: zhouzhaodong
|
||||||
|
* @description: postHandle方法执行完成后执行,一般用于释放资源
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
|
||||||
|
log.info(new Date() + "--afterCompletion:" + request.getRequestURL());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void renderJson(HttpServletResponse response, Object object) {
|
||||||
|
response.reset();
|
||||||
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
||||||
|
response.setHeader("Access-Control-Allow-Methods", "*");
|
||||||
|
response.setHeader("Access-Control-Allow-Headers", "x-requested-with,content-type");
|
||||||
|
response.setContentType("application/json");
|
||||||
|
response.setCharacterEncoding("utf-8");
|
||||||
|
try {
|
||||||
|
response.getWriter().print(JSONObject.toJSONString(object));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.recovery.admin.boot.listener;
|
||||||
|
|
||||||
|
|
||||||
|
import com.recovery.admin.boot.service.ISysPermissionService;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.boot.CommandLineRunner;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class InitResourcePermissionCache implements CommandLineRunner {
|
||||||
|
|
||||||
|
private ISysPermissionService iSysPermissionService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(String... args) {
|
||||||
|
log.info("刷新权限------------------------------");
|
||||||
|
// iSysPermissionService.refreshPermRolesRules();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.recovery.admin.boot.mapper;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.recovery.admin.boot.entity.MemberUser;
|
||||||
|
|
||||||
|
import com.recovery.common.base.dto.MemberUserAuthDTO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface MemberUserMapper extends BaseMapper<MemberUser> {
|
||||||
|
|
||||||
|
MemberUserAuthDTO getByUsername(@Param("userName") String userName);
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.recovery.admin.boot.mapper;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.recovery.admin.boot.entity.SysOauthClient;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface SysOauthClientMapper extends BaseMapper<SysOauthClient> {
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.recovery.admin.boot.mapper;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.recovery.admin.boot.entity.SysPermission;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface SysPermissionMapper extends BaseMapper<SysPermission> {
|
||||||
|
|
||||||
|
List<SysPermission> listPermRoles();
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.recovery.admin.boot.mapper;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.recovery.admin.boot.entity.User;
|
||||||
|
|
||||||
|
import com.recovery.common.base.dto.UserAuthDTO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface UserMapper extends BaseMapper<User> {
|
||||||
|
|
||||||
|
UserAuthDTO getByUsername(@Param("userName") String userName);
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
package com.recovery.admin.boot.rest;
|
||||||
|
|
||||||
|
|
||||||
|
import com.recovery.admin.boot.service.IMemberUserService;
|
||||||
|
import com.recovery.admin.boot.service.ISysUserService;
|
||||||
|
import com.recovery.common.base.dto.MemberUserAuthDTO;
|
||||||
|
import com.recovery.common.base.dto.UserAuthDTO;
|
||||||
|
import com.recovery.common.base.enums.PasswordEncoderTypeEnum;
|
||||||
|
import com.recovery.common.base.result.ApiResult;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/rest/users")
|
||||||
|
@Slf4j
|
||||||
|
public class UserRest {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ISysUserService iSysUserService;
|
||||||
|
@Resource
|
||||||
|
private IMemberUserService memberUserService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户信息
|
||||||
|
*/
|
||||||
|
@GetMapping("/getUserByUsername")
|
||||||
|
public ApiResult<UserAuthDTO> getUserByUsername(@RequestParam String username) {
|
||||||
|
UserAuthDTO user = iSysUserService.getByUsername(username);
|
||||||
|
if (user == null) {
|
||||||
|
throw new RuntimeException();
|
||||||
|
}
|
||||||
|
return ApiResult.ok(user);
|
||||||
|
}
|
||||||
|
/**12
|
||||||
|
* 获取会员用户信息
|
||||||
|
*/
|
||||||
|
@GetMapping("/member/username/{username}")
|
||||||
|
public ApiResult<MemberUserAuthDTO> getMemberUserByUsername(@PathVariable String username) {
|
||||||
|
log.info("获取member user info。。。");
|
||||||
|
MemberUserAuthDTO user = memberUserService.getByUsername(username);
|
||||||
|
return ApiResult.ok(user);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.recovery.admin.boot.service;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.recovery.admin.boot.entity.MemberUser;
|
||||||
|
import com.recovery.common.base.dto.MemberUserAuthDTO;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
public interface IMemberUserService extends IService<MemberUser> {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户名获取认证用户信息,携带角色和密码
|
||||||
|
*
|
||||||
|
* @param username
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
MemberUserAuthDTO getByUsername(String username);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.recovery.admin.boot.service;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.recovery.admin.boot.entity.SysOauthClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
public interface ISysOauthClientService extends IService<SysOauthClient> {
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.recovery.admin.boot.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.recovery.admin.boot.entity.SysPermission;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
public interface ISysPermissionService extends IService<SysPermission> {
|
||||||
|
/**
|
||||||
|
* 刷新Redis缓存中角色菜单的权限规则,角色和菜单信息变更调用
|
||||||
|
*/
|
||||||
|
boolean refreshPermRolesRules();
|
||||||
|
|
||||||
|
List<SysPermission> listPermRoles();
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.recovery.admin.boot.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.recovery.admin.boot.entity.User;
|
||||||
|
import com.recovery.common.base.dto.UserAuthDTO;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
public interface ISysUserService extends IService<User> {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户名获取认证用户信息,携带角色和密码
|
||||||
|
*
|
||||||
|
* @param username
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
UserAuthDTO getByUsername(String username);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.recovery.admin.boot.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.recovery.admin.boot.entity.MemberUser;
|
||||||
|
import com.recovery.admin.boot.mapper.MemberUserMapper;
|
||||||
|
import com.recovery.admin.boot.service.IMemberUserService;
|
||||||
|
|
||||||
|
import com.recovery.common.base.dto.MemberUserAuthDTO;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class MemberUserServiceImpl extends ServiceImpl<MemberUserMapper, MemberUser> implements IMemberUserService {
|
||||||
|
@Override
|
||||||
|
public MemberUserAuthDTO getByUsername(String username) {
|
||||||
|
MemberUserAuthDTO memberUserAuthDTO = this.baseMapper.getByUsername(username);
|
||||||
|
return memberUserAuthDTO;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.recovery.admin.boot.service.impl;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.recovery.admin.boot.entity.SysOauthClient;
|
||||||
|
import com.recovery.admin.boot.mapper.SysOauthClientMapper;
|
||||||
|
import com.recovery.admin.boot.service.ISysOauthClientService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class SysOauthClientServiceImpl extends ServiceImpl<SysOauthClientMapper, SysOauthClient> implements ISysOauthClientService {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
package com.recovery.admin.boot.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.recovery.admin.boot.entity.SysPermission;
|
||||||
|
import com.recovery.admin.boot.mapper.SysPermissionMapper;
|
||||||
|
import com.recovery.admin.boot.service.ISysPermissionService;
|
||||||
|
import com.recovery.common.base.constant.GlobalConstants;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysPermission> implements ISysPermissionService {
|
||||||
|
|
||||||
|
private final RedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean refreshPermRolesRules() {
|
||||||
|
redisTemplate.delete(Arrays.asList(GlobalConstants.URL_PERM_ROLES_KEY));
|
||||||
|
List<SysPermission> permissions = this.listPermRoles();
|
||||||
|
if (CollectionUtil.isNotEmpty(permissions)) {
|
||||||
|
// 初始化URL- 角色规则
|
||||||
|
List<SysPermission> urlPermList = permissions.stream()
|
||||||
|
.filter(item -> StrUtil.isNotBlank(item.getUrlPerm()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (CollectionUtil.isNotEmpty(urlPermList)) {
|
||||||
|
Map<String, List<String>> urlPermRoles = new HashMap<>();
|
||||||
|
urlPermList.stream().forEach(item -> {
|
||||||
|
String perm = item.getUrlPerm();
|
||||||
|
List<String> roles = item.getRoles();
|
||||||
|
urlPermRoles.put(perm, roles);
|
||||||
|
});
|
||||||
|
redisTemplate.opsForHash().putAll(GlobalConstants.URL_PERM_ROLES_KEY, urlPermRoles);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SysPermission> listPermRoles() {
|
||||||
|
return this.baseMapper.listPermRoles();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.recovery.admin.boot.service.impl;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.recovery.admin.boot.entity.User;
|
||||||
|
import com.recovery.admin.boot.mapper.UserMapper;
|
||||||
|
import com.recovery.admin.boot.service.ISysUserService;
|
||||||
|
|
||||||
|
import com.recovery.common.base.dto.UserAuthDTO;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class SysUserServiceImpl extends ServiceImpl<UserMapper, User> implements ISysUserService {
|
||||||
|
@Override
|
||||||
|
public UserAuthDTO getByUsername(String username) {
|
||||||
|
UserAuthDTO userAuthInfo = this.baseMapper.getByUsername(username);
|
||||||
|
return userAuthInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
package com.recovery.admin.boot.util;
|
||||||
|
|
||||||
|
|
||||||
|
import com.recovery.admin.boot.exception.BusinessException;
|
||||||
|
import com.recovery.common.base.constant.Constants;
|
||||||
|
import com.recovery.common.base.dto.UserAuthorityDto;
|
||||||
|
import com.recovery.common.base.result.ResultCode;
|
||||||
|
import com.recovery.common.base.util.RedisUtil;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class UserUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取登录用户信息
|
||||||
|
* @param request
|
||||||
|
* @param redisUtil
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static UserAuthorityDto getLoginUserInfo(HttpServletRequest request, RedisUtil redisUtil){
|
||||||
|
String loginUserToken = (String) request.getHeader(Constants.LOGIN_USRE_TOKEN);
|
||||||
|
Boolean rest = redisUtil.hasKey("userToken:" +loginUserToken);
|
||||||
|
log.info("缓存key:"+"userToken:" +loginUserToken);
|
||||||
|
log.info("缓存中是否有这条用户:"+rest);
|
||||||
|
if (!rest) {
|
||||||
|
throw new BusinessException(ResultCode.TOKEN_INVALID_OR_EXPIRED);
|
||||||
|
}
|
||||||
|
UserAuthorityDto userAuthorityDto = (UserAuthorityDto) redisUtil.get("userToken:" +loginUserToken);
|
||||||
|
return userAuthorityDto;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: hoe-admin
|
||||||
|
main:
|
||||||
|
allow-bean-definition-overriding: true
|
||||||
|
profiles:
|
||||||
|
active: dev
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
# metadata:
|
||||||
|
# serviceGroup: ytChen
|
||||||
|
server-addr: localhost:8848
|
||||||
|
namespace: 11bfd099-10d6-4f2c-b969-58b76e435cce
|
||||||
|
config:
|
||||||
|
server-addr: localhost:8848
|
||||||
|
file-extension: yaml
|
||||||
|
prefix: hoe-admin
|
||||||
|
group: dev
|
||||||
|
namespace: 11bfd099-10d6-4f2c-b969-58b76e435cce
|
||||||
|
server:
|
||||||
|
port: 9002
|
|
@ -0,0 +1,53 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||||
|
<contextName>logback</contextName>
|
||||||
|
<property name="SYS_LOG_DIR" value="logs" />
|
||||||
|
<property name="LOG_FILE" value="demo.log" />
|
||||||
|
<property name="fileLayoutPattern"
|
||||||
|
value="%-20(%d{yyyyMMdd_HH:mm:ss.SSS} [%logger{10}][%thread] [%-4relative])
|
||||||
|
[%X{hostName} %X{requestId} %X{processId} %X{service.timing} ][%level] %msg%n" />
|
||||||
|
<property name="consoleLayoutPattern"
|
||||||
|
value="%-20(%d{yyyyMMdd_HH:mm:ss.SSS} [%logger][%thread] [%-4relative])
|
||||||
|
[%X{hostName} %X{requestId} %X{processId} %X{service.timing} ][%level] %msg%n" />
|
||||||
|
|
||||||
|
<!-- 控制台输出 -->
|
||||||
|
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<layout name="StandardFormat" class="ch.qos.logback.classic.PatternLayout">
|
||||||
|
<pattern>${consoleLayoutPattern}</pattern>
|
||||||
|
</layout>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!--输出到文件-->
|
||||||
|
<appender name="LOG_ROLLING"
|
||||||
|
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<file>${SYS_LOG_DIR}/${LOG_FILE}</file>
|
||||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter"> <!-- 日志过滤器,只记录warn级别日志 ,若要配置其他级别,复制appender,修改level,并在root中配置-->
|
||||||
|
<level>WARN</level>
|
||||||
|
<onMatch>ACCEPT</onMatch>
|
||||||
|
<onMismatch>DENY</onMismatch>
|
||||||
|
</filter>
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<fileNamePattern>${SYS_LOG_DIR}/%d{yyyy-MM-dd}/${LOG_FILE}_%d{yyyy-MM-dd}_%i.zip</fileNamePattern>
|
||||||
|
<timeBasedFileNamingAndTriggeringPolicy
|
||||||
|
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||||
|
<maxFileSize>50MB</maxFileSize>
|
||||||
|
</timeBasedFileNamingAndTriggeringPolicy>
|
||||||
|
</rollingPolicy>
|
||||||
|
<layout>
|
||||||
|
<pattern>${fileLayoutPattern}</pattern>
|
||||||
|
</layout>
|
||||||
|
</appender>
|
||||||
|
<root level="INFO">
|
||||||
|
<appender-ref ref="CONSOLE" /> <!-- 控制台输出 -->
|
||||||
|
<appender-ref ref="LOG_ROLLING" /> <!-- 文件输出 -->
|
||||||
|
</root>
|
||||||
|
<!-- 测试环境+开发环境. 多个使用逗号隔开. -->
|
||||||
|
<springProfile name="test,dev">
|
||||||
|
<logger name="com.recovery.admin.boot.controller" level="INFO" />
|
||||||
|
</springProfile>
|
||||||
|
<!-- 生产环境. -->
|
||||||
|
<springProfile name="prod">
|
||||||
|
<logger name="com.recovery.admin.boot.controller" level="ERROR" />
|
||||||
|
</springProfile>
|
||||||
|
|
||||||
|
</configuration>
|
|
@ -0,0 +1,175 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<!-- 从高到地低 OFF 、 FATAL 、 ERROR 、 WARN 、 INFO 、 DEBUG 、 TRACE 、 ALL -->
|
||||||
|
<!-- 日志输出规则 根据当前ROOT 级别,日志输出时,级别高于root默认的级别时 会输出 -->
|
||||||
|
<!-- 以下 每个配置的 filter 是过滤掉输出文件里面,会出现高级别文件,依然出现低级别的日志信息,通过filter 过滤只记录本级别的日志-->
|
||||||
|
|
||||||
|
|
||||||
|
<!-- 属性描述 scan:性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true scanPeriod:设置监测配置文件是否有修改的时间间隔,如果没有给出时间单位,
|
||||||
|
默认单位是毫秒。当scan为true时,此属性生效。默认的时间间隔为1分钟。
|
||||||
|
debug:当此属性设置为true时,将打印出logback内部日志信息,实时查看logback运行状态。默认值为false。 -->
|
||||||
|
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||||
|
<!-- 定义日志文件 输入位置 -->
|
||||||
|
<springProperty scope="context" name="logPath" source="log.path" defaultValue="logs"/>
|
||||||
|
<property name="log_dir" value="${logPath}/common" />
|
||||||
|
<!-- 日志最大的历史 30天 -->
|
||||||
|
<property name="maxHistory" value="30"/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!-- ConsoleAppender 控制台输出日志 -->
|
||||||
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<withJansi>true</withJansi>
|
||||||
|
<!-- 对日志进行格式化 -->
|
||||||
|
<encoder>
|
||||||
|
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %highlight(%-5level) %cyan(%logger{15}) - %highlight(%msg) %n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- ERROR级别日志 -->
|
||||||
|
<!-- 滚动记录文件,先将日志记录到指定文件,当符合某个条件时,将日志记录到其他文件 RollingFileAppender-->
|
||||||
|
<appender name="ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<!-- 过滤器,只记录WARN级别的日志 -->
|
||||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||||
|
<level>ERROR</level>
|
||||||
|
<onMatch>ACCEPT</onMatch>
|
||||||
|
<onMismatch>DENY</onMismatch>
|
||||||
|
</filter>
|
||||||
|
<!-- 最常用的滚动策略,它根据时间来制定滚动策略.既负责滚动也负责出发滚动 -->
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<!--日志输出位置 可相对、和绝对路径 -->
|
||||||
|
<fileNamePattern>${log_dir}/%d{yyyy-MM-dd}/error-log.log</fileNamePattern>
|
||||||
|
<!-- 可选节点,控制保留的归档文件的最大数量,超出数量就删除旧文件假设设置每个月滚动,且<maxHistory>是6,
|
||||||
|
则只保存最近6个月的文件,删除之前的旧文件。注意,删除旧文件是,那些为了归档而创建的目录也会被删除-->
|
||||||
|
<maxHistory>${maxHistory}</maxHistory>
|
||||||
|
</rollingPolicy>
|
||||||
|
|
||||||
|
<!-- 按照固定窗口模式生成日志文件,当文件大于20MB时,生成新的日志文件。窗口大小是1到3,当保存了3个归档文件后,将覆盖最早的日志。
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
|
||||||
|
<fileNamePattern>${log_dir}/%d{yyyy-MM-dd}/.log.zip</fileNamePattern>
|
||||||
|
<minIndex>1</minIndex>
|
||||||
|
<maxIndex>3</maxIndex>
|
||||||
|
</rollingPolicy> -->
|
||||||
|
<!-- 查看当前活动文件的大小,如果超过指定大小会告知RollingFileAppender 触发当前活动文件滚动
|
||||||
|
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
|
||||||
|
<maxFileSize>5MB</maxFileSize>
|
||||||
|
</triggeringPolicy> -->
|
||||||
|
|
||||||
|
<encoder>
|
||||||
|
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!-- WARN级别日志 appender -->
|
||||||
|
<appender name="WARN" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<!-- 过滤器,只记录WARN级别的日志 -->
|
||||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||||
|
<level>WARN</level>
|
||||||
|
<onMatch>ACCEPT</onMatch>
|
||||||
|
<onMismatch>DENY</onMismatch>
|
||||||
|
</filter>
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<!-- 按天回滚 daily -->
|
||||||
|
<fileNamePattern>${log_dir}/%d{yyyy-MM-dd}/warn-log.log
|
||||||
|
</fileNamePattern>
|
||||||
|
<!-- 日志最大的历史 60天 -->
|
||||||
|
<maxHistory>${maxHistory}</maxHistory>
|
||||||
|
</rollingPolicy>
|
||||||
|
<encoder>
|
||||||
|
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!-- INFO级别日志 appender -->
|
||||||
|
<appender name="INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<!-- 过滤器,只记录INFO级别的日志 -->
|
||||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||||
|
<level>INFO</level>
|
||||||
|
<onMatch>ACCEPT</onMatch>
|
||||||
|
<onMismatch>DENY</onMismatch>
|
||||||
|
</filter>
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<!-- 按天回滚 daily -->
|
||||||
|
<fileNamePattern>${log_dir}/%d{yyyy-MM-dd}/info-log.log
|
||||||
|
</fileNamePattern>
|
||||||
|
<!-- 日志最大的历史 60天 -->
|
||||||
|
<maxHistory>${maxHistory}</maxHistory>
|
||||||
|
</rollingPolicy>
|
||||||
|
<encoder>
|
||||||
|
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!-- DEBUG级别日志 appender -->
|
||||||
|
<appender name="DEBUG" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<!-- 过滤器,只记录DEBUG级别的日志 -->
|
||||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||||
|
<level>DEBUG</level>
|
||||||
|
<onMatch>ACCEPT</onMatch>
|
||||||
|
<onMismatch>DENY</onMismatch>
|
||||||
|
</filter>
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<!-- 按天回滚 daily -->
|
||||||
|
<fileNamePattern>${log_dir}/%d{yyyy-MM-dd}/debug-log.log
|
||||||
|
</fileNamePattern>
|
||||||
|
<!-- 日志最大的历史 60天 -->
|
||||||
|
<maxHistory>${maxHistory}</maxHistory>
|
||||||
|
</rollingPolicy>
|
||||||
|
<encoder>
|
||||||
|
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!-- TRACE级别日志 appender -->
|
||||||
|
<appender name="TRACE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<!-- 过滤器,只记录ERROR级别的日志 -->
|
||||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||||
|
<level>TRACE</level>
|
||||||
|
<onMatch>ACCEPT</onMatch>
|
||||||
|
<onMismatch>DENY</onMismatch>
|
||||||
|
</filter>
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<!-- 按天回滚 daily -->
|
||||||
|
<fileNamePattern>${log_dir}/%d{yyyy-MM-dd}/trace-log.log
|
||||||
|
</fileNamePattern>
|
||||||
|
<!-- 日志最大的历史 60天 -->
|
||||||
|
<maxHistory>${maxHistory}</maxHistory>
|
||||||
|
</rollingPolicy>
|
||||||
|
<encoder>
|
||||||
|
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
|
||||||
|
<logger name="java.sql.PreparedStatement" value="DEBUG" />
|
||||||
|
<logger name="java.sql.Connection" value="DEBUG" />
|
||||||
|
<logger name="java.sql.Statement" value="DEBUG" />
|
||||||
|
<logger name="com.recovery.admin.boot.aspect" value="DEBUG" />
|
||||||
|
|
||||||
|
|
||||||
|
<!-- root级别 DEBUG -->
|
||||||
|
<root level="INFO">
|
||||||
|
<!-- 控制台输出 -->
|
||||||
|
<appender-ref ref="STDOUT" />
|
||||||
|
<!-- 文件输出 -->
|
||||||
|
<appender-ref ref="ERROR" />
|
||||||
|
<appender-ref ref="INFO" />
|
||||||
|
<appender-ref ref="WARN" />
|
||||||
|
<appender-ref ref="DEBUG" />
|
||||||
|
<appender-ref ref="TRACE" />
|
||||||
|
</root>
|
||||||
|
|
||||||
|
</configuration>
|
|
@ -0,0 +1,53 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.recovery.admin.boot.mapper.MemberUserMapper">
|
||||||
|
|
||||||
|
<resultMap id="BaseResultMap" type="com.recovery.admin.boot.entity.MemberUser">
|
||||||
|
<id property="id" column="id" jdbcType="BIGINT"/>
|
||||||
|
<result property="username" column="username" jdbcType="VARCHAR"/>
|
||||||
|
<result property="nickname" column="nickname" jdbcType="VARCHAR"/>
|
||||||
|
<result property="gender" column="gender" jdbcType="BOOLEAN"/>
|
||||||
|
<result property="password" column="password" jdbcType="VARCHAR"/>
|
||||||
|
<result property="avatar" column="avatar" jdbcType="VARCHAR"/>
|
||||||
|
<result property="mobile" column="mobile" jdbcType="VARCHAR"/>
|
||||||
|
<result property="status" column="status" jdbcType="BOOLEAN"/>
|
||||||
|
<result property="email" column="email" jdbcType="VARCHAR"/>
|
||||||
|
<result property="deleted" column="deleted" jdbcType="BOOLEAN"/>
|
||||||
|
<collection property="roles" ofType="string" javaType="list">
|
||||||
|
<result column="roleCode"></result>
|
||||||
|
</collection>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
id
|
||||||
|
,username,nickname,
|
||||||
|
gender,password,dept_id,
|
||||||
|
avatar,mobile,status,
|
||||||
|
email,gmt_create,gmt_modified,
|
||||||
|
deleted
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<resultMap id="MemberUserAuthMap" type="com.recovery.common.base.dto.MemberUserAuthDTO">
|
||||||
|
<id property="userId" column="userId" jdbcType="BIGINT"/>
|
||||||
|
<result property="username" column="username" jdbcType="VARCHAR"/>
|
||||||
|
<result property="password" column="password" jdbcType="VARCHAR"/>
|
||||||
|
<result property="status" column="status" jdbcType="BOOLEAN"/>
|
||||||
|
<collection property="roles" ofType="string" javaType="list">
|
||||||
|
<result column="roleCode"></result>
|
||||||
|
</collection>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<select id="getByUsername" resultMap="MemberUserAuthMap">
|
||||||
|
select t1.id userId, t1.username, t1.nickname, t1.password, t1.status, t3.code roleCode
|
||||||
|
from member_user t1,
|
||||||
|
sys_user_role t2,
|
||||||
|
sys_role t3
|
||||||
|
where t1.username = #{userName}
|
||||||
|
and t1.deleted = 0
|
||||||
|
and t1.id = t2.user_id
|
||||||
|
and t2.role_id = t3.id
|
||||||
|
</select>
|
||||||
|
|
||||||
|
</mapper>
|
|
@ -0,0 +1,35 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.recovery.admin.boot.mapper.SysPermissionMapper">
|
||||||
|
|
||||||
|
<resultMap id="BaseResultMap" type="com.recovery.admin.boot.entity.SysPermission">
|
||||||
|
<id property="id" column="id" jdbcType="BIGINT"/>
|
||||||
|
<result property="name" column="name" jdbcType="VARCHAR"/>
|
||||||
|
<result property="menuId" column="menu_id" jdbcType="BIGINT"/>
|
||||||
|
<result property="urlPerm" column="url_perm" jdbcType="VARCHAR"/>
|
||||||
|
<collection property="roles" ofType="String" javaType="list">
|
||||||
|
<result column="code"/>
|
||||||
|
</collection>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
id
|
||||||
|
,name,menu_id,
|
||||||
|
url_perm,btn_perm,gmt_create,
|
||||||
|
gmt_modified
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<select id="listPermRoles" resultMap="BaseResultMap">
|
||||||
|
SELECT t1.id,
|
||||||
|
t1.NAME,
|
||||||
|
t1.menu_id,
|
||||||
|
t1.url_perm,
|
||||||
|
t3.CODE
|
||||||
|
FROM sys_permission t1
|
||||||
|
LEFT JOIN sys_role_permission t2 ON t1.id = t2.permission_id
|
||||||
|
LEFT JOIN sys_role t3 ON t2.role_id = t3.id
|
||||||
|
</select>
|
||||||
|
|
||||||
|
</mapper>
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.recovery.admin.boot.mapper.UserMapper">
|
||||||
|
|
||||||
|
|
||||||
|
<select id="getByUsername" resultType="com.recovery.common.base.dto.UserAuthDTO">
|
||||||
|
select t1.user_name as userName,t1.password,t1.state as status,t1.id as userId
|
||||||
|
from tbl_user t1 where t1.user_name = #{userName}
|
||||||
|
|
||||||
|
|
||||||
|
</select>
|
||||||
|
</mapper>
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.recovery</groupId>
|
||||||
|
<artifactId>hoe-recovery</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>hoe-admin</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<modules>
|
||||||
|
<module>admin-boot</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,81 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.recovery</groupId>
|
||||||
|
<artifactId>hoe-recovery</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</parent>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<description>认证中心</description>
|
||||||
|
<artifactId>hoe-auth</artifactId>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!--Spring Cloud & Alibaba -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.recovery</groupId>
|
||||||
|
<artifactId>common-base</artifactId>
|
||||||
|
<version>${hoe-version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.recovery</groupId>
|
||||||
|
<artifactId>common-mybatis-plus</artifactId>
|
||||||
|
<version>${hoe-version}</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- 注册中心 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 配置中心 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.security</groupId>
|
||||||
|
<artifactId>spring-security-oauth2-jose</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.recovery</groupId>
|
||||||
|
<artifactId>common-web</artifactId>
|
||||||
|
<version>${hoe-version}</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- OAuth2 认证服务器-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.security.oauth.boot</groupId>
|
||||||
|
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.security</groupId>
|
||||||
|
<artifactId>spring-security-oauth2-jose</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.spotify</groupId>
|
||||||
|
<artifactId>docker-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.recovery.auth;
|
||||||
|
|
||||||
|
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
@SpringBootApplication
|
||||||
|
@EnableDiscoveryClient
|
||||||
|
@EnableFeignClients({"com.recovery.auth.feign"})
|
||||||
|
@ComponentScan(basePackages = {"com.recovery.auth","com.recovery.common.base"})
|
||||||
|
@MapperScan("com.recovery.auth.mapper")
|
||||||
|
public class AuthApp {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(AuthApp.class, args);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.recovery.auth;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
* @date: 2022/5/22
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/oauth")
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Slf4j
|
||||||
|
public class TestController {
|
||||||
|
|
||||||
|
@GetMapping("/public-test")
|
||||||
|
public String test() {
|
||||||
|
return "hoe-auth 为您提供服务";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,77 @@
|
||||||
|
package com.recovery.auth.aspect;
|
||||||
|
|
||||||
|
|
||||||
|
import com.recovery.common.base.ds.DataSourceContextHolder;
|
||||||
|
import com.recovery.common.base.util.HspHostUtil;
|
||||||
|
import com.recovery.common.base.utils.RedisUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.aspectj.lang.JoinPoint;
|
||||||
|
import org.aspectj.lang.annotation.After;
|
||||||
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
import org.aspectj.lang.annotation.Before;
|
||||||
|
import org.aspectj.lang.annotation.Pointcut;
|
||||||
|
import org.springframework.core.annotation.Order;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Web层日志切面
|
||||||
|
*
|
||||||
|
* @author RyanWang
|
||||||
|
* @version 1.0.0
|
||||||
|
* @date 16/5/17 上午10:42.
|
||||||
|
*/
|
||||||
|
@Aspect
|
||||||
|
@Order(0)
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class WebLogAspect {
|
||||||
|
@Resource
|
||||||
|
private StringRedisTemplate stringRedisTemplate;
|
||||||
|
@Pointcut("execution(public * com.recovery.auth.controller..*.*(..)) || execution(public * com.recovery.auth.rest..*.*(..))")
|
||||||
|
public void webLog(){}
|
||||||
|
|
||||||
|
@Before("webLog()")
|
||||||
|
public void doBefore(JoinPoint joinPoint) throws Throwable {
|
||||||
|
|
||||||
|
// 接收到请求,记录请求内容
|
||||||
|
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||||
|
//获取请求的域名
|
||||||
|
HttpServletRequest request = attributes.getRequest();
|
||||||
|
// 根据域名获取网站信息
|
||||||
|
StringBuffer urlBuf = request.getRequestURL();
|
||||||
|
URL url = new URL(urlBuf.toString());
|
||||||
|
String path = url.getPath();
|
||||||
|
HttpServletResponse response = (HttpServletResponse)attributes.getResponse();
|
||||||
|
String hospitalHost = request.getHeader("hospitalHost");
|
||||||
|
// if(StringUtils.isEmpty(hospitalHost)){
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
//切割获取访问目标模块
|
||||||
|
String[] split = path.split("/");
|
||||||
|
String module = split[0];
|
||||||
|
System.out.println(RedisUtils.getDBInfoByHostAndModule(stringRedisTemplate,hospitalHost,"admin"));
|
||||||
|
//根据域名和请求的模块名查询目标数据库
|
||||||
|
HttpSession session = request.getSession();
|
||||||
|
/**
|
||||||
|
* 切换为动态数据源实例
|
||||||
|
*/
|
||||||
|
HspHostUtil.switchDB(hospitalHost,"admin",stringRedisTemplate);
|
||||||
|
|
||||||
|
}
|
||||||
|
//执行完切面后,将线程共享中的数据源名称清空
|
||||||
|
@After("webLog()")
|
||||||
|
public void after(JoinPoint joinPoint){
|
||||||
|
DataSourceContextHolder.clearDBType();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,107 @@
|
||||||
|
package com.recovery.auth.comm.exception;
|
||||||
|
|
||||||
|
|
||||||
|
import com.recovery.common.base.result.ApiResult;
|
||||||
|
import com.recovery.common.base.result.ResultCode;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.core.annotation.Order;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.security.authentication.InternalAuthenticationServiceException;
|
||||||
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
|
import org.springframework.security.oauth2.common.exceptions.InvalidClientException;
|
||||||
|
import org.springframework.security.oauth2.common.exceptions.InvalidGrantException;
|
||||||
|
import org.springframework.security.oauth2.common.exceptions.InvalidTokenException;
|
||||||
|
import org.springframework.security.oauth2.provider.NoSuchClientException;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
@RestControllerAdvice
|
||||||
|
@Slf4j
|
||||||
|
@Order(-1)
|
||||||
|
public class AuthExceptionHandler {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户不存在
|
||||||
|
*
|
||||||
|
* @param e
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||||
|
@ExceptionHandler(UsernameNotFoundException.class)
|
||||||
|
public ApiResult handleUsernameNotFoundException(UsernameNotFoundException e) {
|
||||||
|
log.error("错误信息:{}", e.getMessage(),e);
|
||||||
|
return ApiResult.failed(ResultCode.USER_NOT_EXIST);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名和密码异常
|
||||||
|
*
|
||||||
|
* @param e
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||||
|
@ExceptionHandler(InvalidGrantException.class)
|
||||||
|
public ApiResult handleInvalidGrantException(InvalidGrantException e) {
|
||||||
|
log.error("错误信息:{}", e.getMessage(),e);
|
||||||
|
return ApiResult.failed(ResultCode.USERNAME_OR_PASSWORD_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名和密码异常
|
||||||
|
*
|
||||||
|
* @param e
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||||
|
@ExceptionHandler(InvalidClientException.class)
|
||||||
|
public ApiResult handleInvalidGrantException(InvalidClientException e) {
|
||||||
|
log.error("错误信息:{}", e.getMessage(),e);
|
||||||
|
return ApiResult.failed(ResultCode.CLIENT_AUTHENTICATION_FAILED);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 账户异常(禁用、锁定、过期)
|
||||||
|
*
|
||||||
|
* @param e
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||||
|
@ExceptionHandler({InternalAuthenticationServiceException.class})
|
||||||
|
public ApiResult handleInternalAuthenticationServiceException(InternalAuthenticationServiceException e) {
|
||||||
|
log.error("错误信息:{}", e.getMessage(),e);
|
||||||
|
return ApiResult.failed(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* token 无效或已过期
|
||||||
|
*
|
||||||
|
* @param e
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||||
|
@ExceptionHandler({InvalidTokenException.class})
|
||||||
|
public ApiResult handleInvalidTokenExceptionException(InvalidTokenException e) {
|
||||||
|
log.error("错误信息:{}", e.getMessage(),e);
|
||||||
|
return ApiResult.failed(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* token 无效或已过期
|
||||||
|
*
|
||||||
|
* @param e
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||||
|
@ExceptionHandler({NoSuchClientException.class})
|
||||||
|
public ApiResult noSuchClientException(NoSuchClientException e) {
|
||||||
|
log.error("错误信息:{}", e.getMessage(),e);
|
||||||
|
return ApiResult.failed(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.recovery.auth.comm;
|
||||||
|
|
||||||
|
|
||||||
|
import com.recovery.common.base.enums.PasswordEncoderTypeEnum;
|
||||||
|
import com.recovery.common.base.util.EncryptUtil;
|
||||||
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
|
|
||||||
|
public class test {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println(EncryptUtil.encrypt("123"));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.recovery.auth.comm.utils;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
|
||||||
|
import com.recovery.common.base.constant.SecurityConstants;
|
||||||
|
import org.apache.logging.log4j.util.Strings;
|
||||||
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
* @date: 2022/5/23
|
||||||
|
*/
|
||||||
|
public class CommonUtils {
|
||||||
|
public static String getOAuth2ClientId() {
|
||||||
|
|
||||||
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||||
|
|
||||||
|
String clientId = request.getParameter(SecurityConstants.CLIENT_ID_KEY);
|
||||||
|
if (StrUtil.isNotBlank(clientId)) {
|
||||||
|
return clientId;
|
||||||
|
}
|
||||||
|
|
||||||
|
String basic = request.getHeader(SecurityConstants.AUTHORIZATION_KEY);
|
||||||
|
if (StrUtil.isNotBlank(basic) && basic.startsWith(SecurityConstants.BASIC_PREFIX)) {
|
||||||
|
basic = basic.replace(SecurityConstants.BASIC_PREFIX, Strings.EMPTY);
|
||||||
|
String basicPlainText = new String(Base64.getDecoder().decode(basic.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8);
|
||||||
|
clientId = basicPlainText.split(":")[0];
|
||||||
|
}
|
||||||
|
return clientId;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,138 @@
|
||||||
|
package com.recovery.auth.config;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
|
||||||
|
import com.recovery.auth.security.details.client.ClientDetailsServiceImpl;
|
||||||
|
import com.recovery.auth.security.details.user.SysUserDetails;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
|
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
|
||||||
|
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
|
||||||
|
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
|
||||||
|
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
|
||||||
|
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
|
||||||
|
import org.springframework.security.oauth2.provider.CompositeTokenGranter;
|
||||||
|
import org.springframework.security.oauth2.provider.TokenGranter;
|
||||||
|
import org.springframework.security.oauth2.provider.token.DefaultTokenServices;
|
||||||
|
import org.springframework.security.oauth2.provider.token.TokenEnhancer;
|
||||||
|
import org.springframework.security.oauth2.provider.token.TokenEnhancerChain;
|
||||||
|
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
|
||||||
|
import org.springframework.security.oauth2.provider.token.store.KeyStoreKeyFactory;
|
||||||
|
|
||||||
|
import java.security.KeyPair;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created with IntelliJ IDEA.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @date: 2021/11/24
|
||||||
|
* @description:
|
||||||
|
* @modifiedBy:
|
||||||
|
* @version: 1.0
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@EnableAuthorizationServer
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
|
||||||
|
|
||||||
|
private final AuthenticationManager authenticationManager;
|
||||||
|
private final ClientDetailsServiceImpl clientDetailsService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OAuth2客户端
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@SneakyThrows
|
||||||
|
public void configure(ClientDetailsServiceConfigurer clients) {
|
||||||
|
clients.withClientDetails(clientDetailsService);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置授权(authorization)以及令牌(token)的访问端点和令牌服务(token services)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
|
||||||
|
// Token增强
|
||||||
|
TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
|
||||||
|
List<TokenEnhancer> tokenEnhancers = new ArrayList<>();
|
||||||
|
tokenEnhancers.add(tokenEnhancer());
|
||||||
|
tokenEnhancers.add(jwtAccessTokenConverter());
|
||||||
|
tokenEnhancerChain.setTokenEnhancers(tokenEnhancers);
|
||||||
|
|
||||||
|
// 获取原有默认授权模式(授权码模式、密码模式、客户端模式、简化模式)的授权者
|
||||||
|
List<TokenGranter> granterList = new ArrayList<>(Arrays.asList(endpoints.getTokenGranter()));
|
||||||
|
|
||||||
|
CompositeTokenGranter compositeTokenGranter = new CompositeTokenGranter(granterList);
|
||||||
|
endpoints
|
||||||
|
.authenticationManager(authenticationManager)
|
||||||
|
.accessTokenConverter(jwtAccessTokenConverter())
|
||||||
|
.tokenEnhancer(tokenEnhancerChain)
|
||||||
|
.tokenGranter(compositeTokenGranter)
|
||||||
|
.reuseRefreshTokens(true)
|
||||||
|
.tokenServices(tokenServices(endpoints))
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultTokenServices tokenServices(AuthorizationServerEndpointsConfigurer endpoints) {
|
||||||
|
TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
|
||||||
|
List<TokenEnhancer> tokenEnhancers = new ArrayList<>();
|
||||||
|
tokenEnhancers.add(tokenEnhancer());
|
||||||
|
tokenEnhancers.add(jwtAccessTokenConverter());
|
||||||
|
tokenEnhancerChain.setTokenEnhancers(tokenEnhancers);
|
||||||
|
|
||||||
|
DefaultTokenServices tokenServices = new DefaultTokenServices();
|
||||||
|
tokenServices.setTokenStore(endpoints.getTokenStore());
|
||||||
|
tokenServices.setSupportRefreshToken(true);
|
||||||
|
tokenServices.setClientDetailsService(clientDetailsService);
|
||||||
|
tokenServices.setTokenEnhancer(tokenEnhancerChain);
|
||||||
|
return tokenServices;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JWT内容增强
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public TokenEnhancer tokenEnhancer() {
|
||||||
|
return (accessToken, authentication) -> {
|
||||||
|
Map<String, Object> additionalInfo = CollectionUtil.newHashMap();
|
||||||
|
Object principal = authentication.getUserAuthentication().getPrincipal();
|
||||||
|
if (principal instanceof SysUserDetails){
|
||||||
|
SysUserDetails sysUserDetails = (SysUserDetails) principal;
|
||||||
|
additionalInfo.put("userId", sysUserDetails.getUserId());
|
||||||
|
additionalInfo.put("username", sysUserDetails.getUsername());
|
||||||
|
((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(additionalInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
return accessToken;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用非对称加密算法对token签名
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public JwtAccessTokenConverter jwtAccessTokenConverter() {
|
||||||
|
JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
|
||||||
|
converter.setKeyPair(keyPair());
|
||||||
|
return converter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密钥库中获取密钥对(公钥+私钥)
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public KeyPair keyPair() {
|
||||||
|
KeyStoreKeyFactory factory = new KeyStoreKeyFactory(new ClassPathResource("jwt.jks"), "afd123".toCharArray());
|
||||||
|
KeyPair keyPair = factory.getKeyPair("jwt", "afd123".toCharArray());
|
||||||
|
return keyPair;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,85 @@
|
||||||
|
package com.recovery.auth.config;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
|
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
|
||||||
|
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||||
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||||
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
|
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
|
||||||
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created with IntelliJ IDEA.
|
||||||
|
*
|
||||||
|
* @author:
|
||||||
|
* @date: 2021/11/24
|
||||||
|
* @description:
|
||||||
|
* @modifiedBy:
|
||||||
|
* @version: 1.0
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@EnableWebSecurity
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||||
|
|
||||||
|
private final UserDetailsService sysUserDetailsService;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure(HttpSecurity http) throws Exception {
|
||||||
|
http
|
||||||
|
.authorizeRequests().antMatchers("/api/oauth/**").permitAll()
|
||||||
|
.anyRequest().authenticated()
|
||||||
|
.and()
|
||||||
|
.httpBasic()
|
||||||
|
.and()
|
||||||
|
.csrf().disable();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 认证管理对象
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public AuthenticationManager authenticationManagerBean() throws Exception {
|
||||||
|
return super.authenticationManagerBean();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加自定义认证器
|
||||||
|
*
|
||||||
|
* @param auth
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||||
|
auth.authenticationProvider(daoAuthenticationProvider());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置默认的用户名密码认证授权提供者
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public DaoAuthenticationProvider daoAuthenticationProvider() {
|
||||||
|
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
||||||
|
provider.setUserDetailsService(sysUserDetailsService);
|
||||||
|
provider.setPasswordEncoder(passwordEncoder());
|
||||||
|
provider.setHideUserNotFoundExceptions(false); // 是否隐藏用户不存在异常,默认:true-隐藏;false-抛出异常;
|
||||||
|
return provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public PasswordEncoder passwordEncoder() {
|
||||||
|
return PasswordEncoderFactories.createDelegatingPasswordEncoder();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,95 @@
|
||||||
|
package com.recovery.auth.config.ds;
|
||||||
|
|
||||||
|
import com.alibaba.druid.pool.DruidDataSource;
|
||||||
|
import com.recovery.common.base.ds.DynamicDataSource;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.ibatis.session.SqlSessionFactory;
|
||||||
|
import org.mybatis.spring.SqlSessionFactoryBean;
|
||||||
|
import org.mybatis.spring.SqlSessionTemplate;
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Primary;
|
||||||
|
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||||
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by YHYR on 2017-12-25
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Configuration
|
||||||
|
@MapperScan(basePackages = DataSourceConfig.PACKAGE, sqlSessionFactoryRef = "commonSqlSessionFactory")
|
||||||
|
public class DataSourceConfig {
|
||||||
|
|
||||||
|
// 精确到模块目录,以便跟其他数据源隔离
|
||||||
|
static final String PACKAGE = "com.recovery.admin.boot.mapper";
|
||||||
|
static final String MAPPER_LOCATION = "classpath:mapper/*.xml";
|
||||||
|
|
||||||
|
@Value("${master.datasource.url}")
|
||||||
|
private String masterDBUrl;
|
||||||
|
|
||||||
|
@Value("${master.datasource.username}")
|
||||||
|
private String masterDBUser;
|
||||||
|
|
||||||
|
@Value("${master.datasource.password}")
|
||||||
|
private String masterDBPassword;
|
||||||
|
|
||||||
|
@Value("${master.datasource.driverClassName}")
|
||||||
|
private String masterDBDreiverName;
|
||||||
|
|
||||||
|
|
||||||
|
@Bean(name = "commonDataSource")
|
||||||
|
@Primary
|
||||||
|
public DynamicDataSource dynamicDataSource(){
|
||||||
|
DynamicDataSource dynamicDataSource = DynamicDataSource.getInstance();
|
||||||
|
|
||||||
|
DruidDataSource masterDataSource = new DruidDataSource();
|
||||||
|
try {
|
||||||
|
masterDataSource.setUrl(masterDBUrl);
|
||||||
|
masterDataSource.setUsername(masterDBUser);
|
||||||
|
masterDataSource.setPassword(masterDBPassword);
|
||||||
|
masterDataSource.setDriverClassName(masterDBDreiverName);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<Object,Object> map = new HashMap<>();
|
||||||
|
map.put("master", masterDataSource);
|
||||||
|
dynamicDataSource.setTargetDataSources(map);
|
||||||
|
|
||||||
|
return dynamicDataSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = "commonSqlSessionFactory")
|
||||||
|
@Primary
|
||||||
|
public SqlSessionFactory sqlSessionFactory(
|
||||||
|
@Qualifier("commonDataSource") DataSource dynamicDataSource)
|
||||||
|
throws Exception {
|
||||||
|
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
|
||||||
|
bean.setDataSource(dynamicDataSource);
|
||||||
|
bean.setMapperLocations(new PathMatchingResourcePatternResolver()
|
||||||
|
.getResources(DataSourceConfig.MAPPER_LOCATION));
|
||||||
|
return bean.getObject();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = "commonTransactionManager")
|
||||||
|
@Primary
|
||||||
|
public DataSourceTransactionManager commonTransactionManager() {
|
||||||
|
return new DataSourceTransactionManager(dynamicDataSource());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Bean(name = "commonSqlSessionTemplate")
|
||||||
|
public SqlSessionTemplate sqlSessionTemplate(
|
||||||
|
@Qualifier("commonSqlSessionFactory") SqlSessionFactory sqlSessionFactory)
|
||||||
|
throws Exception {
|
||||||
|
return new SqlSessionTemplate(sqlSessionFactory);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
package com.recovery.auth.config.ds;
|
||||||
|
|
||||||
|
import com.alibaba.druid.pool.DruidDataSource;
|
||||||
|
import org.apache.ibatis.session.SqlSessionFactory;
|
||||||
|
import org.mybatis.spring.SqlSessionFactoryBean;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||||
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
//@Configuration
|
||||||
|
//// 扫描 Mapper 接口并容器管理
|
||||||
|
//@MapperScan(basePackages = TeachingDataSourceConfig.PACKAGE, sqlSessionFactoryRef = "teachingSqlSessionFactory")
|
||||||
|
public class TeachingDataSourceConfig {
|
||||||
|
// 精确到 auth 目录,以便跟其他数据源隔离
|
||||||
|
static final String PACKAGE = "com.recovery.auth.dao.mapper";
|
||||||
|
static final String MAPPER_LOCATION = "classpath:mapper/*.xml";
|
||||||
|
|
||||||
|
@Value("${admin.datasource.url}")
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
@Value("${admin.datasource.username}")
|
||||||
|
private String user;
|
||||||
|
|
||||||
|
@Value("${admin.datasource.password}")
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
@Value("${admin.datasource.driverClassName}")
|
||||||
|
private String driverClass;
|
||||||
|
|
||||||
|
@Bean(name = "adminDataSource")
|
||||||
|
public DataSource cpdDataSource() {
|
||||||
|
DruidDataSource dataSource = new DruidDataSource();
|
||||||
|
dataSource.setDriverClassName(driverClass);
|
||||||
|
dataSource.setUrl(url);
|
||||||
|
dataSource.setUsername(user);
|
||||||
|
dataSource.setPassword(password);
|
||||||
|
return dataSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = "adminTransactionManager")
|
||||||
|
public DataSourceTransactionManager courseTransactionManager() {
|
||||||
|
return new DataSourceTransactionManager(cpdDataSource());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = "adminSqlSessionFactory")
|
||||||
|
public SqlSessionFactory cpdSqlSessionFactory(@Qualifier("adminDataSource") DataSource cpdDataSource)
|
||||||
|
throws Exception {
|
||||||
|
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
|
||||||
|
sessionFactory.setDataSource(cpdDataSource);
|
||||||
|
sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver()
|
||||||
|
.getResources(TeachingDataSourceConfig.MAPPER_LOCATION));
|
||||||
|
return sessionFactory.getObject();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
package com.recovery.auth.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import com.nimbusds.jose.jwk.JWKSet;
|
||||||
|
import com.nimbusds.jose.jwk.RSAKey;
|
||||||
|
import com.recovery.auth.security.details.user.JwtAuthenticationRequest;
|
||||||
|
import com.recovery.auth.service.AuthService;
|
||||||
|
import com.recovery.common.base.result.ApiResult;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.security.oauth2.common.OAuth2AccessToken;
|
||||||
|
import org.springframework.security.oauth2.provider.endpoint.TokenEndpoint;
|
||||||
|
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.security.KeyPair;
|
||||||
|
import java.security.Principal;
|
||||||
|
import java.security.interfaces.RSAPublicKey;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/oauth")
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Slf4j
|
||||||
|
public class AuthController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
AuthService authService;
|
||||||
|
|
||||||
|
@PostMapping("/token")
|
||||||
|
public ApiResult postAccessToken(@RequestBody JwtAuthenticationRequest authenticationRequest, HttpServletRequest request){
|
||||||
|
log.info("----------------获取token");
|
||||||
|
HashMap map= new HashMap();
|
||||||
|
try {
|
||||||
|
map = authService.login(authenticationRequest, request);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error("获取token:"+e.getMessage(),e);
|
||||||
|
return ApiResult.failed(e.getMessage());
|
||||||
|
}
|
||||||
|
return ApiResult.ok(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
// @GetMapping("/public-key")
|
||||||
|
// public Map<String, Object> getPublicKey() {
|
||||||
|
// RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
|
||||||
|
// RSAKey key = new RSAKey.Builder(publicKey).build();
|
||||||
|
// return new JWKSet(key).toJSONObject();
|
||||||
|
// }
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.recovery.auth.exception;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import com.recovery.common.base.result.IResultCode;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义异常类
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class BusinessException extends RuntimeException{
|
||||||
|
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
private String msg;
|
||||||
|
|
||||||
|
|
||||||
|
public BusinessException(IResultCode apiCode) {
|
||||||
|
super(apiCode.getMsg());
|
||||||
|
this.code = apiCode.getCode();
|
||||||
|
this.msg = apiCode.getMsg();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BusinessException(String code, String message) {
|
||||||
|
super(code+":"+message);
|
||||||
|
this.code = code;
|
||||||
|
this.msg = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BusinessException(String message) {
|
||||||
|
super("5001"+":"+message);
|
||||||
|
this.code = "5001";
|
||||||
|
this.msg = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
package com.recovery.auth.exception;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import com.recovery.common.base.result.ApiResult;
|
||||||
|
import com.recovery.common.base.result.ResultCode;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 全局异常处理
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestControllerAdvice
|
||||||
|
public class GlobalExceptionHandler {
|
||||||
|
|
||||||
|
//自定义异常
|
||||||
|
@ExceptionHandler(BusinessException.class)
|
||||||
|
public ApiResult systemExceptionHandler(BusinessException e) {
|
||||||
|
log.error("BusinessException全局异常:{}",e);
|
||||||
|
return ApiResult.failed(e.getCode(), e.getMsg());
|
||||||
|
}
|
||||||
|
|
||||||
|
//系统异常
|
||||||
|
@ExceptionHandler(Exception.class)
|
||||||
|
public ApiResult exceptionHandler(Exception e) {
|
||||||
|
log.error("Exception全局异常:{}",e);
|
||||||
|
return ApiResult.failed(ResultCode.SYSTEM_EXECUTION_ERROR.getCode(), e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
//Security
|
||||||
|
// @ExceptionHandler(value = AccessDeniedException.class)
|
||||||
|
// public void accessDeniedException(AccessDeniedException e) {
|
||||||
|
// throw e;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.recovery.auth.feign;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import com.recovery.common.base.config.feign.FeignConfiguration;
|
||||||
|
import com.recovery.common.base.dto.UserAuthDTO;
|
||||||
|
import com.recovery.common.base.result.ApiResult;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
@FeignClient(value = "hoe-admin",configuration = FeignConfiguration.class)
|
||||||
|
public interface UserFeignClient {
|
||||||
|
|
||||||
|
@GetMapping("/api/rest/users/getUserByUsername")
|
||||||
|
ApiResult<UserAuthDTO> getUserByUsername(@RequestParam String username);
|
||||||
|
|
||||||
|
@GetMapping("/api/rest/users/member/username")
|
||||||
|
ApiResult<UserAuthDTO> getMemberUserByUsername(@RequestParam String username);
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.recovery.auth.mapper;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.recovery.common.base.po.base.OauthClientDetails;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Administrator
|
||||||
|
* @description 针对表【oauth_client_details(存储客户端的配置信息)】的数据库操作Mapper
|
||||||
|
* @createDate 2024-03-04 10:33:19
|
||||||
|
* @Entity dao.entiy.OauthClientDetails
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface OauthClientDetailsMapper extends BaseMapper<OauthClientDetails> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.recovery.auth.rest;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api")
|
||||||
|
@Slf4j
|
||||||
|
public class UserRest {
|
||||||
|
@Resource
|
||||||
|
private StringRedisTemplate stringRedisTemplate;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.recovery.auth.security.details.client;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import com.recovery.common.base.enums.PasswordEncoderTypeEnum;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
|
import org.springframework.security.oauth2.provider.ClientDetails;
|
||||||
|
import org.springframework.security.oauth2.provider.ClientDetailsService;
|
||||||
|
import org.springframework.security.oauth2.provider.client.BaseClientDetails;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created with IntelliJ IDEA.
|
||||||
|
*
|
||||||
|
* @author: AI码师
|
||||||
|
* @date: 2021/11/24
|
||||||
|
* @description:
|
||||||
|
* @modifiedBy:
|
||||||
|
* @version: 1.0
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class ClientDetailsServiceImpl implements ClientDetailsService {
|
||||||
|
@Override
|
||||||
|
@Cacheable(cacheNames = "auth", key = "'oauth-client:'+#clientId")
|
||||||
|
public ClientDetails loadClientByClientId(String clientId) {
|
||||||
|
// 后面通过feign从管理端获取,目前写死
|
||||||
|
BaseClientDetails clientDetails = new BaseClientDetails(
|
||||||
|
"hoe",
|
||||||
|
"",
|
||||||
|
"all",
|
||||||
|
"password,client_credentials,refresh_token,authorization_code",
|
||||||
|
"",
|
||||||
|
"http://www.baidu.com"
|
||||||
|
|
||||||
|
);
|
||||||
|
clientDetails.setClientSecret(PasswordEncoderTypeEnum.NOOP.getPrefix() + "hoe");
|
||||||
|
clientDetails.setAccessTokenValiditySeconds(3600);
|
||||||
|
clientDetails.setRefreshTokenValiditySeconds(36000000);
|
||||||
|
return clientDetails;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,74 @@
|
||||||
|
package com.recovery.auth.security.details.user;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class JwtAuthenticationRequest implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -8445943548965154778L;
|
||||||
|
|
||||||
|
private String username;
|
||||||
|
private String phone;
|
||||||
|
private String password;
|
||||||
|
private String verifyCode;
|
||||||
|
private String loginMethod;
|
||||||
|
private String visitorsType;
|
||||||
|
|
||||||
|
public JwtAuthenticationRequest(String username,String phone,String password,String verifyCode,String loginMethod,String visitorsType) {
|
||||||
|
this.username = username;
|
||||||
|
this.phone = phone;
|
||||||
|
this.password = password;
|
||||||
|
this.verifyCode = verifyCode;
|
||||||
|
this.loginMethod = loginMethod;
|
||||||
|
this.visitorsType = visitorsType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JwtAuthenticationRequest() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUserPhone() {
|
||||||
|
return phone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserPhone(String phone) {
|
||||||
|
this.phone = phone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVerifyCode() {
|
||||||
|
return verifyCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVerifyCode(String verifyCode) {
|
||||||
|
this.verifyCode = verifyCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLoginMethod() {
|
||||||
|
return loginMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLoginMethod(String loginMethod) {
|
||||||
|
this.loginMethod = loginMethod;
|
||||||
|
}
|
||||||
|
public String getVisitorsType() {
|
||||||
|
return visitorsType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVisitorsType(String visitorsType) {
|
||||||
|
this.visitorsType = visitorsType;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,76 @@
|
||||||
|
package com.recovery.auth.security.details.user;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||||
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class SysUserDetails implements UserDetails {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扩展字段
|
||||||
|
*/
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认字段
|
||||||
|
*/
|
||||||
|
private String username;
|
||||||
|
private String password;
|
||||||
|
/**
|
||||||
|
* 是否启用
|
||||||
|
*/
|
||||||
|
private Boolean enabled;
|
||||||
|
/**
|
||||||
|
* 角色
|
||||||
|
*/
|
||||||
|
private Collection<SimpleGrantedAuthority> authorities;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||||
|
return this.authorities;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPassword() {
|
||||||
|
return this.password;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUsername() {
|
||||||
|
return this.username;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAccountNonExpired() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAccountNonLocked() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCredentialsNonExpired() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return this.enabled;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,79 @@
|
||||||
|
package com.recovery.auth.security.details.user;
|
||||||
|
|
||||||
|
import com.recovery.auth.feign.UserFeignClient;
|
||||||
|
import com.recovery.common.base.dto.UserAuthDTO;
|
||||||
|
import com.recovery.common.base.enums.PasswordEncoderTypeEnum;
|
||||||
|
import com.recovery.common.base.result.ApiResult;
|
||||||
|
import com.recovery.common.base.result.ResultCode;
|
||||||
|
import com.recovery.common.base.util.RedisUtil;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.security.authentication.AccountExpiredException;
|
||||||
|
import org.springframework.security.authentication.DisabledException;
|
||||||
|
import org.springframework.security.authentication.LockedException;
|
||||||
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||||
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
@Service("sysUserDetailsService")
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class SysUserDetailsServiceImpl implements UserDetailsService {
|
||||||
|
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private UserFeignClient userFeignClient;
|
||||||
|
@Resource
|
||||||
|
RedisUtil redisUtil;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||||
|
// 后面从管理端获取用户信息
|
||||||
|
ApiResult<UserAuthDTO> result = userFeignClient.getUserByUsername(username);
|
||||||
|
SysUserDetails userDetails = null;
|
||||||
|
if (ApiResult.ok().getCode().equals(result.getCode())) {
|
||||||
|
UserAuthDTO user = result.getData();
|
||||||
|
if (null != user) {
|
||||||
|
userDetails = SysUserDetails.builder()
|
||||||
|
.userId(user.getUserId())
|
||||||
|
.username(user.getUserName())
|
||||||
|
//角色
|
||||||
|
// .authorities(handleRoles(user.getRoles()))
|
||||||
|
.enabled(user.getStatus() == 1)
|
||||||
|
.password(PasswordEncoderTypeEnum.BCRYPT.getPrefix() + user.getPassword())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (Objects.isNull(userDetails)) {
|
||||||
|
throw new UsernameNotFoundException(ResultCode.USER_NOT_EXIST.getMsg());
|
||||||
|
} else if (!userDetails.isEnabled()) {
|
||||||
|
throw new DisabledException("该账户已被禁用!");
|
||||||
|
} else if (!userDetails.isAccountNonLocked()) {
|
||||||
|
throw new LockedException("该账号已被锁定!");
|
||||||
|
} else if (!userDetails.isAccountNonExpired()) {
|
||||||
|
throw new AccountExpiredException("该账号已过期!");
|
||||||
|
}
|
||||||
|
return userDetails;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Collection<SimpleGrantedAuthority> handleRoles(List<String> roles) {
|
||||||
|
Collection<SimpleGrantedAuthority> authorities = new ArrayList<>();
|
||||||
|
for (String role : roles) {
|
||||||
|
authorities.add(new SimpleGrantedAuthority(role));
|
||||||
|
}
|
||||||
|
return authorities;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.recovery.auth.service;
|
||||||
|
|
||||||
|
import com.recovery.auth.security.details.user.JwtAuthenticationRequest;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public interface AuthService {
|
||||||
|
|
||||||
|
HashMap login(JwtAuthenticationRequest authenticationRequest, HttpServletRequest request);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.recovery.auth.service;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.recovery.common.base.po.base.OauthClientDetails;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Administrator
|
||||||
|
* @description 针对表【oauth_client_details(存储客户端的配置信息)】的数据库操作Service
|
||||||
|
* @createDate 2024-03-04 10:33:19
|
||||||
|
*/
|
||||||
|
public interface OauthClientDetailsService extends IService<OauthClientDetails> {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,96 @@
|
||||||
|
package com.recovery.auth.service.impl;
|
||||||
|
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.recovery.auth.exception.BusinessException;
|
||||||
|
import com.recovery.auth.feign.UserFeignClient;
|
||||||
|
import com.recovery.auth.security.details.user.JwtAuthenticationRequest;
|
||||||
|
import com.recovery.auth.security.details.user.SysUserDetails;
|
||||||
|
import com.recovery.auth.service.AuthService;
|
||||||
|
import com.recovery.common.base.dto.UserAuthDTO;
|
||||||
|
import com.recovery.common.base.dto.UserAuthorityDto;
|
||||||
|
import com.recovery.common.base.result.ApiResult;
|
||||||
|
import com.recovery.common.base.result.ResultCode;
|
||||||
|
import com.recovery.common.base.util.EncryptUtil;
|
||||||
|
import com.recovery.common.base.util.RedisUtil;
|
||||||
|
import com.recovery.common.base.utils.JwtUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.security.authentication.AccountExpiredException;
|
||||||
|
import org.springframework.security.authentication.DisabledException;
|
||||||
|
import org.springframework.security.authentication.LockedException;
|
||||||
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Administrator
|
||||||
|
* @description 针对表【oauth_client_details(存储客户端的配置信息)】的数据库操作Service
|
||||||
|
* @createDate 2024-03-04 10:33:19
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class AuthServiceImpl implements AuthService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
UserFeignClient userFeignClient;
|
||||||
|
@Resource
|
||||||
|
RedisUtil redisUtil;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HashMap login(JwtAuthenticationRequest authenticationRequest, HttpServletRequest request) {
|
||||||
|
HashMap map = new HashMap();
|
||||||
|
if(null == authenticationRequest.getUsername() || "".equals(authenticationRequest.getUsername())){
|
||||||
|
throw new BusinessException("账户不能为空");
|
||||||
|
}
|
||||||
|
if(null == authenticationRequest.getPassword() || "".equals(authenticationRequest.getPassword())){
|
||||||
|
throw new BusinessException("密码不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
ApiResult<UserAuthDTO> result = userFeignClient.getUserByUsername(authenticationRequest.getUsername());
|
||||||
|
UserAuthorityDto userDetails = new UserAuthorityDto();
|
||||||
|
if (ResultCode.SUCCESS.getCode().equals(result.getCode())) {
|
||||||
|
UserAuthDTO user = result.getData();
|
||||||
|
if (null != user) {
|
||||||
|
userDetails.setUserName(user.getUserName());
|
||||||
|
userDetails.setId(user.getUserId());
|
||||||
|
userDetails.setPassword(user.getPassword());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Objects.isNull(userDetails)) {
|
||||||
|
throw new BusinessException(result.getMsg());
|
||||||
|
}
|
||||||
|
//加密
|
||||||
|
if (userDetails.getUserName().equals(authenticationRequest.getUsername()) && userDetails.getPassword().equals(EncryptUtil.encrypt(authenticationRequest.getPassword()))) {
|
||||||
|
log.info("密码校验成功!");
|
||||||
|
} else {
|
||||||
|
throw new BusinessException("密码错误!");
|
||||||
|
}
|
||||||
|
//用户信息
|
||||||
|
map.put("userId", userDetails.toString());
|
||||||
|
map.put("name", userDetails.getName());
|
||||||
|
map.put("userName", userDetails.getUserName());
|
||||||
|
map.put("password",userDetails.getPassword());
|
||||||
|
//生成token
|
||||||
|
String token = JwtUtils.generateToken(map);
|
||||||
|
//token
|
||||||
|
map.put("userInfo", userDetails);
|
||||||
|
map.put("token", token);
|
||||||
|
|
||||||
|
//认证通过 使用userid 生成jwt token令牌
|
||||||
|
try {
|
||||||
|
boolean resultRedis = redisUtil.set("userToken:" + token,userDetails , 24 * 600 * 7);
|
||||||
|
if (!resultRedis) {
|
||||||
|
throw new RuntimeException("网络链接失败,登录失败");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.recovery.auth.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
|
||||||
|
import com.recovery.auth.mapper.OauthClientDetailsMapper;
|
||||||
|
import com.recovery.auth.service.OauthClientDetailsService;
|
||||||
|
import com.recovery.common.base.po.base.OauthClientDetails;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Administrator
|
||||||
|
* @description 针对表【oauth_client_details(存储客户端的配置信息)】的数据库操作Service实现
|
||||||
|
* @createDate 2024-03-04 10:33:19
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class OauthClientDetailsServiceImpl extends ServiceImpl<OauthClientDetailsMapper, OauthClientDetails> implements OauthClientDetailsService {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: hoe-auth
|
||||||
|
main:
|
||||||
|
allow-bean-definition-overriding: true
|
||||||
|
profiles:
|
||||||
|
active: dev
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
# metadata:
|
||||||
|
# serviceGroup: ytChen
|
||||||
|
server-addr: localhost:8848
|
||||||
|
namespace: 11bfd099-10d6-4f2c-b969-58b76e435cce
|
||||||
|
config:
|
||||||
|
server-addr: localhost:8848
|
||||||
|
file-extension: yaml
|
||||||
|
prefix: hoe-auth
|
||||||
|
group: dev
|
||||||
|
namespace: 11bfd099-10d6-4f2c-b969-58b76e435cce
|
||||||
|
server:
|
||||||
|
port: 9001
|
Binary file not shown.
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.recovery.auth.mapper.OauthClientDetailsMapper">
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
|
@ -0,0 +1,86 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.recovery</groupId>
|
||||||
|
<artifactId>hoe-common</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>common-base</artifactId>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
<artifactId>logback-classic</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-pool2</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-jdbc</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-annotation</artifactId>
|
||||||
|
<version>3.5.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>fastjson</artifactId>
|
||||||
|
<version>1.2.83</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>druid</artifactId>
|
||||||
|
<version>1.2.6</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- openfeign依赖 1. http客户端选择okhttp 2. loadbalancer替换ribbon -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--引入jwt-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.auth0</groupId>
|
||||||
|
<artifactId>java-jwt</artifactId>
|
||||||
|
<version>3.11.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.github.openfeign</groupId>
|
||||||
|
<artifactId>feign-okhttp</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.tomcat.embed</groupId>
|
||||||
|
<artifactId>tomcat-embed-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-codec</groupId>
|
||||||
|
<artifactId>commons-codec</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,47 @@
|
||||||
|
package com.recovery.common.base.config;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||||
|
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator;
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||||
|
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||||
|
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@AutoConfigureBefore(RedisAutoConfiguration.class)
|
||||||
|
public class RedisConfig {
|
||||||
|
@Bean
|
||||||
|
public RedisTemplate<String, Object> redisTemplate(LettuceConnectionFactory lettuceConnectionFactory) {
|
||||||
|
|
||||||
|
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
||||||
|
redisTemplate.setConnectionFactory(lettuceConnectionFactory);
|
||||||
|
|
||||||
|
// 用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值
|
||||||
|
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
|
||||||
|
redisTemplate.setKeySerializer(stringRedisSerializer); // key
|
||||||
|
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
// 指定要序列化的域(field,get,set),访问修饰符(public,private,protected)
|
||||||
|
objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
||||||
|
objectMapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL);
|
||||||
|
jackson2JsonRedisSerializer.setObjectMapper(objectMapper);
|
||||||
|
|
||||||
|
redisTemplate.setValueSerializer(jackson2JsonRedisSerializer); //value
|
||||||
|
|
||||||
|
redisTemplate.setHashKeySerializer(stringRedisSerializer);
|
||||||
|
redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer);
|
||||||
|
|
||||||
|
redisTemplate.afterPropertiesSet();
|
||||||
|
return redisTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
package com.recovery.common.base.config.feign;
|
||||||
|
|
||||||
|
|
||||||
|
import com.recovery.common.base.util.HspHostUtil;
|
||||||
|
import feign.RequestInterceptor;
|
||||||
|
import feign.RequestTemplate;
|
||||||
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
public class CommonRequestInterceptor implements RequestInterceptor{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(RequestTemplate requestTemplate) {
|
||||||
|
|
||||||
|
HttpServletRequest request = getHttpServletRequest();
|
||||||
|
if(request != null && request.getHeader("hospitalHost") != null){
|
||||||
|
String hospitalHost = request.getHeader("hospitalHost");
|
||||||
|
String hospiatlProt = request.getHeader("hospiatlProt");
|
||||||
|
String websiteDomain = request.getHeader("websiteDomain");
|
||||||
|
String innerInternet = request.getHeader("innerInternet");
|
||||||
|
String token = request.getHeader("userTokenHead");
|
||||||
|
requestTemplate.header("hospitalHost", hospitalHost);
|
||||||
|
requestTemplate.header("innerInternet", innerInternet);
|
||||||
|
requestTemplate.header("websiteDomain",websiteDomain);
|
||||||
|
requestTemplate.header("hospiatlProt",hospiatlProt);
|
||||||
|
requestTemplate.header("userTokenHead",token);
|
||||||
|
} else {
|
||||||
|
//取当前线程变量中的域名进行传递
|
||||||
|
requestTemplate.header("hospitalHost", HspHostUtil.getHspHost());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private HttpServletRequest getHttpServletRequest() {
|
||||||
|
try {
|
||||||
|
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||||
|
if(attributes != null){
|
||||||
|
return attributes.getRequest();
|
||||||
|
}else{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.recovery.common.base.config.feign;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class FeignConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
CommonRequestInterceptor getCommonRequestInterceptor(){
|
||||||
|
return new CommonRequestInterceptor();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
package com.recovery.common.base.config.redis;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public interface BaseRedisCache {
|
||||||
|
/**
|
||||||
|
* 描述:获取缓存
|
||||||
|
*/
|
||||||
|
public String get(String key);
|
||||||
|
public Object get_obj(String key);
|
||||||
|
/**
|
||||||
|
* 描述:删除缓存
|
||||||
|
*/
|
||||||
|
public void remove(String key);
|
||||||
|
/**
|
||||||
|
* 描述:添加缓存
|
||||||
|
*/
|
||||||
|
public void put(String key, String value);
|
||||||
|
public void put_obj(String key, Object value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 描述:添加缓存并且添加失效时间
|
||||||
|
*/
|
||||||
|
public void put(String key, String value, int second);
|
||||||
|
public void put_obj(String key, Object value, int second);
|
||||||
|
/**
|
||||||
|
* 描述:根据缓存value值加减
|
||||||
|
*/
|
||||||
|
public long incr(String key, long value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 描述:设置超时时间
|
||||||
|
*/
|
||||||
|
public void expire(String key);
|
||||||
|
public void expireDays(String key, int days);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否存在
|
||||||
|
* @param key
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Boolean isExists(String key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 匹配所有key值
|
||||||
|
* @param patten
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Set<String> keySet(String patten);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除某类key
|
||||||
|
* @param patten
|
||||||
|
*/
|
||||||
|
public void clean(String patten);
|
||||||
|
}
|
|
@ -0,0 +1,114 @@
|
||||||
|
package com.recovery.common.base.config.redis;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
import org.springframework.data.redis.core.ValueOperations;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@Component("BaseRedisCacheImpl")
|
||||||
|
public class BaseRedisCacheImpl implements BaseRedisCache {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private StringRedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisTemplate<String, Object> redisTemplate_obj;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String get(String key) {
|
||||||
|
ValueOperations<String, String> operations = redisTemplate.opsForValue();
|
||||||
|
return operations.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object get_obj(String key) {
|
||||||
|
return redisTemplate_obj.opsForValue().get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove(String key) {
|
||||||
|
if (redisTemplate.hasKey(key)) {
|
||||||
|
redisTemplate.delete(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void put(String key, String value) {
|
||||||
|
try {
|
||||||
|
if(value == null) {
|
||||||
|
value = "";
|
||||||
|
}
|
||||||
|
ValueOperations<String, String> operations = redisTemplate.opsForValue();
|
||||||
|
operations.set(key, value);
|
||||||
|
} catch (Exception err) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void put_obj(String key, Object value) {
|
||||||
|
redisTemplate_obj.opsForValue().set(key,value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void put(String key, String value, int second) {
|
||||||
|
if(value == null) {
|
||||||
|
value = "";
|
||||||
|
}
|
||||||
|
ValueOperations<String, String> operations = redisTemplate.opsForValue();
|
||||||
|
operations.set(key, value, second, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void put_obj(String key, Object value, int second) {
|
||||||
|
redisTemplate_obj.opsForValue().set(key, value, second, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public long incr(String key, long value) {
|
||||||
|
ValueOperations<String, String> operations = redisTemplate.opsForValue();
|
||||||
|
return operations.increment(key,value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void expire(String key) {
|
||||||
|
try {
|
||||||
|
redisTemplate.expire(key, 15, TimeUnit.DAYS);
|
||||||
|
} catch (Exception err) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void expireDays(String key, int days) {
|
||||||
|
try {
|
||||||
|
redisTemplate.expire(key, days, TimeUnit.DAYS);
|
||||||
|
} catch (Exception err) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean isExists(String key) {
|
||||||
|
if(redisTemplate.hasKey(key)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> keySet(String patten) {
|
||||||
|
return redisTemplate.keys(patten);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clean(String patten) {
|
||||||
|
Set<String> keys = redisTemplate.keys(patten);
|
||||||
|
if(keys.size() > 0) {
|
||||||
|
redisTemplate.delete(keys);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
package com.recovery.common.base.config.redis;
|
||||||
|
|
||||||
|
public interface RedisCache {
|
||||||
|
/**
|
||||||
|
* 描述:获取缓存
|
||||||
|
*/
|
||||||
|
public String get(String key);
|
||||||
|
public Object get_obj(String key);
|
||||||
|
/**
|
||||||
|
* 描述:删除缓存
|
||||||
|
*/
|
||||||
|
public void remove(String key);
|
||||||
|
/**
|
||||||
|
* 描述:添加缓存
|
||||||
|
*/
|
||||||
|
public void put(String key, String value);
|
||||||
|
public void put_obj(String key, Object value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 描述:添加缓存并且添加失效时间
|
||||||
|
*/
|
||||||
|
public void put(String key, String value, int second);
|
||||||
|
public void put_obj(String key, Object value, int second);
|
||||||
|
/**
|
||||||
|
* 描述:根据缓存value值加减
|
||||||
|
*/
|
||||||
|
public long incr(String key, long value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 描述:设置超时时间
|
||||||
|
*/
|
||||||
|
public void expire(String key);
|
||||||
|
public void expireDays(String key,int days);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否存在
|
||||||
|
* @param key
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Boolean isExists(String key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除某类key
|
||||||
|
* @param patten
|
||||||
|
*/
|
||||||
|
public void clean(String patten);
|
||||||
|
}
|
|
@ -0,0 +1,109 @@
|
||||||
|
package com.recovery.common.base.config.redis;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
import org.springframework.data.redis.core.ValueOperations;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@Component("RedisCacheImpl")
|
||||||
|
public class RedisCacheImpl implements RedisCache {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private StringRedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisTemplate<String, Object> redisTemplate_obj;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String get(String key) {
|
||||||
|
if (null == key) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ValueOperations<String, String> operations = redisTemplate.opsForValue();
|
||||||
|
return operations.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object get_obj(String key) {
|
||||||
|
if (null == key) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return redisTemplate_obj.opsForValue().get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove(String key) {
|
||||||
|
if (redisTemplate.hasKey(key)) {
|
||||||
|
redisTemplate.delete(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void put(String key, String value) {
|
||||||
|
try {
|
||||||
|
ValueOperations<String, String> operations = redisTemplate.opsForValue();
|
||||||
|
operations.set(key, value);
|
||||||
|
} catch (Exception err) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void put_obj(String key, Object value) {
|
||||||
|
redisTemplate_obj.opsForValue().set(key,value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void put(String key, String value, int second) {
|
||||||
|
ValueOperations<String, String> operations = redisTemplate.opsForValue();
|
||||||
|
operations.set(key, value, second, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void put_obj(String key, Object value, int second) {
|
||||||
|
redisTemplate_obj.opsForValue().set(key, value, second, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public long incr(String key, long value) {
|
||||||
|
ValueOperations<String, String> operations = redisTemplate.opsForValue();
|
||||||
|
return operations.increment(key,value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void expire(String key) {
|
||||||
|
try {
|
||||||
|
redisTemplate.expire(key, 15, TimeUnit.DAYS);
|
||||||
|
} catch (Exception err) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void expireDays(String key, int days) {
|
||||||
|
try {
|
||||||
|
redisTemplate.expire(key, days, TimeUnit.DAYS);
|
||||||
|
} catch (Exception err) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean isExists(String key) {
|
||||||
|
if(redisTemplate.hasKey(key)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clean(String patten) {
|
||||||
|
Set<String> keys = redisTemplate.keys(patten);
|
||||||
|
if(keys.size() > 0) {
|
||||||
|
redisTemplate.delete(keys);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
package com.recovery.common.base.constant;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class Constants {
|
||||||
|
public static int OK = 1;
|
||||||
|
public static int LOGIN_FAIL = 2;
|
||||||
|
public static int PARAM_NULL = 3;
|
||||||
|
public static int PARAM_ERR = 4;
|
||||||
|
public static int SYSTEM_ERR = 5;
|
||||||
|
public static int OTHER = 6;
|
||||||
|
//格式异常
|
||||||
|
public static int FORMAT_ERR=7;
|
||||||
|
public final static String PARAM_NULL_MSG = "参数为空";
|
||||||
|
public final static String PARAM_ERR_MSG = "参数错误";
|
||||||
|
public final static String SYSTEM_ERR_MSG = "系统异常";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public final static String UPLOAD_SIZE_ERR_MSG = "上传大小错误";
|
||||||
|
|
||||||
|
|
||||||
|
public static final String LOGIN_USRE_TOKEN = "x-userToken";
|
||||||
|
|
||||||
|
|
||||||
|
public final static String WHOLE_DOMAIN_REDIS_KEY = "HOE_WHOLE_DOMAIN_REDIS_KEY";
|
||||||
|
public final static String[] CHINESE_NUM = {"一","二","三","四","五","六","七","八","九","十"
|
||||||
|
,"十一","十二","十三","十四","十五","十六","十七","十八","十九","二十"
|
||||||
|
,"二十一","二十二","二十三","二十四","二十五","二十六","二十七","二十八","二十九","三十"
|
||||||
|
,"三十一","三十一","三十一","三十一","三十一","三十一","三十一","三十一","三十一","四十"};
|
||||||
|
|
||||||
|
|
||||||
|
public final static String[] WEEKS = {"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// String[] distNames = dist_name.split(",");
|
||||||
|
// Random random=new Random();
|
||||||
|
// int number1 = random.nextInt(distNames.length);
|
||||||
|
// String distName1 = distNames[number1];
|
||||||
|
// int number2 = random.nextInt(distNames.length);
|
||||||
|
// String distName2 = distNames[number2];
|
||||||
|
// System.out.println(distName1 + distName2);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
package com.recovery.common.base.constant;
|
||||||
|
|
||||||
|
public interface GlobalConstants {
|
||||||
|
String URL_PERM_ROLES_KEY = "system:perm_roles_rule:url:";
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
package com.recovery.common.base.constant;
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
public interface SecurityConstants {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 认证请求头key
|
||||||
|
*/
|
||||||
|
String AUTHORIZATION_KEY = "Authorization";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JWT令牌前缀
|
||||||
|
*/
|
||||||
|
String JWT_PREFIX = "Bearer ";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basic认证前缀
|
||||||
|
*/
|
||||||
|
String BASIC_PREFIX = "Basic ";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JWT载体key
|
||||||
|
*/
|
||||||
|
String JWT_PAYLOAD_KEY = "payload";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JWT存储权限前缀
|
||||||
|
*/
|
||||||
|
String AUTHORITY_PREFIX = "ROLE_";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JWT存储权限属性
|
||||||
|
*/
|
||||||
|
String JWT_AUTHORITIES_KEY = "authorities";
|
||||||
|
|
||||||
|
|
||||||
|
String CLIENT_ID_KEY = "client_id";
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.recovery.common.base.ds;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by RyanWang on 2019-07-24
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class DataSourceContextHolder {
|
||||||
|
private static final ThreadLocal<String> contextHolder = new ThreadLocal<String>();
|
||||||
|
|
||||||
|
public static synchronized void setDBType(String dbType){
|
||||||
|
contextHolder.set(dbType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getDBType(){
|
||||||
|
return contextHolder.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void clearDBType(){
|
||||||
|
contextHolder.remove();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.recovery.common.base.ds;
|
||||||
|
|
||||||
|
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by RyanWang on 2019-07-24
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class DynamicDataSource extends AbstractRoutingDataSource {
|
||||||
|
private static DynamicDataSource instance;
|
||||||
|
private static byte[] lock=new byte[0];
|
||||||
|
private static Map<Object,Object> dataSourceMap=new HashMap<Object, Object>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setTargetDataSources(Map<Object, Object> targetDataSources) {
|
||||||
|
super.setTargetDataSources(targetDataSources);
|
||||||
|
dataSourceMap.putAll(targetDataSources);
|
||||||
|
super.afterPropertiesSet();// 必须添加该句,否则新添加数据源无法识别到
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<Object, Object> getDataSourceMap() {
|
||||||
|
return dataSourceMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized DynamicDataSource getInstance(){
|
||||||
|
if(instance==null){
|
||||||
|
synchronized (lock){
|
||||||
|
if(instance==null){
|
||||||
|
instance=new DynamicDataSource();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
//必须实现其方法
|
||||||
|
@Override
|
||||||
|
protected Object determineCurrentLookupKey() {
|
||||||
|
return DataSourceContextHolder.getDBType();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
package com.recovery.common.base.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class MemberUserAuthDTO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户ID
|
||||||
|
*/
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户密码
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户状态:1-有效;0-禁用
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户角色编码集合 ["ROOT","ADMIN"]
|
||||||
|
*/
|
||||||
|
|
||||||
|
private List<String> roles;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,66 @@
|
||||||
|
package com.recovery.common.base.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class OAuth2ClientDTO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客户端ID
|
||||||
|
*/
|
||||||
|
private String clientId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客户端密钥
|
||||||
|
*/
|
||||||
|
private String clientSecret;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 资源id列表
|
||||||
|
*/
|
||||||
|
private String resourceIds;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 授权范围
|
||||||
|
*/
|
||||||
|
private String scope;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 授权方式
|
||||||
|
*/
|
||||||
|
private String authorizedGrantTypes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 回调地址
|
||||||
|
*/
|
||||||
|
private String webServerRedirectUri;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 权限列表
|
||||||
|
*/
|
||||||
|
private String authorities;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 认证令牌时效
|
||||||
|
*/
|
||||||
|
private Integer accessTokenValidity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 刷新令牌时效
|
||||||
|
*/
|
||||||
|
private Integer refreshTokenValidity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扩展信息
|
||||||
|
*/
|
||||||
|
private String additionalInformation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否自动放行
|
||||||
|
*/
|
||||||
|
private String autoapprove;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.recovery.common.base.dto;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class RolePermissionDTO {
|
||||||
|
private Long roleId;
|
||||||
|
private List<Long> permissionIds;
|
||||||
|
private Long menuId;
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
package com.recovery.common.base.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class UserAuthDTO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户ID
|
||||||
|
*/
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
private String userName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户密码
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户状态:1-有效;0-禁用
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户角色编码集合 ["ROOT","ADMIN"]
|
||||||
|
*/
|
||||||
|
|
||||||
|
private List<String> roles;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.recovery.common.base.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class UserAuthorityDto implements Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 姓名
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手机号
|
||||||
|
*/
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 账号
|
||||||
|
*/
|
||||||
|
private String userName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.recovery.common.base.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
* @date: 2022/5/23
|
||||||
|
*/
|
||||||
|
public enum ClientEnums {
|
||||||
|
MEMBER_CLIENT("member","会员客户端"),
|
||||||
|
ADMIN_CLIENT("ams","后台客户端");
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private String name;
|
||||||
|
@Getter
|
||||||
|
private String desc;
|
||||||
|
ClientEnums(String name, String desc) {
|
||||||
|
this.name = name;
|
||||||
|
this.desc = desc;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.recovery.common.base.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:
|
||||||
|
*/
|
||||||
|
public enum PasswordEncoderTypeEnum {
|
||||||
|
//
|
||||||
|
BCRYPT("{bcrypt}","BCRYPT加密"),
|
||||||
|
NOOP("{noop}","无加密明文");
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private String prefix;
|
||||||
|
|
||||||
|
PasswordEncoderTypeEnum(String prefix, String desc){
|
||||||
|
this.prefix=prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.recovery.common.base.po.base;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by YHYR on 2017-12-25
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@TableName("db_info")
|
||||||
|
public class DBInfo implements Serializable {
|
||||||
|
|
||||||
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
|
private int id;
|
||||||
|
|
||||||
|
private String dbName;
|
||||||
|
|
||||||
|
private String dbIp;
|
||||||
|
|
||||||
|
private int dbPort;
|
||||||
|
|
||||||
|
private String dbUser;
|
||||||
|
|
||||||
|
private String dbPasswd;
|
||||||
|
|
||||||
|
private String module;
|
||||||
|
|
||||||
|
private String hospitalHost;
|
||||||
|
|
||||||
|
private String hospitalCode;
|
||||||
|
}
|
|
@ -0,0 +1,140 @@
|
||||||
|
package com.recovery.common.base.po.base;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存储客户端的配置信息
|
||||||
|
* @TableName oauth_client_details
|
||||||
|
*/
|
||||||
|
@TableName(value ="oauth_client_details")
|
||||||
|
@Data
|
||||||
|
public class OauthClientDetails implements Serializable {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@TableId
|
||||||
|
private String clientId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private String resourceIds;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private String clientSecret;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private String scope;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private String authorizedGrantTypes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private String webServerRedirectUri;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private String authorities;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Integer accessTokenValidity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Integer refreshTokenValidity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private String additionalInformation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private String autoapprove;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object that) {
|
||||||
|
if (this == that) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (that == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (getClass() != that.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
OauthClientDetails other = (OauthClientDetails) that;
|
||||||
|
return (this.getClientId() == null ? other.getClientId() == null : this.getClientId().equals(other.getClientId()))
|
||||||
|
&& (this.getResourceIds() == null ? other.getResourceIds() == null : this.getResourceIds().equals(other.getResourceIds()))
|
||||||
|
&& (this.getClientSecret() == null ? other.getClientSecret() == null : this.getClientSecret().equals(other.getClientSecret()))
|
||||||
|
&& (this.getScope() == null ? other.getScope() == null : this.getScope().equals(other.getScope()))
|
||||||
|
&& (this.getAuthorizedGrantTypes() == null ? other.getAuthorizedGrantTypes() == null : this.getAuthorizedGrantTypes().equals(other.getAuthorizedGrantTypes()))
|
||||||
|
&& (this.getWebServerRedirectUri() == null ? other.getWebServerRedirectUri() == null : this.getWebServerRedirectUri().equals(other.getWebServerRedirectUri()))
|
||||||
|
&& (this.getAuthorities() == null ? other.getAuthorities() == null : this.getAuthorities().equals(other.getAuthorities()))
|
||||||
|
&& (this.getAccessTokenValidity() == null ? other.getAccessTokenValidity() == null : this.getAccessTokenValidity().equals(other.getAccessTokenValidity()))
|
||||||
|
&& (this.getRefreshTokenValidity() == null ? other.getRefreshTokenValidity() == null : this.getRefreshTokenValidity().equals(other.getRefreshTokenValidity()))
|
||||||
|
&& (this.getAdditionalInformation() == null ? other.getAdditionalInformation() == null : this.getAdditionalInformation().equals(other.getAdditionalInformation()))
|
||||||
|
&& (this.getAutoapprove() == null ? other.getAutoapprove() == null : this.getAutoapprove().equals(other.getAutoapprove()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + ((getClientId() == null) ? 0 : getClientId().hashCode());
|
||||||
|
result = prime * result + ((getResourceIds() == null) ? 0 : getResourceIds().hashCode());
|
||||||
|
result = prime * result + ((getClientSecret() == null) ? 0 : getClientSecret().hashCode());
|
||||||
|
result = prime * result + ((getScope() == null) ? 0 : getScope().hashCode());
|
||||||
|
result = prime * result + ((getAuthorizedGrantTypes() == null) ? 0 : getAuthorizedGrantTypes().hashCode());
|
||||||
|
result = prime * result + ((getWebServerRedirectUri() == null) ? 0 : getWebServerRedirectUri().hashCode());
|
||||||
|
result = prime * result + ((getAuthorities() == null) ? 0 : getAuthorities().hashCode());
|
||||||
|
result = prime * result + ((getAccessTokenValidity() == null) ? 0 : getAccessTokenValidity().hashCode());
|
||||||
|
result = prime * result + ((getRefreshTokenValidity() == null) ? 0 : getRefreshTokenValidity().hashCode());
|
||||||
|
result = prime * result + ((getAdditionalInformation() == null) ? 0 : getAdditionalInformation().hashCode());
|
||||||
|
result = prime * result + ((getAutoapprove() == null) ? 0 : getAutoapprove().hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append(getClass().getSimpleName());
|
||||||
|
sb.append(" [");
|
||||||
|
sb.append("Hash = ").append(hashCode());
|
||||||
|
sb.append(", clientId=").append(clientId);
|
||||||
|
sb.append(", resourceIds=").append(resourceIds);
|
||||||
|
sb.append(", clientSecret=").append(clientSecret);
|
||||||
|
sb.append(", scope=").append(scope);
|
||||||
|
sb.append(", authorizedGrantTypes=").append(authorizedGrantTypes);
|
||||||
|
sb.append(", webServerRedirectUri=").append(webServerRedirectUri);
|
||||||
|
sb.append(", authorities=").append(authorities);
|
||||||
|
sb.append(", accessTokenValidity=").append(accessTokenValidity);
|
||||||
|
sb.append(", refreshTokenValidity=").append(refreshTokenValidity);
|
||||||
|
sb.append(", additionalInformation=").append(additionalInformation);
|
||||||
|
sb.append(", autoapprove=").append(autoapprove);
|
||||||
|
sb.append(", serialVersionUID=").append(serialVersionUID);
|
||||||
|
sb.append("]");
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,95 @@
|
||||||
|
package com.recovery.common.base.result;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created with IntelliJ IDEA.
|
||||||
|
*
|
||||||
|
* @author:
|
||||||
|
* @date:2021/11/24
|
||||||
|
* @description:
|
||||||
|
* @modifiedBy:
|
||||||
|
* @version: 1.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public class ApiResult<T> implements Serializable {
|
||||||
|
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
private T data;
|
||||||
|
|
||||||
|
private String msg;
|
||||||
|
|
||||||
|
private Integer total;
|
||||||
|
|
||||||
|
public static <T> ApiResult<T> ok() {
|
||||||
|
return ok(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> ApiResult<T> ok(T data) {
|
||||||
|
ResultCode rce = ResultCode.SUCCESS;
|
||||||
|
if (data instanceof Boolean && Boolean.FALSE.equals(data)) {
|
||||||
|
rce = ResultCode.SYSTEM_EXECUTION_ERROR;
|
||||||
|
}
|
||||||
|
return result(rce, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> ApiResult<T> ok(T data, Long total) {
|
||||||
|
ApiResult<T> result = new ApiResult<>();
|
||||||
|
result.setCode(ResultCode.SUCCESS.getCode());
|
||||||
|
result.setMsg(ResultCode.SUCCESS.getMsg());
|
||||||
|
result.setData(data);
|
||||||
|
result.setTotal(total.intValue());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static <T> ApiResult<T> failed() {
|
||||||
|
return result(ResultCode.SYSTEM_EXECUTION_ERROR.getCode(), ResultCode.SYSTEM_EXECUTION_ERROR.getMsg(), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> ApiResult<T> failed(String msg) {
|
||||||
|
return result(ResultCode.SYSTEM_EXECUTION_ERROR.getCode(), msg, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> ApiResult<T> judge(boolean status) {
|
||||||
|
if (status) {
|
||||||
|
return ok();
|
||||||
|
} else {
|
||||||
|
return failed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> ApiResult<T> failed(IResultCode resultCode) {
|
||||||
|
return result(resultCode.getCode(), resultCode.getMsg(), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> ApiResult<T> failed(IResultCode resultCode, String msg) {
|
||||||
|
return result(resultCode.getCode(), msg, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> ApiResult<T> failed(String code, String msg) {
|
||||||
|
return result(code, msg, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> ApiResult<T> result(IResultCode resultCode, T data) {
|
||||||
|
return result(resultCode.getCode(), resultCode.getMsg(), data);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> ApiResult<T> result(String code, String msg, T data) {
|
||||||
|
ApiResult<T> result = new ApiResult<>();
|
||||||
|
result.setCode(code);
|
||||||
|
result.setData(data);
|
||||||
|
result.setMsg(msg);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static boolean isSuccess(ApiResult<?> result) {
|
||||||
|
return result != null && ResultCode.SUCCESS.getCode().equals(result.getCode());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.recovery.common.base.result;
|
||||||
|
|
||||||
|
public interface IResultCode {
|
||||||
|
|
||||||
|
|
||||||
|
String getCode();
|
||||||
|
|
||||||
|
String getMsg();
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
package com.recovery.common.base.result;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created with IntelliJ IDEA.
|
||||||
|
*
|
||||||
|
* @author:
|
||||||
|
* @date:2021/11/24
|
||||||
|
* @description:
|
||||||
|
* @modifiedBy:
|
||||||
|
* @version: 1.0
|
||||||
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public enum ResultCode implements IResultCode, Serializable {
|
||||||
|
|
||||||
|
SUCCESS("200", "成功"),
|
||||||
|
SYSTEM_EXECUTION_ERROR("999999", "系统执行出错"),
|
||||||
|
USERNAME_OR_PASSWORD_ERROR("A00100", "用户名或密码错误"),
|
||||||
|
USER_NOT_EXIST("A00101", "用户不存在"),
|
||||||
|
CLIENT_AUTHENTICATION_FAILED("A00212", "客户端认证失败"),
|
||||||
|
ACCESS_UNAUTHORIZED("A00213", "未授权"),
|
||||||
|
TOKEN_INVALID_OR_EXPIRED("A00214", "token非法或失效"),
|
||||||
|
TOKEN_ACCESS_FORBIDDEN("A00215", "token禁止访问"),
|
||||||
|
FLOW_LIMITING("B0210", "系统限流"),
|
||||||
|
DEGRADATION("B0220", "系统功能降级"),
|
||||||
|
SERVICE_NO_AUTHORITY("B0221", "服务未授权"),
|
||||||
|
;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMsg() {
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
private String msg;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "{" +
|
||||||
|
"\"code\":\"" + code + '\"' +
|
||||||
|
", \"msg\":\"" + msg + '\"' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue