Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
govdna
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
开发共享交流平台
govdna
Commits
8bd28814
Commit
8bd28814
authored
Aug 06, 2018
by
Fred
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
http://115.233.227.46:8066/root/govdna.git
parents
Show whitespace changes
Inline
Side-by-side
Showing
43 changed files
with
2330 additions
and
0 deletions
+2330
-0
.classpath
.classpath
+36
-0
.gitignore
.gitignore
+1
-0
.project
.project
+23
-0
org.eclipse.core.resources.prefs
.settings/org.eclipse.core.resources.prefs
+6
-0
org.eclipse.jdt.core.prefs
.settings/org.eclipse.jdt.core.prefs
+5
-0
org.eclipse.m2e.core.prefs
.settings/org.eclipse.m2e.core.prefs
+4
-0
pom.xml
pom.xml
+200
-0
RenrenApplication.java
src/main/java/com/govmade/RenrenApplication.java
+25
-0
OAuth2Filter.java
src/main/java/com/govmade/common/oauth2/OAuth2Filter.java
+0
-0
OAuth2Realm.java
src/main/java/com/govmade/common/oauth2/OAuth2Realm.java
+0
-0
OAuth2Token.java
src/main/java/com/govmade/common/oauth2/OAuth2Token.java
+0
-0
TokenGenerator.java
src/main/java/com/govmade/common/oauth2/TokenGenerator.java
+0
-0
Constant.java
src/main/java/com/govmade/common/utils/Constant.java
+46
-0
MyMetaObjectHandler.java
...in/java/com/govmade/common/utils/MyMetaObjectHandler.java
+42
-0
PageUtils.java
src/main/java/com/govmade/common/utils/PageUtils.java
+99
-0
Query.java
src/main/java/com/govmade/common/utils/Query.java
+91
-0
R.java
src/main/java/com/govmade/common/utils/R.java
+58
-0
HTMLFilter.java
src/main/java/com/govmade/common/xss/HTMLFilter.java
+531
-0
SQLFilter.java
src/main/java/com/govmade/common/xss/SQLFilter.java
+42
-0
XssFilter.java
src/main/java/com/govmade/common/xss/XssFilter.java
+31
-0
XssHttpServletRequestWrapper.java
.../com/govmade/common/xss/XssHttpServletRequestWrapper.java
+140
-0
CorsConfig.java
src/main/java/com/govmade/config/CorsConfig.java
+19
-0
MybatisPlusConfig.java
src/main/java/com/govmade/config/MybatisPlusConfig.java
+25
-0
ShiroConfig.java
src/main/java/com/govmade/config/ShiroConfig.java
+90
-0
SwaggerConfig.java
src/main/java/com/govmade/config/SwaggerConfig.java
+47
-0
DataSourceNames.java
src/main/java/com/govmade/datasources/DataSourceNames.java
+12
-0
DynamicDataSource.java
src/main/java/com/govmade/datasources/DynamicDataSource.java
+40
-0
DynamicDataSourceConfig.java
...java/com/govmade/datasources/DynamicDataSourceConfig.java
+35
-0
AbstractController.java
.../govmade/modules/basic/controller/AbstractController.java
+29
-0
BaseEntity.java
...ain/java/com/govmade/modules/basic/entity/BaseEntity.java
+71
-0
UserController.java
...com/govmade/modules/system/controller/UserController.java
+80
-0
UserDao.java
src/main/java/com/govmade/modules/system/dao/UserDao.java
+36
-0
UserEntity.java
...in/java/com/govmade/modules/system/entity/UserEntity.java
+109
-0
UserService.java
.../java/com/govmade/modules/system/service/UserService.java
+42
-0
UserServiceImpl.java
.../govmade/modules/system/service/impl/UserServiceImpl.java
+65
-0
application-dev.yml
src/main/resources/application-dev.yml
+34
-0
application-prod.yml
src/main/resources/application-prod.yml
+38
-0
application-test.yml
src/main/resources/application-test.yml
+38
-0
application.yml
src/main/resources/application.yml
+76
-0
logback-spring.xml
src/main/resources/logback-spring.xml
+22
-0
index.html
src/main/resources/static/index.html
+2
-0
UserTest.java
src/test/java/test/UserTest.java
+29
-0
SysUserDao.xml
src/test/resources/mapper/system/SysUserDao.xml
+11
-0
No files found.
.classpath
0 → 100644
View file @
8bd28814
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry
kind=
"src"
output=
"target/classes"
path=
"src/main/java"
>
<attributes>
<attribute
name=
"optional"
value=
"true"
/>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
excluding=
"**"
kind=
"src"
output=
"target/classes"
path=
"src/main/resources"
>
<attributes>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"src"
output=
"target/test-classes"
path=
"src/test/java"
>
<attributes>
<attribute
name=
"optional"
value=
"true"
/>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
excluding=
"**"
kind=
"src"
output=
"target/test-classes"
path=
"src/test/resources"
>
<attributes>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"con"
path=
"org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"
>
<attributes>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"con"
path=
"org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"
>
<attributes>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"output"
path=
"target/classes"
/>
</classpath>
.gitignore
0 → 100644
View file @
8bd28814
/target/
.project
0 → 100644
View file @
8bd28814
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>
govdna
</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>
org.eclipse.jdt.core.javabuilder
</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>
org.eclipse.m2e.core.maven2Builder
</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>
org.eclipse.jdt.core.javanature
</nature>
<nature>
org.eclipse.m2e.core.maven2Nature
</nature>
</natures>
</projectDescription>
.settings/org.eclipse.core.resources.prefs
0 → 100644
View file @
8bd28814
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8
.settings/org.eclipse.jdt.core.prefs
0 → 100644
View file @
8bd28814
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8
.settings/org.eclipse.m2e.core.prefs
0 → 100644
View file @
8bd28814
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
pom.xml
0 → 100644
View file @
8bd28814
<?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>
<groupId>
com.govmade
</groupId>
<artifactId>
govdna
</artifactId>
<version>
0.0.1
</version>
<packaging>
jar
</packaging>
<description>
govdna
</description>
<parent>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<version>
1.5.10.RELEASE
</version>
</parent>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<project.reporting.outputEncoding>
UTF-8
</project.reporting.outputEncoding>
<java.version>
1.8
</java.version>
<mybatisplus.spring.boot.version>
1.0.5
</mybatisplus.spring.boot.version>
<mybatisplus.version>
2.1.9
</mybatisplus.version>
<mysql.version>
5.1.38
</mysql.version>
<druid.version>
1.1.3
</druid.version>
<quartz.version>
2.3.0
</quartz.version>
<commons.lang.version>
2.6
</commons.lang.version>
<commons.fileupload.version>
1.3.1
</commons.fileupload.version>
<commons.io.version>
2.5
</commons.io.version>
<commons.codec.version>
1.10
</commons.codec.version>
<commons.configuration.version>
1.10
</commons.configuration.version>
<shiro.version>
1.3.2
</shiro.version>
<jwt.version>
0.7.0
</jwt.version>
<kaptcha.version>
0.0.9
</kaptcha.version>
<aliyun.oss.version>
2.5.0
</aliyun.oss.version>
<swagger.version>
2.2.2
</swagger.version>
<hutool.version>
4.1.0
</hutool.version>
</properties>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-aop
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-context-support
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-configuration-processor
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-devtools
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
com.baomidou
</groupId>
<artifactId>
mybatisplus-spring-boot-starter
</artifactId>
<version>
${mybatisplus.spring.boot.version}
</version>
</dependency>
<dependency>
<groupId>
com.baomidou
</groupId>
<artifactId>
mybatis-plus
</artifactId>
<version>
${mybatisplus.version}
</version>
</dependency>
<dependency>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
druid-spring-boot-starter
</artifactId>
<version>
${druid.version}
</version>
</dependency>
<dependency>
<groupId>
org.quartz-scheduler
</groupId>
<artifactId>
quartz
</artifactId>
<version>
${quartz.version}
</version>
<exclusions>
<exclusion>
<groupId>
com.mchange
</groupId>
<artifactId>
c3p0
</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>
commons-lang
</groupId>
<artifactId>
commons-lang
</artifactId>
<version>
${commons.lang.version}
</version>
</dependency>
<dependency>
<groupId>
commons-fileupload
</groupId>
<artifactId>
commons-fileupload
</artifactId>
<version>
${commons.fileupload.version}
</version>
</dependency>
<dependency>
<groupId>
commons-io
</groupId>
<artifactId>
commons-io
</artifactId>
<version>
${commons.io.version}
</version>
</dependency>
<dependency>
<groupId>
commons-codec
</groupId>
<artifactId>
commons-codec
</artifactId>
</dependency>
<dependency>
<groupId>
commons-configuration
</groupId>
<artifactId>
commons-configuration
</artifactId>
<version>
${commons.configuration.version}
</version>
</dependency>
<dependency>
<groupId>
org.apache.shiro
</groupId>
<artifactId>
shiro-core
</artifactId>
<version>
${shiro.version}
</version>
</dependency>
<dependency>
<groupId>
org.apache.shiro
</groupId>
<artifactId>
shiro-spring
</artifactId>
<version>
${shiro.version}
</version>
</dependency>
<dependency>
<groupId>
io.jsonwebtoken
</groupId>
<artifactId>
jjwt
</artifactId>
<version>
${jwt.version}
</version>
</dependency>
<dependency>
<groupId>
com.github.axet
</groupId>
<artifactId>
kaptcha
</artifactId>
<version>
${kaptcha.version}
</version>
</dependency>
<dependency>
<groupId>
com.aliyun.oss
</groupId>
<artifactId>
aliyun-sdk-oss
</artifactId>
<version>
${aliyun.oss.version}
</version>
</dependency>
<dependency>
<groupId>
cn.hutool
</groupId>
<artifactId>
hutool-all
</artifactId>
<version>
${hutool.version}
</version>
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger2
</artifactId>
<version>
${swagger.version}
</version>
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger-ui
</artifactId>
<version>
${swagger.version}
</version>
</dependency>
</dependencies>
<build>
<finalName>
${project.artifactId}
</finalName>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
<configuration>
<fork>
true
</fork>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>
public
</id>
<name>
aliyun nexus
</name>
<url>
http://maven.aliyun.com/nexus/content/groups/public/
</url>
<releases>
<enabled>
true
</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>
public
</id>
<name>
aliyun nexus
</name>
<url>
http://maven.aliyun.com/nexus/content/groups/public/
</url>
<releases>
<enabled>
true
</enabled>
</releases>
<snapshots>
<enabled>
false
</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
\ No newline at end of file
src/main/java/com/govmade/RenrenApplication.java
0 → 100644
View file @
8bd28814
package
com
.
govmade
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.web.support.SpringBootServletInitializer
;
import
org.springframework.context.annotation.Import
;
import
com.govmade.datasources.DynamicDataSourceConfig
;
@SpringBootApplication
(
exclude
={
DataSourceAutoConfiguration
.
class
})
@Import
({
DynamicDataSourceConfig
.
class
})
public
class
RenrenApplication
extends
SpringBootServletInitializer
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
RenrenApplication
.
class
,
args
);
}
@Override
protected
SpringApplicationBuilder
configure
(
SpringApplicationBuilder
application
)
{
return
application
.
sources
(
RenrenApplication
.
class
);
}
}
src/main/java/com/govmade/common/oauth2/OAuth2Filter.java
0 → 100644
View file @
8bd28814
src/main/java/com/govmade/common/oauth2/OAuth2Realm.java
0 → 100644
View file @
8bd28814
src/main/java/com/govmade/common/oauth2/OAuth2Token.java
0 → 100644
View file @
8bd28814
src/main/java/com/govmade/common/oauth2/TokenGenerator.java
0 → 100644
View file @
8bd28814
src/main/java/com/govmade/common/utils/Constant.java
0 → 100644
View file @
8bd28814
package
com
.
govmade
.
common
.
utils
;
/**
* 常量类
*
* @author Fred
* @email fangtaosh@qq.com
* @date 2018年8月3日
*/
public
class
Constant
{
/** 超级管理员ID */
public
static
final
int
SUPER_ADMIN
=
1
;
/**
* 菜单类型
*
* @author Fred
* @email fangtaosh@qq.com
* @date 2018年8月3日
*/
public
enum
MenuType
{
/**
* 目录
*/
CATALOG
(
0
),
/**
* 菜单
*/
MENU
(
1
),
/**
* 按钮
*/
BUTTON
(
2
);
private
int
value
;
MenuType
(
int
value
)
{
this
.
value
=
value
;
}
public
int
getValue
()
{
return
value
;
}
}
}
src/main/java/com/govmade/common/utils/MyMetaObjectHandler.java
0 → 100644
View file @
8bd28814
package
com
.
govmade
.
common
.
utils
;
import
java.util.Date
;
import
org.apache.ibatis.reflection.MetaObject
;
import
com.baomidou.mybatisplus.mapper.MetaObjectHandler
;
import
com.govmade.modules.system.entity.UserEntity
;
import
cn.hutool.core.date.DateUtil
;
public
class
MyMetaObjectHandler
extends
MetaObjectHandler
{
@Override
public
void
insertFill
(
MetaObject
metaObject
)
{
//获取当前登录用户
UserEntity
ue
=
new
UserEntity
();
ue
.
setId
(
1L
);
// 获取当前时间
Date
date
=
DateUtil
.
date
();
metaObject
.
setValue
(
"createBy"
,
ue
.
getId
());
metaObject
.
setValue
(
"modifyBy"
,
ue
.
getId
());
metaObject
.
setValue
(
"createTime"
,
date
);
metaObject
.
setValue
(
"modifyTime"
,
date
);
setFieldValByName
(
"state"
,
1
,
metaObject
);
}
@Override
public
void
updateFill
(
MetaObject
metaObject
)
{
//获取当前登录用户
UserEntity
ue
=
new
UserEntity
();
ue
.
setId
(
1L
);
// 获取当前时间
Date
date
=
DateUtil
.
date
();
metaObject
.
setValue
(
"modifyBy"
,
ue
.
getId
());
metaObject
.
setValue
(
"modifyTime"
,
date
);
}
}
src/main/java/com/govmade/common/utils/PageUtils.java
0 → 100644
View file @
8bd28814
package
com
.
govmade
.
common
.
utils
;
import
com.baomidou.mybatisplus.plugins.Page
;
import
java.io.Serializable
;
import
java.util.List
;
/**
* 分页工具类
*
* @author Fred
* @email fangtaosh@qq.com
* @date 2018年8月3日
*/
public
class
PageUtils
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
int
totalCount
;
// 总记录数
private
int
pageSize
;
// 每页记录数
private
int
totalPage
;
// 总页数
private
int
currPage
;
// 当前页数
private
List
<?>
list
;
// 列表数据
/**
* 分页
*
* @param list
* 列表数据
* @param totalCount
* 总记录数
* @param pageSize
* 每页记录数
* @param currPage
* 当前页数
*/
public
PageUtils
(
List
<?>
list
,
int
totalCount
,
int
pageSize
,
int
currPage
)
{
this
.
list
=
list
;
this
.
totalCount
=
totalCount
;
this
.
pageSize
=
pageSize
;
this
.
currPage
=
currPage
;
this
.
totalPage
=
(
int
)
Math
.
ceil
((
double
)
totalCount
/
pageSize
);
}
/**
* 分页
*/
public
PageUtils
(
Page
<?>
page
)
{
this
.
list
=
page
.
getRecords
();
this
.
totalCount
=
page
.
getTotal
();
this
.
pageSize
=
page
.
getSize
();
this
.
currPage
=
page
.
getCurrent
();
this
.
totalPage
=
page
.
getPages
();
}
public
int
getTotalCount
()
{
return
totalCount
;
}
public
void
setTotalCount
(
int
totalCount
)
{
this
.
totalCount
=
totalCount
;
}
public
int
getPageSize
()
{
return
pageSize
;
}
public
void
setPageSize
(
int
pageSize
)
{
this
.
pageSize
=
pageSize
;
}
public
int
getTotalPage
()
{
return
totalPage
;
}
public
void
setTotalPage
(
int
totalPage
)
{
this
.
totalPage
=
totalPage
;
}
public
int
getCurrPage
()
{
return
currPage
;
}
public
void
setCurrPage
(
int
currPage
)
{
this
.
currPage
=
currPage
;
}
public
List
<?>
getList
()
{
return
list
;
}
public
void
setList
(
List
<?>
list
)
{
this
.
list
=
list
;
}
}
src/main/java/com/govmade/common/utils/Query.java
0 → 100644
View file @
8bd28814
/**
* Copyright 2018 人人开源 http://www.renren.io
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package
com
.
govmade
.
common
.
utils
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
import
org.apache.commons.lang.StringUtils
;
import
com.baomidou.mybatisplus.plugins.Page
;
import
com.govmade.common.xss.SQLFilter
;
/**
* 查询参数
*
* @author Mark sunlightcs@gmail.com
* @since 2.0.0 2017-03-14
*/
public
class
Query
<
T
>
extends
LinkedHashMap
<
String
,
Object
>
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* mybatis-plus分页参数
*/
private
Page
<
T
>
page
;
/**
* 当前页码
*/
private
int
currPage
=
1
;
/**
* 每页条数
*/
private
int
limit
=
10
;
public
Query
(
Map
<
String
,
Object
>
params
){
this
.
putAll
(
params
);
//分页参数
if
(
params
.
get
(
"page"
)
!=
null
){
currPage
=
Integer
.
parseInt
((
String
)
params
.
get
(
"page"
));
}
if
(
params
.
get
(
"limit"
)
!=
null
){
limit
=
Integer
.
parseInt
((
String
)
params
.
get
(
"limit"
));
}
this
.
put
(
"offset"
,
(
currPage
-
1
)
*
limit
);
this
.
put
(
"page"
,
currPage
);
this
.
put
(
"limit"
,
limit
);
//防止SQL注入(因为sidx、order是通过拼接SQL实现排序的,会有SQL注入风险)
String
sidx
=
SQLFilter
.
sqlInject
((
String
)
params
.
get
(
"sidx"
));
String
order
=
SQLFilter
.
sqlInject
((
String
)
params
.
get
(
"order"
));
this
.
put
(
"sidx"
,
sidx
);
this
.
put
(
"order"
,
order
);
//mybatis-plus分页
this
.
page
=
new
Page
<>(
currPage
,
limit
);
//排序
if
(
StringUtils
.
isNotBlank
(
sidx
)
&&
StringUtils
.
isNotBlank
(
order
)){
this
.
page
.
setOrderByField
(
sidx
);
this
.
page
.
setAsc
(
"ASC"
.
equalsIgnoreCase
(
order
));
}
}
public
Page
<
T
>
getPage
()
{
return
page
;
}
public
int
getCurrPage
()
{
return
currPage
;
}
public
int
getLimit
()
{
return
limit
;
}
}
src/main/java/com/govmade/common/utils/R.java
0 → 100644
View file @
8bd28814
package
com
.
govmade
.
common
.
utils
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.apache.http.HttpStatus
;
/**
* 返回数据
*
* @author Fred
* @email fangtaosh@qq.com
* @date 2018年8月3日
*/
public
class
R
extends
HashMap
<
String
,
Object
>
{
private
static
final
long
serialVersionUID
=
1L
;
public
R
()
{
put
(
"code"
,
0
);
put
(
"msg"
,
"success"
);
}
public
static
R
error
()
{
return
error
(
HttpStatus
.
SC_INTERNAL_SERVER_ERROR
,
"未知异常,请联系管理员"
);
}
public
static
R
error
(
String
msg
)
{
return
error
(
HttpStatus
.
SC_INTERNAL_SERVER_ERROR
,
msg
);
}
public
static
R
error
(
int
code
,
String
msg
)
{
R
r
=
new
R
();
r
.
put
(
"code"
,
code
);
r
.
put
(
"msg"
,
msg
);
return
r
;
}
public
static
R
ok
(
String
msg
)
{
R
r
=
new
R
();
r
.
put
(
"msg"
,
msg
);
return
r
;
}
public
static
R
ok
(
Map
<
String
,
Object
>
map
)
{
R
r
=
new
R
();
r
.
putAll
(
map
);
return
r
;
}
public
static
R
ok
()
{
return
new
R
();
}
public
R
put
(
String
key
,
Object
value
)
{
super
.
put
(
key
,
value
);
return
this
;
}
}
src/main/java/com/govmade/common/xss/HTMLFilter.java
0 → 100644
View file @
8bd28814
package
com
.
govmade
.
common
.
xss
;
import
java.util.*
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentMap
;
import
java.util.logging.Logger
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
/**
*
* HTML filtering utility for protecting against XSS (Cross Site Scripting).
*
* This code is licensed LGPLv3
*
* This code is a Java port of the original work in PHP by Cal Hendersen.
* http://code.iamcal.com/php/lib_filter/
*
* The trickiest part of the translation was handling the differences in regex handling
* between PHP and Java. These resources were helpful in the process:
*
* http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html
* http://us2.php.net/manual/en/reference.pcre.pattern.modifiers.php
* http://www.regular-expressions.info/modifiers.html
*
* A note on naming conventions: instance variables are prefixed with a "v"; global
* constants are in all caps.
*
* Sample use:
* String input = ...
* String clean = new HTMLFilter().filter( input );
*
* The class is not thread safe. Create a new instance if in doubt.
*
* If you find bugs or have suggestions on improvement (especially regarding
* performance), please contact us. The latest version of this
* source, and our contact details, can be found at http://xss-html-filter.sf.net
*
* @author Joseph O'Connell
* @author Cal Hendersen
* @author Michael Semb Wever
*/
public
final
class
HTMLFilter
{
/** regex flag union representing /si modifiers in php **/
private
static
final
int
REGEX_FLAGS_SI
=
Pattern
.
CASE_INSENSITIVE
|
Pattern
.
DOTALL
;
private
static
final
Pattern
P_COMMENTS
=
Pattern
.
compile
(
"<!--(.*?)-->"
,
Pattern
.
DOTALL
);
private
static
final
Pattern
P_COMMENT
=
Pattern
.
compile
(
"^!--(.*)--$"
,
REGEX_FLAGS_SI
);
private
static
final
Pattern
P_TAGS
=
Pattern
.
compile
(
"<(.*?)>"
,
Pattern
.
DOTALL
);
private
static
final
Pattern
P_END_TAG
=
Pattern
.
compile
(
"^/([a-z0-9]+)"
,
REGEX_FLAGS_SI
);
private
static
final
Pattern
P_START_TAG
=
Pattern
.
compile
(
"^([a-z0-9]+)(.*?)(/?)$"
,
REGEX_FLAGS_SI
);
private
static
final
Pattern
P_QUOTED_ATTRIBUTES
=
Pattern
.
compile
(
"([a-z0-9]+)=([\"'])(.*?)\\2"
,
REGEX_FLAGS_SI
);
private
static
final
Pattern
P_UNQUOTED_ATTRIBUTES
=
Pattern
.
compile
(
"([a-z0-9]+)(=)([^\"\\s']+)"
,
REGEX_FLAGS_SI
);
private
static
final
Pattern
P_PROTOCOL
=
Pattern
.
compile
(
"^([^:]+):"
,
REGEX_FLAGS_SI
);
private
static
final
Pattern
P_ENTITY
=
Pattern
.
compile
(
"&#(\\d+);?"
);
private
static
final
Pattern
P_ENTITY_UNICODE
=
Pattern
.
compile
(
"&#x([0-9a-f]+);?"
);
private
static
final
Pattern
P_ENCODE
=
Pattern
.
compile
(
"%([0-9a-f]{2});?"
);
private
static
final
Pattern
P_VALID_ENTITIES
=
Pattern
.
compile
(
"&([^&;]*)(?=(;|&|$))"
);
private
static
final
Pattern
P_VALID_QUOTES
=
Pattern
.
compile
(
"(>|^)([^<]+?)(<|$)"
,
Pattern
.
DOTALL
);
private
static
final
Pattern
P_END_ARROW
=
Pattern
.
compile
(
"^>"
);
private
static
final
Pattern
P_BODY_TO_END
=
Pattern
.
compile
(
"<([^>]*?)(?=<|$)"
);
private
static
final
Pattern
P_XML_CONTENT
=
Pattern
.
compile
(
"(^|>)([^<]*?)(?=>)"
);
private
static
final
Pattern
P_STRAY_LEFT_ARROW
=
Pattern
.
compile
(
"<([^>]*?)(?=<|$)"
);
private
static
final
Pattern
P_STRAY_RIGHT_ARROW
=
Pattern
.
compile
(
"(^|>)([^<]*?)(?=>)"
);
private
static
final
Pattern
P_AMP
=
Pattern
.
compile
(
"&"
);
private
static
final
Pattern
P_QUOTE
=
Pattern
.
compile
(
"<"
);
private
static
final
Pattern
P_LEFT_ARROW
=
Pattern
.
compile
(
"<"
);
private
static
final
Pattern
P_RIGHT_ARROW
=
Pattern
.
compile
(
">"
);
private
static
final
Pattern
P_BOTH_ARROWS
=
Pattern
.
compile
(
"<>"
);
// @xxx could grow large... maybe use sesat's ReferenceMap
private
static
final
ConcurrentMap
<
String
,
Pattern
>
P_REMOVE_PAIR_BLANKS
=
new
ConcurrentHashMap
<
String
,
Pattern
>();
private
static
final
ConcurrentMap
<
String
,
Pattern
>
P_REMOVE_SELF_BLANKS
=
new
ConcurrentHashMap
<
String
,
Pattern
>();
/** set of allowed html elements, along with allowed attributes for each element **/
private
final
Map
<
String
,
List
<
String
>>
vAllowed
;
/** counts of open tags for each (allowable) html element **/
private
final
Map
<
String
,
Integer
>
vTagCounts
=
new
HashMap
<
String
,
Integer
>();
/** html elements which must always be self-closing (e.g. "<img />") **/
private
final
String
[]
vSelfClosingTags
;
/** html elements which must always have separate opening and closing tags (e.g. "<b></b>") **/
private
final
String
[]
vNeedClosingTags
;
/** set of disallowed html elements **/
private
final
String
[]
vDisallowed
;
/** attributes which should be checked for valid protocols **/
private
final
String
[]
vProtocolAtts
;
/** allowed protocols **/
private
final
String
[]
vAllowedProtocols
;
/** tags which should be removed if they contain no content (e.g. "<b></b>" or "<b />") **/
private
final
String
[]
vRemoveBlanks
;
/** entities allowed within html markup **/
private
final
String
[]
vAllowedEntities
;
/** flag determining whether comments are allowed in input String. */
private
final
boolean
stripComment
;
private
final
boolean
encodeQuotes
;
private
boolean
vDebug
=
false
;
/**
* flag determining whether to try to make tags when presented with "unbalanced"
* angle brackets (e.g. "<b text </b>" becomes "<b> text </b>"). If set to false,
* unbalanced angle brackets will be html escaped.
*/
private
final
boolean
alwaysMakeTags
;
/** Default constructor.
*
*/
public
HTMLFilter
()
{
vAllowed
=
new
HashMap
<>();
final
ArrayList
<
String
>
a_atts
=
new
ArrayList
<
String
>();
a_atts
.
add
(
"href"
);
a_atts
.
add
(
"target"
);
vAllowed
.
put
(
"a"
,
a_atts
);
final
ArrayList
<
String
>
img_atts
=
new
ArrayList
<
String
>();
img_atts
.
add
(
"src"
);
img_atts
.
add
(
"width"
);
img_atts
.
add
(
"height"
);
img_atts
.
add
(
"alt"
);
vAllowed
.
put
(
"img"
,
img_atts
);
final
ArrayList
<
String
>
no_atts
=
new
ArrayList
<
String
>();
vAllowed
.
put
(
"b"
,
no_atts
);
vAllowed
.
put
(
"strong"
,
no_atts
);
vAllowed
.
put
(
"i"
,
no_atts
);
vAllowed
.
put
(
"em"
,
no_atts
);
vSelfClosingTags
=
new
String
[]{
"img"
};
vNeedClosingTags
=
new
String
[]{
"a"
,
"b"
,
"strong"
,
"i"
,
"em"
};
vDisallowed
=
new
String
[]{};
vAllowedProtocols
=
new
String
[]{
"http"
,
"mailto"
,
"https"
};
// no ftp.
vProtocolAtts
=
new
String
[]{
"src"
,
"href"
};
vRemoveBlanks
=
new
String
[]{
"a"
,
"b"
,
"strong"
,
"i"
,
"em"
};
vAllowedEntities
=
new
String
[]{
"amp"
,
"gt"
,
"lt"
,
"quot"
};
stripComment
=
true
;
encodeQuotes
=
true
;
alwaysMakeTags
=
true
;
}
/** Set debug flag to true. Otherwise use default settings. See the default constructor.
*
* @param debug turn debug on with a true argument
*/
public
HTMLFilter
(
final
boolean
debug
)
{
this
();
vDebug
=
debug
;
}
/** Map-parameter configurable constructor.
*
* @param conf map containing configuration. keys match field names.
*/
public
HTMLFilter
(
final
Map
<
String
,
Object
>
conf
)
{
assert
conf
.
containsKey
(
"vAllowed"
)
:
"configuration requires vAllowed"
;
assert
conf
.
containsKey
(
"vSelfClosingTags"
)
:
"configuration requires vSelfClosingTags"
;
assert
conf
.
containsKey
(
"vNeedClosingTags"
)
:
"configuration requires vNeedClosingTags"
;
assert
conf
.
containsKey
(
"vDisallowed"
)
:
"configuration requires vDisallowed"
;
assert
conf
.
containsKey
(
"vAllowedProtocols"
)
:
"configuration requires vAllowedProtocols"
;
assert
conf
.
containsKey
(
"vProtocolAtts"
)
:
"configuration requires vProtocolAtts"
;
assert
conf
.
containsKey
(
"vRemoveBlanks"
)
:
"configuration requires vRemoveBlanks"
;
assert
conf
.
containsKey
(
"vAllowedEntities"
)
:
"configuration requires vAllowedEntities"
;
vAllowed
=
Collections
.
unmodifiableMap
((
HashMap
<
String
,
List
<
String
>>)
conf
.
get
(
"vAllowed"
));
vSelfClosingTags
=
(
String
[])
conf
.
get
(
"vSelfClosingTags"
);
vNeedClosingTags
=
(
String
[])
conf
.
get
(
"vNeedClosingTags"
);
vDisallowed
=
(
String
[])
conf
.
get
(
"vDisallowed"
);
vAllowedProtocols
=
(
String
[])
conf
.
get
(
"vAllowedProtocols"
);
vProtocolAtts
=
(
String
[])
conf
.
get
(
"vProtocolAtts"
);
vRemoveBlanks
=
(
String
[])
conf
.
get
(
"vRemoveBlanks"
);
vAllowedEntities
=
(
String
[])
conf
.
get
(
"vAllowedEntities"
);
stripComment
=
conf
.
containsKey
(
"stripComment"
)
?
(
Boolean
)
conf
.
get
(
"stripComment"
)
:
true
;
encodeQuotes
=
conf
.
containsKey
(
"encodeQuotes"
)
?
(
Boolean
)
conf
.
get
(
"encodeQuotes"
)
:
true
;
alwaysMakeTags
=
conf
.
containsKey
(
"alwaysMakeTags"
)
?
(
Boolean
)
conf
.
get
(
"alwaysMakeTags"
)
:
true
;
}
private
void
reset
()
{
vTagCounts
.
clear
();
}
private
void
debug
(
final
String
msg
)
{
if
(
vDebug
)
{
Logger
.
getAnonymousLogger
().
info
(
msg
);
}
}
//---------------------------------------------------------------
// my versions of some PHP library functions
public
static
String
chr
(
final
int
decimal
)
{
return
String
.
valueOf
((
char
)
decimal
);
}
public
static
String
htmlSpecialChars
(
final
String
s
)
{
String
result
=
s
;
result
=
regexReplace
(
P_AMP
,
"&"
,
result
);
result
=
regexReplace
(
P_QUOTE
,
"""
,
result
);
result
=
regexReplace
(
P_LEFT_ARROW
,
"<"
,
result
);
result
=
regexReplace
(
P_RIGHT_ARROW
,
">"
,
result
);
return
result
;
}
//---------------------------------------------------------------
/**
* given a user submitted input String, filter out any invalid or restricted
* html.
*
* @param input text (i.e. submitted by a user) than may contain html
* @return "clean" version of input, with only valid, whitelisted html elements allowed
*/
public
String
filter
(
final
String
input
)
{
reset
();
String
s
=
input
;
debug
(
"************************************************"
);
debug
(
" INPUT: "
+
input
);
s
=
escapeComments
(
s
);
debug
(
" escapeComments: "
+
s
);
s
=
balanceHTML
(
s
);
debug
(
" balanceHTML: "
+
s
);
s
=
checkTags
(
s
);
debug
(
" checkTags: "
+
s
);
s
=
processRemoveBlanks
(
s
);
debug
(
"processRemoveBlanks: "
+
s
);
s
=
validateEntities
(
s
);
debug
(
" validateEntites: "
+
s
);
debug
(
"************************************************\n\n"
);
return
s
;
}
public
boolean
isAlwaysMakeTags
(){
return
alwaysMakeTags
;
}
public
boolean
isStripComments
(){
return
stripComment
;
}
private
String
escapeComments
(
final
String
s
)
{
final
Matcher
m
=
P_COMMENTS
.
matcher
(
s
);
final
StringBuffer
buf
=
new
StringBuffer
();
if
(
m
.
find
())
{
final
String
match
=
m
.
group
(
1
);
//(.*?)
m
.
appendReplacement
(
buf
,
Matcher
.
quoteReplacement
(
"<!--"
+
htmlSpecialChars
(
match
)
+
"-->"
));
}
m
.
appendTail
(
buf
);
return
buf
.
toString
();
}
private
String
balanceHTML
(
String
s
)
{
if
(
alwaysMakeTags
)
{
//
// try and form html
//
s
=
regexReplace
(
P_END_ARROW
,
""
,
s
);
s
=
regexReplace
(
P_BODY_TO_END
,
"<$1>"
,
s
);
s
=
regexReplace
(
P_XML_CONTENT
,
"$1<$2"
,
s
);
}
else
{
//
// escape stray brackets
//
s
=
regexReplace
(
P_STRAY_LEFT_ARROW
,
"<$1"
,
s
);
s
=
regexReplace
(
P_STRAY_RIGHT_ARROW
,
"$1$2><"
,
s
);
//
// the last regexp causes '<>' entities to appear
// (we need to do a lookahead assertion so that the last bracket can
// be used in the next pass of the regexp)
//
s
=
regexReplace
(
P_BOTH_ARROWS
,
""
,
s
);
}
return
s
;
}
private
String
checkTags
(
String
s
)
{
Matcher
m
=
P_TAGS
.
matcher
(
s
);
final
StringBuffer
buf
=
new
StringBuffer
();
while
(
m
.
find
())
{
String
replaceStr
=
m
.
group
(
1
);
replaceStr
=
processTag
(
replaceStr
);
m
.
appendReplacement
(
buf
,
Matcher
.
quoteReplacement
(
replaceStr
));
}
m
.
appendTail
(
buf
);
s
=
buf
.
toString
();
// these get tallied in processTag
// (remember to reset before subsequent calls to filter method)
for
(
String
key
:
vTagCounts
.
keySet
())
{
for
(
int
ii
=
0
;
ii
<
vTagCounts
.
get
(
key
);
ii
++)
{
s
+=
"</"
+
key
+
">"
;
}
}
return
s
;
}
private
String
processRemoveBlanks
(
final
String
s
)
{
String
result
=
s
;
for
(
String
tag
:
vRemoveBlanks
)
{
if
(!
P_REMOVE_PAIR_BLANKS
.
containsKey
(
tag
)){
P_REMOVE_PAIR_BLANKS
.
putIfAbsent
(
tag
,
Pattern
.
compile
(
"<"
+
tag
+
"(\\s[^>]*)?></"
+
tag
+
">"
));
}
result
=
regexReplace
(
P_REMOVE_PAIR_BLANKS
.
get
(
tag
),
""
,
result
);
if
(!
P_REMOVE_SELF_BLANKS
.
containsKey
(
tag
)){
P_REMOVE_SELF_BLANKS
.
putIfAbsent
(
tag
,
Pattern
.
compile
(
"<"
+
tag
+
"(\\s[^>]*)?/>"
));
}
result
=
regexReplace
(
P_REMOVE_SELF_BLANKS
.
get
(
tag
),
""
,
result
);
}
return
result
;
}
private
static
String
regexReplace
(
final
Pattern
regex_pattern
,
final
String
replacement
,
final
String
s
)
{
Matcher
m
=
regex_pattern
.
matcher
(
s
);
return
m
.
replaceAll
(
replacement
);
}
private
String
processTag
(
final
String
s
)
{
// ending tags
Matcher
m
=
P_END_TAG
.
matcher
(
s
);
if
(
m
.
find
())
{
final
String
name
=
m
.
group
(
1
).
toLowerCase
();
if
(
allowed
(
name
))
{
if
(!
inArray
(
name
,
vSelfClosingTags
))
{
if
(
vTagCounts
.
containsKey
(
name
))
{
vTagCounts
.
put
(
name
,
vTagCounts
.
get
(
name
)
-
1
);
return
"</"
+
name
+
">"
;
}
}
}
}
// starting tags
m
=
P_START_TAG
.
matcher
(
s
);
if
(
m
.
find
())
{
final
String
name
=
m
.
group
(
1
).
toLowerCase
();
final
String
body
=
m
.
group
(
2
);
String
ending
=
m
.
group
(
3
);
//debug( "in a starting tag, name='" + name + "'; body='" + body + "'; ending='" + ending + "'" );
if
(
allowed
(
name
))
{
String
params
=
""
;
final
Matcher
m2
=
P_QUOTED_ATTRIBUTES
.
matcher
(
body
);
final
Matcher
m3
=
P_UNQUOTED_ATTRIBUTES
.
matcher
(
body
);
final
List
<
String
>
paramNames
=
new
ArrayList
<
String
>();
final
List
<
String
>
paramValues
=
new
ArrayList
<
String
>();
while
(
m2
.
find
())
{
paramNames
.
add
(
m2
.
group
(
1
));
//([a-z0-9]+)
paramValues
.
add
(
m2
.
group
(
3
));
//(.*?)
}
while
(
m3
.
find
())
{
paramNames
.
add
(
m3
.
group
(
1
));
//([a-z0-9]+)
paramValues
.
add
(
m3
.
group
(
3
));
//([^\"\\s']+)
}
String
paramName
,
paramValue
;
for
(
int
ii
=
0
;
ii
<
paramNames
.
size
();
ii
++)
{
paramName
=
paramNames
.
get
(
ii
).
toLowerCase
();
paramValue
=
paramValues
.
get
(
ii
);
// debug( "paramName='" + paramName + "'" );
// debug( "paramValue='" + paramValue + "'" );
// debug( "allowed? " + vAllowed.get( name ).contains( paramName ) );
if
(
allowedAttribute
(
name
,
paramName
))
{
if
(
inArray
(
paramName
,
vProtocolAtts
))
{
paramValue
=
processParamProtocol
(
paramValue
);
}
params
+=
" "
+
paramName
+
"=\""
+
paramValue
+
"\""
;
}
}
if
(
inArray
(
name
,
vSelfClosingTags
))
{
ending
=
" /"
;
}
if
(
inArray
(
name
,
vNeedClosingTags
))
{
ending
=
""
;
}
if
(
ending
==
null
||
ending
.
length
()
<
1
)
{
if
(
vTagCounts
.
containsKey
(
name
))
{
vTagCounts
.
put
(
name
,
vTagCounts
.
get
(
name
)
+
1
);
}
else
{
vTagCounts
.
put
(
name
,
1
);
}
}
else
{
ending
=
" /"
;
}
return
"<"
+
name
+
params
+
ending
+
">"
;
}
else
{
return
""
;
}
}
// comments
m
=
P_COMMENT
.
matcher
(
s
);
if
(!
stripComment
&&
m
.
find
())
{
return
"<"
+
m
.
group
()
+
">"
;
}
return
""
;
}
private
String
processParamProtocol
(
String
s
)
{
s
=
decodeEntities
(
s
);
final
Matcher
m
=
P_PROTOCOL
.
matcher
(
s
);
if
(
m
.
find
())
{
final
String
protocol
=
m
.
group
(
1
);
if
(!
inArray
(
protocol
,
vAllowedProtocols
))
{
// bad protocol, turn into local anchor link instead
s
=
"#"
+
s
.
substring
(
protocol
.
length
()
+
1
,
s
.
length
());
if
(
s
.
startsWith
(
"#//"
))
{
s
=
"#"
+
s
.
substring
(
3
,
s
.
length
());
}
}
}
return
s
;
}
private
String
decodeEntities
(
String
s
)
{
StringBuffer
buf
=
new
StringBuffer
();
Matcher
m
=
P_ENTITY
.
matcher
(
s
);
while
(
m
.
find
())
{
final
String
match
=
m
.
group
(
1
);
final
int
decimal
=
Integer
.
decode
(
match
).
intValue
();
m
.
appendReplacement
(
buf
,
Matcher
.
quoteReplacement
(
chr
(
decimal
)));
}
m
.
appendTail
(
buf
);
s
=
buf
.
toString
();
buf
=
new
StringBuffer
();
m
=
P_ENTITY_UNICODE
.
matcher
(
s
);
while
(
m
.
find
())
{
final
String
match
=
m
.
group
(
1
);
final
int
decimal
=
Integer
.
valueOf
(
match
,
16
).
intValue
();
m
.
appendReplacement
(
buf
,
Matcher
.
quoteReplacement
(
chr
(
decimal
)));
}
m
.
appendTail
(
buf
);
s
=
buf
.
toString
();
buf
=
new
StringBuffer
();
m
=
P_ENCODE
.
matcher
(
s
);
while
(
m
.
find
())
{
final
String
match
=
m
.
group
(
1
);
final
int
decimal
=
Integer
.
valueOf
(
match
,
16
).
intValue
();
m
.
appendReplacement
(
buf
,
Matcher
.
quoteReplacement
(
chr
(
decimal
)));
}
m
.
appendTail
(
buf
);
s
=
buf
.
toString
();
s
=
validateEntities
(
s
);
return
s
;
}
private
String
validateEntities
(
final
String
s
)
{
StringBuffer
buf
=
new
StringBuffer
();
// validate entities throughout the string
Matcher
m
=
P_VALID_ENTITIES
.
matcher
(
s
);
while
(
m
.
find
())
{
final
String
one
=
m
.
group
(
1
);
//([^&;]*)
final
String
two
=
m
.
group
(
2
);
//(?=(;|&|$))
m
.
appendReplacement
(
buf
,
Matcher
.
quoteReplacement
(
checkEntity
(
one
,
two
)));
}
m
.
appendTail
(
buf
);
return
encodeQuotes
(
buf
.
toString
());
}
private
String
encodeQuotes
(
final
String
s
){
if
(
encodeQuotes
){
StringBuffer
buf
=
new
StringBuffer
();
Matcher
m
=
P_VALID_QUOTES
.
matcher
(
s
);
while
(
m
.
find
())
{
final
String
one
=
m
.
group
(
1
);
//(>|^)
final
String
two
=
m
.
group
(
2
);
//([^<]+?)
final
String
three
=
m
.
group
(
3
);
//(<|$)
m
.
appendReplacement
(
buf
,
Matcher
.
quoteReplacement
(
one
+
regexReplace
(
P_QUOTE
,
"""
,
two
)
+
three
));
}
m
.
appendTail
(
buf
);
return
buf
.
toString
();
}
else
{
return
s
;
}
}
private
String
checkEntity
(
final
String
preamble
,
final
String
term
)
{
return
";"
.
equals
(
term
)
&&
isValidEntity
(
preamble
)
?
'&'
+
preamble
:
"&"
+
preamble
;
}
private
boolean
isValidEntity
(
final
String
entity
)
{
return
inArray
(
entity
,
vAllowedEntities
);
}
private
static
boolean
inArray
(
final
String
s
,
final
String
[]
array
)
{
for
(
String
item
:
array
)
{
if
(
item
!=
null
&&
item
.
equals
(
s
))
{
return
true
;
}
}
return
false
;
}
private
boolean
allowed
(
final
String
name
)
{
return
(
vAllowed
.
isEmpty
()
||
vAllowed
.
containsKey
(
name
))
&&
!
inArray
(
name
,
vDisallowed
);
}
private
boolean
allowedAttribute
(
final
String
name
,
final
String
paramName
)
{
return
allowed
(
name
)
&&
(
vAllowed
.
isEmpty
()
||
vAllowed
.
get
(
name
).
contains
(
paramName
));
}
}
\ No newline at end of file
src/main/java/com/govmade/common/xss/SQLFilter.java
0 → 100644
View file @
8bd28814
package
com
.
govmade
.
common
.
xss
;
import
org.apache.commons.lang.StringUtils
;
/**
* SQL过滤
* @author chenshun
* @email sunlightcs@gmail.com
* @date 2017-04-01 16:16
*/
public
class
SQLFilter
{
/**
* SQL注入过滤
* @param str 待验证的字符串
*/
public
static
String
sqlInject
(
String
str
){
if
(
StringUtils
.
isBlank
(
str
)){
return
null
;
}
//去掉'|"|;|\字符
str
=
StringUtils
.
replace
(
str
,
"'"
,
""
);
str
=
StringUtils
.
replace
(
str
,
"\""
,
""
);
str
=
StringUtils
.
replace
(
str
,
";"
,
""
);
str
=
StringUtils
.
replace
(
str
,
"\\"
,
""
);
//转换成小写
str
=
str
.
toLowerCase
();
//非法字符
String
[]
keywords
=
{
"master"
,
"truncate"
,
"insert"
,
"select"
,
"delete"
,
"update"
,
"declare"
,
"alert"
,
"drop"
};
//判断是否包含非法字符
for
(
String
keyword
:
keywords
){
if
(
str
.
indexOf
(
keyword
)
!=
-
1
){
// throw new RRException("包含非法字符");
}
}
return
str
;
}
}
src/main/java/com/govmade/common/xss/XssFilter.java
0 → 100644
View file @
8bd28814
package
com
.
govmade
.
common
.
xss
;
import
javax.servlet.*
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.IOException
;
/**
* XSS过滤
*
* @author chenshun
* @email sunlightcs@gmail.com
* @date 2017-04-01 10:20
*/
public
class
XssFilter
implements
Filter
{
@Override
public
void
init
(
FilterConfig
config
)
throws
ServletException
{
}
public
void
doFilter
(
ServletRequest
request
,
ServletResponse
response
,
FilterChain
chain
)
throws
IOException
,
ServletException
{
XssHttpServletRequestWrapper
xssRequest
=
new
XssHttpServletRequestWrapper
((
HttpServletRequest
)
request
);
chain
.
doFilter
(
xssRequest
,
response
);
}
@Override
public
void
destroy
()
{
}
}
\ No newline at end of file
src/main/java/com/govmade/common/xss/XssHttpServletRequestWrapper.java
0 → 100644
View file @
8bd28814
package
com
.
govmade
.
common
.
xss
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.MediaType
;
import
javax.servlet.ReadListener
;
import
javax.servlet.ServletInputStream
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequestWrapper
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
/**
* XSS过滤处理
* @author chenshun
* @email sunlightcs@gmail.com
* @date 2017-04-01 11:29
*/
public
class
XssHttpServletRequestWrapper
extends
HttpServletRequestWrapper
{
//没被包装过的HttpServletRequest(特殊场景,需要自己过滤)
HttpServletRequest
orgRequest
;
//html过滤
private
final
static
HTMLFilter
htmlFilter
=
new
HTMLFilter
();
public
XssHttpServletRequestWrapper
(
HttpServletRequest
request
)
{
super
(
request
);
orgRequest
=
request
;
}
@Override
public
ServletInputStream
getInputStream
()
throws
IOException
{
//非json类型,直接返回
if
(!
MediaType
.
APPLICATION_JSON_VALUE
.
equalsIgnoreCase
(
super
.
getHeader
(
HttpHeaders
.
CONTENT_TYPE
))){
return
super
.
getInputStream
();
}
//为空,直接返回
String
json
=
IOUtils
.
toString
(
super
.
getInputStream
(),
"utf-8"
);
if
(
StringUtils
.
isBlank
(
json
))
{
return
super
.
getInputStream
();
}
//xss过滤
json
=
xssEncode
(
json
);
final
ByteArrayInputStream
bis
=
new
ByteArrayInputStream
(
json
.
getBytes
(
"utf-8"
));
return
new
ServletInputStream
()
{
@Override
public
boolean
isFinished
()
{
return
true
;
}
@Override
public
boolean
isReady
()
{
return
true
;
}
@Override
public
void
setReadListener
(
ReadListener
readListener
)
{
}
@Override
public
int
read
()
throws
IOException
{
return
bis
.
read
();
}
};
}
@Override
public
String
getParameter
(
String
name
)
{
String
value
=
super
.
getParameter
(
xssEncode
(
name
));
if
(
StringUtils
.
isNotBlank
(
value
))
{
value
=
xssEncode
(
value
);
}
return
value
;
}
@Override
public
String
[]
getParameterValues
(
String
name
)
{
String
[]
parameters
=
super
.
getParameterValues
(
name
);
if
(
parameters
==
null
||
parameters
.
length
==
0
)
{
return
null
;
}
for
(
int
i
=
0
;
i
<
parameters
.
length
;
i
++)
{
parameters
[
i
]
=
xssEncode
(
parameters
[
i
]);
}
return
parameters
;
}
@Override
public
Map
<
String
,
String
[]>
getParameterMap
()
{
Map
<
String
,
String
[]>
map
=
new
LinkedHashMap
<>();
Map
<
String
,
String
[]>
parameters
=
super
.
getParameterMap
();
for
(
String
key
:
parameters
.
keySet
())
{
String
[]
values
=
parameters
.
get
(
key
);
for
(
int
i
=
0
;
i
<
values
.
length
;
i
++)
{
values
[
i
]
=
xssEncode
(
values
[
i
]);
}
map
.
put
(
key
,
values
);
}
return
map
;
}
@Override
public
String
getHeader
(
String
name
)
{
String
value
=
super
.
getHeader
(
xssEncode
(
name
));
if
(
StringUtils
.
isNotBlank
(
value
))
{
value
=
xssEncode
(
value
);
}
return
value
;
}
private
String
xssEncode
(
String
input
)
{
return
htmlFilter
.
filter
(
input
);
}
/**
* 获取最原始的request
*/
public
HttpServletRequest
getOrgRequest
()
{
return
orgRequest
;
}
/**
* 获取最原始的request
*/
public
static
HttpServletRequest
getOrgRequest
(
HttpServletRequest
request
)
{
if
(
request
instanceof
XssHttpServletRequestWrapper
)
{
return
((
XssHttpServletRequestWrapper
)
request
).
getOrgRequest
();
}
return
request
;
}
}
src/main/java/com/govmade/config/CorsConfig.java
0 → 100644
View file @
8bd28814
package
com
.
govmade
.
config
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.servlet.config.annotation.CorsRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
@Configuration
public
class
CorsConfig
extends
WebMvcConfigurerAdapter
{
@Override
public
void
addCorsMappings
(
CorsRegistry
registry
)
{
registry
.
addMapping
(
"/**"
)
.
allowedOrigins
(
"*"
)
.
allowCredentials
(
true
)
.
allowedMethods
(
"GET"
,
"POST"
,
"PUT"
,
"DELETE"
,
"OPTIONS"
)
.
maxAge
(
3600
);
}
}
\ No newline at end of file
src/main/java/com/govmade/config/MybatisPlusConfig.java
0 → 100644
View file @
8bd28814
package
com
.
govmade
.
config
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
com.baomidou.mybatisplus.plugins.PaginationInterceptor
;
/**
* mybatis-plus配置
*
* @author Fred
* @email fangtaosh@qq.com
* @date 2018年8月3日
*/
@Configuration
public
class
MybatisPlusConfig
{
/**
* 分页插件
*/
@Bean
public
PaginationInterceptor
paginationInterceptor
()
{
return
new
PaginationInterceptor
();
}
}
src/main/java/com/govmade/config/ShiroConfig.java
0 → 100644
View file @
8bd28814
package
com
.
govmade
.
config
;
import
org.apache.shiro.mgt.SecurityManager
;
import
org.apache.shiro.session.mgt.SessionManager
;
import
org.apache.shiro.spring.LifecycleBeanPostProcessor
;
import
org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor
;
import
org.apache.shiro.spring.web.ShiroFilterFactoryBean
;
import
org.apache.shiro.web.session.mgt.DefaultWebSessionManager
;
import
org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
javax.servlet.Filter
;
import
java.util.HashMap
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
/**
* Shiro配置
*
* @author chenshun
* @email sunlightcs@gmail.com
* @date 2017-04-20 18:33
*/
@Configuration
public
class
ShiroConfig
{
@Bean
(
"sessionManager"
)
public
SessionManager
sessionManager
(){
DefaultWebSessionManager
sessionManager
=
new
DefaultWebSessionManager
();
sessionManager
.
setSessionValidationSchedulerEnabled
(
true
);
sessionManager
.
setSessionIdCookieEnabled
(
true
);
return
sessionManager
;
}
// @Bean("securityManager")
// public SecurityManager securityManager(OAuth2Realm oAuth2Realm, SessionManager sessionManager) {
// DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
// securityManager.setRealm(oAuth2Realm);
// securityManager.setSessionManager(sessionManager);
//
// return securityManager;
// }
@Bean
(
"shiroFilter"
)
public
ShiroFilterFactoryBean
shirFilter
(
SecurityManager
securityManager
)
{
ShiroFilterFactoryBean
shiroFilter
=
new
ShiroFilterFactoryBean
();
shiroFilter
.
setSecurityManager
(
securityManager
);
//oauth过滤
Map
<
String
,
Filter
>
filters
=
new
HashMap
<>();
// filters.put("oauth2", new OAuth2Filter());
shiroFilter
.
setFilters
(
filters
);
Map
<
String
,
String
>
filterMap
=
new
LinkedHashMap
<>();
filterMap
.
put
(
"/webjars/**"
,
"anon"
);
filterMap
.
put
(
"/druid/**"
,
"anon"
);
filterMap
.
put
(
"/app/**"
,
"anon"
);
filterMap
.
put
(
"/sys/login"
,
"anon"
);
filterMap
.
put
(
"/swagger/**"
,
"anon"
);
filterMap
.
put
(
"/v2/api-docs"
,
"anon"
);
filterMap
.
put
(
"/swagger-ui.html"
,
"anon"
);
filterMap
.
put
(
"/swagger-resources/**"
,
"anon"
);
filterMap
.
put
(
"/captcha.jpg"
,
"anon"
);
filterMap
.
put
(
"/**"
,
"anon"
);
shiroFilter
.
setFilterChainDefinitionMap
(
filterMap
);
return
shiroFilter
;
}
@Bean
(
"lifecycleBeanPostProcessor"
)
public
LifecycleBeanPostProcessor
lifecycleBeanPostProcessor
()
{
return
new
LifecycleBeanPostProcessor
();
}
@Bean
public
DefaultAdvisorAutoProxyCreator
defaultAdvisorAutoProxyCreator
()
{
DefaultAdvisorAutoProxyCreator
proxyCreator
=
new
DefaultAdvisorAutoProxyCreator
();
proxyCreator
.
setProxyTargetClass
(
true
);
return
proxyCreator
;
}
@Bean
public
AuthorizationAttributeSourceAdvisor
authorizationAttributeSourceAdvisor
(
SecurityManager
securityManager
)
{
AuthorizationAttributeSourceAdvisor
advisor
=
new
AuthorizationAttributeSourceAdvisor
();
advisor
.
setSecurityManager
(
securityManager
);
return
advisor
;
}
}
src/main/java/com/govmade/config/SwaggerConfig.java
0 → 100644
View file @
8bd28814
package
com
.
govmade
.
config
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
import
springfox.documentation.builders.ApiInfoBuilder
;
import
springfox.documentation.builders.PathSelectors
;
import
springfox.documentation.builders.RequestHandlerSelectors
;
import
springfox.documentation.service.ApiInfo
;
import
springfox.documentation.spi.DocumentationType
;
import
springfox.documentation.spring.web.plugins.Docket
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
@Configuration
@EnableSwagger2
public
class
SwaggerConfig
extends
WebMvcConfigurerAdapter
{
@Override
public
void
addResourceHandlers
(
ResourceHandlerRegistry
registry
)
{
registry
.
addResourceHandler
(
"swagger-ui.html"
).
addResourceLocations
(
"classpath:/META-INF/resources/"
);
registry
.
addResourceHandler
(
"/webjars/**"
).
addResourceLocations
(
"classpath:/META-INF/resources/webjars/"
);
}
@Bean
public
Docket
createRestApi
()
{
return
new
Docket
(
DocumentationType
.
SWAGGER_2
)
.
apiInfo
(
apiInfo
())
.
select
()
.
apis
(
RequestHandlerSelectors
.
withMethodAnnotation
(
ApiOperation
.
class
))
//加了ApiOperation注解的方法,生成接口文档
.
apis
(
RequestHandlerSelectors
.
basePackage
(
"com.govmade.modules.system.controller"
))
//包下的类,生成接口文档
.
paths
(
PathSelectors
.
any
())
.
build
();
}
private
ApiInfo
apiInfo
()
{
return
new
ApiInfoBuilder
()
.
title
(
"数据基因"
)
.
description
(
"govdata接口文档"
)
.
termsOfServiceUrl
(
"http://www.govmade.cn"
)
.
version
(
"1.0"
)
.
build
();
}
}
\ No newline at end of file
src/main/java/com/govmade/datasources/DataSourceNames.java
0 → 100644
View file @
8bd28814
package
com
.
govmade
.
datasources
;
/**
* 增加多数据源,在此配置
*
* @author chenshun
* @email sunlightcs@gmail.com
* @date 2017/8/18 23:46
*/
public
interface
DataSourceNames
{
String
GOVMADE
=
"govmade"
;
}
src/main/java/com/govmade/datasources/DynamicDataSource.java
0 → 100644
View file @
8bd28814
package
com
.
govmade
.
datasources
;
import
org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource
;
import
javax.sql.DataSource
;
import
java.util.Map
;
/**
* 动态数据源
* @author chenshun
* @email sunlightcs@gmail.com
* @date 2017/8/19 1:03
*/
public
class
DynamicDataSource
extends
AbstractRoutingDataSource
{
private
static
final
ThreadLocal
<
String
>
contextHolder
=
new
ThreadLocal
<>();
public
DynamicDataSource
(
DataSource
defaultTargetDataSource
,
Map
<
Object
,
Object
>
targetDataSources
)
{
super
.
setDefaultTargetDataSource
(
defaultTargetDataSource
);
super
.
setTargetDataSources
(
targetDataSources
);
super
.
afterPropertiesSet
();
}
@Override
protected
Object
determineCurrentLookupKey
()
{
return
getDataSource
();
}
public
static
void
setDataSource
(
String
dataSource
)
{
contextHolder
.
set
(
dataSource
);
}
public
static
String
getDataSource
()
{
return
contextHolder
.
get
();
}
public
static
void
clearDataSource
()
{
contextHolder
.
remove
();
}
}
src/main/java/com/govmade/datasources/DynamicDataSourceConfig.java
0 → 100644
View file @
8bd28814
package
com
.
govmade
.
datasources
;
import
com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Primary
;
import
javax.sql.DataSource
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* 配置多数据源
* @author chenshun
* @email sunlightcs@gmail.com
* @date 2017/8/19 0:41
*/
@Configuration
public
class
DynamicDataSourceConfig
{
@Bean
@ConfigurationProperties
(
"spring.datasource.druid.govmade"
)
public
DataSource
firstDataSource
(){
return
DruidDataSourceBuilder
.
create
().
build
();
}
@Bean
@Primary
public
DynamicDataSource
dataSource
(
DataSource
firstDataSource
)
{
Map
<
Object
,
Object
>
targetDataSources
=
new
HashMap
<>();
targetDataSources
.
put
(
DataSourceNames
.
GOVMADE
,
firstDataSource
);
return
new
DynamicDataSource
(
firstDataSource
,
targetDataSources
);
}
}
src/main/java/com/govmade/modules/basic/controller/AbstractController.java
0 → 100644
View file @
8bd28814
package
com
.
govmade
.
modules
.
basic
.
controller
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.govmade.modules.system.entity.UserEntity
;
/**
* Controller公共组件
*
* @author Fred
* @email fangtaosh@qq.com
* @date 2018年8月3日
*/
public
abstract
class
AbstractController
{
protected
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
protected
UserEntity
getUser
()
{
//return (UserEntity) SecurityUtils.getSubject().getPrincipal();
UserEntity
ue
=
new
UserEntity
();
ue
.
setDeptId
(
1L
);
return
null
;
}
protected
Long
getUserId
()
{
//return getUser().getId();
return
2L
;
}
}
src/main/java/com/govmade/modules/basic/entity/BaseEntity.java
0 → 100644
View file @
8bd28814
package
com
.
govmade
.
modules
.
basic
.
entity
;
import
java.io.Serializable
;
import
java.util.Date
;
import
com.baomidou.mybatisplus.annotations.TableField
;
import
com.baomidou.mybatisplus.annotations.TableId
;
import
com.baomidou.mybatisplus.enums.FieldFill
;
public
abstract
class
BaseEntity
<
ID
extends
Serializable
>
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@TableId
private
ID
id
;
// 主键ID
@TableField
(
value
=
"create_by"
,
fill
=
FieldFill
.
INSERT
)
private
Long
createBy
;
// 创建者
@TableField
(
value
=
"modify_by"
,
fill
=
FieldFill
.
INSERT_UPDATE
)
private
Long
modifyBy
;
// 更新者
@TableField
(
value
=
"create_time"
,
fill
=
FieldFill
.
INSERT
)
private
Date
createTime
;
// 创建时间
@TableField
(
value
=
"modify_time"
,
fill
=
FieldFill
.
INSERT_UPDATE
)
private
Date
modifyTime
;
// 更新时间
@TableField
(
value
=
"state"
,
fill
=
FieldFill
.
INSERT
)
private
Integer
state
;
// 更新时间
public
ID
getId
()
{
return
id
;
}
public
void
setId
(
ID
id
)
{
this
.
id
=
id
;
}
public
Long
getCreateBy
()
{
return
createBy
;
}
public
void
setCreateBy
(
Long
createBy
)
{
this
.
createBy
=
createBy
;
}
public
Long
getModifyBy
()
{
return
modifyBy
;
}
public
void
setModifyBy
(
Long
modifyBy
)
{
this
.
modifyBy
=
modifyBy
;
}
public
Date
getCreateTime
()
{
return
createTime
;
}
public
void
setCreateTime
(
Date
createTime
)
{
this
.
createTime
=
createTime
;
}
public
Date
getModifyTime
()
{
return
modifyTime
;
}
public
void
setModifyTime
(
Date
modifyTime
)
{
this
.
modifyTime
=
modifyTime
;
}
}
src/main/java/com/govmade/modules/system/controller/UserController.java
0 → 100644
View file @
8bd28814
package
com
.
govmade
.
modules
.
system
.
controller
;
import
java.util.Map
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.govmade.common.utils.Constant
;
import
com.govmade.common.utils.PageUtils
;
import
com.govmade.common.utils.R
;
import
com.govmade.modules.basic.controller.AbstractController
;
import
com.govmade.modules.system.entity.UserEntity
;
import
com.govmade.modules.system.service.UserService
;
import
cn.hutool.crypto.SecureUtil
;
/**
* 系统管理 - 用户设置
*
* @author Fred
* @email fangtaosh@qq.com
* @date 2018年8月3日
*/
@RestController
@RequestMapping
(
"/system/user"
)
public
class
UserController
extends
AbstractController
{
@Autowired
private
UserService
userService
;
/**
* 保存或更新用户
*/
@PostMapping
(
"/save"
)
public
R
save
(
UserEntity
ue
)
{
if
(
null
==
ue
.
getId
())
{
if
(
this
.
userService
.
checkUser
(
ue
.
getUsername
())
>
0
)
{
return
R
.
error
(
ue
.
getUsername
()
+
" 已存在!"
);
}
String
password
=
SecureUtil
.
md5
(
"123456"
);
ue
.
setPassword
(
password
);
}
userService
.
save
(
ue
);
return
R
.
ok
();
}
/**
* 用户列表
*/
@GetMapping
(
"/list"
)
public
R
list
(
Map
<
String
,
Object
>
params
)
{
// 只有超级管理员,才能查看所有用户列表
if
(
getUserId
()
!=
Constant
.
SUPER_ADMIN
)
{
params
.
put
(
"createBy"
,
getUserId
());
}
else
{
params
.
put
(
"deptId"
,
getUser
().
getDeptId
());
// 部门管理员,查看本部门用户列表
}
PageUtils
page
=
userService
.
queryPage
(
params
);
return
R
.
ok
().
put
(
"page"
,
page
);
}
/**
* 根据ID查询用户
*
* @param id
* @return
*/
@GetMapping
(
"info/{id}"
)
public
R
info
(
@PathVariable
(
"id"
)
Long
id
)
{
return
R
.
ok
().
put
(
"user"
,
userService
.
queryById
(
id
));
}
}
src/main/java/com/govmade/modules/system/dao/UserDao.java
0 → 100644
View file @
8bd28814
package
com
.
govmade
.
modules
.
system
.
dao
;
import
java.util.List
;
import
org.apache.ibatis.annotations.Mapper
;
import
com.baomidou.mybatisplus.mapper.BaseMapper
;
import
com.govmade.modules.system.entity.UserEntity
;
/**
* 系统管理 - 用户设置
*
* @author Fred
* @email fangtaosh@qq.com
* @date 2018年8月3日
*/
@Mapper
public
interface
UserDao
extends
BaseMapper
<
UserEntity
>
{
/**
* 查询用户的所有权限
* @param userId 用户ID
*/
List
<
String
>
queryAllPerms
(
Long
userId
);
/**
* 查询用户的所有菜单ID
*/
List
<
Long
>
queryAllMenuId
(
Long
userId
);
/**
* 根据用户名,查询系统用户
*/
UserEntity
queryByUserName
(
String
username
);
}
src/main/java/com/govmade/modules/system/entity/UserEntity.java
0 → 100644
View file @
8bd28814
package
com
.
govmade
.
modules
.
system
.
entity
;
import
java.util.Date
;
import
com.baomidou.mybatisplus.annotations.TableName
;
import
com.govmade.modules.basic.entity.BaseEntity
;
/**
* 系统管理 - 用户设置
*
* @author Fred
* @email fangtaosh@qq.com
* @date 2018年8月3日
*/
@TableName
(
"system_users"
)
public
class
UserEntity
extends
BaseEntity
<
Long
>
{
private
static
final
long
serialVersionUID
=
1L
;
private
Long
deptId
;
// 部门ID
private
Long
roleId
;
// 角色ID
private
String
username
;
// 用户名
private
String
password
;
// 密码
private
String
realname
;
// 真实姓名
private
String
email
;
// 邮箱
private
String
telephone
;
// 电话号码
private
String
lastLoginIp
;
// 最后一次登录IP
private
Date
lastLoginTime
;
// 最后一次登录时间
public
Long
getDeptId
()
{
return
deptId
;
}
public
void
setDeptId
(
Long
deptId
)
{
this
.
deptId
=
deptId
;
}
public
Long
getRoleId
()
{
return
roleId
;
}
public
void
setRoleId
(
Long
roleId
)
{
this
.
roleId
=
roleId
;
}
public
String
getUsername
()
{
return
username
;
}
public
void
setUsername
(
String
username
)
{
this
.
username
=
username
;
}
public
String
getPassword
()
{
return
password
;
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
public
String
getRealname
()
{
return
realname
;
}
public
void
setRealname
(
String
realname
)
{
this
.
realname
=
realname
;
}
public
String
getEmail
()
{
return
email
;
}
public
void
setEmail
(
String
email
)
{
this
.
email
=
email
;
}
public
String
getTelephone
()
{
return
telephone
;
}
public
void
setTelephone
(
String
telephone
)
{
this
.
telephone
=
telephone
;
}
public
String
getLastLoginIp
()
{
return
lastLoginIp
;
}
public
void
setLastLoginIp
(
String
lastLoginIp
)
{
this
.
lastLoginIp
=
lastLoginIp
;
}
public
Date
getLastLoginTime
()
{
return
lastLoginTime
;
}
public
void
setLastLoginTime
(
Date
lastLoginTime
)
{
this
.
lastLoginTime
=
lastLoginTime
;
}
}
src/main/java/com/govmade/modules/system/service/UserService.java
0 → 100644
View file @
8bd28814
package
com
.
govmade
.
modules
.
system
.
service
;
import
java.util.Map
;
import
com.baomidou.mybatisplus.service.IService
;
import
com.govmade.common.utils.PageUtils
;
import
com.govmade.modules.system.entity.UserEntity
;
/**
* 系统管理 - 用户设置
*
* @author Fred
* @email fangtaosh@qq.com
* @date 2018年8月3日
*/
public
interface
UserService
extends
IService
<
UserEntity
>
{
PageUtils
queryPage
(
Map
<
String
,
Object
>
params
);
UserEntity
queryById
(
Long
id
);
/**
* 保存或修改用户
*/
void
save
(
UserEntity
user
);
/**
* 删除用户
*/
void
deleteBatch
(
Long
[]
userIds
);
/**
* 修改密码
* @param userId 用户ID
* @param password 原密码
* @param newPassword 新密码
*/
boolean
updatePassword
(
Long
userId
,
String
password
,
String
newPassword
);
Integer
checkUser
(
String
username
);
}
src/main/java/com/govmade/modules/system/service/impl/UserServiceImpl.java
0 → 100644
View file @
8bd28814
package
com
.
govmade
.
modules
.
system
.
service
.
impl
;
import
java.util.Map
;
import
org.springframework.stereotype.Service
;
import
com.baomidou.mybatisplus.mapper.EntityWrapper
;
import
com.baomidou.mybatisplus.plugins.Page
;
import
com.baomidou.mybatisplus.service.impl.ServiceImpl
;
import
com.govmade.common.utils.PageUtils
;
import
com.govmade.common.utils.Query
;
import
com.govmade.modules.system.dao.UserDao
;
import
com.govmade.modules.system.entity.UserEntity
;
import
com.govmade.modules.system.service.UserService
;
import
cn.hutool.core.util.StrUtil
;
/**
* 系统用户
*
* @author chenshun
* @email sunlightcs@gmail.com
* @date 2016年9月18日 上午9:46:09
*/
@Service
(
"UserService"
)
public
class
UserServiceImpl
extends
ServiceImpl
<
UserDao
,
UserEntity
>
implements
UserService
{
@Override
public
PageUtils
queryPage
(
Map
<
String
,
Object
>
params
)
{
// TODO Auto-generated method stub
String
username
=
(
String
)
params
.
get
(
"username"
);
Long
createBy
=
(
Long
)
params
.
get
(
"createBy"
);
Page
<
UserEntity
>
page
=
this
.
selectPage
(
new
Query
<
UserEntity
>(
params
).
getPage
(),
new
EntityWrapper
<
UserEntity
>()
.
eq
(
StrUtil
.
isNotBlank
(
username
),
"username"
,
username
).
eq
(
createBy
!=
null
,
"create_by"
,
createBy
));
return
new
PageUtils
(
page
);
}
@Override
public
UserEntity
queryById
(
Long
id
)
{
return
super
.
selectById
(
id
);
}
@Override
public
void
save
(
UserEntity
user
)
{
super
.
insertOrUpdate
(
user
);
}
@Override
public
void
deleteBatch
(
Long
[]
userIds
)
{
// TODO Auto-generated method stub
}
@Override
public
boolean
updatePassword
(
Long
userId
,
String
password
,
String
newPassword
)
{
// TODO Auto-generated method stub
return
false
;
}
@Override
public
Integer
checkUser
(
String
username
)
{
return
super
.
selectCount
(
new
EntityWrapper
<
UserEntity
>().
eq
(
"username"
,
username
));
}
}
src/main/resources/application-dev.yml
0 → 100644
View file @
8bd28814
spring
:
datasource
:
type
:
com.alibaba.druid.pool.DruidDataSource
driverClassName
:
com.mysql.jdbc.Driver
druid
:
govmade
:
#数据源(多源)
url
:
jdbc:mysql://115.233.227.46:13308/govmade?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8
username
:
root
password
:
gov567
initial-size
:
10
max-active
:
100
min-idle
:
10
max-wait
:
60000
pool-prepared-statements
:
true
max-pool-prepared-statement-per-connection-size
:
20
time-between-eviction-runs-millis
:
60000
min-evictable-idle-time-millis
:
300000
validation-query
:
SELECT 1 FROM DUAL
test-while-idle
:
true
test-on-borrow
:
false
test-on-return
:
false
stat-view-servlet
:
enabled
:
true
url-pattern
:
/druid/*
#login-username: admin
#login-password: admin
filter
:
stat
:
log-slow-sql
:
true
slow-sql-millis
:
1000
merge-sql
:
true
wall
:
config
:
multi-statement-allow
:
true
src/main/resources/application-prod.yml
0 → 100644
View file @
8bd28814
spring
:
datasource
:
type
:
com.alibaba.druid.pool.DruidDataSource
driverClassName
:
com.mysql.jdbc.Driver
druid
:
first
:
url
:
jdbc:mysql://localhost:3306/renren_fast?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8
username
:
renren
password
:
123456
second
:
url
:
jdbc:mysql://localhost:3306/renren_fast?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8
username
:
renren
password
:
123456
initial-size
:
10
max-active
:
100
min-idle
:
10
max-wait
:
60000
pool-prepared-statements
:
true
max-pool-prepared-statement-per-connection-size
:
20
time-between-eviction-runs-millis
:
60000
min-evictable-idle-time-millis
:
300000
validation-query
:
SELECT 1 FROM DUAL
test-while-idle
:
true
test-on-borrow
:
false
test-on-return
:
false
stat-view-servlet
:
enabled
:
true
url-pattern
:
/druid/*
#login-username: admin
#login-password: admin
filter
:
stat
:
log-slow-sql
:
true
slow-sql-millis
:
1000
merge-sql
:
true
wall
:
config
:
multi-statement-allow
:
true
src/main/resources/application-test.yml
0 → 100644
View file @
8bd28814
spring
:
datasource
:
type
:
com.alibaba.druid.pool.DruidDataSource
driverClassName
:
com.mysql.jdbc.Driver
druid
:
first
:
url
:
jdbc:mysql://localhost:3306/renren_fast?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8
username
:
renren
password
:
123456
second
:
url
:
jdbc:mysql://localhost:3306/renren_fast?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8
username
:
renren
password
:
123456
initial-size
:
10
max-active
:
100
min-idle
:
10
max-wait
:
60000
pool-prepared-statements
:
true
max-pool-prepared-statement-per-connection-size
:
20
time-between-eviction-runs-millis
:
60000
min-evictable-idle-time-millis
:
300000
validation-query
:
SELECT 1 FROM DUAL
test-while-idle
:
true
test-on-borrow
:
false
test-on-return
:
false
stat-view-servlet
:
enabled
:
true
url-pattern
:
/druid/*
#login-username: admin
#login-password: admin
filter
:
stat
:
log-slow-sql
:
true
slow-sql-millis
:
1000
merge-sql
:
true
wall
:
config
:
multi-statement-allow
:
true
src/main/resources/application.yml
0 → 100644
View file @
8bd28814
# Tomcat
server
:
tomcat
:
uri-encoding
:
UTF-8
max-threads
:
1000
min-spare-threads
:
30
port
:
18080
connection-timeout
:
5000
context-path
:
/govdna
spring
:
# 环境 dev|test|prod
profiles
:
active
:
dev
# jackson时间格式化
jackson
:
time-zone
:
GMT+8
date-format
:
yyyy-MM-dd HH:mm:ss
http
:
multipart
:
max-file-size
:
100MB
max-request-size
:
100MB
enabled
:
true
redis
:
open
:
false
# 是否开启redis缓存 true开启 false关闭
database
:
0
host
:
localhost
port
:
6379
password
:
# 密码(默认为空)
timeout
:
6000
# 连接超时时长(毫秒)
pool
:
max-active
:
1000
# 连接池最大连接数(使用负值表示没有限制)
max-wait
:
-1
# 连接池最大阻塞等待时间(使用负值表示没有限制)
max-idle
:
10
# 连接池中的最大空闲连接
min-idle
:
5
# 连接池中的最小空闲连接
#mybatis
mybatis-plus
:
mapper-locations
:
classpath:mapper/**/*.xml
#实体扫描,多个package用逗号或者分号分隔
typeAliasesPackage
:
com.govmade.modules.*.entity
global-config
:
#主键类型 0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
id-type
:
0
#字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"
field-strategy
:
2
#驼峰下划线转换
db-column-underline
:
true
#刷新mapper 调试神器
refresh-mapper
:
true
#数据库大写下划线转换
#capital-mode: true
#序列接口实现类配置
#key-generator: com.baomidou.springboot.xxx
#逻辑删除配置
logic-delete-value
:
-1
logic-not-delete-value
:
0
#自定义填充策略接口实现
meta-object-handler
:
com.govmade.common.utils.MyMetaObjectHandler
#自定义SQL注入器
sql-injector
:
com.baomidou.mybatisplus.mapper.LogicSqlInjector
configuration
:
map-underscore-to-camel-case
:
true
cache-enabled
:
false
call-setters-on-nulls
:
true
renren
:
# APP模块,是通过jwt认证的,如果要使用APP模块,则需要修改【加密秘钥】
jwt
:
# 加密秘钥
secret
:
f4e2e52034348f86b67cde581c0f9eb5[www.renren.io]
# token有效时长,7天,单位秒
expire
:
604800
header
:
token
src/main/resources/logback-spring.xml
0 → 100644
View file @
8bd28814
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include
resource=
"org/springframework/boot/logging/logback/base.xml"
/>
<logger
name=
"org.springframework.web"
level=
"INFO"
/>
<logger
name=
"org.springboot.sample"
level=
"TRACE"
/>
<!-- 开发、测试环境 -->
<springProfile
name=
"dev,test"
>
<logger
name=
"org.springframework.web"
level=
"INFO"
/>
<logger
name=
"org.springboot.sample"
level=
"INFO"
/>
<logger
name=
"com.govmade"
level=
"DEBUG"
/>
</springProfile>
<!-- 生产环境 -->
<springProfile
name=
"prod"
>
<logger
name=
"org.springframework.web"
level=
"ERROR"
/>
<logger
name=
"org.springboot.sample"
level=
"ERROR"
/>
<logger
name=
"com.govmade"
level=
"ERROR"
/>
</springProfile>
</configuration>
\ No newline at end of file
src/main/resources/static/index.html
0 → 100644
View file @
8bd28814
这是首页吗
\ No newline at end of file
src/test/java/test/UserTest.java
0 → 100644
View file @
8bd28814
package
test
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
com.govmade.modules.system.entity.UserEntity
;
import
com.govmade.modules.system.service.UserService
;
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
public
class
UserTest
{
@Autowired
private
UserService
userService
;
@Test
public
void
contextLoads
()
{
UserEntity
user
=
new
UserEntity
();
user
.
setEmail
(
"qqq@qq.com"
);
user
.
setDeptId
(
1L
);
user
.
setRoleId
(
1L
);
System
.
out
.
println
(
user
);
//userService.save(user);
}
}
src/test/resources/mapper/system/SysUserDao.xml
0 → 100644
View file @
8bd28814
<?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=
"io.renren.modules.sys.dao.SysUserDao"
>
<select
id=
"queryByUserName"
resultType=
"io.renren.modules.sys.entity.SysUserEntity"
>
select * from sys_user where username = #{username}
</select>
</mapper>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment