BAEL-649 Making updates to add two service applications that are domain specific
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package com.baeldung.spring.cloud.bootstrap.svcrating;
|
||||
|
||||
public class Rating {
|
||||
private Long id;
|
||||
private Long bookId;
|
||||
private int stars;
|
||||
|
||||
public Rating() {
|
||||
}
|
||||
|
||||
public Rating(Long id, Long bookId, int stars) {
|
||||
this.id = id;
|
||||
this.bookId = bookId;
|
||||
this.stars = stars;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getBookId() {
|
||||
return bookId;
|
||||
}
|
||||
|
||||
public void setBookId(Long bookId) {
|
||||
this.bookId = bookId;
|
||||
}
|
||||
|
||||
public int getStars() {
|
||||
return stars;
|
||||
}
|
||||
|
||||
public void setStars(int stars) {
|
||||
this.stars = stars;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.baeldung.spring.cloud.bootstrap.svcrating;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableEurekaClient
|
||||
@RestController
|
||||
@RequestMapping("/ratings")
|
||||
public class RatingServiceApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(RatingServiceApplication.class, args);
|
||||
}
|
||||
|
||||
private List<Rating> ratingList = Arrays.asList(
|
||||
new Rating(1L, 1L, 2),
|
||||
new Rating(2L, 1L, 3),
|
||||
new Rating(3L, 2L, 4),
|
||||
new Rating(4L, 2L, 5)
|
||||
);
|
||||
|
||||
@GetMapping("")
|
||||
public List<Rating> findRatingsByBookId(@RequestParam Long bookId) {
|
||||
return bookId == null || bookId.equals(0L) ? Collections.EMPTY_LIST : ratingList.stream().filter(r -> r.getBookId().equals(bookId)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@GetMapping("/all")
|
||||
public List<Rating> findAllRatings() {
|
||||
return ratingList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.baeldung.spring.cloud.bootstrap.svcrating;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
|
||||
@EnableWebSecurity
|
||||
@Configuration
|
||||
public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Autowired
|
||||
public void configureGlobal1(AuthenticationManagerBuilder auth) throws Exception {
|
||||
//try in memory auth with no users to support the case that this will allow for users that are logged in to go anywhere
|
||||
auth.inMemoryAuthentication();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http.httpBasic()
|
||||
.disable()
|
||||
.authorizeRequests()
|
||||
.antMatchers("/ratings").hasRole("USER")
|
||||
.antMatchers("/ratings/all").hasAnyRole("USER", "ADMIN")
|
||||
.anyRequest().authenticated()
|
||||
.and()
|
||||
.csrf()
|
||||
.disable();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.baeldung.spring.cloud.bootstrap.svcrating;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
|
||||
import org.springframework.session.web.context.AbstractHttpSessionApplicationInitializer;
|
||||
|
||||
@Configuration
|
||||
@EnableRedisHttpSession
|
||||
public class SessionConfig extends AbstractHttpSessionApplicationInitializer {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
spring.cloud.config.name=rating-service
|
||||
spring.cloud.config.discovery.service-id=config
|
||||
spring.cloud.config.discovery.enabled=true
|
||||
spring.cloud.config.username=configUser
|
||||
spring.cloud.config.password=configPassword
|
||||
|
||||
eureka.client.serviceUrl.defaultZone=http://discUser:discPassword@localhost:8082/eureka/
|
||||
Reference in New Issue
Block a user