Skip to content

Commit ffde263

Browse files
committed
Implementation v1 of oauth2 - gateway based on spring-oauth2
1 parent 66a3333 commit ffde263

File tree

19 files changed

+1248
-21
lines changed

19 files changed

+1248
-21
lines changed

.gitignore

Lines changed: 103 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
1-
# Compiled class file
2-
*.class
1+
### Linux template
2+
*~
3+
4+
# KDE directory preferences
5+
.directory
6+
7+
# Linux trash folder which might appear on any partition or disk
8+
.Trash-*
9+
### Windows template
10+
# Windows image file caches
11+
Thumbs.db
12+
ehthumbs.db
13+
14+
# Folder config file
15+
Desktop.ini
316

4-
# Log file
5-
*.log
17+
# Recycle Bin used on file shares
18+
$RECYCLE.BIN/
619

7-
# BlueJ files
8-
*.ctxt
20+
# Windows Installer files
21+
*.cab
22+
*.msi
23+
*.msm
24+
*.msp
25+
26+
# Windows shortcuts
27+
*.lnk
28+
### Java template
29+
*.class
930

1031
# Mobile Tools for Java (J2ME)
1132
.mtj.tmp/
@@ -14,9 +35,82 @@
1435
*.jar
1536
*.war
1637
*.ear
17-
*.zip
18-
*.tar.gz
19-
*.rar
2038

2139
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
2240
hs_err_pid*
41+
### OSX template
42+
.DS_Store
43+
.AppleDouble
44+
.LSOverride
45+
46+
# Icon must end with two \r
47+
Icon
48+
49+
# Thumbnails
50+
._*
51+
52+
# Files that might appear in the root of a volume
53+
.DocumentRevisions-V100
54+
.fseventsd
55+
.Spotlight-V100
56+
.TemporaryItems
57+
.Trashes
58+
.VolumeIcon.icns
59+
60+
# Directories potentially created on remote AFP share
61+
.AppleDB
62+
.AppleDesktop
63+
Network Trash Folder
64+
Temporary Items
65+
.apdisk
66+
### JetBrains template
67+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
68+
69+
*.iml
70+
71+
## Directory-based project format:
72+
.idea/
73+
# if you remove the above rule, at least ignore the following:
74+
75+
# User-specific stuff:
76+
# .idea/workspace.xml
77+
# .idea/tasks.xml
78+
# .idea/dictionaries
79+
80+
# Sensitive or high-churn files:
81+
# .idea/dataSources.ids
82+
# .idea/dataSources.xml
83+
# .idea/sqlDataSources.xml
84+
# .idea/dynamic.xml
85+
# .idea/uiDesigner.xml
86+
87+
# Gradle:
88+
# .idea/gradle.xml
89+
# .idea/libraries
90+
91+
# Mongo Explorer plugin:
92+
# .idea/mongoSettings.xml
93+
94+
## File-based project format:
95+
*.ipr
96+
*.iws
97+
98+
## Plugin-specific files:
99+
100+
# IntelliJ
101+
/out/
102+
103+
# mpeltonen/sbt-idea plugin
104+
.idea_modules/
105+
106+
# JIRA plugin
107+
atlassian-ide-plugin.xml
108+
109+
# Crashlytics plugin (for Android Studio and IntelliJ)
110+
com_crashlytics_export_strings.xml
111+
crashlytics.properties
112+
crashlytics-build.properties
113+
114+
115+
target/
116+

LICENSE

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,7 @@
175175

176176
END OF TERMS AND CONDITIONS
177177

178-
APPENDIX: How to apply the Apache License to your work.
179-
180-
To apply the Apache License to your work, attach the following
181-
boilerplate notice, with the fields enclosed by brackets "[]"
182-
replaced with your own identifying information. (Don't include
183-
the brackets!) The text should be enclosed in the appropriate
184-
comment syntax for the file format. We also recommend that a
185-
file or class name and description of purpose be included on the
186-
same "printed page" as the copyright notice for easier
187-
identification within third-party archives.
188-
189-
Copyright [yyyy] [name of copyright owner]
178+
Copyright 2017 Thomas Bolis
190179

191180
Licensed under the Apache License, Version 2.0 (the "License");
192181
you may not use this file except in compliance with the License.

