Skip to content

Commit

Permalink
Release 2 (#25)
Browse files Browse the repository at this point in the history
* #1 Initialize (#4)

* #2 agent approval (#5)

* #3 report operations (#6)

* #3 report operations

* #3 authority

* mvn base images admin service nistagram (#19)

* Dockerfile Nistagram Admin Microservice (#20)

* CI pipelines (#21)

* feign admin service (#24)

Co-authored-by: DusanStevic <40674641+DusanStevic@users.noreply.github.com>
  • Loading branch information
MilePrastalo and DusanStevic authored Sep 15, 2021
1 parent 2cc0663 commit 1d2d476
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 36 deletions.
75 changes: 49 additions & 26 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<appName>admin_service</appName>
<sonar.organization>devops-nistagram-organization</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<spring-cloud.version>2020.0.3</spring-cloud.version>
</properties>
<dependencies>
<dependency>
Expand All @@ -43,24 +42,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand All @@ -72,17 +57,55 @@
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<build.profile.id>dev</build.profile.id>
<profileActive>dev</profileActive>
</properties>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
</profile>
<profile>
<id>test</id>
<properties>
<build.profile.id>test</build.profile.id>
<profileActive>test</profileActive>
</properties>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
</profile>
<profile>
<id>prod</id>
<properties>
<build.profile.id>prod</build.profile.id>
<profileActive>prod</profileActive>
</properties>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
</profile>
</profiles>


<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;

@SpringBootApplication
@EnableFeignClients
@EnableEurekaClient
public class AdministratorApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@FeignClient(url = "${api.postService}", name = "PostService")
// app.post.url from application.properties
@FeignClient(name = "post", url = "${app.post.url}")
public interface PostClient {
@DeleteMapping(value = "delete/{id}")
@DeleteMapping(value = "post/delete/{id}")
ResponseEntity<Boolean> deletePost(@PathVariable("id") Long id, @RequestHeader("Authorization") String bearerToken);
}
11 changes: 6 additions & 5 deletions src/main/java/com/nistagram/administrator/client/UserClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@

import java.util.List;

@FeignClient(url = "${api.userService}", name = "UserService")
// app.user.url from application.properties
@FeignClient(name = "user", url = "${app.user.url}")
public interface UserClient {
@GetMapping(value = "getUser/{username}")
@GetMapping(value = "user/getUser/{username}")
UserInfoDTO getUser(@PathVariable("username") String username);

@GetMapping(value = "getNotApprovedAgents")
@GetMapping(value = "user/getNotApprovedAgents")
ResponseEntity<List<UserInfoDTO>> getNotApprovedAgents(@RequestHeader("Authorization") String bearerToken);

@PostMapping(value = "approveAgent")
@PostMapping(value = "user/approveAgent")
ResponseEntity<UserInfoDTO> approveAgent(@RequestBody() UsernameWrapper dto, @RequestHeader("Authorization") String bearerToken);

@PostMapping(value = "rejectAgent")
@PostMapping(value = "user/rejectAgent")
ResponseEntity<UserInfoDTO> rejectAgent(@RequestBody() UsernameWrapper dto, @RequestHeader("Authorization") String bearerToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import java.util.Arrays;
import org.springframework.http.HttpMethod;


@Configuration
Expand Down Expand Up @@ -43,6 +48,23 @@ public PasswordEncoder passwordEncoder() {
@Autowired
private JwtUserDetailsService jwtUserDetailsService;

@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(false);
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
config.setExposedHeaders(Arrays.asList("Access-Control-Allow-Origin", "Location", "X-Requested-With", "Authorization", "Cache-Control", "Content-Type", "X-Total-Count", "allowedOriginPatterns"));
config.addAllowedMethod(HttpMethod.OPTIONS.name());
config.addAllowedMethod(HttpMethod.GET.name());
config.addAllowedMethod(HttpMethod.PUT.name());
config.addAllowedMethod(HttpMethod.POST.name());
config.addAllowedMethod(HttpMethod.DELETE.name());
source.registerCorsConfiguration("/**", config);
return new org.springframework.web.filter.CorsFilter(source);
}


// Defining access rights to specific URLs
@Override
Expand All @@ -65,7 +87,8 @@ protected void configure(HttpSecurity http) throws Exception {
// intercept every request and add filter
http.addFilterBefore(jwtRequestFilter, UsernamePasswordAuthenticationFilter.class);

http.csrf().disable();
//http.csrf().disable();
http.cors().and().csrf().disable();

/* http.headers().addHeaderWriter(
new StaticHeadersWriter("Access-Control-Allow-Origin", "*"));*/
Expand Down
17 changes: 17 additions & 0 deletions src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# DATABASE
spring.datasource.username=${DATABASE_USERNAME:root}
spring.datasource.password=${DATABASE_PASSWORD:password}
spring.datasource.url=jdbc:mysql://${DATABASE_DOMAIN:localhost}:${DATABASE_PORT:3306}/${DATABASE_SCHEMA:admin_db}
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.sql.init.continue-on-error=true

server.port=8080
spring.application.name=admin

app.user.url = ${USER_SERVICE_PROTOCOL:http}://${USER_SERVICE_DOMAIN:localhost}:${USER_SERVICE_PORT:8080}
app.post.url = ${POST_SERVICE_PROTOCOL:http}://${POST_SERVICE_DOMAIN:localhost}:${POST_SERVICE_PORT:8080}

jwt.secret=nistagram
16 changes: 16 additions & 0 deletions src/main/resources/application-prod.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# DATABASE
spring.datasource.username=${DATABASE_USERNAME:root}
spring.datasource.password=${DATABASE_PASSWORD:password}
spring.datasource.url=jdbc:postgresql://${DATABASE_DOMAIN:localhost}:${DATABASE_PORT:5432}/${DATABASE_SCHEMA:admin_db}
spring.datasource.platform=postgres
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true

server.port=8080
spring.application.name=admin

app.user.url = ${USER_SERVICE_PROTOCOL:http}://${USER_SERVICE_DOMAIN:localhost}:${USER_SERVICE_PORT:8080}
app.post.url = ${POST_SERVICE_PROTOCOL:http}://${POST_SERVICE_DOMAIN:localhost}:${POST_SERVICE_PORT:8080}

jwt.secret=${JWT_SECRET:nistagram}
16 changes: 16 additions & 0 deletions src/main/resources/application-test.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# DATABASE
spring.datasource.username=${DATABASE_USERNAME:root}
spring.datasource.password=${DATABASE_PASSWORD:password}
spring.datasource.url=jdbc:postgresql://${DATABASE_DOMAIN:localhost}:${DATABASE_PORT:5432}/${DATABASE_SCHEMA:admin_db}
spring.datasource.platform=postgres
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true

server.port=8080
spring.application.name=admin

app.user.url = ${USER_SERVICE_PROTOCOL:http}://${USER_SERVICE_DOMAIN:localhost}:${USER_SERVICE_PORT:8080}
app.post.url = ${POST_SERVICE_PROTOCOL:http}://${POST_SERVICE_DOMAIN:localhost}:${POST_SERVICE_PORT:8080}

jwt.secret=${JWT_SECRET:nistagram}
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
spring.profiles.active=@profileActive@

0 comments on commit 1d2d476

Please sign in to comment.