Skip to content

Commit b395dc1

Browse files
rozagerardomaibin
authored andcommitted
Now using Auth and Resource servers from Baeldung/spring-security-oauth (eugenp#6128)
1 parent 469e36f commit b395dc1

21 files changed

+48
-174
lines changed

spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/OauthClientApplication.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
/**
88
*
9-
* Note: This app is configured to use the authorization service and the resource service located in module spring-5-security-oauth
9+
* Note: This app is configured to use the authorization service and the resource service located in Baeldung/spring-security-oauth repo
1010
*
11-
* As we usually do with other well-known auth providers (github/facebook/...) we have to log-in using user credentials (bael-user/bael-password) and client configurations (bael-client-id/bael-secret) handled by the auth server
11+
* As we usually do with other well-known auth providers (github/facebook/...) we have to log-in using user credentials (john/123) and client configurations handled by the auth server
1212
*
1313
* @author rozagerardo
1414
*

spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/web/ClientRestController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
@RestController
1616
public class ClientRestController {
1717

18-
private static final String RESOURCE_URI = "http://localhost:8084/retrieve-resource";
18+
private static final String RESOURCE_URI = "http://localhost:8082/spring-security-oauth-resource/foos/1";
1919

2020
@Autowired
2121
WebClient webClient;
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66

77
/**
88
*
9-
* Note: This app is configured to use the authorization service and the resource service located in module spring-5-security-oauth
9+
* Note: This app is configured to use the authorization service and the resource service located in Baeldung/spring-security-oauth repo
1010
*
11-
* As we usually do with other well-known auth providers (github/facebook/...) we have to log-in using user credentials (bael-user/bael-password) and client configurations (bael-client-id/bael-secret) handled by the auth server
11+
* As we usually do with other well-known auth providers (github/facebook/...) we have to log-in using user credentials (john/123) and client configurations handled by the auth server
1212
*
1313
* @author rozagerardo
1414
*
1515
*/
1616
@PropertySource("classpath:webclient-auth-code-login-application.properties")
1717
@SpringBootApplication
18-
public class OauthClientApplication {
18+
public class OauthClientLoginApplication {
1919

2020
public static void main(String[] args) {
21-
SpringApplication.run(OauthClientApplication.class, args);
21+
SpringApplication.run(OauthClientLoginApplication.class, args);
2222
}
2323

2424
}

spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/web/ClientRestController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
@RestController
1717
public class ClientRestController {
1818

19-
private static final String RESOURCE_URI = "http://localhost:8084/retrieve-resource";
19+
private static final String RESOURCE_URI = "http://localhost:8082/spring-security-oauth-resource/foos/1";
2020

2121
@Autowired
2222
WebClient webClient;

spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/clientcredentials/ClientCredentialsOauthApplication.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77

88
/**
99
*
10-
* Note: This app is configured to use the authorization service and the resource service located in module spring-5-security-oauth
11-
*
12-
* As we usually do with other well-known auth providers (github/facebook/...) we have to log-in using credentials handled by the auth server (bael-user/bael-password)
10+
* Note: This app is configured to use the authorization service and the resource service located in Baeldung/spring-security-oauth repo
1311
*
1412
* @author rozagerardo
1513
*

spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/clientcredentials/service/WebClientChonJob.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import org.slf4j.LoggerFactory;
55
import org.springframework.beans.factory.annotation.Autowired;
66
import org.springframework.scheduling.annotation.Scheduled;
7-
import org.springframework.security.oauth2.client.OAuth2AuthorizedClient;
8-
import org.springframework.security.oauth2.client.annotation.RegisteredOAuth2AuthorizedClient;
97
import org.springframework.stereotype.Component;
108
import org.springframework.web.reactive.function.client.WebClient;
119

@@ -14,12 +12,12 @@ public class WebClientChonJob {
1412

1513
Logger logger = LoggerFactory.getLogger(WebClientChonJob.class);
1614

17-
private static final String RESOURCE_URI = "http://localhost:8084/retrieve-resource";
15+
private static final String RESOURCE_URI = "localhost:8082/spring-security-oauth-resource/foos/1";
1816

1917
@Autowired
2018
private WebClient webClient;
2119

22-
@Scheduled(fixedRate = 1000)
20+
@Scheduled(fixedRate = 5000)
2321
public void logResourceServiceResponse() {
2422

2523
webClient.get()

spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/ManualRequestApplication.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66

77
/**
88
*
9-
* Note: This app is configured to use the authorization service and the resource service located in module spring-5-security-oauth
10-
*
11-
* As we usually do with other well-known auth providers (github/facebook/...) we have to log-in using user credentials (bael-user/bael-password) and client configurations (bael-client-id/bael-secret) handled by the auth server
9+
* Note: This app is configured to use the authorization service and the resource service located in Baeldung/spring-security-oauth repo
1210
*
1311
* @author rozagerardo
1412
*
1513
*/
14+
@PropertySource("classpath:webclient-manual-request-oauth-application.properties")
1615
@SpringBootApplication
1716
public class ManualRequestApplication {
1817

spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/web/ManualOauthRequestController.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
55
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.beans.factory.annotation.Value;
67
import org.springframework.http.HttpHeaders;
7-
import org.springframework.http.MediaType;
88
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
99
import org.springframework.util.Base64Utils;
1010
import org.springframework.web.bind.annotation.GetMapping;
@@ -22,10 +22,16 @@ public class ManualOauthRequestController {
2222

2323
private static Logger logger = LoggerFactory.getLogger(ManualOauthRequestController.class);
2424

25-
private static final String TOKEN_ENDPOINT = "localhost:8085/oauth/token";
26-
private static final String RESOURCE_ENDPOINT = "localhost:8084/retrieve-resource";
27-
private static final String CLIENT_ID = "bael-client-id";
28-
private static final String CLIENT_SECRET = "bael-secret";
25+
private static final String RESOURCE_ENDPOINT = "localhost:8082/spring-security-oauth-resource/foos/1";
26+
27+
@Value("${the.authorization.client-id}")
28+
private String clientId;
29+
30+
@Value("${the.authorization.client-secret}")
31+
private String clientSecret;
32+
33+
@Value("${the.authorization.token-uri}")
34+
private String tokenUri;
2935

3036
@Autowired
3137
WebClient client;
@@ -34,8 +40,8 @@ public class ManualOauthRequestController {
3440
public Mono<String> obtainSecuredResource() {
3541
logger.info("Creating web client...");
3642
Mono<String> resource = client.post()
37-
.uri(TOKEN_ENDPOINT)
38-
.header(HttpHeaders.AUTHORIZATION, "Basic " + Base64Utils.encodeToString((CLIENT_ID + ":" + CLIENT_SECRET).getBytes()))
43+
.uri(tokenUri)
44+
.header(HttpHeaders.AUTHORIZATION, "Basic " + Base64Utils.encodeToString((clientId + ":" + clientSecret).getBytes()))
3945
.body(BodyInserters.fromFormData(OAuth2ParameterNames.GRANT_TYPE, GrantType.CLIENT_CREDENTIALS.getValue()))
4046
.retrieve()
4147
.bodyToMono(JsonNode.class)
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
spring.security.oauth2.client.registration.bael.client-name=bael
2-
spring.security.oauth2.client.registration.bael.client-id=bael-client-id
3-
spring.security.oauth2.client.registration.bael.client-secret=bael-secret
2+
spring.security.oauth2.client.registration.bael.client-id=fooClientIdPassword
3+
spring.security.oauth2.client.registration.bael.client-secret=secret
44
spring.security.oauth2.client.registration.bael.authorization-grant-type=authorization_code
55
spring.security.oauth2.client.registration.bael.redirect-uri=http://localhost:8080/authorize/oauth2/code/bael
66

7-
spring.security.oauth2.client.provider.bael.token-uri=http://localhost:8085/oauth/token
8-
spring.security.oauth2.client.provider.bael.authorization-uri=http://localhost:8085/oauth/authorize
7+
spring.security.oauth2.client.provider.bael.token-uri=http://localhost:8081/spring-security-oauth-server/oauth/token
8+
spring.security.oauth2.client.provider.bael.authorization-uri=http://localhost:8081/spring-security-oauth-server/oauth/authorize
99

1010
spring.security.user.password=pass
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
spring.security.oauth2.client.registration.bael.client-name=bael
2-
spring.security.oauth2.client.registration.bael.client-id=bael-client-id
3-
spring.security.oauth2.client.registration.bael.client-secret=bael-secret
2+
spring.security.oauth2.client.registration.bael.client-id=fooClientIdPassword
3+
spring.security.oauth2.client.registration.bael.client-secret=secret
44
spring.security.oauth2.client.registration.bael.authorization-grant-type=authorization_code
55
spring.security.oauth2.client.registration.bael.redirect-uri=http://localhost:8080/login/oauth2/code/bael
66

7-
spring.security.oauth2.client.provider.bael.token-uri=http://localhost:8085/oauth/token
8-
spring.security.oauth2.client.provider.bael.authorization-uri=http://localhost:8085/oauth/authorize
9-
spring.security.oauth2.client.provider.bael.user-info-uri=http://localhost:8084/user
10-
spring.security.oauth2.client.provider.bael.user-name-attribute=name
7+
spring.security.oauth2.client.provider.bael.token-uri=http://localhost:8081/spring-security-oauth-server/oauth/token
8+
spring.security.oauth2.client.provider.bael.authorization-uri=http://localhost:8081/spring-security-oauth-server/oauth/authorize
9+
spring.security.oauth2.client.provider.bael.user-info-uri=http://localhost:8082/spring-security-oauth-resource/users/extra
10+
spring.security.oauth2.client.provider.bael.user-name-attribute=user_name

0 commit comments

Comments
 (0)