Skip to content

Commit 626360d

Browse files
committed
BAEL-649 Making updates to add two service applications that are domain specific
1 parent 299fed2 commit 626360d

18 files changed

Lines changed: 328 additions & 55 deletions

File tree

spring-cloud/spring-cloud-bootstrap/application-config/resource.properties renamed to spring-cloud/spring-cloud-bootstrap/application-config/book-service.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
spring.application.name=resource
1+
spring.application.name=book-service
22
server.port=8083
33

44
resource.returnString=hello cloud

‎spring-cloud/spring-cloud-bootstrap/application-config/gateway.properties‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ eureka.client.registryFetchIntervalSeconds = 5
66

77
management.security.sessions=always
88

9-
zuul.routes.resource.path=/resource/**
10-
zuul.routes.resource.sensitive-headers=Set-Cookie,Authorization
11-
hystrix.command.resource.execution.isolation.thread.timeoutInMilliseconds=600000
9+
zuul.routes.book-service.path=/book-service/**
10+
zuul.routes.book-service.sensitive-headers=Set-Cookie,Authorization
11+
hystrix.command.book-service.execution.isolation.thread.timeoutInMilliseconds=600000
12+
13+
zuul.routes.rating-service.path=/rating-service/**
14+
zuul.routes.rating-service.sensitive-headers=Set-Cookie,Authorization
15+
hystrix.command.rating-service.execution.isolation.thread.timeoutInMilliseconds=600000
1216

1317
zuul.routes.discovery.path=/discovery/**
1418
zuul.routes.discovery.sensitive-headers=Set-Cookie,Authorization
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
spring.application.name=rating-service
2+
server.port=8084
3+
4+
resource.returnString=hello cloud
5+
resource.user.returnString=hello cloud user
6+
resource.admin.returnString=hello cloud admin
7+
8+
eureka.client.region = default
9+
eureka.client.registryFetchIntervalSeconds = 5
10+
11+
management.security.sessions=never
12+
13+
logging.level.org.springframework.web.=debug
14+
logging.level.org.springframework.security=debug
15+
16+
spring.redis.host=localhost
17+
spring.redis.port=6379

‎spring-cloud/spring-cloud-bootstrap/gateway/src/main/java/com/baeldung/spring/cloud/bootstrap/gateway/SecurityConfig.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception
2222
@Override
2323
protected void configure(HttpSecurity http) throws Exception {
2424
http.authorizeRequests()
25-
.antMatchers("/resource/hello/cloud").permitAll()
25+
.antMatchers("/book-service/books").permitAll()
2626
.antMatchers("/eureka/**").hasRole("ADMIN")
2727
.anyRequest().authenticated()
2828
.and()
2929
.formLogin()
3030
.and()
3131
.logout().permitAll()
32-
.logoutSuccessUrl("/resource/hello/cloud").permitAll()
32+
.logoutSuccessUrl("/book-service/books").permitAll()
3333
.and()
3434
.csrf()
3535
.disable();

‎spring-cloud/spring-cloud-bootstrap/pom.xml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
<module>config</module>
1515
<module>discovery</module>
1616
<module>gateway</module>
17-
<module>resource</module>
17+
<module>svc-book</module>
18+
<module>svc-rating</module>
1819
</modules>
1920

2021

‎spring-cloud/spring-cloud-bootstrap/resource/src/main/java/com/baeldung/spring/cloud/bootstrap/resource/ResourceApplication.java‎

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

spring-cloud/spring-cloud-bootstrap/resource/pom.xml renamed to spring-cloud/spring-cloud-bootstrap/svc-book/pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66

7-
<artifactId>resource</artifactId>
7+
<groupId>com.baeldung.spring.cloud</groupId>
8+
<artifactId>svc-book</artifactId>
89
<version>1.0.0-SNAPSHOT</version>
910

1011
<parent>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.baeldung.spring.cloud.bootstrap.svcbook;
2+
3+
public class Book {
4+
private Long id;
5+
private String author;
6+
private String title;
7+
8+
public Book(Long id, String title, String author) {
9+
this.id = id;
10+
this.author = author;
11+
this.title = title;
12+
}
13+
14+
public Book() {
15+
}
16+
17+
public Long getId() {
18+
return id;
19+
}
20+
21+
public void setId(Long id) {
22+
this.id = id;
23+
}
24+
25+
public String getAuthor() {
26+
return author;
27+
}
28+
29+
public void setAuthor(String author) {
30+
this.author = author;
31+
}
32+
33+
public String getTitle() {
34+
return title;
35+
}
36+
37+
public void setTitle(String title) {
38+
this.title = title;
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.baeldung.spring.cloud.bootstrap.svcbook;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
6+
import org.springframework.web.bind.annotation.GetMapping;
7+
import org.springframework.web.bind.annotation.PathVariable;
8+
import org.springframework.web.bind.annotation.RequestMapping;
9+
import org.springframework.web.bind.annotation.RestController;
10+
11+
import java.util.Arrays;
12+
import java.util.List;
13+
14+
@SpringBootApplication
15+
@EnableEurekaClient
16+
@RestController
17+
@RequestMapping("/books")
18+
public class BookServiceApplication {
19+
public static void main(String[] args) {
20+
SpringApplication.run(BookServiceApplication.class, args);
21+
}
22+
23+
private List<Book> bookList = Arrays.asList(
24+
new Book(1L, "Baeldung goes to the market", "Tim Schimandle"),
25+
new Book(2L, "Baeldung goes to the park", "Slavisa")
26+
);
27+
28+
@GetMapping("")
29+
public List<Book> findAllBooks() {
30+
return bookList;
31+
}
32+
33+
@GetMapping("/{bookId}")
34+
public Book findBook(@PathVariable Long bookId) {
35+
return bookList.stream().filter(b -> b.getId().equals(bookId)).findFirst().orElse(null);
36+
}
37+
}

spring-cloud/spring-cloud-bootstrap/resource/src/main/java/com/baeldung/spring/cloud/bootstrap/resource/SecurityConfig.java renamed to spring-cloud/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/SecurityConfig.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.baeldung.spring.cloud.bootstrap.resource;
1+
package com.baeldung.spring.cloud.bootstrap.svcbook;
22

33
import org.springframework.beans.factory.annotation.Autowired;
44
import org.springframework.context.annotation.Configuration;
@@ -22,9 +22,8 @@ protected void configure(HttpSecurity http) throws Exception {
2222
http.httpBasic()
2323
.disable()
2424
.authorizeRequests()
25-
.antMatchers("/hello/cloud").permitAll()
26-
.antMatchers("/hello/user").hasAnyRole("USER", "ADMIN")
27-
.antMatchers("/hello/admin").hasRole("ADMIN")
25+
.antMatchers("/books").permitAll()
26+
.antMatchers("/books/*").hasAnyRole("USER", "ADMIN")
2827
.anyRequest().authenticated()
2928
.and()
3029
.csrf()

0 commit comments

Comments
 (0)