17 |
--------------------------------------------------------------------------------
/oauth2-vanilla/ui/src/app/app.component.html:
--------------------------------------------------------------------------------
1 |
9 |
Greeting
10 |
11 |
The ID is {{greeting.id}}
12 |
The content is {{greeting.content}}
13 |
14 |
15 |
Login to see your greeting
16 |
17 |
--------------------------------------------------------------------------------
/oauth2-vanilla/authserver/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | server.port: 9999
2 | server.contextPath: /uaa
3 | security.user.password: password
4 | security.sessions: if-required
5 | security.oauth2.client.clientId: acme
6 | security.oauth2.client.clientSecret: acmesecret
7 | security.oauth2.client.authorized-grant-types: authorization_code,refresh_token,password
8 | security.oauth2.client.scope: openid
9 | #security.oauth2.client.accessTokenValiditySeconds: 10
10 | logging.level.org.springframework.security: DEBUG
11 |
--------------------------------------------------------------------------------
/spring-session/README.adoc:
--------------------------------------------------------------------------------
1 | This application uses http://projects.spring.io/spring-security[Spring Security] with http://angularjs.org[Angular JS] in a "single page application" where the UI and resource servers are separate, and secured using a shared token store implemented with https://github.com/spring-projects/spring-session/[Spring Session].
2 |
3 | It is one of a pair of samples from an section and both are described in more detail https://github.com/spring-guides/tut-spring-security-and-angular-js/blob/master/vanilla/README.adoc[here].
4 |
--------------------------------------------------------------------------------
/double/gateway/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | logging:
2 | level:
3 | org.springframework.security: DEBUG
4 | security:
5 | sessions: ALWAYS
6 | ignored:
7 | - "*.bundle.*"
8 | - favicon.ico
9 | spring:
10 | session:
11 | store-type: redis
12 | zuul:
13 | routes:
14 | ui:
15 | url: http://localhost:8081
16 | sensitive-headers:
17 | admin:
18 | url: http://localhost:8082
19 | sensitive-headers:
20 | resource:
21 | url: http://localhost:9000
22 | sensitive-headers:
23 |
--------------------------------------------------------------------------------
/proxy/ui/src/app/home.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { AppService } from './app.service';
3 | import { HttpClient } from '@angular/common/http';
4 |
5 | @Component({
6 | templateUrl: './home.component.html'
7 | })
8 | export class HomeComponent {
9 |
10 | title = 'Demo';
11 | greeting = {};
12 |
13 | constructor(private app: AppService, private http: HttpClient) {
14 | http.get('resource').subscribe(data => this.greeting = data);
15 | }
16 |
17 | authenticated() { return this.app.authenticated; }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/single/src/app/home.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { AppService } from './app.service';
3 | import { HttpClient } from '@angular/common/http';
4 |
5 | @Component({
6 | templateUrl: './home.component.html'
7 | })
8 | export class HomeComponent {
9 |
10 | title = 'Demo';
11 | greeting = {};
12 |
13 | constructor(private app: AppService, private http: HttpClient) {
14 | http.get('resource').subscribe(data => this.greeting = data);
15 | }
16 |
17 | authenticated() { return this.app.authenticated; }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/proxy/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | org.demo
6 | pairs-proxy
7 | 0.0.1-SNAPSHOT
8 | pom
9 | Spring Pairs Samples Proxy
10 |
11 |
12 | ui
13 | resource
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/vanilla/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | org.demo
6 | pairs-vanilla
7 | 0.0.1-SNAPSHOT
8 | pom
9 | Spring Pairs Samples Vanilla
10 |
11 |
12 | ui
13 | resource
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/vanilla/ui/src/app/home.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { AppService } from './app.service';
3 | import { HttpClient } from '@angular/common/http';
4 |
5 | @Component({
6 | templateUrl: './home.component.html'
7 | })
8 | export class HomeComponent {
9 |
10 | title = 'Demo';
11 | greeting = {};
12 |
13 | constructor(private app: AppService, private http: HttpClient) {
14 | http.get('http://localhost:9000').subscribe(data => this.greeting = data);
15 | }
16 |
17 | authenticated() { return this.app.authenticated; }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/double/admin/src/app/write.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 | import { HttpClient } from '@angular/common/http';
3 |
4 | @Component({
5 | templateUrl: './write.component.html'
6 | })
7 | export class WriteComponent {
8 |
9 | greeting = {};
10 |
11 | constructor(private http: HttpClient) {
12 | this.http.get('/resource').subscribe(data => this.greeting = data);
13 | }
14 |
15 | update() {
16 | this.http.post('/resource', {content: this.greeting['content']}).subscribe(response => {
17 | this.greeting = response;
18 | });
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/oauth2/resource/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | server.port: 9000
2 | logging.level.org.springframework.security: DEBUG
3 | security.oauth2.resource.jwt.keyValue: -----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnGp/Q5lh0P8nPL21oMMrt2RrkT9AW5jgYwLfSUnJVc9G6uR3cXRRDCjHqWU5WYwivcF180A6CWp/ireQFFBNowgc5XaA0kPpzEtgsA5YsNX7iSnUibB004iBTfU9hZ2Rbsc8cWqynT0RyN4TP1RYVSeVKvMQk4GT1r7JCEC+TNu1ELmbNwMQyzKjsfBXyIOCFU/E94ktvsTZUHF4Oq44DBylCDsS1k7/sfZC2G5EU7Oz0mhG8+Uz6MSEQHtoIi6mc8u64Rwi3Z3tscuWG2ShtsUFuNSAFNkY7LkLn+/hxLCu2bNISMaESa8dG22CIMuIeRLVcAmEWEWH5EEforTg+QIDAQAB\n-----END PUBLIC KEY-----
4 |
--------------------------------------------------------------------------------
/spring-session/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | org.demo
6 | pairs-spring-session
7 | 0.0.1-SNAPSHOT
8 | pom
9 | Spring Pairs Samples Spring Session
10 |
11 |
12 | ui
13 | resource
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/oauth2-logout/resource/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | server.port: 9000
2 | logging.level.org.springframework.security: DEBUG
3 | security.oauth2.resource.jwt.keyValue: -----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnGp/Q5lh0P8nPL21oMMrt2RrkT9AW5jgYwLfSUnJVc9G6uR3cXRRDCjHqWU5WYwivcF180A6CWp/ireQFFBNowgc5XaA0kPpzEtgsA5YsNX7iSnUibB004iBTfU9hZ2Rbsc8cWqynT0RyN4TP1RYVSeVKvMQk4GT1r7JCEC+TNu1ELmbNwMQyzKjsfBXyIOCFU/E94ktvsTZUHF4Oq44DBylCDsS1k7/sfZC2G5EU7Oz0mhG8+Uz6MSEQHtoIi6mc8u64Rwi3Z3tscuWG2ShtsUFuNSAFNkY7LkLn+/hxLCu2bNISMaESa8dG22CIMuIeRLVcAmEWEWH5EEforTg+QIDAQAB\n-----END PUBLIC KEY-----
4 |
--------------------------------------------------------------------------------
/oauth2/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | org.demo
6 | pairs-oauth2
7 | 0.0.1-SNAPSHOT
8 | pom
9 | Spring Pairs Samples OAuth2
10 |
11 |
12 | authserver
13 | ui
14 | resource
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /Servers
2 | /.metadata
3 | /application.yml
4 | /application.properties
5 | *~
6 | .#*
7 | *#
8 | target/
9 | bin
10 | /data
11 | .classpath
12 | .project
13 | .settings
14 | .springBeans
15 | .sts4-cache/
16 | .attach_pid*
17 | .DS_Store
18 | *.sw*
19 | *.iml
20 | .idea
21 | nbproject/private/
22 | build/
23 | nbbuild/
24 | dist/
25 | nbdist/
26 | .nb-gradle/# See http://help.github.com/ignore-files/ for more about ignoring files.
27 | .vscode/*
28 | !.vscode/settings.json
29 | !.vscode/tasks.json
30 | !.vscode/launch.json
31 | !.vscode/extensions.json
32 | node/
33 | node_modules/
34 | e2e/*.js
35 | e2e/*.map
36 |
--------------------------------------------------------------------------------
/oauth2-logout/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | org.demo
6 | pairs-oauth2-logout
7 | 0.0.1-SNAPSHOT
8 | pom
9 | Spring Pairs Samples OAuth2
10 |
11 |
12 | authserver
13 | ui
14 | resource
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/double/admin/src/app/app.component.html:
--------------------------------------------------------------------------------
1 |
13 |
14 |
Admin
15 |
16 |
17 |
--------------------------------------------------------------------------------
/oauth2-vanilla/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | org.demo
6 | pairs-oauth2-vanilla
7 | 0.0.1-SNAPSHOT
8 | pom
9 | Spring Pairs Samples OAuth2 Vanilla
10 |
11 |
12 | authserver
13 | ui
14 | resource
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/double/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | org.demo
6 | pairs-double
7 | 0.0.1-SNAPSHOT
8 | pom
9 | Spring Security Angular Sample Double
10 |
11 |
12 | gateway
13 | ui
14 | resource
15 | admin
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/proxy/ui/src/app/login.component.html:
--------------------------------------------------------------------------------
1 |
2 | There was a problem logging in. Please try again.
3 |
4 |
15 |
--------------------------------------------------------------------------------
/single/src/app/login.component.html:
--------------------------------------------------------------------------------
1 |
2 | There was a problem logging in. Please try again.
3 |
4 |
15 |
--------------------------------------------------------------------------------
/proxy/ui/src/app/login.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { AppService } from './app.service';
3 | import { HttpClient } from '@angular/common/http';
4 | import { Router } from '@angular/router';
5 |
6 | @Component({
7 | templateUrl: './login.component.html'
8 | })
9 | export class LoginComponent {
10 |
11 | credentials = {username: '', password: ''};
12 |
13 | constructor(private app: AppService, private http: HttpClient, private router: Router) {
14 | }
15 |
16 | login() {
17 | this.app.authenticate(this.credentials, () => {
18 | this.router.navigateByUrl('/');
19 | });
20 | return false;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/single/src/app/login.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { AppService } from './app.service';
3 | import { HttpClient } from '@angular/common/http';
4 | import { Router } from '@angular/router';
5 |
6 | @Component({
7 | templateUrl: './login.component.html'
8 | })
9 | export class LoginComponent {
10 |
11 | credentials = {username: '', password: ''};
12 |
13 | constructor(private app: AppService, private http: HttpClient, private router: Router) {
14 | }
15 |
16 | login() {
17 | this.app.authenticate(this.credentials, () => {
18 | this.router.navigateByUrl('/');
19 | });
20 | return false;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/vanilla/ui/src/app/login.component.html:
--------------------------------------------------------------------------------
1 |
2 | There was a problem logging in. Please try again.
3 |
4 |
15 |
--------------------------------------------------------------------------------
/spring-session/ui/src/app/login.component.html:
--------------------------------------------------------------------------------
1 |
2 | There was a problem logging in. Please try again.
3 |
4 |
15 |
--------------------------------------------------------------------------------
/vanilla/ui/src/app/login.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { AppService } from './app.service';
3 | import { HttpClient } from '@angular/common/http';
4 | import { Router } from '@angular/router';
5 |
6 | @Component({
7 | templateUrl: './login.component.html'
8 | })
9 | export class LoginComponent {
10 |
11 | credentials = {username: '', password: ''};
12 |
13 | constructor(private app: AppService, private http: HttpClient, private router: Router) {
14 | }
15 |
16 | login() {
17 | this.app.authenticate(this.credentials, () => {
18 | this.router.navigateByUrl('/');
19 | });
20 | return false;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/spring-session/ui/src/app/login.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { AppService } from './app.service';
3 | import { HttpClient } from '@angular/common/http';
4 | import { Router } from '@angular/router';
5 |
6 | @Component({
7 | templateUrl: './login.component.html'
8 | })
9 | export class LoginComponent {
10 |
11 | credentials = {username: '', password: ''};
12 |
13 | constructor(private app: AppService, private http: HttpClient, private router: Router) {
14 | }
15 |
16 | login() {
17 | this.app.authenticate(this.credentials, () => {
18 | this.router.navigateByUrl('/');
19 | });
20 | return false;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/oauth2/README.adoc:
--------------------------------------------------------------------------------
1 | = Bootstrap UI and JWT Tokens for the Authorization Server
2 |
3 | You will find a version of this application in the https://github.com/dsyer/spring-security-angular/tree/master/oauth2-vanilla[source code in Github] which has a whitelabel HTML interface and HTTP Basic authentication. This one has a pretty login page and user approval page implemented similarly to the way we did the login page in https://github.com/dsyer/spring-security-angular/tree/master/single[the single server sample]. It also uses http://en.wikipedia.org/wiki/JWT[JWT] to encode the tokens, so instead of using the "/user" endpoint, the resource server can pull enough information out of the token itself to do a simple authentication.
--------------------------------------------------------------------------------
/README.adoc:
--------------------------------------------------------------------------------
1 | ---
2 | tags: [security,angular,rest,oauth]
3 | projects: [spring-security,spring-security-oauth]
4 | ---
5 | :toc: left
6 | :icons: font
7 | :source-highlighter: prettify
8 | :image-width: 500
9 |
10 | = Spring Security and Angular
11 |
12 | include::basic/README.adoc[leveloffset=+1]
13 | include::single/README.adoc[leveloffset=+1]
14 | include::vanilla/README.adoc[leveloffset=+1]
15 | include::proxy/README.adoc[leveloffset=+1]
16 | include::oauth2-vanilla/README.adoc[leveloffset=+1]
17 | include::double/README.adoc[leveloffset=+1]
18 | include::testing.adoc[leveloffset=+1]
19 | include::oauth2-logout/README.adoc[leveloffset=+1]
20 |
21 | include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/footer.adoc[]
22 |
--------------------------------------------------------------------------------
/double/ui/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 | import { HttpClient } from '@angular/common/http';
3 |
4 | @Component({
5 | selector: 'app-root',
6 | templateUrl: './app.component.html',
7 | styleUrls: ['./app.component.css']
8 | })
9 | export class AppComponent {
10 | title = 'Demo';
11 | greeting = {};
12 | authenticated = false;
13 | user = '';
14 | constructor(private http: HttpClient) {
15 | http.get('/user').subscribe(data => {
16 | if (data['name']) {
17 | this.authenticated = true;
18 | http.get('/resource').subscribe(response => this.greeting = response);
19 | } else {
20 | this.authenticated = false;
21 | }
22 | }, () => { this.authenticated = false; });
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/basic/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to learn about possible attributes.
3 | // Hover to view descriptions of existing attributes.
4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "type": "java",
9 | "name": "Debug (Launch)",
10 | "request": "launch",
11 | "cwd": "${workspaceFolder}",
12 | "mainClass": "demo.UiApplication",
13 | "projectName": "basic",
14 | "args": ""
15 | },
16 | {
17 | "type": "java",
18 | "name": "Debug (Attach)",
19 | "request": "attach",
20 | "hostName": "localhost",
21 | "port": 0
22 | }
23 | ]
24 | }
25 |
--------------------------------------------------------------------------------
/single/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to learn about possible attributes.
3 | // Hover to view descriptions of existing attributes.
4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "type": "java",
9 | "name": "Debug (Launch)",
10 | "request": "launch",
11 | "cwd": "${workspaceFolder}",
12 | "mainClass": "demo.UiApplication",
13 | "projectName": "basic",
14 | "args": ""
15 | },
16 | {
17 | "type": "java",
18 | "name": "Debug (Attach)",
19 | "request": "attach",
20 | "hostName": "localhost",
21 | "port": 0
22 | }
23 | ]
24 | }
25 |
--------------------------------------------------------------------------------
/LICENSE.code.txt:
--------------------------------------------------------------------------------
1 | All code in this repository is:
2 | =======================================================================
3 | Copyright (c) 2013 GoPivotal, Inc. All Rights Reserved
4 |
5 | Licensed under the Apache License, Version 2.0 (the "License");
6 | you may not use this file except in compliance with the License.
7 | You may obtain a copy of the License at
8 |
9 | http://www.apache.org/licenses/LICENSE-2.0
10 |
11 | Unless required by applicable law or agreed to in writing, software
12 | distributed under the License is distributed on an "AS IS" BASIS,
13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | See the License for the specific language governing permissions and
15 | limitations under the License.
16 |
17 |
--------------------------------------------------------------------------------
/spring-session/ui/src/app/home.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { AppService } from './app.service';
3 | import { HttpClient, HttpHeaders } from '@angular/common/http';
4 |
5 | @Component({
6 | templateUrl: './home.component.html'
7 | })
8 | export class HomeComponent {
9 |
10 | title = 'Demo';
11 | greeting = {};
12 |
13 | constructor(private app: AppService, private http: HttpClient) {
14 | http.get('token').subscribe(data => {
15 | const token = data['token'];
16 | http.get('http://localhost:9000', {headers : new HttpHeaders().set('X-Auth-Token', token)})
17 | .subscribe(response => this.greeting = response);
18 | }, () => {});
19 | }
20 |
21 | authenticated() { return this.app.authenticated; }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/oauth2-logout/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to learn about possible attributes.
3 | // Hover to view descriptions of existing attributes.
4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "type": "chrome",
9 | "request": "launch",
10 | "name": "Launch Chrome",
11 | "url": "http://localhost:8080",
12 | "webRoot": "${workspaceFolder}"
13 | },
14 | {
15 | "type": "chrome",
16 | "request": "launch",
17 | "name": "Launch Chrome against localhost",
18 | "url": "http://localhost:8080",
19 | "webRoot": "${workspaceFolder}"
20 | }
21 | ]
22 | }
--------------------------------------------------------------------------------
/oauth2-vanilla/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to learn about possible attributes.
3 | // Hover to view descriptions of existing attributes.
4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "type": "chrome",
9 | "request": "launch",
10 | "name": "Launch Chrome",
11 | "url": "http://localhost:8080",
12 | "webRoot": "${workspaceFolder}"
13 | },
14 | {
15 | "type": "chrome",
16 | "request": "launch",
17 | "name": "Launch Chrome against localhost",
18 | "url": "http://localhost:8080",
19 | "webRoot": "${workspaceFolder}"
20 | }
21 | ]
22 | }
--------------------------------------------------------------------------------
/proxy/ui/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 | import { AppService } from './app.service';
3 | import { HttpClient } from '@angular/common/http';
4 | import { Router } from '@angular/router';
5 | import 'rxjs/add/operator/finally';
6 |
7 | @Component({
8 | selector: 'app-root',
9 | templateUrl: './app.component.html',
10 | styleUrls: ['./app.component.css']
11 | })
12 | export class AppComponent {
13 | constructor(private app: AppService, private http: HttpClient, private router: Router) {
14 | this.app.authenticate({}, undefined);
15 | }
16 | logout() {
17 | this.http.post('logout', {}).finally(() => {
18 | this.app.authenticated = false;
19 | this.router.navigateByUrl('/login');
20 | }).subscribe();
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/single/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 | import { AppService } from './app.service';
3 | import { HttpClient } from '@angular/common/http';
4 | import { Router } from '@angular/router';
5 | import 'rxjs/add/operator/finally';
6 |
7 | @Component({
8 | selector: 'app-root',
9 | templateUrl: './app.component.html',
10 | styleUrls: ['./app.component.css']
11 | })
12 | export class AppComponent {
13 | constructor(private app: AppService, private http: HttpClient, private router: Router) {
14 | this.app.authenticate(undefined, undefined);
15 | }
16 | logout() {
17 | this.http.post('logout', {}).finally(() => {
18 | this.app.authenticated = false;
19 | this.router.navigateByUrl('/login');
20 | }).subscribe();
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/vanilla/ui/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 | import { AppService } from './app.service';
3 | import { HttpClient } from '@angular/common/http';
4 | import { Router } from '@angular/router';
5 | import 'rxjs/add/operator/finally';
6 |
7 | @Component({
8 | selector: 'app-root',
9 | templateUrl: './app.component.html',
10 | styleUrls: ['./app.component.css']
11 | })
12 | export class AppComponent {
13 | constructor(private app: AppService, private http: HttpClient, private router: Router) {
14 | this.app.authenticate({}, undefined);
15 | }
16 | logout() {
17 | this.http.post('logout', {}).finally(() => {
18 | this.app.authenticated = false;
19 | this.router.navigateByUrl('/login');
20 | }).subscribe();
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/oauth2-vanilla/ui/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | aop:
3 | proxy-target-class: true
4 |
5 | security:
6 | user:
7 | password: password
8 | ignored:
9 | - "*.bundle.*"
10 | oauth2:
11 | client:
12 | accessTokenUri: http://localhost:9999/uaa/oauth/token
13 | userAuthorizationUri: http://localhost:9999/uaa/oauth/authorize
14 | clientId: acme
15 | clientSecret: acmesecret
16 | resource:
17 | userInfoUri: http://localhost:9999/uaa/user
18 |
19 | zuul:
20 | routes:
21 | resource:
22 | path: /resource/**
23 | url: http://localhost:9000
24 | user:
25 | path: /user/**
26 | url: http://localhost:9999/uaa/user
27 |
28 | logging:
29 | level:
30 | org.springframework.security: DEBUG
31 | org.springframework.web: DEBUG
32 |
--------------------------------------------------------------------------------
/spring-session/ui/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 | import { AppService } from './app.service';
3 | import { HttpClient } from '@angular/common/http';
4 | import { Router } from '@angular/router';
5 | import 'rxjs/add/operator/finally';
6 |
7 | @Component({
8 | selector: 'app-root',
9 | templateUrl: './app.component.html',
10 | styleUrls: ['./app.component.css']
11 | })
12 | export class AppComponent {
13 | constructor(private app: AppService, private http: HttpClient, private router: Router) {
14 | this.app.authenticate({}, undefined);
15 | }
16 | logout() {
17 | this.http.post('logout', {}).finally(() => {
18 | this.app.authenticated = false;
19 | this.router.navigateByUrl('/login');
20 | }).subscribe();
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/basic/protractor.conf.js:
--------------------------------------------------------------------------------
1 | // Protractor configuration file, see link for more information
2 | // https://github.com/angular/protractor/blob/master/lib/config.ts
3 |
4 | const { SpecReporter } = require('jasmine-spec-reporter');
5 |
6 | exports.config = {
7 | allScriptsTimeout: 11000,
8 | specs: [
9 | './e2e/**/*.e2e-spec.ts'
10 | ],
11 | capabilities: {
12 | 'browserName': 'chrome'
13 | },
14 | directConnect: true,
15 | baseUrl: 'http://localhost:4200/',
16 | framework: 'jasmine',
17 | jasmineNodeOpts: {
18 | showColors: true,
19 | defaultTimeoutInterval: 30000,
20 | print: function() {}
21 | },
22 | onPrepare() {
23 | require('ts-node').register({
24 | project: 'e2e/tsconfig.e2e.json'
25 | });
26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
27 | }
28 | };
29 |
--------------------------------------------------------------------------------
/single/protractor.conf.js:
--------------------------------------------------------------------------------
1 | // Protractor configuration file, see link for more information
2 | // https://github.com/angular/protractor/blob/master/lib/config.ts
3 |
4 | const { SpecReporter } = require('jasmine-spec-reporter');
5 |
6 | exports.config = {
7 | allScriptsTimeout: 11000,
8 | specs: [
9 | './e2e/**/*.e2e-spec.ts'
10 | ],
11 | capabilities: {
12 | 'browserName': 'chrome'
13 | },
14 | directConnect: true,
15 | baseUrl: 'http://localhost:4200/',
16 | framework: 'jasmine',
17 | jasmineNodeOpts: {
18 | showColors: true,
19 | defaultTimeoutInterval: 30000,
20 | print: function() {}
21 | },
22 | onPrepare() {
23 | require('ts-node').register({
24 | project: 'e2e/tsconfig.e2e.json'
25 | });
26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
27 | }
28 | };
29 |
--------------------------------------------------------------------------------
/double/ui/protractor.conf.js:
--------------------------------------------------------------------------------
1 | // Protractor configuration file, see link for more information
2 | // https://github.com/angular/protractor/blob/master/lib/config.ts
3 |
4 | const { SpecReporter } = require('jasmine-spec-reporter');
5 |
6 | exports.config = {
7 | allScriptsTimeout: 11000,
8 | specs: [
9 | './e2e/**/*.e2e-spec.ts'
10 | ],
11 | capabilities: {
12 | 'browserName': 'chrome'
13 | },
14 | directConnect: true,
15 | baseUrl: 'http://localhost:4200/',
16 | framework: 'jasmine',
17 | jasmineNodeOpts: {
18 | showColors: true,
19 | defaultTimeoutInterval: 30000,
20 | print: function() {}
21 | },
22 | onPrepare() {
23 | require('ts-node').register({
24 | project: 'e2e/tsconfig.e2e.json'
25 | });
26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
27 | }
28 | };
29 |
--------------------------------------------------------------------------------
/oauth2/ui/protractor.conf.js:
--------------------------------------------------------------------------------
1 | // Protractor configuration file, see link for more information
2 | // https://github.com/angular/protractor/blob/master/lib/config.ts
3 |
4 | const { SpecReporter } = require('jasmine-spec-reporter');
5 |
6 | exports.config = {
7 | allScriptsTimeout: 11000,
8 | specs: [
9 | './e2e/**/*.e2e-spec.ts'
10 | ],
11 | capabilities: {
12 | 'browserName': 'chrome'
13 | },
14 | directConnect: true,
15 | baseUrl: 'http://localhost:4200/',
16 | framework: 'jasmine',
17 | jasmineNodeOpts: {
18 | showColors: true,
19 | defaultTimeoutInterval: 30000,
20 | print: function() {}
21 | },
22 | onPrepare() {
23 | require('ts-node').register({
24 | project: 'e2e/tsconfig.e2e.json'
25 | });
26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
27 | }
28 | };
29 |
--------------------------------------------------------------------------------
/proxy/ui/protractor.conf.js:
--------------------------------------------------------------------------------
1 | // Protractor configuration file, see link for more information
2 | // https://github.com/angular/protractor/blob/master/lib/config.ts
3 |
4 | const { SpecReporter } = require('jasmine-spec-reporter');
5 |
6 | exports.config = {
7 | allScriptsTimeout: 11000,
8 | specs: [
9 | './e2e/**/*.e2e-spec.ts'
10 | ],
11 | capabilities: {
12 | 'browserName': 'chrome'
13 | },
14 | directConnect: true,
15 | baseUrl: 'http://localhost:4200/',
16 | framework: 'jasmine',
17 | jasmineNodeOpts: {
18 | showColors: true,
19 | defaultTimeoutInterval: 30000,
20 | print: function() {}
21 | },
22 | onPrepare() {
23 | require('ts-node').register({
24 | project: 'e2e/tsconfig.e2e.json'
25 | });
26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
27 | }
28 | };
29 |
--------------------------------------------------------------------------------
/vanilla/ui/protractor.conf.js:
--------------------------------------------------------------------------------
1 | // Protractor configuration file, see link for more information
2 | // https://github.com/angular/protractor/blob/master/lib/config.ts
3 |
4 | const { SpecReporter } = require('jasmine-spec-reporter');
5 |
6 | exports.config = {
7 | allScriptsTimeout: 11000,
8 | specs: [
9 | './e2e/**/*.e2e-spec.ts'
10 | ],
11 | capabilities: {
12 | 'browserName': 'chrome'
13 | },
14 | directConnect: true,
15 | baseUrl: 'http://localhost:4200/',
16 | framework: 'jasmine',
17 | jasmineNodeOpts: {
18 | showColors: true,
19 | defaultTimeoutInterval: 30000,
20 | print: function() {}
21 | },
22 | onPrepare() {
23 | require('ts-node').register({
24 | project: 'e2e/tsconfig.e2e.json'
25 | });
26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
27 | }
28 | };
29 |
--------------------------------------------------------------------------------
/double/admin/protractor.conf.js:
--------------------------------------------------------------------------------
1 | // Protractor configuration file, see link for more information
2 | // https://github.com/angular/protractor/blob/master/lib/config.ts
3 |
4 | const { SpecReporter } = require('jasmine-spec-reporter');
5 |
6 | exports.config = {
7 | allScriptsTimeout: 11000,
8 | specs: [
9 | './e2e/**/*.e2e-spec.ts'
10 | ],
11 | capabilities: {
12 | 'browserName': 'chrome'
13 | },
14 | directConnect: true,
15 | baseUrl: 'http://localhost:4200/',
16 | framework: 'jasmine',
17 | jasmineNodeOpts: {
18 | showColors: true,
19 | defaultTimeoutInterval: 30000,
20 | print: function() {}
21 | },
22 | onPrepare() {
23 | require('ts-node').register({
24 | project: 'e2e/tsconfig.e2e.json'
25 | });
26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
27 | }
28 | };
29 |
--------------------------------------------------------------------------------
/double/gateway/protractor.conf.js:
--------------------------------------------------------------------------------
1 | // Protractor configuration file, see link for more information
2 | // https://github.com/angular/protractor/blob/master/lib/config.ts
3 |
4 | const { SpecReporter } = require('jasmine-spec-reporter');
5 |
6 | exports.config = {
7 | allScriptsTimeout: 11000,
8 | specs: [
9 | './e2e/**/*.e2e-spec.ts'
10 | ],
11 | capabilities: {
12 | 'browserName': 'chrome'
13 | },
14 | directConnect: true,
15 | baseUrl: 'http://localhost:4200/',
16 | framework: 'jasmine',
17 | jasmineNodeOpts: {
18 | showColors: true,
19 | defaultTimeoutInterval: 30000,
20 | print: function() {}
21 | },
22 | onPrepare() {
23 | require('ts-node').register({
24 | project: 'e2e/tsconfig.e2e.json'
25 | });
26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
27 | }
28 | };
29 |
--------------------------------------------------------------------------------
/oauth2-logout/ui/protractor.conf.js:
--------------------------------------------------------------------------------
1 | // Protractor configuration file, see link for more information
2 | // https://github.com/angular/protractor/blob/master/lib/config.ts
3 |
4 | const { SpecReporter } = require('jasmine-spec-reporter');
5 |
6 | exports.config = {
7 | allScriptsTimeout: 11000,
8 | specs: [
9 | './e2e/**/*.e2e-spec.ts'
10 | ],
11 | capabilities: {
12 | 'browserName': 'chrome'
13 | },
14 | directConnect: true,
15 | baseUrl: 'http://localhost:4200/',
16 | framework: 'jasmine',
17 | jasmineNodeOpts: {
18 | showColors: true,
19 | defaultTimeoutInterval: 30000,
20 | print: function() {}
21 | },
22 | onPrepare() {
23 | require('ts-node').register({
24 | project: 'e2e/tsconfig.e2e.json'
25 | });
26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
27 | }
28 | };
29 |
--------------------------------------------------------------------------------
/oauth2-vanilla/ui/protractor.conf.js:
--------------------------------------------------------------------------------
1 | // Protractor configuration file, see link for more information
2 | // https://github.com/angular/protractor/blob/master/lib/config.ts
3 |
4 | const { SpecReporter } = require('jasmine-spec-reporter');
5 |
6 | exports.config = {
7 | allScriptsTimeout: 11000,
8 | specs: [
9 | './e2e/**/*.e2e-spec.ts'
10 | ],
11 | capabilities: {
12 | 'browserName': 'chrome'
13 | },
14 | directConnect: true,
15 | baseUrl: 'http://localhost:4200/',
16 | framework: 'jasmine',
17 | jasmineNodeOpts: {
18 | showColors: true,
19 | defaultTimeoutInterval: 30000,
20 | print: function() {}
21 | },
22 | onPrepare() {
23 | require('ts-node').register({
24 | project: 'e2e/tsconfig.e2e.json'
25 | });
26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
27 | }
28 | };
29 |
--------------------------------------------------------------------------------
/spring-session/ui/protractor.conf.js:
--------------------------------------------------------------------------------
1 | // Protractor configuration file, see link for more information
2 | // https://github.com/angular/protractor/blob/master/lib/config.ts
3 |
4 | const { SpecReporter } = require('jasmine-spec-reporter');
5 |
6 | exports.config = {
7 | allScriptsTimeout: 11000,
8 | specs: [
9 | './e2e/**/*.e2e-spec.ts'
10 | ],
11 | capabilities: {
12 | 'browserName': 'chrome'
13 | },
14 | directConnect: true,
15 | baseUrl: 'http://localhost:4200/',
16 | framework: 'jasmine',
17 | jasmineNodeOpts: {
18 | showColors: true,
19 | defaultTimeoutInterval: 30000,
20 | print: function() {}
21 | },
22 | onPrepare() {
23 | require('ts-node').register({
24 | project: 'e2e/tsconfig.e2e.json'
25 | });
26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
27 | }
28 | };
29 |
--------------------------------------------------------------------------------
/proxy/ui/src/app/app.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { HttpClient, HttpHeaders } from '@angular/common/http';
3 |
4 | @Injectable()
5 | export class AppService {
6 |
7 | authenticated = false;
8 |
9 | constructor(private http: HttpClient) {
10 | }
11 |
12 | authenticate(credentials, callback) {
13 |
14 | const headers = new HttpHeaders(credentials ? {
15 | authorization : 'Basic ' + btoa(credentials.username + ':' + credentials.password)
16 | } : {});
17 |
18 | this.http.get('user', {headers: headers}).subscribe(response => {
19 | if (response['name']) {
20 | this.authenticated = true;
21 | } else {
22 | this.authenticated = false;
23 | }
24 | return callback && callback();
25 | });
26 |
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/single/src/app/app.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { HttpClient, HttpHeaders } from '@angular/common/http';
3 |
4 | @Injectable()
5 | export class AppService {
6 |
7 | authenticated = false;
8 |
9 | constructor(private http: HttpClient) {
10 | }
11 |
12 | authenticate(credentials, callback) {
13 |
14 | const headers = new HttpHeaders(credentials ? {
15 | authorization : 'Basic ' + btoa(credentials.username + ':' + credentials.password)
16 | } : {});
17 |
18 | this.http.get('user', {headers: headers}).subscribe(response => {
19 | if (response['name']) {
20 | this.authenticated = true;
21 | } else {
22 | this.authenticated = false;
23 | }
24 | return callback && callback();
25 | });
26 |
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/spring-session/ui/src/app/app.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { HttpClient, HttpHeaders } from '@angular/common/http';
3 |
4 | @Injectable()
5 | export class AppService {
6 |
7 | authenticated = false;
8 |
9 | constructor(private http: HttpClient) {
10 | }
11 |
12 | authenticate(credentials, callback) {
13 |
14 | const headers = new HttpHeaders(credentials ? {
15 | authorization : 'Basic ' + btoa(credentials.username + ':' + credentials.password)
16 | } : {});
17 |
18 | this.http.get('user', {headers: headers}).subscribe(response => {
19 | if (response['name']) {
20 | this.authenticated = true;
21 | } else {
22 | this.authenticated = false;
23 | }
24 | return callback && callback();
25 | });
26 |
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/basic/src/main/java/demo/UiApplication.java:
--------------------------------------------------------------------------------
1 | package demo;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 | import java.util.UUID;
6 |
7 | import org.springframework.boot.SpringApplication;
8 | import org.springframework.boot.autoconfigure.SpringBootApplication;
9 | import org.springframework.web.bind.annotation.RequestMapping;
10 | import org.springframework.web.bind.annotation.RestController;
11 |
12 | @SpringBootApplication
13 | @RestController
14 | public class UiApplication {
15 |
16 | @RequestMapping("/resource")
17 | public Map
home() {
18 | Map model = new HashMap();
19 | model.put("id", UUID.randomUUID().toString());
20 | model.put("content", "Hello World");
21 | return model;
22 | }
23 |
24 | public static void main(String[] args) {
25 | SpringApplication.run(UiApplication.class, args);
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | org.springframework.guides
6 | tut-spring-security-and-angular-js
7 | 0.0.1-SNAPSHOT
8 | pom
9 | Spring Security Angular Samples
10 |
11 |
12 | basic
13 | single
14 | vanilla
15 | spring-session
16 | proxy
17 | oauth2-vanilla
18 | oauth2
19 | oauth2-logout
20 | double
21 | modular
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/vanilla/ui/src/app/app.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
3 |
4 | @Injectable()
5 | export class AppService {
6 |
7 | authenticated = false;
8 |
9 | constructor(private http: HttpClient) {
10 | }
11 |
12 | authenticate(credentials, callback) {
13 |
14 | const headers = new HttpHeaders(credentials ? {
15 | 'content-type' : 'application/x-www-form-urlencoded'
16 | } : {});
17 | const params = new HttpParams()
18 | .set('username', credentials['username'])
19 | .set('password', credentials['password']);
20 |
21 | this.http.post('login', params.toString(), {headers: headers}).subscribe(response => {
22 | this.authenticated = true;
23 | if (callback) { callback(); }
24 | }, () => {
25 | this.authenticated = false;
26 | });
27 |
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/oauth2-vanilla/authserver/src/main/java/demo/AuthserverApplication.java:
--------------------------------------------------------------------------------
1 | package demo;
2 |
3 | import java.security.Principal;
4 |
5 | import org.springframework.boot.SpringApplication;
6 | import org.springframework.boot.autoconfigure.SpringBootApplication;
7 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
8 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
9 | import org.springframework.web.bind.annotation.RequestMapping;
10 | import org.springframework.web.bind.annotation.RestController;
11 |
12 | @SpringBootApplication
13 | @RestController
14 | @EnableResourceServer
15 | @EnableAuthorizationServer
16 | public class AuthserverApplication {
17 |
18 | @RequestMapping("/user")
19 | public Principal user(Principal user) {
20 | return user;
21 | }
22 |
23 | public static void main(String[] args) {
24 | SpringApplication.run(AuthserverApplication.class, args);
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/double/gateway/src/app/app.module.ts:
--------------------------------------------------------------------------------
1 | import { BrowserModule } from '@angular/platform-browser';
2 | import { FormsModule } from '@angular/forms';
3 | import { NgModule, Injectable } from '@angular/core';
4 | import {
5 | HttpClientModule, HttpInterceptor, HttpHandler, HttpRequest, HTTP_INTERCEPTORS
6 | } from '@angular/common/http';
7 |
8 | import { AppComponent } from './app.component';
9 |
10 | @Injectable()
11 | export class XhrInterceptor implements HttpInterceptor {
12 |
13 | intercept(req: HttpRequest, next: HttpHandler) {
14 | const xhr = req.clone({
15 | headers: req.headers.set('X-Requested-With', 'XMLHttpRequest')
16 | });
17 | return next.handle(xhr);
18 | }
19 | }
20 |
21 | @NgModule({
22 | declarations: [
23 | AppComponent
24 | ],
25 | imports: [
26 | BrowserModule,
27 | HttpClientModule,
28 | FormsModule
29 | ],
30 | providers: [{ provide: HTTP_INTERCEPTORS, useClass: XhrInterceptor, multi: true }],
31 | bootstrap: [AppComponent]
32 | })
33 | export class AppModule { }
34 |
--------------------------------------------------------------------------------
/basic/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration file, see link for more information
2 | // https://karma-runner.github.io/1.0/config/configuration-file.html
3 |
4 | module.exports = function (config) {
5 | config.set({
6 | basePath: '',
7 | frameworks: ['jasmine', '@angular/cli'],
8 | plugins: [
9 | require('karma-jasmine'),
10 | require('karma-chrome-launcher'),
11 | require('karma-jasmine-html-reporter'),
12 | require('karma-coverage-istanbul-reporter'),
13 | require('@angular/cli/plugins/karma')
14 | ],
15 | client:{
16 | clearContext: false // leave Jasmine Spec Runner output visible in browser
17 | },
18 | coverageIstanbulReporter: {
19 | reports: [ 'html', 'lcovonly' ],
20 | fixWebpackSourcePaths: true
21 | },
22 | angularCli: {
23 | environment: 'dev'
24 | },
25 | reporters: ['progress', 'kjhtml'],
26 | port: 9876,
27 | colors: true,
28 | logLevel: config.LOG_INFO,
29 | autoWatch: true,
30 | browsers: ['Chrome'],
31 | singleRun: false
32 | });
33 | };
34 |
--------------------------------------------------------------------------------
/oauth2/ui/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 | import { HttpClient } from '@angular/common/http';
3 | import 'rxjs/add/operator/finally';
4 |
5 | @Component({
6 | selector: 'app-root',
7 | templateUrl: './app.component.html',
8 | styleUrls: ['./app.component.css']
9 | })
10 | export class AppComponent {
11 |
12 | title = 'Demo';
13 | authenticated = false;
14 | greeting = {};
15 |
16 | constructor(private http: HttpClient) {
17 | this.authenticate();
18 | }
19 |
20 | authenticate() {
21 |
22 | this.http.get('user').subscribe(response => {
23 | if (response['name']) {
24 | this.authenticated = true;
25 | this.http.get('resource').subscribe(data => this.greeting = data);
26 | } else {
27 | this.authenticated = false;
28 | }
29 | }, () => { this.authenticated = false; });
30 |
31 | }
32 | logout() {
33 | this.http.post('logout', {}).finally(() => {
34 | this.authenticated = false;
35 | }).subscribe();
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/double/ui/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration file, see link for more information
2 | // https://karma-runner.github.io/1.0/config/configuration-file.html
3 |
4 | module.exports = function (config) {
5 | config.set({
6 | basePath: '',
7 | frameworks: ['jasmine', '@angular/cli'],
8 | plugins: [
9 | require('karma-jasmine'),
10 | require('karma-chrome-launcher'),
11 | require('karma-jasmine-html-reporter'),
12 | require('karma-coverage-istanbul-reporter'),
13 | require('@angular/cli/plugins/karma')
14 | ],
15 | client:{
16 | clearContext: false // leave Jasmine Spec Runner output visible in browser
17 | },
18 | coverageIstanbulReporter: {
19 | reports: [ 'html', 'lcovonly' ],
20 | fixWebpackSourcePaths: true
21 | },
22 | angularCli: {
23 | environment: 'dev'
24 | },
25 | reporters: ['progress', 'kjhtml'],
26 | port: 9876,
27 | colors: true,
28 | logLevel: config.LOG_INFO,
29 | autoWatch: true,
30 | browsers: ['Chrome'],
31 | singleRun: false
32 | });
33 | };
34 |
--------------------------------------------------------------------------------
/oauth2-logout/ui/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 | import { HttpClient } from '@angular/common/http';
3 | import 'rxjs/add/operator/finally';
4 |
5 | @Component({
6 | selector: 'app-root',
7 | templateUrl: './app.component.html',
8 | styleUrls: ['./app.component.css']
9 | })
10 | export class AppComponent {
11 |
12 | title = 'Demo';
13 | authenticated = false;
14 | greeting = {};
15 |
16 | constructor(private http: HttpClient) {
17 | this.authenticate();
18 | }
19 |
20 | authenticate() {
21 |
22 | this.http.get('user').subscribe(response => {
23 | if (response['name']) {
24 | this.authenticated = true;
25 | this.http.get('resource').subscribe(data => this.greeting = data);
26 | } else {
27 | this.authenticated = false;
28 | }
29 | }, () => { this.authenticated = false; });
30 |
31 | }
32 | logout() {
33 | this.http.post('logout', {}).finally(() => {
34 | this.authenticated = false;
35 | }).subscribe();
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/oauth2-vanilla/ui/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 | import { HttpClient } from '@angular/common/http';
3 | import 'rxjs/add/operator/finally';
4 |
5 | @Component({
6 | selector: 'app-root',
7 | templateUrl: './app.component.html',
8 | styleUrls: ['./app.component.css']
9 | })
10 | export class AppComponent {
11 |
12 | title = 'Demo';
13 | authenticated = false;
14 | greeting = {};
15 |
16 | constructor(private http: HttpClient) {
17 | this.authenticate();
18 | }
19 |
20 | authenticate() {
21 |
22 | this.http.get('user').subscribe(response => {
23 | if (response['name']) {
24 | this.authenticated = true;
25 | this.http.get('resource').subscribe(data => this.greeting = data);
26 | } else {
27 | this.authenticated = false;
28 | }
29 | }, () => { this.authenticated = false; });
30 |
31 | }
32 | logout() {
33 | this.http.post('logout', {}).finally(() => {
34 | this.authenticated = false;
35 | }).subscribe();
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/oauth2/ui/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration file, see link for more information
2 | // https://karma-runner.github.io/1.0/config/configuration-file.html
3 |
4 | module.exports = function (config) {
5 | config.set({
6 | basePath: '',
7 | frameworks: ['jasmine', '@angular/cli'],
8 | plugins: [
9 | require('karma-jasmine'),
10 | require('karma-chrome-launcher'),
11 | require('karma-jasmine-html-reporter'),
12 | require('karma-coverage-istanbul-reporter'),
13 | require('@angular/cli/plugins/karma')
14 | ],
15 | client:{
16 | clearContext: false // leave Jasmine Spec Runner output visible in browser
17 | },
18 | coverageIstanbulReporter: {
19 | reports: [ 'html', 'lcovonly' ],
20 | fixWebpackSourcePaths: true
21 | },
22 | angularCli: {
23 | environment: 'dev'
24 | },
25 | reporters: ['progress', 'kjhtml'],
26 | port: 9876,
27 | colors: true,
28 | logLevel: config.LOG_INFO,
29 | autoWatch: true,
30 | browsers: ['Chrome'],
31 | singleRun: false
32 | });
33 | };
34 |
--------------------------------------------------------------------------------
/proxy/ui/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration file, see link for more information
2 | // https://karma-runner.github.io/1.0/config/configuration-file.html
3 |
4 | module.exports = function (config) {
5 | config.set({
6 | basePath: '',
7 | frameworks: ['jasmine', '@angular/cli'],
8 | plugins: [
9 | require('karma-jasmine'),
10 | require('karma-chrome-launcher'),
11 | require('karma-jasmine-html-reporter'),
12 | require('karma-coverage-istanbul-reporter'),
13 | require('@angular/cli/plugins/karma')
14 | ],
15 | client:{
16 | clearContext: false // leave Jasmine Spec Runner output visible in browser
17 | },
18 | coverageIstanbulReporter: {
19 | reports: [ 'html', 'lcovonly' ],
20 | fixWebpackSourcePaths: true
21 | },
22 | angularCli: {
23 | environment: 'dev'
24 | },
25 | reporters: ['progress', 'kjhtml'],
26 | port: 9876,
27 | colors: true,
28 | logLevel: config.LOG_INFO,
29 | autoWatch: true,
30 | browsers: ['Chrome'],
31 | singleRun: false
32 | });
33 | };
34 |
--------------------------------------------------------------------------------
/single/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration file, see link for more information
2 | // https://karma-runner.github.io/1.0/config/configuration-file.html
3 |
4 | module.exports = function (config) {
5 | config.set({
6 | basePath: '',
7 | frameworks: ['jasmine', '@angular/cli'],
8 | plugins: [
9 | require('karma-jasmine'),
10 | require('karma-chrome-launcher'),
11 | require('karma-jasmine-html-reporter'),
12 | require('karma-coverage-istanbul-reporter'),
13 | require('@angular/cli/plugins/karma')
14 | ],
15 | client:{
16 | clearContext: false // leave Jasmine Spec Runner output visible in browser
17 | },
18 | coverageIstanbulReporter: {
19 | reports: [ 'html', 'lcovonly' ],
20 | fixWebpackSourcePaths: true
21 | },
22 | angularCli: {
23 | environment: 'dev'
24 | },
25 | reporters: ['progress', 'kjhtml'],
26 | port: 9876,
27 | colors: true,
28 | logLevel: config.LOG_INFO,
29 | autoWatch: true,
30 | browsers: ['Chrome'],
31 | singleRun: false
32 | });
33 | };
34 |
--------------------------------------------------------------------------------
/vanilla/ui/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration file, see link for more information
2 | // https://karma-runner.github.io/1.0/config/configuration-file.html
3 |
4 | module.exports = function (config) {
5 | config.set({
6 | basePath: '',
7 | frameworks: ['jasmine', '@angular/cli'],
8 | plugins: [
9 | require('karma-jasmine'),
10 | require('karma-chrome-launcher'),
11 | require('karma-jasmine-html-reporter'),
12 | require('karma-coverage-istanbul-reporter'),
13 | require('@angular/cli/plugins/karma')
14 | ],
15 | client:{
16 | clearContext: false // leave Jasmine Spec Runner output visible in browser
17 | },
18 | coverageIstanbulReporter: {
19 | reports: [ 'html', 'lcovonly' ],
20 | fixWebpackSourcePaths: true
21 | },
22 | angularCli: {
23 | environment: 'dev'
24 | },
25 | reporters: ['progress', 'kjhtml'],
26 | port: 9876,
27 | colors: true,
28 | logLevel: config.LOG_INFO,
29 | autoWatch: true,
30 | browsers: ['Chrome'],
31 | singleRun: false
32 | });
33 | };
34 |
--------------------------------------------------------------------------------
/double/admin/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration file, see link for more information
2 | // https://karma-runner.github.io/1.0/config/configuration-file.html
3 |
4 | module.exports = function (config) {
5 | config.set({
6 | basePath: '',
7 | frameworks: ['jasmine', '@angular/cli'],
8 | plugins: [
9 | require('karma-jasmine'),
10 | require('karma-chrome-launcher'),
11 | require('karma-jasmine-html-reporter'),
12 | require('karma-coverage-istanbul-reporter'),
13 | require('@angular/cli/plugins/karma')
14 | ],
15 | client:{
16 | clearContext: false // leave Jasmine Spec Runner output visible in browser
17 | },
18 | coverageIstanbulReporter: {
19 | reports: [ 'html', 'lcovonly' ],
20 | fixWebpackSourcePaths: true
21 | },
22 | angularCli: {
23 | environment: 'dev'
24 | },
25 | reporters: ['progress', 'kjhtml'],
26 | port: 9876,
27 | colors: true,
28 | logLevel: config.LOG_INFO,
29 | autoWatch: true,
30 | browsers: ['Chrome'],
31 | singleRun: false
32 | });
33 | };
34 |
--------------------------------------------------------------------------------
/double/gateway/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration file, see link for more information
2 | // https://karma-runner.github.io/1.0/config/configuration-file.html
3 |
4 | module.exports = function (config) {
5 | config.set({
6 | basePath: '',
7 | frameworks: ['jasmine', '@angular/cli'],
8 | plugins: [
9 | require('karma-jasmine'),
10 | require('karma-chrome-launcher'),
11 | require('karma-jasmine-html-reporter'),
12 | require('karma-coverage-istanbul-reporter'),
13 | require('@angular/cli/plugins/karma')
14 | ],
15 | client:{
16 | clearContext: false // leave Jasmine Spec Runner output visible in browser
17 | },
18 | coverageIstanbulReporter: {
19 | reports: [ 'html', 'lcovonly' ],
20 | fixWebpackSourcePaths: true
21 | },
22 | angularCli: {
23 | environment: 'dev'
24 | },
25 | reporters: ['progress', 'kjhtml'],
26 | port: 9876,
27 | colors: true,
28 | logLevel: config.LOG_INFO,
29 | autoWatch: true,
30 | browsers: ['Chrome'],
31 | singleRun: false
32 | });
33 | };
34 |
--------------------------------------------------------------------------------
/basic/src/test/java/demo/ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package demo;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.boot.context.embedded.LocalServerPort;
8 | import org.springframework.boot.test.context.SpringBootTest;
9 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
10 | import org.springframework.boot.test.web.client.TestRestTemplate;
11 | import org.springframework.http.HttpStatus;
12 | import org.springframework.http.ResponseEntity;
13 | import org.springframework.test.context.junit4.SpringRunner;
14 |
15 | @RunWith(SpringRunner.class)
16 | @SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)
17 | public class ApplicationTests {
18 |
19 | @LocalServerPort
20 | private int port;
21 |
22 | @Test
23 | public void homePageProtected() {
24 | ResponseEntity response = new TestRestTemplate().getForEntity("http://localhost:" + port + "/", String.class);
25 | assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/double/resource/src/test/java/demo/ResourceTests.java:
--------------------------------------------------------------------------------
1 | package demo;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import java.security.Principal;
6 |
7 | import org.junit.Test;
8 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
9 |
10 |
11 | public class ResourceTests {
12 |
13 | private ResourceApplication resource = new ResourceApplication();
14 |
15 | @Test
16 | public void home() {
17 | assertEquals("Hello World", resource.home().getContent());
18 | }
19 |
20 | @Test
21 | public void changes() {
22 | Principal user = new UsernamePasswordAuthenticationToken("admin", "");
23 | resource.update(new Message("Foo"), user);
24 | assertEquals(1, resource.changes().size());
25 | }
26 |
27 | @Test
28 | public void changesOverflow() {
29 | for (int i=1; i<=11; i++) { resource.changes().add(new Change("foo", "bar")); }
30 | Principal user = new UsernamePasswordAuthenticationToken("admin", "");
31 | resource.update(new Message("Foo"), user);
32 | assertEquals(10, resource.changes().size());
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/oauth2-logout/ui/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration file, see link for more information
2 | // https://karma-runner.github.io/1.0/config/configuration-file.html
3 |
4 | module.exports = function (config) {
5 | config.set({
6 | basePath: '',
7 | frameworks: ['jasmine', '@angular/cli'],
8 | plugins: [
9 | require('karma-jasmine'),
10 | require('karma-chrome-launcher'),
11 | require('karma-jasmine-html-reporter'),
12 | require('karma-coverage-istanbul-reporter'),
13 | require('@angular/cli/plugins/karma')
14 | ],
15 | client:{
16 | clearContext: false // leave Jasmine Spec Runner output visible in browser
17 | },
18 | coverageIstanbulReporter: {
19 | reports: [ 'html', 'lcovonly' ],
20 | fixWebpackSourcePaths: true
21 | },
22 | angularCli: {
23 | environment: 'dev'
24 | },
25 | reporters: ['progress', 'kjhtml'],
26 | port: 9876,
27 | colors: true,
28 | logLevel: config.LOG_INFO,
29 | autoWatch: true,
30 | browsers: ['Chrome'],
31 | singleRun: false
32 | });
33 | };
34 |
--------------------------------------------------------------------------------
/oauth2-vanilla/ui/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration file, see link for more information
2 | // https://karma-runner.github.io/1.0/config/configuration-file.html
3 |
4 | module.exports = function (config) {
5 | config.set({
6 | basePath: '',
7 | frameworks: ['jasmine', '@angular/cli'],
8 | plugins: [
9 | require('karma-jasmine'),
10 | require('karma-chrome-launcher'),
11 | require('karma-jasmine-html-reporter'),
12 | require('karma-coverage-istanbul-reporter'),
13 | require('@angular/cli/plugins/karma')
14 | ],
15 | client:{
16 | clearContext: false // leave Jasmine Spec Runner output visible in browser
17 | },
18 | coverageIstanbulReporter: {
19 | reports: [ 'html', 'lcovonly' ],
20 | fixWebpackSourcePaths: true
21 | },
22 | angularCli: {
23 | environment: 'dev'
24 | },
25 | reporters: ['progress', 'kjhtml'],
26 | port: 9876,
27 | colors: true,
28 | logLevel: config.LOG_INFO,
29 | autoWatch: true,
30 | browsers: ['Chrome'],
31 | singleRun: false
32 | });
33 | };
34 |
--------------------------------------------------------------------------------
/spring-session/ui/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration file, see link for more information
2 | // https://karma-runner.github.io/1.0/config/configuration-file.html
3 |
4 | module.exports = function (config) {
5 | config.set({
6 | basePath: '',
7 | frameworks: ['jasmine', '@angular/cli'],
8 | plugins: [
9 | require('karma-jasmine'),
10 | require('karma-chrome-launcher'),
11 | require('karma-jasmine-html-reporter'),
12 | require('karma-coverage-istanbul-reporter'),
13 | require('@angular/cli/plugins/karma')
14 | ],
15 | client:{
16 | clearContext: false // leave Jasmine Spec Runner output visible in browser
17 | },
18 | coverageIstanbulReporter: {
19 | reports: [ 'html', 'lcovonly' ],
20 | fixWebpackSourcePaths: true
21 | },
22 | angularCli: {
23 | environment: 'dev'
24 | },
25 | reporters: ['progress', 'kjhtml'],
26 | port: 9876,
27 | colors: true,
28 | logLevel: config.LOG_INFO,
29 | autoWatch: true,
30 | browsers: ['Chrome'],
31 | singleRun: false
32 | });
33 | };
34 |
--------------------------------------------------------------------------------
/vanilla/resource/src/test/java/demo/ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package demo;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.boot.context.embedded.LocalServerPort;
8 | import org.springframework.boot.test.context.SpringBootTest;
9 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
10 | import org.springframework.boot.test.web.client.TestRestTemplate;
11 | import org.springframework.http.HttpStatus;
12 | import org.springframework.http.ResponseEntity;
13 | import org.springframework.test.context.junit4.SpringRunner;
14 |
15 | @RunWith(SpringRunner.class)
16 | @SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)
17 | public class ApplicationTests {
18 |
19 | @LocalServerPort
20 | private int port;
21 |
22 | private TestRestTemplate template = new TestRestTemplate();
23 |
24 | @Test
25 | public void resourceLoads() {
26 | ResponseEntity response = template.getForEntity("http://localhost:{port}/", String.class, port);
27 | assertEquals(HttpStatus.OK, response.getStatusCode());
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/proxy/resource/src/test/java/demo/ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package demo;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.boot.context.embedded.LocalServerPort;
8 | import org.springframework.boot.test.context.SpringBootTest;
9 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
10 | import org.springframework.boot.test.web.client.TestRestTemplate;
11 | import org.springframework.http.HttpStatus;
12 | import org.springframework.http.ResponseEntity;
13 | import org.springframework.test.context.junit4.SpringRunner;
14 |
15 | @RunWith(SpringRunner.class)
16 | @SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)
17 | public class ApplicationTests {
18 |
19 | @LocalServerPort
20 | private int port;
21 |
22 | private TestRestTemplate template = new TestRestTemplate();
23 |
24 | @Test
25 | public void resourceLoads() {
26 | ResponseEntity response = template.getForEntity("http://localhost:{port}/", String.class, port);
27 | assertEquals(HttpStatus.FORBIDDEN, response.getStatusCode());
28 | }
29 | }
30 |
31 |
--------------------------------------------------------------------------------
/double/gateway/src/test/java/demo/ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package demo;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.boot.context.embedded.LocalServerPort;
8 | import org.springframework.boot.test.context.SpringBootTest;
9 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
10 | import org.springframework.boot.test.web.client.TestRestTemplate;
11 | import org.springframework.http.HttpStatus;
12 | import org.springframework.http.ResponseEntity;
13 | import org.springframework.test.context.junit4.SpringRunner;
14 |
15 | @RunWith(SpringRunner.class)
16 | @SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)
17 | public class ApplicationTests {
18 |
19 | @LocalServerPort
20 | private int port;
21 |
22 | private TestRestTemplate template = new TestRestTemplate();
23 |
24 | @Test
25 | public void homePageLoads() {
26 | ResponseEntity response = template.getForEntity("http://localhost:"
27 | + port + "/", String.class);
28 | assertEquals(HttpStatus.OK, response.getStatusCode());
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/spring-session/resource/src/test/java/demo/ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package demo;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.boot.context.embedded.LocalServerPort;
8 | import org.springframework.boot.test.context.SpringBootTest;
9 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
10 | import org.springframework.boot.test.web.client.TestRestTemplate;
11 | import org.springframework.http.HttpStatus;
12 | import org.springframework.http.ResponseEntity;
13 | import org.springframework.test.context.junit4.SpringRunner;
14 |
15 | @RunWith(SpringRunner.class)
16 | @SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)
17 | public class ApplicationTests {
18 |
19 | @LocalServerPort
20 | private int port;
21 |
22 | private TestRestTemplate template = new TestRestTemplate();
23 |
24 | @Test
25 | public void resourceLoads() {
26 | ResponseEntity response = template.getForEntity("http://localhost:{port}/", String.class, port);
27 | assertEquals(HttpStatus.FORBIDDEN, response.getStatusCode());
28 | }
29 | }
30 |
31 |
--------------------------------------------------------------------------------
/vanilla/resource/src/main/java/demo/ResourceApplication.java:
--------------------------------------------------------------------------------
1 | package demo;
2 |
3 | import java.util.UUID;
4 |
5 | import org.springframework.boot.SpringApplication;
6 | import org.springframework.boot.autoconfigure.SpringBootApplication;
7 | import org.springframework.web.bind.annotation.CrossOrigin;
8 | import org.springframework.web.bind.annotation.RequestMapping;
9 | import org.springframework.web.bind.annotation.RestController;
10 |
11 | @SpringBootApplication
12 | @RestController
13 | public class ResourceApplication {
14 |
15 | @RequestMapping("/")
16 | @CrossOrigin(origins="*", maxAge=3600)
17 | public Message home() {
18 | return new Message("Hello World");
19 | }
20 |
21 | public static void main(String[] args) {
22 | SpringApplication.run(ResourceApplication.class, args);
23 | }
24 |
25 | }
26 |
27 | class Message {
28 | private String id = UUID.randomUUID().toString();
29 | private String content;
30 |
31 | Message() {
32 | }
33 |
34 | public Message(String content) {
35 | this.content = content;
36 | }
37 |
38 | public String getId() {
39 | return id;
40 | }
41 |
42 | public String getContent() {
43 | return content;
44 | }
45 | }
--------------------------------------------------------------------------------
/oauth2/authserver/src/main/resources/templates/login.ftl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
8 |
9 |
10 | <#if RequestParameters['error']??>
11 |
12 | There was a problem logging in. Please try again.
13 |
14 | #if>
15 |
29 |
30 |
--------------------------------------------------------------------------------
/oauth2/resource/src/main/java/demo/ResourceApplication.java:
--------------------------------------------------------------------------------
1 | package demo;
2 |
3 | import java.util.UUID;
4 |
5 | import org.springframework.boot.SpringApplication;
6 | import org.springframework.boot.autoconfigure.SpringBootApplication;
7 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
8 | import org.springframework.web.bind.annotation.RequestMapping;
9 | import org.springframework.web.bind.annotation.RestController;
10 |
11 | @SpringBootApplication
12 | @RestController
13 | @EnableResourceServer
14 | public class ResourceApplication {
15 |
16 | @RequestMapping("/")
17 | public Message home() {
18 | return new Message("Hello World");
19 | }
20 |
21 | public static void main(String[] args) {
22 | SpringApplication.run(ResourceApplication.class, args);
23 | }
24 |
25 | }
26 |
27 | class Message {
28 | private String id = UUID.randomUUID().toString();
29 | private String content;
30 |
31 | Message() {
32 | }
33 |
34 | public Message(String content) {
35 | this.content = content;
36 | }
37 |
38 | public String getId() {
39 | return id;
40 | }
41 |
42 | public String getContent() {
43 | return content;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/oauth2-logout/resource/src/main/java/demo/ResourceApplication.java:
--------------------------------------------------------------------------------
1 | package demo;
2 |
3 | import java.util.UUID;
4 |
5 | import org.springframework.boot.SpringApplication;
6 | import org.springframework.boot.autoconfigure.SpringBootApplication;
7 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
8 | import org.springframework.web.bind.annotation.RequestMapping;
9 | import org.springframework.web.bind.annotation.RestController;
10 |
11 | @SpringBootApplication
12 | @RestController
13 | @EnableResourceServer
14 | public class ResourceApplication {
15 |
16 | @RequestMapping("/")
17 | public Message home() {
18 | return new Message("Hello World");
19 | }
20 |
21 | public static void main(String[] args) {
22 | SpringApplication.run(ResourceApplication.class, args);
23 | }
24 |
25 | }
26 |
27 | class Message {
28 | private String id = UUID.randomUUID().toString();
29 | private String content;
30 |
31 | Message() {
32 | }
33 |
34 | public Message(String content) {
35 | this.content = content;
36 | }
37 |
38 | public String getId() {
39 | return id;
40 | }
41 |
42 | public String getContent() {
43 | return content;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/oauth2-vanilla/resource/src/main/java/demo/ResourceApplication.java:
--------------------------------------------------------------------------------
1 | package demo;
2 |
3 | import java.util.UUID;
4 |
5 | import org.springframework.boot.SpringApplication;
6 | import org.springframework.boot.autoconfigure.SpringBootApplication;
7 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
8 | import org.springframework.web.bind.annotation.RequestMapping;
9 | import org.springframework.web.bind.annotation.RestController;
10 |
11 | @SpringBootApplication
12 | @RestController
13 | @EnableResourceServer
14 | public class ResourceApplication {
15 |
16 | @RequestMapping("/")
17 | public Message home() {
18 | return new Message("Hello World");
19 | }
20 |
21 | public static void main(String[] args) {
22 | SpringApplication.run(ResourceApplication.class, args);
23 | }
24 |
25 | }
26 |
27 | class Message {
28 | private String id = UUID.randomUUID().toString();
29 | private String content;
30 |
31 | Message() {
32 | }
33 |
34 | public Message(String content) {
35 | this.content = content;
36 | }
37 |
38 | public String getId() {
39 | return id;
40 | }
41 |
42 | public String getContent() {
43 | return content;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/basic/src/test.ts:
--------------------------------------------------------------------------------
1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2 |
3 | import 'zone.js/dist/long-stack-trace-zone';
4 | import 'zone.js/dist/proxy.js';
5 | import 'zone.js/dist/sync-test';
6 | import 'zone.js/dist/jasmine-patch';
7 | import 'zone.js/dist/async-test';
8 | import 'zone.js/dist/fake-async-test';
9 | import { getTestBed } from '@angular/core/testing';
10 | import {
11 | BrowserDynamicTestingModule,
12 | platformBrowserDynamicTesting
13 | } from '@angular/platform-browser-dynamic/testing';
14 |
15 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
16 | declare const __karma__: any;
17 | declare const require: any;
18 |
19 | // Prevent Karma from running prematurely.
20 | __karma__.loaded = function () {};
21 |
22 | // First, initialize the Angular testing environment.
23 | getTestBed().initTestEnvironment(
24 | BrowserDynamicTestingModule,
25 | platformBrowserDynamicTesting()
26 | );
27 | // Then we find all the tests.
28 | const context = require.context('./', true, /\.spec\.ts$/);
29 | // And load the modules.
30 | context.keys().map(context);
31 | // Finally, start Karma to run the tests.
32 | __karma__.start();
33 |
--------------------------------------------------------------------------------
/oauth2-logout/authserver/src/main/resources/templates/login.ftl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
8 |
9 |
10 | <#if RequestParameters['error']??>
11 |
12 | There was a problem logging in. Please try again.
13 |
14 | #if>
15 |
29 |
30 |
--------------------------------------------------------------------------------
/double/ui/src/test.ts:
--------------------------------------------------------------------------------
1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2 |
3 | import 'zone.js/dist/long-stack-trace-zone';
4 | import 'zone.js/dist/proxy.js';
5 | import 'zone.js/dist/sync-test';
6 | import 'zone.js/dist/jasmine-patch';
7 | import 'zone.js/dist/async-test';
8 | import 'zone.js/dist/fake-async-test';
9 | import { getTestBed } from '@angular/core/testing';
10 | import {
11 | BrowserDynamicTestingModule,
12 | platformBrowserDynamicTesting
13 | } from '@angular/platform-browser-dynamic/testing';
14 |
15 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
16 | declare const __karma__: any;
17 | declare const require: any;
18 |
19 | // Prevent Karma from running prematurely.
20 | __karma__.loaded = function () {};
21 |
22 | // First, initialize the Angular testing environment.
23 | getTestBed().initTestEnvironment(
24 | BrowserDynamicTestingModule,
25 | platformBrowserDynamicTesting()
26 | );
27 | // Then we find all the tests.
28 | const context = require.context('./', true, /\.spec\.ts$/);
29 | // And load the modules.
30 | context.keys().map(context);
31 | // Finally, start Karma to run the tests.
32 | __karma__.start();
33 |
--------------------------------------------------------------------------------
/oauth2/ui/src/test.ts:
--------------------------------------------------------------------------------
1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2 |
3 | import 'zone.js/dist/long-stack-trace-zone';
4 | import 'zone.js/dist/proxy.js';
5 | import 'zone.js/dist/sync-test';
6 | import 'zone.js/dist/jasmine-patch';
7 | import 'zone.js/dist/async-test';
8 | import 'zone.js/dist/fake-async-test';
9 | import { getTestBed } from '@angular/core/testing';
10 | import {
11 | BrowserDynamicTestingModule,
12 | platformBrowserDynamicTesting
13 | } from '@angular/platform-browser-dynamic/testing';
14 |
15 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
16 | declare const __karma__: any;
17 | declare const require: any;
18 |
19 | // Prevent Karma from running prematurely.
20 | __karma__.loaded = function () {};
21 |
22 | // First, initialize the Angular testing environment.
23 | getTestBed().initTestEnvironment(
24 | BrowserDynamicTestingModule,
25 | platformBrowserDynamicTesting()
26 | );
27 | // Then we find all the tests.
28 | const context = require.context('./', true, /\.spec\.ts$/);
29 | // And load the modules.
30 | context.keys().map(context);
31 | // Finally, start Karma to run the tests.
32 | __karma__.start();
33 |
--------------------------------------------------------------------------------
/proxy/ui/src/test.ts:
--------------------------------------------------------------------------------
1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2 |
3 | import 'zone.js/dist/long-stack-trace-zone';
4 | import 'zone.js/dist/proxy.js';
5 | import 'zone.js/dist/sync-test';
6 | import 'zone.js/dist/jasmine-patch';
7 | import 'zone.js/dist/async-test';
8 | import 'zone.js/dist/fake-async-test';
9 | import { getTestBed } from '@angular/core/testing';
10 | import {
11 | BrowserDynamicTestingModule,
12 | platformBrowserDynamicTesting
13 | } from '@angular/platform-browser-dynamic/testing';
14 |
15 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
16 | declare const __karma__: any;
17 | declare const require: any;
18 |
19 | // Prevent Karma from running prematurely.
20 | __karma__.loaded = function () {};
21 |
22 | // First, initialize the Angular testing environment.
23 | getTestBed().initTestEnvironment(
24 | BrowserDynamicTestingModule,
25 | platformBrowserDynamicTesting()
26 | );
27 | // Then we find all the tests.
28 | const context = require.context('./', true, /\.spec\.ts$/);
29 | // And load the modules.
30 | context.keys().map(context);
31 | // Finally, start Karma to run the tests.
32 | __karma__.start();
33 |
--------------------------------------------------------------------------------
/single/src/test.ts:
--------------------------------------------------------------------------------
1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2 |
3 | import 'zone.js/dist/long-stack-trace-zone';
4 | import 'zone.js/dist/proxy.js';
5 | import 'zone.js/dist/sync-test';
6 | import 'zone.js/dist/jasmine-patch';
7 | import 'zone.js/dist/async-test';
8 | import 'zone.js/dist/fake-async-test';
9 | import { getTestBed } from '@angular/core/testing';
10 | import {
11 | BrowserDynamicTestingModule,
12 | platformBrowserDynamicTesting
13 | } from '@angular/platform-browser-dynamic/testing';
14 |
15 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
16 | declare const __karma__: any;
17 | declare const require: any;
18 |
19 | // Prevent Karma from running prematurely.
20 | __karma__.loaded = function () {};
21 |
22 | // First, initialize the Angular testing environment.
23 | getTestBed().initTestEnvironment(
24 | BrowserDynamicTestingModule,
25 | platformBrowserDynamicTesting()
26 | );
27 | // Then we find all the tests.
28 | const context = require.context('./', true, /\.spec\.ts$/);
29 | // And load the modules.
30 | context.keys().map(context);
31 | // Finally, start Karma to run the tests.
32 | __karma__.start();
33 |
--------------------------------------------------------------------------------
/vanilla/ui/src/test.ts:
--------------------------------------------------------------------------------
1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2 |
3 | import 'zone.js/dist/long-stack-trace-zone';
4 | import 'zone.js/dist/proxy.js';
5 | import 'zone.js/dist/sync-test';
6 | import 'zone.js/dist/jasmine-patch';
7 | import 'zone.js/dist/async-test';
8 | import 'zone.js/dist/fake-async-test';
9 | import { getTestBed } from '@angular/core/testing';
10 | import {
11 | BrowserDynamicTestingModule,
12 | platformBrowserDynamicTesting
13 | } from '@angular/platform-browser-dynamic/testing';
14 |
15 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
16 | declare const __karma__: any;
17 | declare const require: any;
18 |
19 | // Prevent Karma from running prematurely.
20 | __karma__.loaded = function () {};
21 |
22 | // First, initialize the Angular testing environment.
23 | getTestBed().initTestEnvironment(
24 | BrowserDynamicTestingModule,
25 | platformBrowserDynamicTesting()
26 | );
27 | // Then we find all the tests.
28 | const context = require.context('./', true, /\.spec\.ts$/);
29 | // And load the modules.
30 | context.keys().map(context);
31 | // Finally, start Karma to run the tests.
32 | __karma__.start();
33 |
--------------------------------------------------------------------------------
/double/admin/src/test.ts:
--------------------------------------------------------------------------------
1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2 |
3 | import 'zone.js/dist/long-stack-trace-zone';
4 | import 'zone.js/dist/proxy.js';
5 | import 'zone.js/dist/sync-test';
6 | import 'zone.js/dist/jasmine-patch';
7 | import 'zone.js/dist/async-test';
8 | import 'zone.js/dist/fake-async-test';
9 | import { getTestBed } from '@angular/core/testing';
10 | import {
11 | BrowserDynamicTestingModule,
12 | platformBrowserDynamicTesting
13 | } from '@angular/platform-browser-dynamic/testing';
14 |
15 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
16 | declare const __karma__: any;
17 | declare const require: any;
18 |
19 | // Prevent Karma from running prematurely.
20 | __karma__.loaded = function () {};
21 |
22 | // First, initialize the Angular testing environment.
23 | getTestBed().initTestEnvironment(
24 | BrowserDynamicTestingModule,
25 | platformBrowserDynamicTesting()
26 | );
27 | // Then we find all the tests.
28 | const context = require.context('./', true, /\.spec\.ts$/);
29 | // And load the modules.
30 | context.keys().map(context);
31 | // Finally, start Karma to run the tests.
32 | __karma__.start();
33 |
--------------------------------------------------------------------------------
/double/gateway/src/test.ts:
--------------------------------------------------------------------------------
1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2 |
3 | import 'zone.js/dist/long-stack-trace-zone';
4 | import 'zone.js/dist/proxy.js';
5 | import 'zone.js/dist/sync-test';
6 | import 'zone.js/dist/jasmine-patch';
7 | import 'zone.js/dist/async-test';
8 | import 'zone.js/dist/fake-async-test';
9 | import { getTestBed } from '@angular/core/testing';
10 | import {
11 | BrowserDynamicTestingModule,
12 | platformBrowserDynamicTesting
13 | } from '@angular/platform-browser-dynamic/testing';
14 |
15 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
16 | declare const __karma__: any;
17 | declare const require: any;
18 |
19 | // Prevent Karma from running prematurely.
20 | __karma__.loaded = function () {};
21 |
22 | // First, initialize the Angular testing environment.
23 | getTestBed().initTestEnvironment(
24 | BrowserDynamicTestingModule,
25 | platformBrowserDynamicTesting()
26 | );
27 | // Then we find all the tests.
28 | const context = require.context('./', true, /\.spec\.ts$/);
29 | // And load the modules.
30 | context.keys().map(context);
31 | // Finally, start Karma to run the tests.
32 | __karma__.start();
33 |
--------------------------------------------------------------------------------
/double/admin/src/app/app.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
3 |
4 | @Injectable()
5 | export class AppService {
6 |
7 | error: string;
8 | writer: boolean;
9 | authenticated = false;
10 |
11 | constructor(private http: HttpClient) {
12 | }
13 |
14 | authenticate(callback) {
15 |
16 | this.http.get('/user').subscribe(user => {
17 | if (user['name']) {
18 | this.authenticated = true;
19 | this.writer = user['roles'] && user['roles'].indexOf('ROLE_WRITER') > 0;
20 | } else {
21 | this.authenticated = false;
22 | this.writer = false;
23 | }
24 | if (callback) { callback(user); }
25 | }, response => {
26 | if (response.status === 0) {
27 | this.error = 'No connection. Verify application is running.';
28 | } else if (response.status === 401) {
29 | this.error = 'Unauthorized.';
30 | } else if (response.status === 403) {
31 | this.error = 'Forbidden.';
32 | } else {
33 | this.error = 'Unknown.';
34 | }
35 | this.authenticated = false;
36 | this.writer = false;
37 | });
38 |
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/oauth2-logout/ui/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | aop:
3 | proxy-target-class: true
4 |
5 |
6 | security:
7 | user:
8 | password: none
9 | ignored:
10 | - "*.bundle.*"
11 | oauth2:
12 | client:
13 | accessTokenUri: http://localhost:9999/uaa/oauth/token
14 | userAuthorizationUri: http://localhost:9999/uaa/oauth/authorize
15 | clientId: acme
16 | clientSecret: acmesecret
17 | resource:
18 | jwt:
19 | keyValue: |
20 | -----BEGIN PUBLIC KEY-----
21 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnGp/Q5lh0P8nPL21oMMrt2RrkT9AW5jgYwLfSUnJVc9G6uR3cXRRDCjHqWU5WYwivcF180A6CWp/ireQFFBNowgc5XaA0kPpzEtgsA5YsNX7iSnUibB004iBTfU9hZ2Rbsc8cWqynT0RyN4TP1RYVSeVKvMQk4GT1r7JCEC+TNu1ELmbNwMQyzKjsfBXyIOCFU/E94ktvsTZUHF4Oq44DBylCDsS1k7/sfZC2G5EU7Oz0mhG8+Uz6MSEQHtoIi6mc8u64Rwi3Z3tscuWG2ShtsUFuNSAFNkY7LkLn+/hxLCu2bNISMaESa8dG22CIMuIeRLVcAmEWEWH5EEforTg+QIDAQAB
22 | -----END PUBLIC KEY-----
23 |
24 | zuul:
25 | routes:
26 | resource:
27 | path: /resource/**
28 | url: http://localhost:9000
29 | user:
30 | path: /user/**
31 | url: http://localhost:9999/uaa/user
32 |
33 | logging:
34 | level:
35 | org.springframework.security: DEBUG
--------------------------------------------------------------------------------
/oauth2-logout/ui/src/test.ts:
--------------------------------------------------------------------------------
1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2 |
3 | import 'zone.js/dist/long-stack-trace-zone';
4 | import 'zone.js/dist/proxy.js';
5 | import 'zone.js/dist/sync-test';
6 | import 'zone.js/dist/jasmine-patch';
7 | import 'zone.js/dist/async-test';
8 | import 'zone.js/dist/fake-async-test';
9 | import { getTestBed } from '@angular/core/testing';
10 | import {
11 | BrowserDynamicTestingModule,
12 | platformBrowserDynamicTesting
13 | } from '@angular/platform-browser-dynamic/testing';
14 |
15 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
16 | declare const __karma__: any;
17 | declare const require: any;
18 |
19 | // Prevent Karma from running prematurely.
20 | __karma__.loaded = function () {};
21 |
22 | // First, initialize the Angular testing environment.
23 | getTestBed().initTestEnvironment(
24 | BrowserDynamicTestingModule,
25 | platformBrowserDynamicTesting()
26 | );
27 | // Then we find all the tests.
28 | const context = require.context('./', true, /\.spec\.ts$/);
29 | // And load the modules.
30 | context.keys().map(context);
31 | // Finally, start Karma to run the tests.
32 | __karma__.start();
33 |
--------------------------------------------------------------------------------
/oauth2-vanilla/ui/src/test.ts:
--------------------------------------------------------------------------------
1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2 |
3 | import 'zone.js/dist/long-stack-trace-zone';
4 | import 'zone.js/dist/proxy.js';
5 | import 'zone.js/dist/sync-test';
6 | import 'zone.js/dist/jasmine-patch';
7 | import 'zone.js/dist/async-test';
8 | import 'zone.js/dist/fake-async-test';
9 | import { getTestBed } from '@angular/core/testing';
10 | import {
11 | BrowserDynamicTestingModule,
12 | platformBrowserDynamicTesting
13 | } from '@angular/platform-browser-dynamic/testing';
14 |
15 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
16 | declare const __karma__: any;
17 | declare const require: any;
18 |
19 | // Prevent Karma from running prematurely.
20 | __karma__.loaded = function () {};
21 |
22 | // First, initialize the Angular testing environment.
23 | getTestBed().initTestEnvironment(
24 | BrowserDynamicTestingModule,
25 | platformBrowserDynamicTesting()
26 | );
27 | // Then we find all the tests.
28 | const context = require.context('./', true, /\.spec\.ts$/);
29 | // And load the modules.
30 | context.keys().map(context);
31 | // Finally, start Karma to run the tests.
32 | __karma__.start();
33 |
--------------------------------------------------------------------------------
/oauth2/ui/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | aop:
3 | proxy-target-class: true
4 |
5 |
6 | security:
7 | user:
8 | password: none
9 | ignored:
10 | - "*.bundle.*"
11 | oauth2:
12 | client:
13 | accessTokenUri: http://localhost:9999/uaa/oauth/token
14 | userAuthorizationUri: http://localhost:9999/uaa/oauth/authorize
15 | clientId: acme
16 | clientSecret: acmesecret
17 | resource:
18 | jwt:
19 | keyValue: |
20 | -----BEGIN PUBLIC KEY-----
21 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnGp/Q5lh0P8nPL21oMMrt2RrkT9AW5jgYwLfSUnJVc9G6uR3cXRRDCjHqWU5WYwivcF180A6CWp/ireQFFBNowgc5XaA0kPpzEtgsA5YsNX7iSnUibB004iBTfU9hZ2Rbsc8cWqynT0RyN4TP1RYVSeVKvMQk4GT1r7JCEC+TNu1ELmbNwMQyzKjsfBXyIOCFU/E94ktvsTZUHF4Oq44DBylCDsS1k7/sfZC2G5EU7Oz0mhG8+Uz6MSEQHtoIi6mc8u64Rwi3Z3tscuWG2ShtsUFuNSAFNkY7LkLn+/hxLCu2bNISMaESa8dG22CIMuIeRLVcAmEWEWH5EEforTg+QIDAQAB
22 | -----END PUBLIC KEY-----
23 |
24 | zuul:
25 | routes:
26 | resource:
27 | path: /resource/**
28 | url: http://localhost:9000
29 | user:
30 | path: /user/**
31 | url: http://localhost:9999/uaa/user
32 |
33 | logging:
34 | level:
35 | org.springframework.security: DEBUG
36 |
--------------------------------------------------------------------------------
/spring-session/ui/src/test.ts:
--------------------------------------------------------------------------------
1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2 |
3 | import 'zone.js/dist/long-stack-trace-zone';
4 | import 'zone.js/dist/proxy.js';
5 | import 'zone.js/dist/sync-test';
6 | import 'zone.js/dist/jasmine-patch';
7 | import 'zone.js/dist/async-test';
8 | import 'zone.js/dist/fake-async-test';
9 | import { getTestBed } from '@angular/core/testing';
10 | import {
11 | BrowserDynamicTestingModule,
12 | platformBrowserDynamicTesting
13 | } from '@angular/platform-browser-dynamic/testing';
14 |
15 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
16 | declare const __karma__: any;
17 | declare const require: any;
18 |
19 | // Prevent Karma from running prematurely.
20 | __karma__.loaded = function () {};
21 |
22 | // First, initialize the Angular testing environment.
23 | getTestBed().initTestEnvironment(
24 | BrowserDynamicTestingModule,
25 | platformBrowserDynamicTesting()
26 | );
27 | // Then we find all the tests.
28 | const context = require.context('./', true, /\.spec\.ts$/);
29 | // And load the modules.
30 | context.keys().map(context);
31 | // Finally, start Karma to run the tests.
32 | __karma__.start();
33 |
--------------------------------------------------------------------------------
/single/src/app/app.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { TestBed, async } from '@angular/core/testing';
2 | import { AppComponent } from './app.component';
3 | import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
4 | describe('AppComponent', () => {
5 | beforeEach(async(() => {
6 | TestBed.configureTestingModule({
7 | imports: [HttpClientTestingModule],
8 | declarations: [
9 | AppComponent
10 | ]
11 | }).compileComponents();
12 | }));
13 | it('should create the app', async(() => {
14 | const fixture = TestBed.createComponent(AppComponent);
15 | const app = fixture.debugElement.componentInstance;
16 | expect(app).toBeTruthy();
17 | }));
18 | it(`should have as title 'app'`, async(() => {
19 | const fixture = TestBed.createComponent(AppComponent);
20 | const app = fixture.debugElement.componentInstance;
21 | expect(app.title).toEqual('Demo');
22 | }));
23 | it('should render title in a h1 tag', async(() => {
24 | const fixture = TestBed.createComponent(AppComponent);
25 | fixture.detectChanges();
26 | const compiled = fixture.debugElement.nativeElement;
27 | expect(compiled.querySelector('h1').textContent).toContain('Welcome Demo!');
28 | }));
29 | });
30 |
--------------------------------------------------------------------------------
/double/resource/src/test/java/demo/ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package demo;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.boot.context.embedded.LocalServerPort;
8 | import org.springframework.boot.test.context.SpringBootTest;
9 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
10 | import org.springframework.boot.test.web.client.TestRestTemplate;
11 | import org.springframework.http.HttpStatus;
12 | import org.springframework.http.ResponseEntity;
13 | import org.springframework.test.context.junit4.SpringRunner;
14 |
15 |
16 | @RunWith(SpringRunner.class)
17 | @SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)
18 | public class ApplicationTests {
19 |
20 | @LocalServerPort
21 | private int port;
22 |
23 | private TestRestTemplate template = new TestRestTemplate();
24 |
25 | @Test
26 | public void resourceProtected() {
27 | ResponseEntity response = template.getForEntity("http://localhost:{port}/", String.class, port);
28 | // N.B. better if it was UNAUTHORIZED but that means we have to add a custom authentication entry point
29 | assertEquals(HttpStatus.FORBIDDEN, response.getStatusCode());
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/proxy/ui/src/app/app.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { TestBed, async } from '@angular/core/testing';
2 | import { AppComponent } from './app.component';
3 | import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
4 | describe('AppComponent', () => {
5 | beforeEach(async(() => {
6 | TestBed.configureTestingModule({
7 | imports: [HttpClientTestingModule],
8 | declarations: [
9 | AppComponent
10 | ]
11 | }).compileComponents();
12 | }));
13 | it('should create the app', async(() => {
14 | const fixture = TestBed.createComponent(AppComponent);
15 | const app = fixture.debugElement.componentInstance;
16 | expect(app).toBeTruthy();
17 | }));
18 | it(`should have as title 'app'`, async(() => {
19 | const fixture = TestBed.createComponent(AppComponent);
20 | const app = fixture.debugElement.componentInstance;
21 | expect(app.title).toEqual('Demo');
22 | }));
23 | it('should render title in a h1 tag', async(() => {
24 | const fixture = TestBed.createComponent(AppComponent);
25 | fixture.detectChanges();
26 | const compiled = fixture.debugElement.nativeElement;
27 | expect(compiled.querySelector('h1').textContent).toContain('Welcome Demo!');
28 | }));
29 | });
30 |
--------------------------------------------------------------------------------
/vanilla/ui/src/app/app.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { TestBed, async } from '@angular/core/testing';
2 | import { AppComponent } from './app.component';
3 | import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
4 | describe('AppComponent', () => {
5 | beforeEach(async(() => {
6 | TestBed.configureTestingModule({
7 | imports: [HttpClientTestingModule],
8 | declarations: [
9 | AppComponent
10 | ]
11 | }).compileComponents();
12 | }));
13 | it('should create the app', async(() => {
14 | const fixture = TestBed.createComponent(AppComponent);
15 | const app = fixture.debugElement.componentInstance;
16 | expect(app).toBeTruthy();
17 | }));
18 | it(`should have as title 'app'`, async(() => {
19 | const fixture = TestBed.createComponent(AppComponent);
20 | const app = fixture.debugElement.componentInstance;
21 | expect(app.title).toEqual('Demo');
22 | }));
23 | it('should render title in a h1 tag', async(() => {
24 | const fixture = TestBed.createComponent(AppComponent);
25 | fixture.detectChanges();
26 | const compiled = fixture.debugElement.nativeElement;
27 | expect(compiled.querySelector('h1').textContent).toContain('Welcome Demo!');
28 | }));
29 | });
30 |
--------------------------------------------------------------------------------
/double/admin/src/app/app.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { TestBed, async } from '@angular/core/testing';
2 | import { AppComponent } from './app.component';
3 | import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
4 | describe('AppComponent', () => {
5 | beforeEach(async(() => {
6 | TestBed.configureTestingModule({
7 | imports: [HttpClientTestingModule],
8 | declarations: [
9 | AppComponent
10 | ]
11 | }).compileComponents();
12 | }));
13 | it('should create the app', async(() => {
14 | const fixture = TestBed.createComponent(AppComponent);
15 | const app = fixture.debugElement.componentInstance;
16 | expect(app).toBeTruthy();
17 | }));
18 | it(`should have as title 'app'`, async(() => {
19 | const fixture = TestBed.createComponent(AppComponent);
20 | const app = fixture.debugElement.componentInstance;
21 | expect(app.title).toEqual('Demo');
22 | }));
23 | it('should render title in a h1 tag', async(() => {
24 | const fixture = TestBed.createComponent(AppComponent);
25 | fixture.detectChanges();
26 | const compiled = fixture.debugElement.nativeElement;
27 | expect(compiled.querySelector('h1').textContent).toContain('Welcome Demo!');
28 | }));
29 | });
30 |
--------------------------------------------------------------------------------
/spring-session/ui/src/app/app.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { TestBed, async } from '@angular/core/testing';
2 | import { AppComponent } from './app.component';
3 | import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
4 | describe('AppComponent', () => {
5 | beforeEach(async(() => {
6 | TestBed.configureTestingModule({
7 | imports: [HttpClientTestingModule],
8 | declarations: [
9 | AppComponent
10 | ]
11 | }).compileComponents();
12 | }));
13 | it('should create the app', async(() => {
14 | const fixture = TestBed.createComponent(AppComponent);
15 | const app = fixture.debugElement.componentInstance;
16 | expect(app).toBeTruthy();
17 | }));
18 | it(`should have as title 'app'`, async(() => {
19 | const fixture = TestBed.createComponent(AppComponent);
20 | const app = fixture.debugElement.componentInstance;
21 | expect(app.title).toEqual('Demo');
22 | }));
23 | it('should render title in a h1 tag', async(() => {
24 | const fixture = TestBed.createComponent(AppComponent);
25 | fixture.detectChanges();
26 | const compiled = fixture.debugElement.nativeElement;
27 | expect(compiled.querySelector('h1').textContent).toContain('Welcome Demo!');
28 | }));
29 | });
30 |
--------------------------------------------------------------------------------
/oauth2-logout/ui/src/main/java/demo/UiApplication.java:
--------------------------------------------------------------------------------
1 | package demo;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso;
6 | import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
7 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
8 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
9 | import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
10 |
11 | @SpringBootApplication
12 | @EnableZuulProxy
13 | @EnableOAuth2Sso
14 | public class UiApplication extends WebSecurityConfigurerAdapter {
15 |
16 | public static void main(String[] args) {
17 | SpringApplication.run(UiApplication.class, args);
18 | }
19 |
20 | @Override
21 | public void configure(HttpSecurity http) throws Exception {
22 | // @formatter:off
23 | http
24 | .logout().and()
25 | .authorizeRequests()
26 | .antMatchers("/index.html", "/", "/login").permitAll()
27 | .anyRequest().authenticated()
28 | .and()
29 | .csrf()
30 | .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
31 | // @formatter:on
32 | }
33 | }
34 |
35 |
--------------------------------------------------------------------------------
/double/gateway/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 | import { HttpClient, HttpHeaders } from '@angular/common/http';
3 |
4 | @Component({
5 | selector: 'app-root',
6 | templateUrl: './app.component.html',
7 | styleUrls: ['./app.component.css']
8 | })
9 | export class AppComponent {
10 |
11 | admin: boolean;
12 | user: any;
13 | title = 'Demo';
14 | credentials = {username: '', password: ''};
15 | authenticated = false;
16 |
17 | constructor(private http: HttpClient) {
18 | this.login();
19 | }
20 |
21 | login() {
22 | const headers = this.credentials.username ? new HttpHeaders().set(
23 | 'authorization', 'Basic ' + btoa(this.credentials.username + ':' + this.credentials.password)
24 | ) : new HttpHeaders();
25 | this.http.get('user', {headers: headers}).subscribe(data => {
26 | this.authenticated = data && data['name'];
27 | this.user = this.authenticated ? data['name'] : '';
28 | this.admin = this.authenticated && data['roles'] && data['roles'].indexOf('ROLE_ADMIN') > -1;
29 | });
30 | return false;
31 | }
32 |
33 | logout() {
34 | this.http.post('logout', {}).subscribe(function() {
35 | this.authenticated = false;
36 | this.admin = false;
37 | });
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/oauth2-vanilla/resource/src/test/java/demo/ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package demo;
2 |
3 | import static org.junit.Assert.assertEquals;
4 | import static org.junit.Assert.assertTrue;
5 |
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 | import org.springframework.boot.context.embedded.LocalServerPort;
9 | import org.springframework.boot.test.context.SpringBootTest;
10 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
11 | import org.springframework.boot.test.web.client.TestRestTemplate;
12 | import org.springframework.http.HttpStatus;
13 | import org.springframework.http.ResponseEntity;
14 | import org.springframework.test.context.junit4.SpringRunner;
15 |
16 | @RunWith(SpringRunner.class)
17 | @SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)
18 | public class ApplicationTests {
19 |
20 | @LocalServerPort
21 | private int port;
22 |
23 | private TestRestTemplate template = new TestRestTemplate();
24 |
25 | @Test
26 | public void resourceLoads() {
27 | ResponseEntity response = template.getForEntity("http://localhost:{port}/", String.class, port);
28 | assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
29 | String auth = response.getHeaders().getFirst("WWW-Authenticate");
30 | assertTrue("Wrong header: " + auth , auth.startsWith("Bearer"));
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/oauth2/resource/src/test/java/demo/ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package demo;
2 |
3 | import static org.junit.Assert.assertEquals;
4 | import static org.junit.Assert.assertTrue;
5 |
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 | import org.springframework.boot.context.embedded.LocalServerPort;
9 | import org.springframework.boot.test.context.SpringBootTest;
10 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
11 | import org.springframework.boot.test.web.client.TestRestTemplate;
12 | import org.springframework.http.HttpStatus;
13 | import org.springframework.http.ResponseEntity;
14 | import org.springframework.test.context.junit4.SpringRunner;
15 |
16 | @RunWith(SpringRunner.class)
17 | @SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)
18 | public class ApplicationTests {
19 |
20 | @LocalServerPort
21 | private int port;
22 |
23 | private TestRestTemplate template = new TestRestTemplate();
24 |
25 | @Test
26 | public void resourceLoads() {
27 | ResponseEntity response = template.getForEntity("http://localhost:{port}/resource/", String.class, port);
28 | assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
29 | String auth = response.getHeaders().getFirst("WWW-Authenticate");
30 | assertTrue("Wrong header: " + auth , auth.startsWith("Bearer"));
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/proxy/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to learn about possible attributes.
3 | // Hover to view descriptions of existing attributes.
4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "type": "java",
9 | "name": "Debug (Launch)-ResourceApplication",
10 | "request": "launch",
11 | "cwd": "${workspaceFolder}",
12 | "console": "internalConsole",
13 | "stopOnEntry": false,
14 | "mainClass": "demo.ResourceApplication",
15 | "projectName": "proxy-resource",
16 | "args": ""
17 | },
18 | {
19 | "type": "java",
20 | "name": "Debug (Launch)-UiApplication",
21 | "request": "launch",
22 | "cwd": "${workspaceFolder}",
23 | "console": "internalConsole",
24 | "stopOnEntry": false,
25 | "mainClass": "demo.UiApplication",
26 | "projectName": "proxy-ui",
27 | "args": ""
28 | },
29 | {
30 | "type": "java",
31 | "name": "Debug (Attach)",
32 | "request": "attach",
33 | "hostName": "localhost",
34 | "port": 0
35 | }
36 | ]
37 | }
38 |
--------------------------------------------------------------------------------
/oauth2-logout/resource/src/test/java/demo/ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package demo;
2 |
3 | import static org.junit.Assert.assertEquals;
4 | import static org.junit.Assert.assertTrue;
5 |
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 | import org.springframework.boot.context.embedded.LocalServerPort;
9 | import org.springframework.boot.test.context.SpringBootTest;
10 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
11 | import org.springframework.boot.test.web.client.TestRestTemplate;
12 | import org.springframework.http.HttpStatus;
13 | import org.springframework.http.ResponseEntity;
14 | import org.springframework.test.context.junit4.SpringRunner;
15 |
16 | @RunWith(SpringRunner.class)
17 | @SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)
18 | public class ApplicationTests {
19 |
20 | @LocalServerPort
21 | private int port;
22 |
23 | private TestRestTemplate template = new TestRestTemplate();
24 |
25 | @Test
26 | public void resourceLoads() {
27 | ResponseEntity response = template.getForEntity("http://localhost:{port}/resource/", String.class, port);
28 | assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
29 | String auth = response.getHeaders().getFirst("WWW-Authenticate");
30 | assertTrue("Wrong header: " + auth , auth.startsWith("Bearer"));
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/spring-session/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to learn about possible attributes.
3 | // Hover to view descriptions of existing attributes.
4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "type": "java",
9 | "name": "Debug (Launch)-ResourceApplication",
10 | "request": "launch",
11 | "cwd": "${workspaceFolder}",
12 | "console": "internalConsole",
13 | "stopOnEntry": false,
14 | "mainClass": "demo.ResourceApplication",
15 | "projectName": "spring-session-resource",
16 | "args": ""
17 | },
18 | {
19 | "type": "java",
20 | "name": "Debug (Launch)-UiApplication",
21 | "request": "launch",
22 | "cwd": "${workspaceFolder}",
23 | "console": "internalConsole",
24 | "stopOnEntry": false,
25 | "mainClass": "demo.UiApplication",
26 | "projectName": "spring-session-ui",
27 | "args": ""
28 | },
29 | {
30 | "type": "java",
31 | "name": "Debug (Attach)",
32 | "request": "attach",
33 | "hostName": "localhost",
34 | "port": 0
35 | }
36 | ]
37 | }
--------------------------------------------------------------------------------
/double/admin/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 | import { AppService } from './app.service';
3 | import { HttpClient } from '@angular/common/http';
4 | import { Router } from '@angular/router';
5 | import 'rxjs/add/operator/finally';
6 |
7 | @Component({
8 | selector: 'app-root',
9 | templateUrl: './app.component.html',
10 | styleUrls: ['./app.component.css']
11 | })
12 | export class AppComponent {
13 |
14 | user: {};
15 |
16 | constructor(private app: AppService, private http: HttpClient, private router: Router) {
17 | app.authenticate(response => {
18 | this.user = response;
19 | this.message();
20 | });
21 | }
22 |
23 | logout() {
24 | this.http.post('logout', {}).subscribe(function() {
25 | this.app.authenticated = false;
26 | this.router.navigateByUrl('/login');
27 | });
28 | }
29 |
30 | message() {
31 | if (!this.app.authenticated) {
32 | this.router.navigate(['/unauthenticated']);
33 | } else {
34 | if (this.app.writer) {
35 | this.router.navigate(['/write']);
36 | } else {
37 | this.router.navigate(['/read']);
38 | }
39 | }
40 | }
41 |
42 | changes() {
43 | if (!this.app.authenticated) {
44 | this.router.navigate(['/unauthenticated']);
45 | } else {
46 | this.router.navigate(['/changes']);
47 | }
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/oauth2/authserver/src/main/resources/templates/authorize.ftl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
8 |
9 |
10 |
11 |
Please Confirm
12 |
13 |
14 | Do you authorize "${authorizationRequest.clientId}" at "${authorizationRequest.redirectUri}" to access your protected resources
15 | with scope ${authorizationRequest.scope?join(", ")}.
16 |
17 |
23 |
29 |
30 |
31 |
--------------------------------------------------------------------------------