common-lib/pom.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<parent>
4+
<artifactId>oauth2-gateway</artifactId>
5+
<groupId>io.spring.oauth2</groupId>
6+
<version>1.0.0-SNAPSHOT</version>
7+
</parent>
8+
<modelVersion>4.0.0</modelVersion>
9+
10+
<artifactId>common-lib</artifactId>
11+
<packaging>jar</packaging>
12+
13+
<name>Common Lib</name>
14+
<url>http://maven.apache.org</url>
15+
16+
<properties>
17+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18+
</properties>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>junit</groupId>
23+
<artifactId>junit</artifactId>
24+
<version>3.8.1</version>
25+
<scope>test</scope>
26+
</dependency>
27+
</dependencies>
28+
</project>
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package io.spring.oauth2.common.config;
2+
3+
/**
4+
* OAuth 2 defines four grant types, each of which is useful in different cases
5+
* <ul>
6+
* <li>Authorization: Code for apps running on a web server</li>
7+
* <li>Implicit: for browser-based or mobile apps</li>
8+
* <li>Password: for logging in with a username and password</li>
9+
* <li>Client credentials: for application access</li>
10+
* </ul>
11+
*/
12+
public class AuthorizedGrantTypes {
13+
14+
/**
15+
* Web server apps are the most common type of application you encounter when dealing with OAuth servers. Web apps
16+
* are written in a server-side language and run on a server where the source code of the application is not
17+
* available to the public.
18+
* <p>
19+
* Create a "Log In" link sending the user to:<br/>
20+
* https://oauth2server.com/auth?response_type=code&client_id=CLIENT_ID&redirect_uri=REDIRECT_URI&scope=photos
21+
* <p>
22+
* The service redirects the user back to your site with an auth code:<br/>
23+
* https://oauth2client.com/cb?code=AUTH_CODE_HERE
24+
* <p>
25+
* Your server exchanges the auth code for an access token<br/>
26+
* POST https://api.oauth2server.com/token<br/>
27+
* grant_type=authorization_code&<br/>
28+
* code=AUTH_CODE_HERE&<br/>
29+
* redirect_uri=REDIRECT_URI&<br/>
30+
* client_id=CLIENT_ID&<br/>
31+
* client_secret=CLIENT_SECRET<br/>
32+
* <p>
33+
* The server replies with an access token
34+
* <p>
35+
* {"access_token":"RsT5OjbzRn430zqMLgV3Ia"}<br/>
36+
* or if there was an error<br/>
37+
* {"error":"invalid_request" }
38+
* <p>
39+
* Security: Note that the service must require apps to pre-register their redirect URIs.
40+
*/
41+
public static final String AUTHORIZATION_CODE = "authorization_code";
42+
43+
/**
44+
* Refresh Token grant type, will generate a refresh_token to be able to refresh the validity of your token by
45+
* providing a new token
46+
* <p>
47+
* call goes as follows :
48+
* <p>
49+
* POST https://oauthServer/oauth/token Authorization:"Basic ZXNzYmFja2VuZDpteVNlY3JldE9BdXRoU2VjcmV0" Content-Type:"application/x-www-form-urlencoded" Accept:"application/json"
50+
* <p>
51+
* refresh_token=a0c8ecb7-198f-4a55-bdbb-f18f376c55bc&<br/>
52+
* grant_type=refresh_token&<br/>
53+
* scope=read%20write&<br/>
54+
* client_secret=mySecretOAuthSecret&<br/>
55+
* client_id=essbackend& <br/>
56+
*/
57+
public static final String REFRESH_TOKEN = "refresh_token";
58+
59+
/**
60+
* Obtain an access token via a username, password login
61+
* <p>
62+
* POST localhost:8080/oauth/token Content-Type:"application/x-www-form-urlencoded" Accept:"application/json" Authorization:"Basic ZXNzYmFja2VuZDpteVNlY3JldE9BdXRoU2VjcmV0"<br/>
63+
* username=admin&<br/>
64+
* password=admin&<br/>
65+
* grant_type=password&<br/>
66+
* scope=read%20write&<br/>
67+
* client_secret=mySecretOAuthSecret&<br/>
68+
* client_id=essbackend&<br/>
69+
*/
70+
public static final String PASSWORD = "password";
71+
72+
/**
73+
* Implicit: used with Mobile Apps or Web Applications (applications that run on the user's device)
74+
*/
75+
public static final String IMPLICIT = "implicit";
76+
77+
public static final String CLIENT_CREDENTIALS = "client-credentials";
78+
79+
private AuthorizedGrantTypes() {
80+
}
81+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package io.spring.oauth2.common.config;
2+
3+
/**
4+
* Application constants.
5+
*/
6+
public final class Constants {
7+
8+
public static final String SYSTEM_ACCOUNT = "system";
9+
public static final String RESOURCE_ID = "OAuth2Server";
10+
11+
private Constants() {
12+
/* Prevent instantiation */
13+
}
14+
}

domain-model/pom.xml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<parent>
4+
<artifactId>oauth2-gateway</artifactId>
5+
<groupId>io.spring.oauth2</groupId>
6+
<version>1.0.0-SNAPSHOT</version>
7+
</parent>
8+
<modelVersion>4.0.0</modelVersion>
9+
<artifactId>domain-model</artifactId>
10+
<packaging>jar</packaging>
11+
<name>Domain Model</name>
12+
<url>http://maven.apache.org</url>
13+
<dependencies>
14+
<!--
15+
Spring Boot makes it easy to create Spring-powered, production-grade applications and services with
16+
absolute minimum fuss. It takes an opinionated view of the Spring platform so that new and existing
17+
users can quickly get to the bits they need.
18+
-->
19+
<dependency>
20+
<groupId>org.springframework.boot</groupId>
21+
<artifactId>spring-boot-starter</artifactId>
22+
</dependency>
23+
<!--
24+
Support for the “Java Persistence API” including spring-data-jpa,
25+
spring-orm and Hibernate
26+
-->
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-data-jpa</artifactId>
30+
</dependency>
31+
<!--
32+
Hibernate specific
33+
-->
34+
<dependency>
35+
<groupId>org.hibernate</groupId>
36+
<artifactId>hibernate-envers</artifactId>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.hibernate</groupId>
40+
<artifactId>hibernate-validator</artifactId>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.flywaydb</groupId>
44+
<artifactId>flyway-core</artifactId>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.postgresql</groupId>
48+
<artifactId>postgresql</artifactId>
49+
<version>${postgresql.version}</version>
50+
</dependency>
51+
<dependency>
52+
<groupId>com.zaxxer</groupId>
53+
<artifactId>HikariCP</artifactId>
54+
<exclusions>
55+
<exclusion>
56+
<artifactId>tools</artifactId>
57+
<groupId>com.sun</groupId>
58+
</exclusion>
59+
</exclusions>
60+
</dependency>
61+
<!--
62+
Jackson
63+
-->
64+
<dependency>
65+
<groupId>com.fasterxml.jackson.datatype</groupId>
66+
<artifactId>jackson-datatype-hibernate4</artifactId>
67+
<version>${jackson.version}</version>
68+
</dependency>
69+
<dependency>
70+
<groupId>com.fasterxml.jackson.datatype</groupId>
71+
<artifactId>jackson-datatype-hppc</artifactId>
72+
<version>${jackson.version}</version>
73+
</dependency>
74+
<dependency>
75+
<groupId>com.fasterxml.jackson.datatype</groupId>
76+
<artifactId>jackson-datatype-jsr310</artifactId>
77+
</dependency>
78+
<dependency>
79+
<groupId>com.fasterxml.jackson.datatype</groupId>
80+
<artifactId>jackson-datatype-json-org</artifactId>
81+
<version>${jackson.version}</version>
82+
</dependency>
83+
84+
<!--
85+
The javax.inject API
86+
-->
87+
<dependency>
88+
<groupId>javax.inject</groupId>
89+
<artifactId>javax.inject</artifactId>
90+
<version>${javax.inject.version}</version>
91+
</dependency>
92+
<!--
93+
Production ready features to help you monitor and manage your application
94+
-->
95+
<dependency>
96+
<groupId>org.springframework.boot</groupId>
97+
<artifactId>spring-boot-starter-actuator</artifactId>
98+
</dependency>
99+
<dependency>
100+
<groupId>org.springframework.security</groupId>
101+
<artifactId>spring-security-web</artifactId>
102+
</dependency>
103+
</dependencies>
104+
<build>
105+
<finalName>${project.artifactId}</finalName>
106+
</build>
107+
</project>

0 commit comments

Comments
 (0)