forked from fp2952/spring-cloud-base
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git commit -m init
- Loading branch information
fangp
committed
Apr 13, 2018
1 parent
2d0e166
commit 034f0a6
Showing
72 changed files
with
3,466 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
*/target | ||
*.iml | ||
/.idea | ||
.idea | ||
*.class | ||
target/ | ||
.project | ||
.settings/ | ||
.classpath | ||
logs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?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"> | ||
<parent> | ||
<artifactId>spring-cloud</artifactId> | ||
<groupId>com.github.peng</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>api-gateway</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-consul-discovery</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-zuul</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-actuator</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-feign</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-hystrix</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-ribbon</artifactId> | ||
</dependency> | ||
|
||
</dependencies> | ||
</project> |
16 changes: 16 additions & 0 deletions
16
api-gateway/src/main/java/com/peng/gateway/ApiGatewayApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.peng.gateway; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.cloud.client.SpringCloudApplication; | ||
import org.springframework.cloud.netflix.zuul.EnableZuulProxy; | ||
|
||
/** | ||
* Created by fp295 on 2018/4/10. | ||
*/ | ||
@EnableZuulProxy | ||
@SpringCloudApplication | ||
public class ApiGatewayApplication { | ||
public static void main(String[] args){ | ||
SpringApplication.run(ApiGatewayApplication.class, args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
spring: | ||
cloud: | ||
consul: | ||
host: 127.0.0.1 | ||
port: 8500 | ||
discovery: | ||
prefer-ip-address: true | ||
application: | ||
name: api-gateway | ||
server: | ||
port: 21000 | ||
zuul: | ||
routes: | ||
main-data: | ||
path: /main-data/api/** | ||
serviceId: main-data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?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"> | ||
<parent> | ||
<artifactId>auth-center</artifactId> | ||
<groupId>com.github.peng</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>auth-center-api</artifactId> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-redis</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
|
||
</project> |
43 changes: 43 additions & 0 deletions
43
...-center/auth-center-api/src/main/java/com/peng/auth/api/config/RedisObjectSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.peng.auth.api.config; | ||
|
||
import org.springframework.core.convert.converter.Converter; | ||
import org.springframework.core.serializer.support.DeserializingConverter; | ||
import org.springframework.core.serializer.support.SerializingConverter; | ||
import org.springframework.data.redis.serializer.RedisSerializer; | ||
import org.springframework.data.redis.serializer.SerializationException; | ||
|
||
|
||
public class RedisObjectSerializer implements RedisSerializer { | ||
|
||
static final byte[] EMPTY_ARRAY = new byte[0]; | ||
|
||
private Converter<Object, byte[]> serializer = new SerializingConverter(); | ||
private Converter<byte[], Object> deserializer = new DeserializingConverter(); | ||
|
||
@Override | ||
public byte[] serialize(Object o) throws SerializationException { | ||
if(o == null) | ||
return EMPTY_ARRAY; | ||
try { | ||
return serializer.convert(o); | ||
}catch (Exception e){ | ||
return EMPTY_ARRAY; | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public Object deserialize(byte[] bytes) throws SerializationException { | ||
if(isEmpty(bytes)) | ||
return null; | ||
try { | ||
return deserializer.convert(bytes); | ||
}catch (Exception e){ | ||
throw new SerializationException("Cannot deserialize", e); | ||
} | ||
} | ||
|
||
private boolean isEmpty(byte[] bytes){ | ||
return (bytes == null || bytes.length == 0) ; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
auth-center/auth-center-api/src/main/java/com/peng/auth/api/pojo/ResponseCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.peng.auth.api.pojo; | ||
|
||
public enum ResponseCode { | ||
|
||
SUCCESS(1200, "success."), | ||
ERROR(1201, "error."), | ||
PARA_ERROR(1202, "parameters error."); | ||
|
||
ResponseCode(Integer code, String message) { | ||
this.code = code; | ||
this.message = message; | ||
} | ||
|
||
private Integer code; | ||
|
||
private String message; | ||
|
||
public Integer getCode() { | ||
return code; | ||
} | ||
|
||
public void setCode(Integer code) { | ||
this.code = code; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public void setMessage(String message) { | ||
this.message = message; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?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"> | ||
<parent> | ||
<artifactId>auth-center</artifactId> | ||
<groupId>com.github.peng</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>auth-center-provider</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.github.peng</groupId> | ||
<artifactId>auth-center-api</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.github.peng</groupId> | ||
<artifactId>main-data-client</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-actuator</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-consul-discovery</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-hystrix</artifactId> | ||
</dependency> | ||
|
||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
|
||
</project> |
14 changes: 14 additions & 0 deletions
14
...h-center-provider/src/main/java/com/peng/auth/provider/AuthCenterProviderApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.peng.auth.provider; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.cloud.client.SpringCloudApplication; | ||
|
||
/** | ||
* Created by fp295 on 2018/4/2. | ||
*/ | ||
@SpringCloudApplication | ||
public class AuthCenterProviderApplication { | ||
public static void main(String[] args){ | ||
SpringApplication.run(AuthCenterProviderApplication.class, args); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...er-provider/src/main/java/com/peng/auth/provider/config/redis/RedisAuthConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.peng.auth.provider.config.redis; | ||
|
||
import com.peng.auth.api.config.RedisObjectSerializer; | ||
import com.peng.main.api.mapper.model.BaseModuleResources; | ||
import com.peng.main.api.mapper.model.BaseRole; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
|
||
/** | ||
* Created by fp295 on 2018/4/12. | ||
*/ | ||
@Configuration | ||
public class RedisAuthConfiguration { | ||
|
||
@Autowired | ||
private JedisConnectionFactory con; | ||
|
||
@Bean | ||
public RedisTemplate<String, BaseRole> baseRoleTemplate() { | ||
RedisTemplate<String, BaseRole> template = new RedisTemplate(); | ||
template.setConnectionFactory(con); | ||
template.setKeySerializer(new StringRedisSerializer()); | ||
template.setValueSerializer(new RedisObjectSerializer()); | ||
return template; | ||
} | ||
|
||
@Bean | ||
public RedisTemplate<String, BaseModuleResources> baseModelTemplate() { | ||
RedisTemplate<String, BaseModuleResources> template = new RedisTemplate(); | ||
template.setConnectionFactory(con); | ||
template.setKeySerializer(new StringRedisSerializer()); | ||
template.setValueSerializer(new RedisObjectSerializer()); | ||
return template; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
auth-center/auth-center-provider/src/main/resources/application.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
server: | ||
context-path: /auth | ||
port: 21001 | ||
spring: | ||
cloud: | ||
consul: | ||
host: 127.0.0.1 | ||
port: 8500 | ||
discovery: | ||
prefer-ip-address: true | ||
health-check-path: ${server.context-path}/health | ||
tags: management.context-path=${server.context-path} | ||
application: | ||
name: auth-center | ||
redis: | ||
database: 0 | ||
host: 127.0.0.1 | ||
port: 6379 |
34 changes: 34 additions & 0 deletions
34
auth-center/auth-center-provider/src/test/java/com/peng/auth/provider/ApplicationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.peng.auth.provider; | ||
|
||
import com.peng.main.api.mapper.model.BaseRole; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.core.StringRedisTemplate; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
/** | ||
* Created by fp295 on 2018/4/12. | ||
*/ | ||
@RunWith(SpringRunner.class) | ||
@SpringBootTest | ||
public class ApplicationTests { | ||
|
||
@Autowired | ||
private RedisTemplate<String, BaseRole> baseRoleTemplate; | ||
|
||
@Test | ||
public void test() throws Exception { | ||
|
||
BaseRole baseRole = new BaseRole(); | ||
baseRole.setId("id"); | ||
baseRole.setRoleCode("code"); | ||
baseRoleTemplate.opsForValue().set(baseRole.getId(), baseRole); | ||
Assert.assertEquals(baseRole.getRoleCode(), baseRoleTemplate.opsForValue().get(baseRole.getId()).getRoleCode()); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?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"> | ||
<parent> | ||
<artifactId>spring-cloud</artifactId> | ||
<groupId>com.github.peng</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<packaging>pom</packaging> | ||
<modules> | ||
<module>auth-center-provider</module> | ||
<module>auth-center-api</module> | ||
</modules> | ||
<artifactId>auth-center</artifactId> | ||
|
||
|
||
</project> |
Oops, something went wrong.