Skip to content

Commit 73c1397

Browse files
Anil AllewarAnil Allewar
authored andcommitted
Got angular application to work with SSO to the user webservice
1 parent e3a9eba commit 73c1397

File tree

18 files changed

+90
-55
lines changed

18 files changed

+90
-55
lines changed

api-gateway/src/main/java/com/rohitghatol/microservice/gateway/Application.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.springframework.cloud.security.oauth2.sso.EnableOAuth2Sso;
1111
import org.springframework.context.annotation.ComponentScan;
1212
import org.springframework.context.annotation.Configuration;
13-
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableOAuth2Client;
1413

1514

1615
/**

api-gateway/src/main/java/com/rohitghatol/microservice/gateway/config/OAuthConfiguration.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import org.springframework.context.annotation.Configuration;
55
import org.springframework.http.HttpMethod;
66
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
7-
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
8-
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
97
import org.springframework.stereotype.Component;
108

119

auth-server/src/main/java/com/rohitghatol/microservice/auth/Application.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616
* @author rohitghatol
1717
*/
1818

19-
@Configuration
2019
@ComponentScan
2120
@EnableAutoConfiguration
2221
@EnableEurekaClient
23-
@EnableResourceServer
2422
public class Application {
2523

2624
/**

auth-server/src/main/java/com/rohitghatol/microservice/auth/config/ResourceServerConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*/
1717
@Configuration
18-
@Component
18+
@EnableResourceServer
1919
public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
2020
@Override
2121
public void configure(HttpSecurity http) throws Exception {

config-server/application.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ spring:
44
server:
55
git:
66
uri: https://github.com/anilallewar/sample-config
7+
# While in development mode, you can configure the config server to pick up configuration files from
8+
# the file system
9+
10+
# uri: file://Users/anilallewar/Documents/Anil Allewar/Trainings/Code Samples/Enterprise Java/Micro Services/sample-config
711

812
server:
913
port: 8888

task-webservice/src/main/java/com/rohitghatol/microservices/task/Application.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@
88
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
99
import org.springframework.cloud.security.oauth2.resource.EnableOAuth2Resource;
1010
import org.springframework.context.annotation.ComponentScan;
11-
import org.springframework.context.annotation.Configuration;
1211

1312
/**
1413
* @author rohitghatol
1514
*
1615
*/
1716
@EnableAutoConfiguration
1817
@ComponentScan
19-
@Configuration
2018
@EnableEurekaClient
2119
@EnableOAuth2Resource
2220
public class Application {

task-webservice/src/main/java/com/rohitghatol/microservices/task/apis/TaskController.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ public class TaskController {
1919
@RequestMapping(method = RequestMethod.GET, headers = "Accept=application/json")
2020
public List<TaskDTO> getTasks() {
2121
tasks = new ArrayList<TaskDTO>();
22-
tasks.add(new TaskDTO("task", "description"));
22+
tasks.add(new TaskDTO("task1", "description1"));
23+
tasks.add(new TaskDTO("task2", "description2"));
2324
return tasks;
2425
}
2526

2627
@RequestMapping(value = "{taskId}", method = RequestMethod.GET, headers = "Accept=application/json")
2728
public TaskDTO getUserByUserName(@PathVariable("taskId") String taskId) {
28-
return new TaskDTO("task", "description");
29+
return new TaskDTO("taskDetails", "descriptionDetails");
2930
}
3031
}

task-webservice/src/main/java/com/rohitghatol/microservices/task/config/TaskConfiguration.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,29 @@
33
*/
44
package com.rohitghatol.microservices.task.config;
55

6+
import org.springframework.context.annotation.Configuration;
67
import org.springframework.http.HttpMethod;
78
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
9+
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
810
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
911
import org.springframework.stereotype.Component;
1012

1113
/**
1214
* @author anilallewar
1315
*
1416
*/
15-
@Component
17+
@Configuration
18+
@EnableResourceServer
1619
public class TaskConfiguration extends ResourceServerConfigurerAdapter {
1720

1821
@Override
1922
public void configure(HttpSecurity http) throws Exception {
20-
http.requestMatchers().
21-
antMatchers("/**")
22-
.and().authorizeRequests()
23-
.antMatchers(HttpMethod.GET, "/**").access("#oauth2.hasScope('read')")
24-
.antMatchers(HttpMethod.OPTIONS, "/**").access("#oauth2.hasScope('read')")
25-
.antMatchers(HttpMethod.POST, "/**").access("#oauth2.hasScope('write')")
26-
.antMatchers(HttpMethod.PUT, "/**").access("#oauth2.hasScope('write')")
27-
.antMatchers(HttpMethod.PATCH, "/**").access("#oauth2.hasScope('write')")
28-
.antMatchers(HttpMethod.DELETE, "/**").access("#oauth2.hasScope('write')");
23+
http.requestMatchers()
24+
.antMatchers("/**")
25+
.and()
26+
.authorizeRequests()
27+
.anyRequest()
28+
.authenticated();
2929
}
3030

3131
}

user-webservice/application.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
logging:
2+
level:
3+
org:
4+
springframework:
5+
security: DEBUG

user-webservice/build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ distDocker {
5656
exposePort 8080
5757
}
5858

59+
bootRun {
60+
jvmArgs = ['-Xdebug', '-Xrunjdwp:server=y,transport=dt_socket,address=4200,suspend=n','-Dspring.profiles.active=dev']
61+
}
62+
63+
run {
64+
jvmArgs = ['-Xdebug', '-Xrunjdwp:server=y,transport=dt_socket,address=4200,suspend=n','-Dspring.profiles.active=dev']
65+
}
66+
5967
task createWrapper(type: Wrapper) {
6068
gradleVersion = '2.0'
6169
}

0 commit comments

Comments
 (0)