Skip to content

Commit 8585745

Browse files
committed
small changes to oauth server
1 parent 5bd0615 commit 8585745

6 files changed

Lines changed: 110 additions & 75 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ curl -H "Content-Type: application/json" -X POST -d '{"id":161,"caption":"Test c
129129
```
130130

131131
## TODO
132+
* Deploy the project to Amazon ECS
132133
* Integrate turbine in the Admin dashboard
133134
* Add private maven repository Artifactory
134135
* Manager services integration through Spring Webflow

oauth-docker-compose.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
version: '2'
2+
3+
services:
4+
config:
5+
image: todo/config-server
6+
ports:
7+
- 8888:8888
8+
networks:
9+
- net
10+
hostname: config
11+
container_name: config
12+
external_links:
13+
- elk
14+
- kafka
15+
16+
oauth:
17+
image: todo/oauth-server
18+
ports:
19+
- 8017:8017
20+
networks:
21+
- net
22+
depends_on:
23+
- user
24+
hostname: oauth
25+
container_name: oauth
26+
command: ["./wait-for-it.sh","eureka:8010","--timeout=150","--","/usr/local/bin/start.sh"]
27+
external_links:
28+
- elk
29+
30+
eureka:
31+
image: todo/eureka-server
32+
ports:
33+
- 8010:8010
34+
networks:
35+
- net
36+
depends_on:
37+
- config
38+
hostname: eureka
39+
container_name: eureka
40+
command: ["./wait-for-it.sh","config:8888","--timeout=100","--","/usr/local/bin/start.sh"]
41+
external_links:
42+
- elk
43+
44+
gateway:
45+
image: todo/api-gateway
46+
ports:
47+
- 8018:8018
48+
networks:
49+
- net
50+
hostname: gateway
51+
command: ["./wait-for-it.sh","eureka:8010","--timeout=150","--","/usr/local/bin/start.sh"]
52+
external_links:
53+
- elk
54+
55+
user:
56+
image: todo/user-service
57+
ports:
58+
- 8016:8016
59+
networks:
60+
- net
61+
hostname: user
62+
container_name: user
63+
command: ["./wait-for-it.sh","eureka:8010","--timeout=150","--","/usr/local/bin/start.sh"]
64+
external_links:
65+
- elk
66+
- kafka
67+
68+
volumes:
69+
todo_data:
70+
external: true
71+
todo_elk:
72+
external: true
73+
74+
networks:
75+
net:
76+
driver: bridge

oauth-server/src/main/java/com/apssouza/auth/CustomTokenEnhancer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
package com.apssouza.auth;
32

43
import java.util.HashMap;
@@ -17,7 +16,8 @@ public class CustomTokenEnhancer implements TokenEnhancer {
1716
@Override
1817
public OAuth2AccessToken enhance(
1918
OAuth2AccessToken accessToken,
20-
OAuth2Authentication authentication) {
19+
OAuth2Authentication authentication
20+
) {
2121
Map<String, Object> additionalInfo = new HashMap<>();
2222
additionalInfo.put("name", authentication.getName());
2323
((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(additionalInfo);

oauth-server/src/main/java/com/apssouza/configuration/CORSFilterConfiguration.java

Lines changed: 0 additions & 70 deletions
This file was deleted.

oauth-server/src/main/java/com/apssouza/configuration/JwtServerConfiguration.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
@Configuration
1717
public class JwtServerConfiguration {
18+
19+
private static final String ENC_PASSWORD = "58347105";
1820

1921
@Bean
2022
public TokenStore tokenStore() {
@@ -23,7 +25,10 @@ public TokenStore tokenStore() {
2325

2426
@Bean
2527
protected JwtAccessTokenConverter jwtTokenEnhancer() {
26-
KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory(new ClassPathResource("jwt.jks"), "58347105".toCharArray());
28+
KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory(
29+
new ClassPathResource("jwt.jks"),
30+
ENC_PASSWORD.toCharArray()
31+
);
2732
JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
2833
converter.setKeyPair(keyStoreKeyFactory.getKeyPair("jwt"));
2934
return converter;

oauth-server/src/main/java/com/apssouza/configuration/OAuth2ServerConfiguration.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
package com.apssouza.configuration;
22

33
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.boot.web.servlet.FilterRegistrationBean;
5+
import org.springframework.context.annotation.Bean;
46
import org.springframework.context.annotation.Configuration;
5-
import org.springframework.http.HttpMethod;
7+
import org.springframework.core.Ordered;
68
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
7-
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
89
import org.springframework.security.core.Authentication;
910
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
1011
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
1112
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
1213
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
14+
import org.springframework.web.cors.CorsConfiguration;
15+
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
16+
import org.springframework.web.filter.CorsFilter;
1317

1418
/**
1519
* Oauth server configuration
@@ -49,4 +53,23 @@ public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws E
4953
.authenticate(authentication)
5054
);
5155
}
56+
57+
/**
58+
* CORS Filter
59+
*
60+
* @return Filter
61+
*/
62+
@Bean
63+
public FilterRegistrationBean filterRegistrationBean() {
64+
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
65+
CorsConfiguration config = new CorsConfiguration();
66+
config.setAllowCredentials(true);
67+
config.addAllowedOrigin("*");
68+
config.addAllowedHeader("*");
69+
config.addAllowedMethod("*");
70+
source.registerCorsConfiguration("/**", config);
71+
FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
72+
bean.setOrder(Ordered.HIGHEST_PRECEDENCE);
73+
return bean;
74+
}
5275
}

0 commit comments

Comments
 (0)