Skip to content

Instantly share code, notes, and snippets.

View OmarElgabry's full-sized avatar
🧑‍🌾

Omar Elgabry OmarElgabry

🧑‍🌾
View GitHub Profile
@OmarElgabry
OmarElgabry / pom.xml
Created February 19, 2019 08:43
Gateway Zuul 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
Created June 10, 2018 23:10
Eureka Gallery Service Controller with Hystrix
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 / JwtUsernameAndPasswordAuthenticationFilter.java
Last active February 9, 2019 17:59
JWT UsernameAndPassword Authentication Filter
package com.eureka.auth.security;
import java.io.IOException;
import java.sql.Date;
import java.util.Collections;
import java.util.stream.Collectors;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
@OmarElgabry
OmarElgabry / UserDetailsServiceImpl.java
Last active June 10, 2018 20:36
UserDetailsService Implementation
package com.eureka.auth.security;
import java.util.Arrays;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
@OmarElgabry
OmarElgabry / SecurityCredentialsConfig.java
Last active June 10, 2018 19:37
Auth Service Security Configurations
package com.eureka.auth.security;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpMethod;
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;
@OmarElgabry
OmarElgabry / application.properties
Created June 10, 2018 19:27
Auth Configurations
spring.application.name=auth-service
server.port=9100
eureka.client.service-url.default-zone=http://localhost:8761/eureka
@OmarElgabry
OmarElgabry / application.properties
Created June 10, 2018 19:11
Gateway Configurations
# Map path to auth service
zuul.routes.auth-service.path=/auth/**
zuul.routes.auth-service.service-id=AUTH-SERVICE
# By default, all requests to gallery service for example will start with: "/gallery/"
# What will be sent to the gallery service is what comes after the path defined,
# So, if request is "/gallery/view/1", gallery service will get "/view/1".
# In case of auth, we need to pass the "/auth/" in the path to auth service. So, set strip-prefix to false
zuul.routes.auth-service.strip-prefix=false
@OmarElgabry
OmarElgabry / JwtTokenAuthenticationFilter.java
Last active April 16, 2024 02:21
JWT Token Authentication Filter
package com.eureka.zuul.security;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@OmarElgabry
OmarElgabry / JwtConfig.java
Last active December 11, 2018 12:18
JWT Configurations Class
public class JwtConfig {
@Value("${security.jwt.uri:/auth/**}")
private String Uri;
@Value("${security.jwt.header:Authorization}")
private String header;
@Value("${security.jwt.prefix:Bearer }")
private String prefix;
@OmarElgabry
OmarElgabry / SecurityTokenConfig.java
Last active April 30, 2019 21:33
Gateway Security Configurations
package com.eureka.zuul.security;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpMethod;
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;