mirror of https://gitee.com/maxjhandsome/pig
【优化】 公共部分、细节优化
This commit is contained in:
parent
fc5baba24d
commit
39469e857a
|
@ -1,12 +1,21 @@
|
|||
server:
|
||||
port: 4000
|
||||
spring:
|
||||
application:
|
||||
name: pig-admin-service
|
||||
|
||||
eureka:
|
||||
instance:
|
||||
prefer-ip-address: true
|
||||
client:
|
||||
serviceUrl:
|
||||
defaultZone: http://127.0.0.1:9000/eureka/
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: pig-admin-service
|
||||
cloud:
|
||||
config:
|
||||
fail-fast: true
|
||||
discovery:
|
||||
service-id: pig-config-server
|
||||
enabled: true
|
||||
profile: dev
|
||||
label: master
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -18,6 +18,11 @@
|
|||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.pig</groupId>
|
||||
<artifactId>pig-common</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!--Redis-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
|
|
@ -13,7 +13,6 @@ public class AuthServerConfig {
|
|||
private String clientId;
|
||||
private String clientSecret;
|
||||
private String scope;
|
||||
private String signKey;
|
||||
|
||||
public String getClientId() {
|
||||
return clientId;
|
||||
|
@ -38,12 +37,4 @@ public class AuthServerConfig {
|
|||
public void setScope(String scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
public String getSignKey() {
|
||||
return signKey;
|
||||
}
|
||||
|
||||
public void setSignKey(String signKey) {
|
||||
this.signKey = signKey;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.github.pig.auth.config;
|
||||
|
||||
import com.github.pig.common.web.constant.CommonConstant;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
@ -13,8 +14,6 @@ import org.springframework.security.oauth2.config.annotation.web.configurers.Aut
|
|||
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
|
||||
import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2017/10/27
|
||||
|
@ -55,9 +54,9 @@ public class PigAuthorizationConfig extends AuthorizationServerConfigurerAdapter
|
|||
}
|
||||
|
||||
@Bean
|
||||
public JwtAccessTokenConverter jwtAccessTokenConverter(){
|
||||
public JwtAccessTokenConverter jwtAccessTokenConverter() {
|
||||
JwtAccessTokenConverter jwtAccessTokenConverter = new JwtAccessTokenConverter();
|
||||
jwtAccessTokenConverter.setSigningKey(authServerConfig.getSignKey());
|
||||
jwtAccessTokenConverter.setSigningKey(CommonConstant.SIGN_KEY);
|
||||
return jwtAccessTokenConverter;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
eureka:
|
||||
instance:
|
||||
prefer-ip-address: true
|
||||
client:
|
||||
serviceUrl:
|
||||
defaultZone: http://127.0.0.1:9000/eureka/
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: pig-auth-service
|
||||
|
@ -9,12 +16,4 @@ spring:
|
|||
enabled: true
|
||||
profile: dev
|
||||
label: master
|
||||
bus:
|
||||
trace:
|
||||
enabled: true
|
||||
eureka:
|
||||
instance:
|
||||
prefer-ip-address: true
|
||||
client:
|
||||
serviceUrl:
|
||||
defaultZone: http://127.0.0.1:9000/eureka/
|
||||
|
||||
|
|
|
@ -18,11 +18,35 @@
|
|||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<!--JWT-->
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt</artifactId>
|
||||
<version>0.7.0</version>
|
||||
</dependency>
|
||||
<!--MySQL-->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
<!-- mybatis-plus start -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus</artifactId>
|
||||
<version>2.1.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatisplus-spring-boot-starter</artifactId>
|
||||
<version>1.0.5</version>
|
||||
</dependency>
|
||||
<!--myabtis-plus 代码生成依赖-->
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity-engine-core</artifactId>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
<!--mybatis-plus end -->
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.github.pig.common.web;
|
||||
|
||||
import com.github.pig.common.web.constant.CommonConstant;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
@ -18,12 +19,13 @@ public class BaseController {
|
|||
|
||||
/**
|
||||
* 根据请求heard中的token获取用户
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getUser() {
|
||||
String authorization = request.getHeader("Authorization");
|
||||
String token = StringUtils.substringAfter(authorization, "Bearer ");
|
||||
String key = Base64.getEncoder().encodeToString("pig".getBytes());
|
||||
String authorization = request.getHeader(CommonConstant.REQ_HEADER);
|
||||
String token = StringUtils.substringAfter(authorization, CommonConstant.TOKEN_SPLIT);
|
||||
String key = Base64.getEncoder().encodeToString(CommonConstant.SIGN_KEY.getBytes());
|
||||
Claims claims = Jwts.parser().setSigningKey(key).parseClaimsJws(token).getBody();
|
||||
return claims.get("user_name").toString();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package com.github.pig.common.web.config;
|
||||
|
||||
import com.baomidou.mybatisplus.plugins.PaginationInterceptor;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2017/10/29
|
||||
*/
|
||||
@Configuration
|
||||
@MapperScan("com.github.pig")
|
||||
public class MybatisPlusConfig {
|
||||
@Bean
|
||||
public PaginationInterceptor paginationInterceptor() {
|
||||
return new PaginationInterceptor();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.github.pig.common.web.constant;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2017/10/29
|
||||
*/
|
||||
public interface CommonConstant {
|
||||
/**
|
||||
* token请求头名称
|
||||
*/
|
||||
String REQ_HEADER = "Authorization";
|
||||
|
||||
/**
|
||||
* token分割符
|
||||
*/
|
||||
String TOKEN_SPLIT = "Bearer ";
|
||||
|
||||
/**
|
||||
* jwt签名
|
||||
*/
|
||||
String SIGN_KEY = "PIG";
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.github.pig.common.web.util;
|
||||
|
||||
import com.baomidou.mybatisplus.generator.AutoGenerator;
|
||||
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.PackageConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.DbType;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2017/10/29
|
||||
*/
|
||||
public class MybatisPlusGenerator {
|
||||
public static void main(String[] args) {
|
||||
AutoGenerator mpg = new AutoGenerator();
|
||||
|
||||
// 全局配置
|
||||
GlobalConfig gc = new GlobalConfig();
|
||||
gc.setOutputDir("D://data");
|
||||
gc.setFileOverride(true);
|
||||
gc.setActiveRecord(true);
|
||||
gc.setEnableCache(false);// XML 二级缓存
|
||||
gc.setBaseResultMap(true);// XML ResultMap
|
||||
gc.setBaseColumnList(false);// XML columList
|
||||
gc.setAuthor("lengleng");
|
||||
mpg.setGlobalConfig(gc);
|
||||
|
||||
// 数据源配置
|
||||
DataSourceConfig dsc = new DataSourceConfig();
|
||||
dsc.setDbType(DbType.MYSQL);
|
||||
dsc.setDriverName("com.mysql.jdbc.Driver");
|
||||
dsc.setUsername("root");
|
||||
dsc.setPassword("root");
|
||||
dsc.setUrl("jdbc:mysql://127.0.0.1:3306/pig?characterEncoding=utf8");
|
||||
mpg.setDataSource(dsc);
|
||||
|
||||
// 策略配置
|
||||
StrategyConfig strategy = new StrategyConfig();
|
||||
// strategy.setCapitalMode(true);// 全局大写命名 ORACLE 注意
|
||||
strategy.setTablePrefix(new String[]{"tlog_", "tsys_"});// 此处可以修改为您的表前缀
|
||||
strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略
|
||||
mpg.setStrategy(strategy);
|
||||
|
||||
// 包配置
|
||||
PackageConfig pc = new PackageConfig();
|
||||
pc.setParent("com.example.sbmp");
|
||||
mpg.setPackageInfo(pc);
|
||||
|
||||
mpg.execute();
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
server:
|
||||
port: 4000
|
||||
spring:
|
||||
application:
|
||||
name: pig-demo-service
|
||||
|
||||
eureka:
|
||||
instance:
|
||||
prefer-ip-address: true
|
||||
client:
|
||||
serviceUrl:
|
||||
defaultZone: http://127.0.0.1:9000/eureka/
|
|
@ -1,3 +1,10 @@
|
|||
eureka:
|
||||
instance:
|
||||
prefer-ip-address: true
|
||||
client:
|
||||
serviceUrl:
|
||||
defaultZone: http://127.0.0.1:9000/eureka/
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: pig-gateway
|
||||
|
@ -9,22 +16,3 @@ spring:
|
|||
enabled: true
|
||||
profile: dev
|
||||
label: master
|
||||
bus:
|
||||
trace:
|
||||
enabled: true
|
||||
|
||||
eureka:
|
||||
instance:
|
||||
prefer-ip-address: true
|
||||
client:
|
||||
serviceUrl:
|
||||
defaultZone: http://127.0.0.1:9000/eureka/
|
||||
|
||||
security:
|
||||
sessions: stateless
|
||||
oauth2:
|
||||
resource:
|
||||
loadBalanced: true
|
||||
user-info-uri: http://pig-auth-service/user
|
||||
prefer-token-info: false
|
||||
service-id: pig-gateway
|
Loading…
Reference in New Issue