Commit fa7a8ada by fengshuonan

抽出rest模块

parent 46fa7fe4
<?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>
......@@ -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.BizExceptionEnum;
import cn.stylefeng.guns.sys.core.util.JwtTokenUtil;
import cn.stylefeng.guns.api.core.constant.JwtConstants;
import cn.stylefeng.guns.api.core.exception.RestExceptionEnum;
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;
......
......@@ -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相关配置
......
/**
* 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;
}
}
......@@ -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.*;
......
/**
* 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;
}
}
......@@ -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>
......
......@@ -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 ApiLoginController 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;
}
}
......@@ -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;
......
......@@ -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>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment