Skip to content

Commit 73750a4

Browse files
committed
Add SSO example
1 parent 72a117c commit 73750a4

8 files changed

Lines changed: 186 additions & 0 deletions

File tree

spring-boot-sso-example/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
4+
### STS ###
5+
.apt_generated
6+
.classpath
7+
.factorypath
8+
.project
9+
.settings
10+
.springBeans
11+
12+
### IntelliJ IDEA ###
13+
.idea
14+
*.iws
15+
*.iml
16+
*.ipr
17+
18+
### NetBeans ###
19+
nbproject/private/
20+
build/
21+
nbbuild/
22+
dist/
23+
nbdist/
24+
.nb-gradle/

spring-boot-sso-example/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Spring Boot Single Sign-On
2+
This repository contains Spring Boot Single Sign-On example

spring-boot-sso-example/pom.xml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>pl.codecouple</groupId>
7+
<artifactId>sso</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<name>sso</name>
12+
<description>Single Sign-On</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.5.9.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24+
<java.version>1.8</java.version>
25+
<spring-cloud.version>Edgware.RELEASE</spring-cloud.version>
26+
</properties>
27+
28+
<dependencies>
29+
<dependency>
30+
<groupId>org.springframework.cloud</groupId>
31+
<artifactId>spring-cloud-starter-oauth2</artifactId>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter-web</artifactId>
36+
</dependency>
37+
38+
<dependency>
39+
<groupId>org.springframework.boot</groupId>
40+
<artifactId>spring-boot-starter-test</artifactId>
41+
<scope>test</scope>
42+
</dependency>
43+
</dependencies>
44+
45+
<dependencyManagement>
46+
<dependencies>
47+
<dependency>
48+
<groupId>org.springframework.cloud</groupId>
49+
<artifactId>spring-cloud-dependencies</artifactId>
50+
<version>${spring-cloud.version}</version>
51+
<type>pom</type>
52+
<scope>import</scope>
53+
</dependency>
54+
</dependencies>
55+
</dependencyManagement>
56+
57+
<build>
58+
<plugins>
59+
<plugin>
60+
<groupId>org.springframework.boot</groupId>
61+
<artifactId>spring-boot-maven-plugin</artifactId>
62+
</plugin>
63+
</plugins>
64+
</build>
65+
66+
67+
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package pl.codecouple;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class SsoApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(SsoApplication.class, args);
11+
}
12+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package pl.codecouple.configuration;
2+
3+
import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
6+
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
7+
8+
/**
9+
* Created by CodeCouple.pl
10+
*/
11+
@Configuration
12+
@EnableOAuth2Sso
13+
class WebSecurityConfig extends WebSecurityConfigurerAdapter {
14+
15+
@Override
16+
protected void configure(HttpSecurity http) throws Exception {
17+
http.authorizeRequests()
18+
.antMatchers("/for-all")
19+
.permitAll()
20+
.anyRequest()
21+
.authenticated();
22+
}
23+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package pl.codecouple.web;
2+
3+
import org.springframework.web.bind.annotation.GetMapping;
4+
import org.springframework.web.bind.annotation.RestController;
5+
6+
/**
7+
* Created by CodeCouple.pl
8+
*/
9+
@RestController
10+
class CodeCoupleController {
11+
12+
@GetMapping("/for-all")
13+
String showCodeCouple(){
14+
return "Code Couple!";
15+
}
16+
17+
@GetMapping("/not-for-all")
18+
String showCodeCoupleAwesome(){
19+
return "Code Couple is awesome!";
20+
}
21+
22+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#Application name
2+
spring.application.name=auth-service
3+
#Server port
4+
server.port=9191
5+
6+
#Client id from GitHub
7+
security.oauth2.client.client-id=generated-id
8+
#Client secret from GitHub
9+
security.oauth2.client.client-secret=generated-secret
10+
#URI with access token
11+
security.oauth2.client.access-token-uri=https://github.com/login/oauth/access_token
12+
#URI for authorization
13+
security.oauth2.client.user-authorization-uri=https://github.com/login/oauth/authorize
14+
#Scheme of authentication
15+
security.oauth2.client.client-authentication-scheme=form
16+
17+
#User info endpoint
18+
security.oauth2.resource.user-info-uri=https://api.github.com/user
19+
#Prefer user info
20+
security.oauth2.resource.prefer-token-info=false
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package pl.codecouple;
2+
3+
import org.junit.Test;
4+
import org.junit.runner.RunWith;
5+
import org.springframework.boot.test.context.SpringBootTest;
6+
import org.springframework.test.context.junit4.SpringRunner;
7+
8+
@RunWith(SpringRunner.class)
9+
@SpringBootTest
10+
public class SsoApplicationTests {
11+
12+
@Test
13+
public void contextLoads() {
14+
}
15+
16+
}

0 commit comments

Comments
 (0)