Skip to content

Commit d2195e7

Browse files
committed
Added Dockerfile and docker-compose.yml
1 parent a77bc65 commit d2195e7

File tree

43 files changed

+335
-896
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+335
-896
lines changed

.idea/compiler.xml

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api-gateway-service/Dockerfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#stage 1
2+
#Start with a base image containing Java runtime
3+
FROM openjdk:11-slim as build
4+
5+
# Add Maintainer Info
6+
LABEL maintainer="Nasruddin <nasruddin.java@gmail.com>"
7+
8+
# The application's jar file
9+
ARG JAR_FILE
10+
11+
# Add the application's jar to the container
12+
COPY ${JAR_FILE} app.jar
13+
14+
#unpackage jar file
15+
RUN mkdir -p target/dependency && (cd target/dependency; jar -xf /app.jar)
16+
17+
#stage 2
18+
#Same Java runtime
19+
FROM openjdk:11-slim
20+
21+
#Add volume pointing to /tmp
22+
VOLUME /tmp
23+
24+
#Copy unpackaged application to new container
25+
ARG DEPENDENCY=/target/dependency
26+
COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /app/lib
27+
COPY --from=build ${DEPENDENCY}/META-INF /app/META-INF
28+
COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /app
29+
30+
#execute the application
31+
ENTRYPOINT ["java","-cp","app:app/lib/*","com.javatab.apigatewayservice.ApiGatewayServiceApplication"]

api-gateway-service/pom.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<groupId>com.javatab</groupId>
1414
<artifactId>api-gateway-service</artifactId>
15-
<version>0.0.1-SNAPSHOT</version>
15+
<version>1.0.0</version>
1616
<name>api-gateway-service</name>
1717
<description>Demo project for Spring Boot</description>
1818

@@ -39,6 +39,10 @@
3939
<groupId>org.springframework.cloud</groupId>
4040
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
4141
</dependency>
42+
<dependency>
43+
<groupId>org.springframework.cloud</groupId>
44+
<artifactId>spring-cloud-starter-config</artifactId>
45+
</dependency>
4246
<dependency>
4347
<groupId>org.springframework.boot</groupId>
4448
<artifactId>spring-boot-devtools</artifactId>
@@ -107,7 +111,6 @@
107111
<phase>install</phase>
108112
<goals>
109113
<goal>build</goal>
110-
<goal>push</goal>
111114
</goals>
112115
</execution>
113116
</executions>

api-gateway-service/src/main/java/com/javatab/apigatewayservice/security/JwtTokenAuthenticationFilter.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.javatab.apigatewayservice.security;
22

3-
import com.javatab.commonservice.JwtConfig;
43
import io.jsonwebtoken.Claims;
54
import io.jsonwebtoken.Jwts;
65
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@@ -18,27 +17,21 @@
1817

1918
public class JwtTokenAuthenticationFilter extends OncePerRequestFilter {
2019

21-
private final JwtConfig jwtConfig;
22-
23-
public JwtTokenAuthenticationFilter(JwtConfig jwtConfig) {
24-
this.jwtConfig = jwtConfig;
25-
}
26-
2720
@Override
2821
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
2922
throws ServletException, IOException {
3023

31-
String header = request.getHeader(jwtConfig.getHeader());
24+
String header = request.getHeader("Authorization");
3225

33-
if(header == null || !header.startsWith(jwtConfig.getPrefix())) {
26+
if(header == null || !header.startsWith("Bearer")) {
3427
chain.doFilter(request, response); // If not valid, go to the next filter.
3528
return;
3629
}
37-
String token = header.replace(jwtConfig.getPrefix(), "");
30+
String token = header.replace("Bearer", "");
3831

3932
try {
4033
Claims claims = Jwts.parser()
41-
.setSigningKey(jwtConfig.getSecret().getBytes())
34+
.setSigningKey("JwtSecretKey".getBytes())
4235
.parseClaimsJws(token)
4336
.getBody();
4437

api-gateway-service/src/main/java/com/javatab/apigatewayservice/security/SecurityTokenConfig.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.javatab.apigatewayservice.security;
22

3-
import com.javatab.commonservice.JwtConfig;
4-
import org.springframework.beans.factory.annotation.Autowired;
53
import org.springframework.context.annotation.Bean;
64
import org.springframework.http.HttpMethod;
75
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
@@ -18,10 +16,8 @@
1816
import java.util.Collections;
1917
import java.util.stream.Collectors;
2018

21-
@EnableWebSecurity // Enable security config. This annotation denotes config for spring security.
19+
@EnableWebSecurity
2220
public class SecurityTokenConfig extends WebSecurityConfigurerAdapter {
23-
@Autowired
24-
private JwtConfig jwtConfig;
2521

2622
@Override
2723
protected void configure(HttpSecurity http) throws Exception {
@@ -32,9 +28,9 @@ protected void configure(HttpSecurity http) throws Exception {
3228
.and()
3329
.exceptionHandling().authenticationEntryPoint((req, rsp, e) -> rsp.sendError(HttpServletResponse.SC_UNAUTHORIZED))
3430
.and()
35-
.addFilterAfter(new JwtTokenAuthenticationFilter(jwtConfig), UsernamePasswordAuthenticationFilter.class)
31+
.addFilterAfter(new JwtTokenAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class)
3632
.authorizeRequests()
37-
.antMatchers(HttpMethod.POST, jwtConfig.getUri()).permitAll()
33+
.antMatchers(HttpMethod.POST, "/auth/**").permitAll()
3834
.antMatchers("/admin/**").hasRole("ADMIN")
3935
.anyRequest().authenticated();
4036

@@ -51,9 +47,4 @@ public CorsFilter corsFilter() {
5147
source.registerCorsConfiguration("/**", config);
5248
return new CorsFilter(source);
5349
}
54-
55-
@Bean
56-
public JwtConfig jwtConfig() {
57-
return new JwtConfig();
58-
}
5950
}

api-gateway-service/src/main/resources/application.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
spring:
2+
application:
3+
name: api-gateway-service
4+
cloud:
5+
config:
6+
uri: http://config-server:8071 # using old spring config, upgrade!
7+
discovery:
8+
service-id: config-server
9+
enabled: true

auth-service/Dockerfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#stage 1
2+
#Start with a base image containing Java runtime
3+
FROM openjdk:11-slim as build
4+
5+
# Add Maintainer Info
6+
LABEL maintainer="Nasruddin <nasruddin.java@gmail.com>"
7+
8+
# The application's jar file
9+
ARG JAR_FILE
10+
11+
# Add the application's jar to the container
12+
COPY ${JAR_FILE} app.jar
13+
14+
#unpackage jar file
15+
RUN mkdir -p target/dependency && (cd target/dependency; jar -xf /app.jar)
16+
17+
#stage 2
18+
#Same Java runtime
19+
FROM openjdk:11-slim
20+
21+
#Add volume pointing to /tmp
22+
VOLUME /tmp
23+
24+
#Copy unpackaged application to new container
25+
ARG DEPENDENCY=/target/dependency
26+
COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /app/lib
27+
COPY --from=build ${DEPENDENCY}/META-INF /app/META-INF
28+
COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /app
29+
30+
#execute the application
31+
ENTRYPOINT ["java","-cp","app:app/lib/*","com.javatab.authservice.AuthServiceApplication"]

0 commit comments

Comments
 (0)