Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
guns-vip
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenjunxiong
guns-vip
Commits
fa7a8ada
Commit
fa7a8ada
authored
Jun 20, 2019
by
fengshuonan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
抽出rest模块
parent
46fa7fe4
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
171 additions
and
24 deletions
+171
-24
guns-rest-api/pom.xml
+33
-0
guns-rest-api/src/main/java/cn/stylefeng/guns/api/core/aop/RestApiInteceptor.java
+12
-7
guns-rest-api/src/main/java/cn/stylefeng/guns/api/core/constant/JwtConstants.java
+1
-1
guns-rest-api/src/main/java/cn/stylefeng/guns/api/core/exception/RestExceptionEnum.java
+66
-0
guns-rest-api/src/main/java/cn/stylefeng/guns/api/core/util/JwtTokenUtil.java
+2
-2
guns-rest-api/src/main/java/cn/stylefeng/guns/api/modular/ApiController.java
+44
-0
guns-sys/pom.xml
+7
-0
guns-sys/src/main/java/cn/stylefeng/guns/sys/modular/rest/ApiLoginController.java
+4
-13
guns-vip-main/src/main/java/cn/stylefeng/guns/config/web/WebConfig.java
+1
-1
pom.xml
+1
-0
No files found.
guns-rest-api/pom.xml
0 → 100644
View file @
fa7a8ada
<?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>
cn.stylefeng
</groupId>
<artifactId>
guns-vip
</artifactId>
<version>
1.0.0
</version>
<relativePath>
../pom.xml
</relativePath>
</parent>
<artifactId>
guns-rest-api
</artifactId>
<packaging>
jar
</packaging>
<dependencies>
<!--基础组件-->
<dependency>
<groupId>
cn.stylefeng
</groupId>
<artifactId>
guns-base
</artifactId>
<version>
1.0.0
</version>
</dependency>
</dependencies>
<build>
<finalName>
${project.artifactId}
</finalName>
</build>
</project>
guns-
sys/src/main/java/cn/stylefeng/guns/sys/modular/api
/aop/RestApiInteceptor.java
→
guns-
rest-api/src/main/java/cn/stylefeng/guns/api/core
/aop/RestApiInteceptor.java
View file @
fa7a8ada
...
...
@@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
cn
.
stylefeng
.
guns
.
sys
.
modular
.
api
.
aop
;
package
cn
.
stylefeng
.
guns
.
api
.
core
.
aop
;
import
cn.stylefeng.guns.
sys
.core.constant.JwtConstants
;
import
cn.stylefeng.guns.
sys.core.exception.enums.Biz
ExceptionEnum
;
import
cn.stylefeng.guns.
sys
.core.util.JwtTokenUtil
;
import
cn.stylefeng.guns.
api
.core.constant.JwtConstants
;
import
cn.stylefeng.guns.
api.core.exception.Rest
ExceptionEnum
;
import
cn.stylefeng.guns.
api
.core.util.JwtTokenUtil
;
import
cn.stylefeng.roses.core.reqres.response.ErrorResponseData
;
import
cn.stylefeng.roses.core.util.RenderUtil
;
import
io.jsonwebtoken.JwtException
;
...
...
@@ -56,17 +56,22 @@ public class RestApiInteceptor extends HandlerInterceptorAdapter {
try
{
boolean
flag
=
JwtTokenUtil
.
isTokenExpired
(
authToken
);
if
(
flag
)
{
RenderUtil
.
renderJson
(
response
,
new
ErrorResponseData
(
BizExceptionEnum
.
TOKEN_EXPIRED
.
getCode
(),
BizExceptionEnum
.
TOKEN_EXPIRED
.
getMessage
()));
RenderUtil
.
renderJson
(
response
,
new
ErrorResponseData
(
RestExceptionEnum
.
TOKEN_EXPIRED
.
getCode
(),
RestExceptionEnum
.
TOKEN_EXPIRED
.
getMessage
()));
return
false
;
}
}
catch
(
JwtException
e
)
{
//有异常就是token解析失败
RenderUtil
.
renderJson
(
response
,
new
ErrorResponseData
(
BizExceptionEnum
.
TOKEN_ERROR
.
getCode
(),
BizExceptionEnum
.
TOKEN_ERROR
.
getMessage
()));
RenderUtil
.
renderJson
(
response
,
new
ErrorResponseData
(
RestExceptionEnum
.
TOKEN_ERROR
.
getCode
(),
RestExceptionEnum
.
TOKEN_ERROR
.
getMessage
()));
return
false
;
}
}
else
{
//header没有带Bearer字段
RenderUtil
.
renderJson
(
response
,
new
ErrorResponseData
(
BizExceptionEnum
.
TOKEN_ERROR
.
getCode
(),
BizExceptionEnum
.
TOKEN_ERROR
.
getMessage
()));
RenderUtil
.
renderJson
(
response
,
new
ErrorResponseData
(
RestExceptionEnum
.
TOKEN_ERROR
.
getCode
(),
RestExceptionEnum
.
TOKEN_ERROR
.
getMessage
()));
return
false
;
}
return
true
;
...
...
guns-
sys/src/main/java/cn/stylefeng/guns/sys
/core/constant/JwtConstants.java
→
guns-
rest-api/src/main/java/cn/stylefeng/guns/api
/core/constant/JwtConstants.java
View file @
fa7a8ada
...
...
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
cn
.
stylefeng
.
guns
.
sys
.
core
.
constant
;
package
cn
.
stylefeng
.
guns
.
api
.
core
.
constant
;
/**
* jwt相关配置
...
...
guns-rest-api/src/main/java/cn/stylefeng/guns/api/core/exception/RestExceptionEnum.java
0 → 100644
View file @
fa7a8ada
/**
* Copyright 2018-2020 stylefeng & fengshuonan (https://gitee.com/stylefeng)
* <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
cn
.
stylefeng
.
guns
.
api
.
core
.
exception
;
import
cn.stylefeng.roses.kernel.model.exception.AbstractBaseExceptionEnum
;
/**
* rest异常
*
* @author fengshuonan
* @date 2016年11月12日 下午5:04:51
*/
public
enum
RestExceptionEnum
implements
AbstractBaseExceptionEnum
{
/**
* token异常
*/
TOKEN_EXPIRED
(
700
,
"token过期"
),
TOKEN_ERROR
(
700
,
"token验证失败"
),
/**
* 签名异常
*/
SIGN_ERROR
(
700
,
"签名验证失败"
);
RestExceptionEnum
(
int
code
,
String
message
)
{
this
.
code
=
code
;
this
.
message
=
message
;
}
private
Integer
code
;
private
String
message
;
@Override
public
Integer
getCode
()
{
return
code
;
}
public
void
setCode
(
Integer
code
)
{
this
.
code
=
code
;
}
@Override
public
String
getMessage
()
{
return
message
;
}
public
void
setMessage
(
String
message
)
{
this
.
message
=
message
;
}
}
guns-
sys/src/main/java/cn/stylefeng/guns/sys
/core/util/JwtTokenUtil.java
→
guns-
rest-api/src/main/java/cn/stylefeng/guns/api
/core/util/JwtTokenUtil.java
View file @
fa7a8ada
...
...
@@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
cn
.
stylefeng
.
guns
.
sys
.
core
.
util
;
package
cn
.
stylefeng
.
guns
.
api
.
core
.
util
;
import
cn.stylefeng.guns.
sys
.core.constant.JwtConstants
;
import
cn.stylefeng.guns.
api
.core.constant.JwtConstants
;
import
cn.stylefeng.roses.core.util.ToolUtil
;
import
io.jsonwebtoken.*
;
...
...
guns-rest-api/src/main/java/cn/stylefeng/guns/api/modular/ApiController.java
0 → 100644
View file @
fa7a8ada
/**
* Copyright 2018-2020 stylefeng & fengshuonan (https://gitee.com/stylefeng)
* <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
cn
.
stylefeng
.
guns
.
api
.
modular
;
import
cn.stylefeng.roses.core.base.controller.BaseController
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* 接口控制器提供
* <p>
* 所有的api都要以gunsApi开头,可以在cn.stylefeng.guns.config.web.WebConfig中配置这个开头
*
* @author stylefeng
* @Date 2018/7/20 23:39
*/
@RestController
@RequestMapping
(
"/gunsApi"
)
public
class
ApiController
extends
BaseController
{
/**
* 测试接口是否走鉴权
*/
@RequestMapping
(
value
=
"/test"
,
method
=
RequestMethod
.
POST
)
public
Object
test
()
{
return
SUCCESS_TIP
;
}
}
guns-sys/pom.xml
View file @
fa7a8ada
...
...
@@ -24,6 +24,13 @@
<version>
1.0.0
</version>
</dependency>
<!-- rest-api-->
<dependency>
<groupId>
cn.stylefeng
</groupId>
<artifactId>
guns-rest-api
</artifactId>
<version>
1.0.0
</version>
</dependency>
<!-- 第三方登录-->
<dependency>
<groupId>
me.zhyd.oauth
</groupId>
...
...
guns-sys/src/main/java/cn/stylefeng/guns/sys/modular/
api/controller/Api
Controller.java
→
guns-sys/src/main/java/cn/stylefeng/guns/sys/modular/
rest/ApiLogin
Controller.java
View file @
fa7a8ada
...
...
@@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
cn
.
stylefeng
.
guns
.
sys
.
modular
.
api
.
controller
;
package
cn
.
stylefeng
.
guns
.
sys
.
modular
.
rest
;
import
cn.stylefeng.guns.api.core.util.JwtTokenUtil
;
import
cn.stylefeng.guns.base.shiro.ShiroUser
;
import
cn.stylefeng.guns.sys.core.shiro.ShiroKit
;
import
cn.stylefeng.guns.sys.core.util.JwtTokenUtil
;
import
cn.stylefeng.guns.sys.modular.system.entity.User
;
import
cn.stylefeng.guns.sys.modular.system.mapper.UserMapper
;
import
cn.stylefeng.roses.core.base.controller.BaseController
;
...
...
@@ -29,21 +29,20 @@ import org.apache.shiro.crypto.hash.Md5Hash;
import
org.apache.shiro.util.ByteSource
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.HashMap
;
/**
*
接口控制器提供
*
api登录接口,获取token
*
* @author stylefeng
* @Date 2018/7/20 23:39
*/
@RestController
@RequestMapping
(
"/gunsApi"
)
public
class
ApiController
extends
BaseController
{
public
class
Api
Login
Controller
extends
BaseController
{
@Autowired
private
UserMapper
userMapper
;
...
...
@@ -83,13 +82,5 @@ public class ApiController extends BaseController {
}
}
/**
* 测试接口是否走鉴权
*/
@RequestMapping
(
value
=
"/test"
,
method
=
RequestMethod
.
POST
)
public
Object
test
()
{
return
SUCCESS_TIP
;
}
}
guns-vip-main/src/main/java/cn/stylefeng/guns/config/web/WebConfig.java
View file @
fa7a8ada
...
...
@@ -15,11 +15,11 @@
*/
package
cn
.
stylefeng
.
guns
.
config
.
web
;
import
cn.stylefeng.guns.api.core.aop.RestApiInteceptor
;
import
cn.stylefeng.guns.sys.core.attribute.AttributeSetInteceptor
;
import
cn.stylefeng.guns.sys.core.constant.Const
;
import
cn.stylefeng.guns.sys.core.exception.page.GunsErrorView
;
import
cn.stylefeng.guns.sys.core.listener.ConfigListener
;
import
cn.stylefeng.guns.sys.modular.api.aop.RestApiInteceptor
;
import
cn.stylefeng.roses.core.xss.XssFilter
;
import
com.alibaba.druid.pool.DruidDataSource
;
import
com.alibaba.druid.support.http.StatViewServlet
;
...
...
pom.xml
View file @
fa7a8ada
...
...
@@ -25,6 +25,7 @@
<module>
guns-base-sms
</module>
<module>
guns-base-email
</module>
<module>
guns-base-timers
</module>
<module>
guns-rest-api
</module>
<module>
guns-sys
</module>
<module>
guns-vip-gen
</module>
<module>
guns-vip-main
</module>
...
...
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