Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
customer-service
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SuperHive
back-end
customer-service
Commits
4c13d8f6
Commit
4c13d8f6
authored
Apr 23, 2020
by
huangcb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增AuthFilter过滤器
parent
bb8adb0e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
108 additions
and
15 deletions
+108
-15
pom.xml
pom.xml
+1
-13
AuthFilter.java
...va/com/esv/freight/customer/common/filter/AuthFilter.java
+75
-0
EResponse.java
...a/com/esv/freight/customer/common/response/EResponse.java
+8
-0
LogFilterConfig.java
...java/com/esv/freight/customer/config/LogFilterConfig.java
+17
-0
bootstrap.yml
src/main/resources/bootstrap.yml
+2
-2
logback-spring.xml
src/main/resources/logback-spring.xml
+5
-0
No files found.
pom.xml
View file @
4c13d8f6
...
...
@@ -134,7 +134,7 @@
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-surefire-plugin
</artifactId>
<configuration>
<skipTests>
fals
e
</skipTests>
<skipTests>
tru
e
</skipTests>
</configuration>
</plugin>
</plugins>
...
...
@@ -204,18 +204,6 @@
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>
src/main/resources
</directory>
<includes>
<include>
**/*.*
</include>
</includes>
<excludes>
</excludes>
<filtering>
true
</filtering>
</resource>
</resources>
</build>
</project>
src/main/java/com/esv/freight/customer/common/filter/AuthFilter.java
0 → 100644
View file @
4c13d8f6
package
com
.
esv
.
freight
.
customer
.
common
.
filter
;
import
com.esv.freight.customer.common.response.EResponse
;
import
lombok.extern.slf4j.Slf4j
;
import
javax.servlet.*
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.io.OutputStreamWriter
;
import
java.io.PrintWriter
;
/**
* @description: 权限过滤器
* @project: freight-customer-service
* @name: com.esv.freight.customer.common.filter.AuthFilter
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/04/23 14:11
* @version:1.0
*/
@Slf4j
public
class
AuthFilter
implements
Filter
{
@Override
public
void
init
(
FilterConfig
filterConfig
)
throws
ServletException
{
}
@Override
public
void
doFilter
(
ServletRequest
servletRequest
,
ServletResponse
servletResponse
,
FilterChain
filterChain
)
throws
IOException
,
ServletException
{
// HttpServletRequest request = (HttpServletRequest) servletRequest;
// HttpServletResponse response = (HttpServletResponse) servletResponse;
// String accessToken = request.getHeader("Union-Authorization");
// if (StringUtils.isBlank(accessToken)) {
// this.errorResponse(EResponse.error(ECode.TOKEN_INVALID), response);
// return;
// } else {
// // 解析并校验Token
// }
filterChain
.
doFilter
(
servletRequest
,
servletResponse
);
}
@Override
public
void
destroy
()
{
}
private
void
errorResponse
(
EResponse
eResponse
,
HttpServletResponse
response
)
{
response
.
setCharacterEncoding
(
"UTF-8"
);
response
.
setContentType
(
"application/json; charset=utf-8"
);
OutputStreamWriter
osw
=
null
;
PrintWriter
writer
=
null
;
try
{
osw
=
new
OutputStreamWriter
(
response
.
getOutputStream
(),
"UTF-8"
);
writer
=
new
PrintWriter
(
osw
,
true
);
writer
.
write
(
eResponse
.
toString
());
writer
.
flush
();
osw
.
close
();
}
catch
(
IOException
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
}
finally
{
if
(
null
!=
writer
)
{
writer
.
close
();
}
if
(
null
!=
osw
)
{
try
{
osw
.
close
();
}
catch
(
IOException
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
}
}
}
}
}
src/main/java/com/esv/freight/customer/common/response/EResponse.java
View file @
4c13d8f6
package
com
.
esv
.
freight
.
customer
.
common
.
response
;
import
org.apache.commons.lang3.builder.ToStringBuilder
;
import
org.apache.commons.lang3.builder.ToStringStyle
;
import
java.io.Serializable
;
/**
...
...
@@ -153,4 +156,9 @@ public class EResponse<T> implements Serializable {
public
void
setData
(
T
data
)
{
this
.
data
=
data
;
}
@Override
public
String
toString
()
{
return
ToStringBuilder
.
reflectionToString
(
this
,
ToStringStyle
.
JSON_STYLE
);
}
}
\ No newline at end of file
src/main/java/com/esv/freight/customer/config/LogFilterConfig.java
View file @
4c13d8f6
package
com
.
esv
.
freight
.
customer
.
config
;
import
com.esv.freight.customer.common.filter.AuthFilter
;
import
com.esv.freight.customer.common.filter.LogbackFilter
;
import
com.esv.freight.customer.common.filter.RestLogFilter
;
import
org.springframework.boot.web.servlet.FilterRegistrationBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
javax.servlet.Filter
;
/**
* @description: 注册请求Filter
* @project: SpringCloudTemplate
...
...
@@ -37,4 +40,18 @@ public class LogFilterConfig {
filterRegistrationBean
.
setOrder
(
Integer
.
MIN_VALUE
+
1
);
return
filterRegistrationBean
;
}
@Bean
public
AuthFilter
getAuthFilter
()
{
return
new
AuthFilter
();
}
@Bean
public
FilterRegistrationBean
<
AuthFilter
>
authFilterRegister
()
{
FilterRegistrationBean
<
AuthFilter
>
filterRegistrationBean
=
new
FilterRegistrationBean
<>();
filterRegistrationBean
.
setFilter
(
getAuthFilter
());
filterRegistrationBean
.
addUrlPatterns
(
URL
);
filterRegistrationBean
.
setOrder
(
Integer
.
MIN_VALUE
+
2
);
return
filterRegistrationBean
;
}
}
src/main/resources/bootstrap.yml
View file @
4c13d8f6
...
...
@@ -3,8 +3,8 @@ server:
servlet
:
context-path
:
/customer
nacos
:
url
:
1
92.168.31.248
:8848
namespace
:
aad5aa26-5351-4e7a-a65e-ecb332f3c52c
url
:
1
27.0.0.1
:8848
namespace
:
548b506d-8d19-4d54-9715-bb0ac3a655b2
group
:
FREIGHT_GROUP
spring
:
application
:
...
...
src/main/resources/logback-spring.xml
View file @
4c13d8f6
...
...
@@ -48,6 +48,11 @@
<appender-ref
ref=
"FILE_APPENDER"
/>
</logger>
<logger
name=
"com.esv.freight.customer.config.mybatis"
level=
"INFO"
additivity=
"false"
>
<appender-ref
ref=
"CONSOLE_APPENDER"
/>
<appender-ref
ref=
"FILE_APPENDER"
/>
</logger>
<!--控制台和日志文件输出级别-->
<root
level=
"INFO"
additivity=
"false"
>
<appender-ref
ref=
"CONSOLE_APPENDER"
/>
...
...
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