Skip to content

Commit 7deaf55

Browse files
committed
Adding OAuth 2.0 + Swagger ui + Spring boot + JWT
0 parents  commit 7deaf55

30 files changed

+1757
-0
lines changed

authentication/.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#target
2+
*/target/*
3+
target/*
4+
#intellij-files
5+
*.idea/*
6+
*.iml
7+
*.DS_Store
8+
*-pom.xml
9+
RemoteSystemsTempFiles/*
10+
.svn/*
11+
.settings/
12+
.project
13+
.metadata/
14+
.idea/
15+
.classpath
16+
../.DS_Store
17+
.idea/libraries/Maven*

authentication/README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Spring Boot + OAuth 2.0 + JWT + Swagger-UI 2?
2+
3+
## How to start ?
4+
5+
```
6+
$ mvn spring-boot:run
7+
```
8+
9+
## Swagger-UI
10+
* After starting the application Click on [Swagger-home](http://localhost:8080/api/swagger-ui.html)
11+
12+
![Swagger-Home](authentication/src/main/resources/images/Swagger-UI-Home.png "Swagger UI Home")
13+
14+
15+
## User Data
16+
17+
```
18+
user-name | password
19+
[email protected] | password
20+
[email protected] | password
21+
[email protected] | password
22+
```
23+
24+
25+
## Authorize
26+
* Use above given user details to login and generate the authorization token.
27+
![Swagger-Home](authentication/src/main/resources/images/Swagger-ui-auth.png "Swagger UI Home")
28+
29+
![Swagger-Home](authentication/src/main/resources/images/swagger-ui-login.png "Swagger UI Home")
30+
31+
* Login using the generated token
32+
![Swagger-Home](authentication/src/main/resources/images/swagger-ui-login-token.png "Swagger UI Home")
33+
34+
35+
36+
## Change OAuth configuration
37+
* Edit the configuration in the file [application.properties](/authentication/src/main/resources/application.properties)
38+
39+
```
40+
server.port=8080
41+
server.contextPath=/api
42+
43+
logging.level.com.alfred=DEBUG
44+
45+
# Data source properties
46+
spring.jpa.hibernate.ddl-auto=validate
47+
spring.jpa.show-sql=true
48+
49+
# openssl genrsa -out jwt.pem 2048
50+
# openssl rsa -in jwt.pem
51+
config.oauth2.privateKey=MIICXQIBAAKBgQDNQZKqTlO/+2b4ZdhqGJzGBDltb5PZmBz1ALN2YLvt341pH6i5mO1V9cX5Ty1LM70fKfnIoYUP4KCE33dPnC7LkUwE/myh1zM6m8cbL5cYFPyP099thbVxzJkjHWqywvQih/qOOjliomKbM9pxG8Z1dB26hL9dSAZuA8xExjlPmQIDAQABAoGAImnYGU3ApPOVtBf/TOqLfne+2SZX96eVU06myDY3zA4rO3DfbR7CzCLE6qPnyDAIiW0UQBs0oBDdWOnOqz5YaePZu/yrLyj6KM6Q2e9ywRDtDh3ywrSfGpjdSvvoaeL1WesBWsgWv1vFKKvES7ILFLUxKwyCRC2Lgh7aI9GGZfECQQD84m98Yrehhin3fZuRaBNIu348Ci7ZFZmrvyxAIxrV4jBjpACW0RM2BvF5oYM2gOJqIfBOVjmPwUrobYEFcHRvAkEAz8jsfmxsZVwh3Y/Y47BzhKIC5FLaads541jNjVWfrPirljyCy1n4sg3WQH2IEyap3WTP84+csCtsfNfyK7fQdwJBAJNRyobY74cupJYkW5OK4OkXKQQLHp2iosJV/Y5jpQeC3JO/gARcSmfIBbbI66q9zKjtmpPYUXI4tc3PtUEY8QsCQQCcxySyC0sKe6bNzyC+Q8AVvkxiTKWiI5idEr8duhJd589H72Zc2wkMB+a2CEGo+Y5Hjy5cvuph/pG/7Qw7sljnAkAy/feClt1mUEiAcWrHRwcQ71AoA0+21yC9VkqPNrn3w7OEg8gBqPjRlXBNb00QieNeGGSkXOoU6gFschR22Dzy
52+
53+
# openssl rsa -in jwt.pem -pubout
54+
config.oauth2.publicKey=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDNQZKqTlO/+2b4ZdhqGJzGBDltb5PZmBz1ALN2YLvt341pH6i5mO1V9cX5Ty1LM70fKfnIoYUP4KCE33dPnC7LkUwE/myh1zM6m8cbL5cYFPyP099thbVxzJkjHWqywvQih/qOOjliomKbM9pxG8Z1dB26hL9dSAZuA8xExjlPmQIDAQAB
55+
56+
57+
#oauth configurations
58+
config.oauth2.tokenTimeout=3600
59+
config.oauth2.resource.id=oauth2-resource
60+
config.oauth2.clientID=client
61+
config.oauth2.clientSecret=secret
62+
security.oauth2.client.grantType=client_credentials
63+
config.oauth2.accessTokenUri=http://localhost:8080/api/oauth/token
64+
config.oauth2.userAuthorizationUri=http://localhost:8080/api/oauth/authorize
65+
config.oauth2.resourceURI= http://localhost:8080/api/oauth/authorize
66+
```
67+
68+
69+
70+
71+
72+
73+
74+
75+

authentication/pom.xml

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
<?xml version="1.0"?>
2+
<project
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
4+
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
5+
<modelVersion>4.0.0</modelVersion>
6+
<groupId>authentication</groupId>
7+
<artifactId>authentication-service</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<name>Authentication Service</name>
10+
<url>http://maven.apache.org</url>
11+
12+
<parent>
13+
<groupId>org.springframework.boot</groupId>
14+
<artifactId>spring-boot-starter-parent</artifactId>
15+
<version>1.5.7.RELEASE</version>
16+
</parent>
17+
18+
<properties>
19+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
20+
<maven.compiler.source>1.8</maven.compiler.source>
21+
<maven.compiler.target>1.8</maven.compiler.target>
22+
</properties>
23+
24+
<dependencies>
25+
26+
<!-- Spring Boot -->
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-web</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-starter-security</artifactId>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.springframework.security.oauth</groupId>
37+
<artifactId>spring-security-oauth2</artifactId>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.springframework.boot</groupId>
41+
<artifactId>spring-boot-starter-data-jpa</artifactId>
42+
</dependency>
43+
44+
<!-- Spring Boot jakson depenedcy issue https://dzone.com/articles/jackson-dependency-issue-in-spring-boot-with-maven-->
45+
<dependency>
46+
<groupId>com.fasterxml.jackson.core</groupId>
47+
<artifactId>jackson-databind</artifactId>
48+
<version>2.7.4</version>
49+
<exclusions>
50+
<exclusion>
51+
<groupId>com.fasterxml.jackson.core</groupId>
52+
<artifactId>jackson-core</artifactId>
53+
</exclusion>
54+
<exclusion>
55+
<groupId>com.fasterxml.jackson.core</groupId>
56+
<artifactId>jackson-annotations</artifactId>
57+
</exclusion>
58+
</exclusions>
59+
</dependency>
60+
<dependency>
61+
<groupId>com.fasterxml.jackson.core</groupId>
62+
<artifactId>jackson-core</artifactId>
63+
<version>2.7.4</version>
64+
</dependency>
65+
<dependency>
66+
<groupId>com.fasterxml.jackson.core</groupId>
67+
<artifactId>jackson-annotations</artifactId>
68+
<version>2.7.4</version>
69+
</dependency>
70+
71+
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-jwt -->
72+
<dependency>
73+
<groupId>org.springframework.security</groupId>
74+
<artifactId>spring-security-jwt</artifactId>
75+
<version>1.0.8.RELEASE</version>
76+
</dependency>
77+
78+
<dependency>
79+
<groupId>org.hibernate</groupId>
80+
<artifactId>hibernate-core</artifactId>
81+
<version>5.2.2.Final</version>
82+
</dependency>
83+
<dependency>
84+
<groupId>org.hibernate</groupId>
85+
<artifactId>hibernate-entitymanager</artifactId>
86+
<version>5.2.2.Final</version>
87+
</dependency>
88+
<!-- https://mvnrepository.com/artifact/javassist/javassist -->
89+
<dependency>
90+
<groupId>javassist</groupId>
91+
<artifactId>javassist</artifactId>
92+
<version>3.3</version>
93+
</dependency>
94+
95+
96+
<dependency>
97+
<groupId>com.h2database</groupId>
98+
<artifactId>h2</artifactId>
99+
<scope>runtime</scope>
100+
</dependency>
101+
102+
<!-- Swagger-ui -->
103+
<dependency>
104+
<groupId>io.springfox</groupId>
105+
<artifactId>springfox-swagger2</artifactId>
106+
<version>2.8.0</version>
107+
</dependency>
108+
<dependency>
109+
<groupId>io.springfox</groupId>
110+
<artifactId>springfox-swagger-ui</artifactId>
111+
<version>2.8.0</version>
112+
</dependency>
113+
<dependency>
114+
<groupId>io.springfox</groupId>
115+
<artifactId>springfox-bean-validators</artifactId>
116+
<version>2.8.0</version>
117+
</dependency>
118+
<dependency>
119+
<artifactId>guava</artifactId>
120+
<groupId>com.google.guava</groupId>
121+
<type>jar</type>
122+
<version>18.0</version>
123+
</dependency>
124+
125+
<!-- test -->
126+
<dependency>
127+
<groupId>org.springframework.boot</groupId>
128+
<artifactId>spring-boot-starter-test</artifactId>
129+
<scope>test</scope>
130+
</dependency>
131+
<dependency>
132+
<groupId>org.mockito</groupId>
133+
<artifactId>mockito-all</artifactId>
134+
<version>1.9.5</version>
135+
<scope>test</scope>
136+
</dependency>
137+
138+
</dependencies>
139+
140+
<build>
141+
<pluginManagement>
142+
<plugins>
143+
<plugin>
144+
<groupId>org.springframework.boot</groupId>
145+
<artifactId>spring-boot-maven-plugin</artifactId>
146+
</plugin>
147+
</plugins>
148+
</pluginManagement>
149+
</build>
150+
151+
152+
153+
</project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.authentication;
2+
3+
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
7+
/**
8+
* @author Rohit.Kumar
9+
*/
10+
@SpringBootApplication
11+
public class Application {
12+
13+
public static void main(String[] args) {
14+
SpringApplication.run(Application.class, args);
15+
}
16+
17+
}

0 commit comments

Comments
 (0)