Merge remote-tracking branch 'origin/master'

master
yangjie 4 years ago
commit 7edc6b080a
  1. 9
      pom.xml
  2. 1
      src/main/java/com/yipin/liuwanr/ProjectMaagementApplication.java
  3. 50
      src/main/java/com/yipin/liuwanr/config/AuthConfig.java
  4. 58
      src/main/java/com/yipin/liuwanr/filter/AuthInterceptor.java
  5. 29
      src/main/resources/application-keda.properties
  6. 5
      src/main/resources/application-occupationlab.properties

@ -70,6 +70,15 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-redis</artifactId>
<version>1.4.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency> <dependency>
<groupId>io.springfox</groupId> <groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId> <artifactId>springfox-swagger-ui</artifactId>

@ -3,6 +3,7 @@ package com.yipin.liuwanr;
import org.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import springfox.documentation.swagger2.annotations.EnableSwagger2; import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableSwagger2 @EnableSwagger2

@ -0,0 +1,50 @@
package com.yipin.liuwanr.config;
import com.yipin.liuwanr.filter.AuthInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.List;
/**
* @description
* @author: Mr.JK
* @create: 2021-06-03 17:26
**/
@Configuration
@ConfigurationProperties(prefix = "auth")
public class AuthConfig implements WebMvcConfigurer {
//开启拦截字符串
public static String openInterceptStr;
//放行url
public static List<String> permitUrl;
@Value("${auth.openInterceptStr}")
public void setOpenInterceptStr(String openInterceptStr) {
AuthConfig.openInterceptStr = openInterceptStr;
}
@Value("${auth.permitUrl}")
public void setPermitUrl(List<String> permitUrl) {
AuthConfig.permitUrl = permitUrl;
}
@Bean
public AuthInterceptor initAuthInterceptor(){
return new AuthInterceptor();
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(initAuthInterceptor()).addPathPatterns(openInterceptStr)
.excludePathPatterns(permitUrl);
}
}

@ -0,0 +1,58 @@
package com.yipin.liuwanr.filter;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Objects;
/**
* @description
* @author: Mr.JK
* @create: 2021-06-03 17:29
**/
public class AuthInterceptor implements HandlerInterceptor {
@Resource
StringRedisTemplate stringRedisTemplate;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=utf-8");
String token = request.getHeader("token");
if (StringUtils.isEmpty(token)) {
//用户未登录,请登录后操作!
response.getWriter().print("0");
return false;
}
ValueOperations<String, String> ops = stringRedisTemplate.opsForValue();
Object loginStatus = ops.get(token);
if( Objects.isNull(loginStatus)){
//token错误
response.getWriter().print("1");
return false;
}
return true;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
}
}

@ -3,16 +3,16 @@ server.port=1010
server.servlet.context-path=/project server.servlet.context-path=/project
#\u79D1\u5927\u6570\u636E\u5E93\u8FDE\u63A5 #\u79D1\u5927\u6570\u636E\u5E93\u8FDE\u63A5
#spring.datasource.url=jdbc:mysql://rm-wz9y13wf7u8q8610fwo.mysql.rds.aliyuncs.com:3306/keda?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai spring.datasource.url=jdbc:mysql://rm-wz9y13wf7u8q8610fwo.mysql.rds.aliyuncs.com:3306/keda?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
#spring.datasource.username=super spring.datasource.username=super
#spring.datasource.password=huoran888 spring.datasource.password=huoran888
#spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#\u79D1\u5927\u6B63\u5F0F\u6570\u636E\u5E93\u8FDE\u63A5 #\u79D1\u5927\u6B63\u5F0F\u6570\u636E\u5E93\u8FDE\u63A5
spring.datasource.url=jdbc:mysql://192.168.0.99:3306/keda?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai #spring.datasource.url=jdbc:mysql://192.168.0.99:3306/keda?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
spring.datasource.username=root #spring.datasource.username=root
spring.datasource.password=mssdk@028 #spring.datasource.password=mssdk@028
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver #spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jackson.default-property-inclusion=non_null spring.jackson.default-property-inclusion=non_null
@ -23,3 +23,16 @@ logging.level.jdbc.resultsettable=DEBUG
logging.level.com.yipin.liuwar.mapper=DEBUG logging.level.com.yipin.liuwar.mapper=DEBUG
logging.level.com.yipin.liuwanr.mapper=DEBUG logging.level.com.yipin.liuwanr.mapper=DEBUG
spring.redis.database=0
spring.redis.host=127.0.0.1
spring.redis.password=msdw@2021
spring.redis.port=6379
spring.redis.timeout=3000
#开启全局拦截,为空不开启拦截
#auth.openInterceptStr=
auth.openInterceptStr=/**
#放行Url
auth.permitUrl=

@ -23,3 +23,8 @@ logging.level.jdbc.resultsettable=DEBUG
logging.level.com.yipin.liuwar.mapper=DEBUG logging.level.com.yipin.liuwar.mapper=DEBUG
logging.level.com.yipin.liuwanr.mapper=DEBUG logging.level.com.yipin.liuwanr.mapper=DEBUG
#开启全局拦截,为空不开启拦截
auth.openInterceptStr=
#auth.openInterceptStr=/**
#放行Url
auth.permitUrl=
Loading…
Cancel
Save