【优化】 优化配置

This commit is contained in:
wangiegie@gmail.com 2017-10-28 22:44:40 +08:00
parent a123034e01
commit fc5baba24d
10 changed files with 65 additions and 34 deletions

View File

@ -11,8 +11,8 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
*/
@SpringBootApplication
@EnableDiscoveryClient
public class AdminApplication extends BaseController {
public class PigAdminApplication extends BaseController {
public static void main(String[] args) {
SpringApplication.run(AdminApplication.class, args);
SpringApplication.run(PigAdminApplication.class, args);
}
}

View File

@ -1,6 +1,7 @@
package com.github.pig.admin.controller;
import com.github.pig.common.web.BaseController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -11,5 +12,8 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/user")
public class UserController extends BaseController {
@GetMapping
public String user() {
return getUser();
}
}

View File

@ -18,11 +18,6 @@
</parent>
<dependencies>
<!--消息总线-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
<!--Redis-->
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@ -0,0 +1,49 @@
package com.github.pig.auth.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
/**
* @author lengleng
* @date 2017/10/28
*/
@Configuration
@ConfigurationProperties(prefix = "pig.auth")
public class AuthServerConfig {
private String clientId;
private String clientSecret;
private String scope;
private String signKey;
public String getClientId() {
return clientId;
}
public void setClientId(String clientId) {
this.clientId = clientId;
}
public String getClientSecret() {
return clientSecret;
}
public void setClientSecret(String clientSecret) {
this.clientSecret = clientSecret;
}
public String getScope() {
return scope;
}
public void setScope(String scope) {
this.scope = scope;
}
public String getSignKey() {
return signKey;
}
public void setSignKey(String signKey) {
this.signKey = signKey;
}
}

View File

@ -13,6 +13,8 @@ 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
@ -22,6 +24,8 @@ import org.springframework.security.oauth2.provider.token.store.redis.RedisToken
@Configuration
@EnableAuthorizationServer
public class PigAuthorizationConfig extends AuthorizationServerConfigurerAdapter {
@Autowired
private AuthServerConfig authServerConfig;
@Autowired
private AuthenticationManager authenticationManager;
@ -35,10 +39,10 @@ public class PigAuthorizationConfig extends AuthorizationServerConfigurerAdapter
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("lengleng")
.secret("lengleng")
.withClient(authServerConfig.getClientId())
.secret(authServerConfig.getClientSecret())
.authorizedGrantTypes("refresh_token", "password")
.scopes("ui");
.scopes(authServerConfig.getScope());
}
@Override
@ -53,7 +57,7 @@ public class PigAuthorizationConfig extends AuthorizationServerConfigurerAdapter
@Bean
public JwtAccessTokenConverter jwtAccessTokenConverter(){
JwtAccessTokenConverter jwtAccessTokenConverter = new JwtAccessTokenConverter();
jwtAccessTokenConverter.setSigningKey("pig");
jwtAccessTokenConverter.setSigningKey(authServerConfig.getSignKey());
return jwtAccessTokenConverter;
}
}

View File

@ -12,15 +12,9 @@ spring:
bus:
trace:
enabled: true
rabbitmq:
port: 5672
host: localhost
username: guest
password: guest
eureka:
instance:
prefer-ip-address: true
client:
serviceUrl:
defaultZone: http://127.0.0.1:9000/eureka/

View File

@ -22,11 +22,6 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<!--消息总线-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
</dependencies>

View File

@ -28,11 +28,6 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
</dependency>
<!--消息总线-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
<!--oauth2.0-->
<dependency>
<groupId>org.springframework.cloud</groupId>

View File

@ -26,7 +26,7 @@ public class PermissionServiceImpl implements PermissionService {
if (principal != null) {
//TODO 根据用户名查询缓存没有的查询数据库
Set<String> urls = new HashSet<>();
urls.add("/demo");
urls.add("/user");
for (String url : urls) {
if (request.getRequestURI().contains(url)){

View File

@ -12,11 +12,6 @@ spring:
bus:
trace:
enabled: true
rabbitmq:
port: 5672
host: localhost
username: guest
password: guest
eureka:
instance: