Skip to content

Instantly share code, notes, and snippets.

View OmarElgabry's full-sized avatar
🧑‍🌾

Omar Elgabry OmarElgabry

🧑‍🌾
View GitHub Profile
@OmarElgabry
OmarElgabry / SecurityTokenConfig.java
Last active June 10, 2018 18:56
Gateway Security Configurations
http
.csrf().disable()
// make sure we use stateless session; session won't be used to store user's state.
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
// handle an authorized attempts
.exceptionHandling().authenticationEntryPoint((req, rsp, e) -> rsp.sendError(HttpServletResponse.SC_UNAUTHORIZED))
.and()
// Add a filter to validate the tokens with every request
package com.eureka.zuul;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
@SpringBootApplication
@EnableEurekaClient // It acts as a eureka client
@EnableZuulProxy // Enable Zuul
@OmarElgabry
OmarElgabry / application.properties
Last active June 10, 2018 17:05
Gateway Configuration
server.port=8762
spring.application.name=zuul-server
eureka.client.service-url.default-zone=http://localhost:8761/eureka/
# A prefix that can added to beginning of all requests.
#zuul.prefix=/api
# Disable accessing services using service name (i.e. gallery-service).
# They should be only accessed through the path defined below.
zuul.ignored-services=*
@OmarElgabry
OmarElgabry / pom.xml
Last active February 19, 2019 08:37
Auth Service pom.xml
....
<dependencies>
<dependency>
<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>
@OmarElgabry
OmarElgabry / HomeController.java
Last active June 10, 2018 20:47
Eureka Gallery Service Controller
package com.eureka.gallery.controllers;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@OmarElgabry
OmarElgabry / SpringEurekaGalleryApp.java
Last active June 10, 2018 17:10
Eureka Gallery Service Class
package com.eureka.gallery;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
@OmarElgabry
OmarElgabry / application.properties
Last active January 28, 2020 17:22
Eureka Gallery Service Configurations
spring.application.name=gallery-service
server.port=8100
eureka.client.service-url.default-zone=http://localhost:8761/eureka
@OmarElgabry
OmarElgabry / HomeController.java
Last active February 19, 2019 08:33
Eureka Image Service Controller
package com.eureka.image.controllers;
import java.util.Arrays;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@OmarElgabry
OmarElgabry / SpringEurekaImageApp.java
Last active June 10, 2018 17:28
Eureka Image Service Class
package com.eureka.image;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
@SpringBootApplication
@EnableEurekaClient // Enable eureka client. It inherits from @EnableDiscoveryClient.
public class SpringEurekaImageApp {
public static void main(String[] args) {
@OmarElgabry
OmarElgabry / application.properties
Last active June 10, 2018 17:28
Eureka Image Service Configurations
# serivce name
spring.application.name=image-service
# port
server.port=8200
# eureka server url
eureka.client.service-url.default-zone=http://localhost:8761/eureka