{
17 | return this.text(ApiConst.ECHO);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/client/src/main/ng/src/app/feature/layout/home/home.component.html:
--------------------------------------------------------------------------------
1 | Hi, {{ username }}
2 | Echo from server: {{echo}}
3 |
--------------------------------------------------------------------------------
/client/src/main/ng/src/app/feature/layout/home/home.component.ts:
--------------------------------------------------------------------------------
1 | import {Component, OnInit} from '@angular/core';
2 | import {EchoService} from '../../../core/service/echo.service';
3 | import {AuthService} from '../../../core/service/auth.service';
4 |
5 | @Component({
6 | selector: 'app-home',
7 | templateUrl: './home.component.html'
8 | })
9 | export class HomeComponent implements OnInit {
10 | echo = 'nope';
11 | username = '';
12 |
13 | constructor(
14 | private echoService: EchoService,
15 | private authService: AuthService
16 | ) {
17 | }
18 |
19 | ngOnInit(): void {
20 | this.username = this.authService.username;
21 | this.echoService.echo().subscribe(result => {
22 | this.echo = result;
23 | });
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/client/src/main/ng/src/app/feature/layout/layout.component.html:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/client/src/main/ng/src/app/feature/layout/layout.component.ts:
--------------------------------------------------------------------------------
1 | import {Component} from '@angular/core';
2 | import {AuthService} from '../../core/service/auth.service';
3 | import {Router} from '@angular/router';
4 |
5 | @Component({
6 | selector: 'app-layout',
7 | templateUrl: './layout.component.html'
8 | })
9 | export class LayoutComponent {
10 |
11 | constructor(
12 | private router: Router,
13 | private authService: AuthService
14 | ) {}
15 |
16 | logout() {
17 | this.authService.logout().subscribe(_ => {
18 | this.router.navigate(['/']);
19 | });
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/client/src/main/ng/src/app/feature/layout/layout.module.ts:
--------------------------------------------------------------------------------
1 | import {NgModule} from '@angular/core';
2 | import {SharedModule} from '../../shared/shared.module';
3 | import {LayoutComponent} from './layout.component';
4 | import {LayoutRouteModule} from './layout.route-module';
5 | import {HomeComponent} from './home/home.component';
6 |
7 | @NgModule({
8 | imports: [
9 | SharedModule,
10 | LayoutRouteModule,
11 | ],
12 | declarations: [
13 | HomeComponent,
14 | LayoutComponent
15 | ],
16 | exports: [
17 | LayoutComponent
18 | ]
19 | })
20 | export class LayoutModule {
21 | }
22 |
--------------------------------------------------------------------------------
/client/src/main/ng/src/app/feature/layout/layout.route-module.ts:
--------------------------------------------------------------------------------
1 | import {RouterModule, Routes} from '@angular/router';
2 | import {HomeComponent} from './home/home.component';
3 | import {NgModule} from '@angular/core';
4 | import {AuthGuard} from '../../core/guard/auth.guard';
5 | import {LayoutComponent} from './layout.component';
6 |
7 | const routes: Routes = [
8 | {
9 | path: '', component: LayoutComponent,
10 | children: [
11 | { path: '', redirectTo: '/home', pathMatch: 'full', canActivate: [AuthGuard] },
12 | { path: 'home', component: HomeComponent, canActivate: [AuthGuard] },
13 | { path: 'lazy', loadChildren: './lazy/lazy.module#LazyModule', canActivate: [AuthGuard] }
14 | ]
15 | }
16 | ];
17 |
18 | @NgModule({
19 | imports: [
20 | RouterModule.forChild(routes)
21 | ],
22 | exports: [
23 | RouterModule
24 | ]
25 | })
26 | export class LayoutRouteModule {
27 | }
28 |
--------------------------------------------------------------------------------
/client/src/main/ng/src/app/feature/layout/lazy/lazy.component.ts:
--------------------------------------------------------------------------------
1 | import {Component} from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-lazy',
5 | template: `I'm Lazy
`
6 | })
7 | export class LazyComponent {
8 | }
9 |
--------------------------------------------------------------------------------
/client/src/main/ng/src/app/feature/layout/lazy/lazy.module.ts:
--------------------------------------------------------------------------------
1 | import {RouterModule, Routes} from '@angular/router';
2 | import {NgModule} from '@angular/core';
3 | import {LazyComponent} from './lazy.component';
4 | import {SharedModule} from '../../../shared/shared.module';
5 |
6 | const routes: Routes = [
7 | {path: '', component: LazyComponent},
8 | ];
9 |
10 | @NgModule({
11 | imports: [SharedModule, RouterModule.forChild(routes)],
12 | exports: [LazyComponent],
13 | declarations: [LazyComponent]
14 | })
15 | export class LazyModule {}
16 |
--------------------------------------------------------------------------------
/client/src/main/ng/src/app/feature/login/login.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/client/src/main/ng/src/app/feature/login/login.component.scss:
--------------------------------------------------------------------------------
1 | $element-height: 34px;
2 | $element-margin-bottom: 16px;
3 | $element-width: 400px;
4 |
5 | :host {
6 | left: 50%;
7 | margin: (-($element-height*3 + $element-margin-bottom*2)/2) 0 0 (-$element-width/2);
8 | position: absolute;
9 | top: 50%;
10 | width: $element-width;
11 | }
12 |
13 | button {
14 | background-color: #636262;
15 | border: none;
16 | color: #fff;
17 | cursor: pointer;
18 | font-size: 14px;
19 | height: $element-height;
20 | line-height: $element-height;
21 | width: 100%;
22 | }
23 |
24 | button:disabled {
25 | background-color: #bdbbbb;
26 | cursor: default;
27 | }
28 |
29 | input {
30 | box-sizing: border-box;
31 | display: inline-block;
32 | font-size: 14px;
33 | height: $element-height;
34 | line-height: $element-height;
35 | margin-bottom: $element-margin-bottom;
36 | padding: 0 10px;
37 | width: 100%;
38 | }
39 |
--------------------------------------------------------------------------------
/client/src/main/ng/src/app/feature/login/login.component.ts:
--------------------------------------------------------------------------------
1 | import {Component} from '@angular/core';
2 | import {AuthService} from '../../core/service/auth.service';
3 | import {FormBuilder, FormGroup} from '@angular/forms';
4 | import {debounceTime} from 'rxjs/operators';
5 | import {Router} from '@angular/router';
6 |
7 | @Component({
8 | selector: 'app-login',
9 | templateUrl: './login.component.html',
10 | styleUrls: ['./login.component.scss']
11 | })
12 | export class LoginComponent {
13 |
14 | form: FormGroup;
15 |
16 | constructor(
17 | formBuilder: FormBuilder,
18 | private router: Router,
19 | private authService: AuthService
20 | ) {
21 | this.form = formBuilder.group({
22 | username: null,
23 | password: null
24 | });
25 | }
26 |
27 | login() {
28 | this.authService.authenticate(this.form.value).pipe(debounceTime(400)).subscribe(result => {
29 | if (result) {
30 | this.router.navigate(['/']);
31 | } else {
32 | this.form.reset();
33 | }
34 | });
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/client/src/main/ng/src/app/feature/login/login.module.ts:
--------------------------------------------------------------------------------
1 | import {NgModule} from '@angular/core';
2 | import {SharedModule} from '../../shared/shared.module';
3 | import {LoginComponent} from './login.component';
4 |
5 | @NgModule({
6 | imports: [
7 | SharedModule
8 | ],
9 | declarations: [
10 | LoginComponent
11 | ],
12 | exports: [
13 | LoginComponent
14 | ]
15 | })
16 | export class LoginModule {
17 | }
18 |
--------------------------------------------------------------------------------
/client/src/main/ng/src/app/feature/page-not-found/page-not-found.component.html:
--------------------------------------------------------------------------------
1 | Page not found 404
--------------------------------------------------------------------------------
/client/src/main/ng/src/app/feature/page-not-found/page-not-found.component.ts:
--------------------------------------------------------------------------------
1 | import {Component} from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-page-not-found',
5 | templateUrl: './page-not-found.component.html'
6 | })
7 |
8 | export class PageNotFoundComponent {
9 | }
10 |
--------------------------------------------------------------------------------
/client/src/main/ng/src/app/model/credentials.model.ts:
--------------------------------------------------------------------------------
1 | export interface Credentials {
2 | username: string;
3 | password: string;
4 | }
5 |
--------------------------------------------------------------------------------
/client/src/main/ng/src/app/shared/shared.module.ts:
--------------------------------------------------------------------------------
1 | import {CommonModule} from '@angular/common';
2 | import {NgModule} from '@angular/core';
3 | import {ReactiveFormsModule} from '@angular/forms';
4 |
5 | @NgModule({
6 | imports: [
7 | CommonModule,
8 | ReactiveFormsModule
9 | ],
10 | declarations: [
11 | ],
12 | exports: [
13 | CommonModule,
14 | ReactiveFormsModule
15 | ]
16 | })
17 | export class SharedModule {
18 | }
19 |
--------------------------------------------------------------------------------
/client/src/main/ng/src/app/util/api.const.ts:
--------------------------------------------------------------------------------
1 | export class ApiConst {
2 | static readonly ECHO = '/api/echo';
3 | static readonly LOGOUT = '/api/logout';
4 | static readonly USER = '/api/user';
5 | }
6 |
--------------------------------------------------------------------------------
/client/src/main/ng/src/assets/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hiper2d/spring-boot-angular-maven-starter/38901aacbaa52c578bfb86213c1a55cd090da8b6/client/src/main/ng/src/assets/favicon.ico
--------------------------------------------------------------------------------
/client/src/main/ng/src/assets/global.scss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hiper2d/spring-boot-angular-maven-starter/38901aacbaa52c578bfb86213c1a55cd090da8b6/client/src/main/ng/src/assets/global.scss
--------------------------------------------------------------------------------
/client/src/main/ng/src/assets/reset.scss:
--------------------------------------------------------------------------------
1 | html, body, div, span, applet, object, iframe,
2 | h1, h2, h3, h4, h5, h6, p, blockquote, pre,
3 | a, abbr, acronym, address, big, cite, code,
4 | del, dfn, em, img, ins, kbd, q, s, samp,
5 | small, strike, strong, sub, sup, tt, var,
6 | b, u, i, center,
7 | dl, dt, dd, ol, ul, li,
8 | fieldset, form, label, legend,
9 | table, caption, tbody, tfoot, thead, tr, th, td,
10 | article, aside, canvas, details, embed,
11 | figure, figcaption, footer, header,
12 | main, menu, nav, output, ruby, section, summary,
13 | time, mark, audio, video {
14 | margin: 0;
15 | padding: 0;
16 | border: 0;
17 | vertical-align: baseline;
18 | }
19 | /* HTML5 display-role reset for older browsers */
20 | article, aside, details, figcaption, figure,
21 | footer, header, main, menu, nav, section {
22 | display: block;
23 | }
24 | body {
25 | line-height: 1;
26 | }
27 | ol, ul {
28 | list-style: none;
29 | }
30 | blockquote, q {
31 | quotes: none;
32 | }
33 | blockquote:before, blockquote:after,
34 | q:before, q:after {
35 | content: '';
36 | content: none;
37 | }
38 |
39 | /* Don't kill focus outline for keyboard users: http://24ways.org/2009/dont-lose-your-focus */
40 | a:hover, a:active {
41 | outline: none;
42 | }
43 |
44 | table {
45 | border-collapse: collapse;
46 | border-spacing: 0;
47 | }
--------------------------------------------------------------------------------
/client/src/main/ng/src/environments/environment.prod.ts:
--------------------------------------------------------------------------------
1 | export const environment = {
2 | production: true
3 | };
4 |
--------------------------------------------------------------------------------
/client/src/main/ng/src/environments/environment.ts:
--------------------------------------------------------------------------------
1 | // The file contents for the current environment will overwrite these during build.
2 | // The build system defaults to the dev environment which uses `environment.ts`, but if you do
3 | // `ng build --env=prod` then `environment.prod.ts` will be used instead.
4 | // The list of which env maps to which file can be found in `.angular-cli.json`.
5 |
6 | export const environment = {
7 | production: false
8 | };
9 |
--------------------------------------------------------------------------------
/client/src/main/ng/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SpringBootAngularMavenStarter
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/client/src/main/ng/src/main.ts:
--------------------------------------------------------------------------------
1 | import { enableProdMode } from '@angular/core';
2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3 |
4 | import { AppModule } from './app/app.module';
5 | import { environment } from './environments/environment';
6 |
7 | if (environment.production) {
8 | enableProdMode();
9 | }
10 |
11 | platformBrowserDynamic().bootstrapModule(AppModule)
12 | .catch(err => console.log(err));
13 |
--------------------------------------------------------------------------------
/client/src/main/ng/src/polyfills.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * This file includes polyfills needed by Angular and is loaded before the app.
3 | * You can add your own extra polyfills to this file.
4 | *
5 | * This file is divided into 2 sections:
6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main
8 | * file.
9 | *
10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
13 | *
14 | * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
15 | */
16 |
17 | /***************************************************************************************************
18 | * BROWSER POLYFILLS
19 | */
20 |
21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/
22 | // import 'core-js/es6/symbol';
23 | // import 'core-js/es6/object';
24 | // import 'core-js/es6/function';
25 | // import 'core-js/es6/parse-int';
26 | // import 'core-js/es6/parse-float';
27 | // import 'core-js/es6/number';
28 | // import 'core-js/es6/math';
29 | // import 'core-js/es6/string';
30 | // import 'core-js/es6/date';
31 | // import 'core-js/es6/array';
32 | // import 'core-js/es6/regexp';
33 | // import 'core-js/es6/map';
34 | // import 'core-js/es6/weak-map';
35 | // import 'core-js/es6/set';
36 |
37 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */
38 | // import 'classlist.js'; // Run `npm install --save classlist.js`.
39 |
40 | /** IE10 and IE11 requires the following for the Reflect API. */
41 | // import 'core-js/es6/reflect';
42 |
43 |
44 | /** Evergreen browsers require these. **/
45 | // Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove.
46 | import 'core-js/es7/reflect';
47 |
48 |
49 | /**
50 | * Required to support Web Animations `@angular/platform-browser/animations`.
51 | * Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation
52 | **/
53 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`.
54 |
55 |
56 |
57 | /***************************************************************************************************
58 | * Zone JS is required by Angular itself.
59 | */
60 | import 'zone.js/dist/zone'; // Included with Angular CLI.
61 |
62 |
63 |
64 | /***************************************************************************************************
65 | * APPLICATION IMPORTS
66 | */
67 |
68 | /**
69 | * Date, currency, decimal and percent pipes.
70 | * Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10
71 | */
72 | // import 'intl'; // Run `npm install --save intl`.
73 | /**
74 | * Need to import at least one locale-data with intl.
75 | */
76 | // import 'intl/locale-data/jsonp/en';
77 |
--------------------------------------------------------------------------------
/client/src/main/ng/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 |
--------------------------------------------------------------------------------
/client/src/main/ng/src/tsconfig.app.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/app",
5 | "baseUrl": "./",
6 | "module": "es2015",
7 | "types": []
8 | },
9 | "exclude": [
10 | "test.ts",
11 | "**/*.spec.ts"
12 | ]
13 | }
14 |
--------------------------------------------------------------------------------
/client/src/main/ng/src/tsconfig.spec.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/spec",
5 | "baseUrl": "./",
6 | "module": "commonjs",
7 | "target": "es5",
8 | "types": [
9 | "jasmine",
10 | "node"
11 | ]
12 | },
13 | "files": [
14 | "test.ts",
15 | "polyfills.ts"
16 | ],
17 | "include": [
18 | "**/*.spec.ts",
19 | "**/*.d.ts"
20 | ]
21 | }
22 |
--------------------------------------------------------------------------------
/client/src/main/ng/src/typings.d.ts:
--------------------------------------------------------------------------------
1 | /* SystemJS module definition */
2 | declare var module: NodeModule;
3 | interface NodeModule {
4 | id: string;
5 | }
6 |
--------------------------------------------------------------------------------
/client/src/main/ng/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compileOnSave": false,
3 | "compilerOptions": {
4 | "outDir": "./dist/out-tsc",
5 | "sourceMap": true,
6 | "declaration": false,
7 | "moduleResolution": "node",
8 | "emitDecoratorMetadata": true,
9 | "experimentalDecorators": true,
10 | "target": "es5",
11 | "typeRoots": [
12 | "node_modules/@types"
13 | ],
14 | "lib": [
15 | "es2017",
16 | "dom"
17 | ]
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/client/src/main/ng/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "rulesDirectory": [
3 | "node_modules/codelyzer"
4 | ],
5 | "rules": {
6 | "arrow-return-shorthand": true,
7 | "callable-types": true,
8 | "class-name": true,
9 | "comment-format": [
10 | true,
11 | "check-space"
12 | ],
13 | "curly": true,
14 | "eofline": true,
15 | "forin": true,
16 | "import-blacklist": [
17 | true,
18 | "rxjs/Rx"
19 | ],
20 | "import-spacing": true,
21 | "indent": [
22 | true,
23 | "spaces"
24 | ],
25 | "interface-over-type-literal": true,
26 | "label-position": true,
27 | "max-line-length": [
28 | true,
29 | 140
30 | ],
31 | "member-access": false,
32 | "member-ordering": [
33 | true,
34 | {
35 | "order": [
36 | "static-field",
37 | "instance-field",
38 | "static-method",
39 | "instance-method"
40 | ]
41 | }
42 | ],
43 | "no-arg": true,
44 | "no-bitwise": true,
45 | "no-console": [
46 | true,
47 | "debug",
48 | "info",
49 | "time",
50 | "timeEnd",
51 | "trace"
52 | ],
53 | "no-construct": true,
54 | "no-debugger": true,
55 | "no-duplicate-super": true,
56 | "no-empty": false,
57 | "no-empty-interface": true,
58 | "no-eval": true,
59 | "no-inferrable-types": [
60 | true,
61 | "ignore-params"
62 | ],
63 | "no-misused-new": true,
64 | "no-non-null-assertion": true,
65 | "no-shadowed-variable": true,
66 | "no-string-literal": false,
67 | "no-string-throw": true,
68 | "no-switch-case-fall-through": true,
69 | "no-trailing-whitespace": true,
70 | "no-unnecessary-initializer": true,
71 | "no-unused-expression": true,
72 | "no-use-before-declare": true,
73 | "no-var-keyword": true,
74 | "object-literal-sort-keys": false,
75 | "one-line": [
76 | true,
77 | "check-open-brace",
78 | "check-catch",
79 | "check-else",
80 | "check-whitespace"
81 | ],
82 | "prefer-const": true,
83 | "quotemark": [
84 | true,
85 | "single"
86 | ],
87 | "radix": true,
88 | "semicolon": [
89 | true,
90 | "always"
91 | ],
92 | "triple-equals": [
93 | true,
94 | "allow-null-check"
95 | ],
96 | "typedef-whitespace": [
97 | true,
98 | {
99 | "call-signature": "nospace",
100 | "index-signature": "nospace",
101 | "parameter": "nospace",
102 | "property-declaration": "nospace",
103 | "variable-declaration": "nospace"
104 | }
105 | ],
106 | "typeof-compare": true,
107 | "unified-signatures": true,
108 | "variable-name": false,
109 | "whitespace": [
110 | true,
111 | "check-branch",
112 | "check-decl",
113 | "check-operator",
114 | "check-separator",
115 | "check-type"
116 | ],
117 | "directive-selector": [
118 | true,
119 | "attribute",
120 | "app",
121 | "camelCase"
122 | ],
123 | "component-selector": [
124 | true,
125 | "element",
126 | "app",
127 | "kebab-case"
128 | ],
129 | "use-input-property-decorator": true,
130 | "use-output-property-decorator": true,
131 | "use-host-property-decorator": true,
132 | "no-input-rename": true,
133 | "no-output-rename": true,
134 | "use-life-cycle-interface": true,
135 | "use-pipe-transform-interface": true,
136 | "component-class-suffix": true,
137 | "directive-class-suffix": true,
138 | "invoke-injectable": true
139 | }
140 | }
141 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.hiper2d
8 | spring-boot-angular-maven-starter
9 | 1.0-SNAPSHOT
10 | pom
11 |
12 |
13 | client
14 | server
15 |
16 |
--------------------------------------------------------------------------------
/server/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | server
8 | 1.0-SNAPSHOT
9 | war
10 |
11 |
12 | com.hiper2d
13 | spring-boot-angular-maven-starter
14 | 1.0-SNAPSHOT
15 |
16 |
17 |
18 | 2.9.4.1
19 | 1.2.50
20 | true
21 | 1.8
22 | 1.8
23 | 3.1.0
24 | 2.0.3.RELEASE
25 | com.hiper2d.Application
26 |
27 |
28 |
29 |
30 |
31 | org.springframework.boot
32 | spring-boot-dependencies
33 | ${spring-boot-version}
34 | pom
35 | import
36 |
37 |
38 |
39 |
40 |
41 |
42 | spring-milestones
43 | Spring Milestones
44 | http://repo.spring.io/milestone
45 |
46 |
47 |
48 |
49 |
50 | org.springframework.boot
51 | spring-boot-starter-web
52 |
53 |
54 | org.springframework.boot
55 | spring-boot-starter-logging
56 |
57 |
58 |
59 |
60 |
61 | org.springframework.boot
62 | spring-boot-starter-security
63 |
64 |
65 |
66 | org.springframework.boot
67 | spring-boot-starter-log4j2
68 |
69 |
70 |
71 | org.jetbrains.kotlin
72 | kotlin-stdlib-jdk8
73 | ${kotlin.version}
74 |
75 |
76 |
77 | org.jetbrains.kotlin
78 | kotlin-reflect
79 | ${kotlin.version}
80 |
81 |
82 |
83 | com.fasterxml.jackson.module
84 | jackson-module-kotlin
85 | ${jackson-module-kotlin.version}
86 |
87 |
88 |
89 |
90 | ${project.basedir}/src/main/kotlin
91 |
92 |
93 |
94 | kotlin-maven-plugin
95 | org.jetbrains.kotlin
96 | ${kotlin.version}
97 |
98 |
99 | spring
100 |
101 | 1.8
102 |
103 |
104 |
105 | compile
106 | compile
107 |
108 | compile
109 |
110 |
111 |
112 | test-compile
113 | test-compile
114 |
115 | test-compile
116 |
117 |
118 |
119 |
120 |
121 | org.jetbrains.kotlin
122 | kotlin-maven-allopen
123 | ${kotlin.version}
124 |
125 |
126 |
127 |
128 |
129 | maven-war-plugin
130 | ${maven.war.plugin.version}
131 |
132 |
133 |
134 | org.springframework.boot
135 | spring-boot-maven-plugin
136 | ${spring-boot-version}
137 |
138 |
139 |
140 | repackage
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 | prod
151 |
152 |
153 | com.hiper2d
154 | client
155 | 1.0-SNAPSHOT
156 |
157 |
158 |
159 |
160 |
--------------------------------------------------------------------------------
/server/src/main/kotlin/com/hiper2d/Application.kt:
--------------------------------------------------------------------------------
1 | package com.hiper2d
2 |
3 | import org.springframework.boot.SpringApplication
4 | import org.springframework.boot.autoconfigure.SpringBootApplication
5 | import org.springframework.boot.builder.SpringApplicationBuilder
6 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer
7 |
8 | @SpringBootApplication
9 | class Application: SpringBootServletInitializer()
10 |
11 | fun main(args: Array) {
12 | SpringApplication.run(Application::class.java, *args)
13 | }
--------------------------------------------------------------------------------
/server/src/main/kotlin/com/hiper2d/config/WebConfig.kt:
--------------------------------------------------------------------------------
1 | package com.hiper2d.config
2 |
3 | import org.springframework.context.annotation.Configuration
4 | import org.springframework.web.servlet.config.annotation.CorsRegistry
5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
6 |
7 | @Configuration
8 | class WebConfig: WebMvcConfigurer {
9 |
10 | // todo: Understand why it is ignored. Probably some headers should be added to a client
11 | override fun addCorsMappings(registry: CorsRegistry) {
12 | registry.addMapping("/api/**")
13 | .allowedOrigins("http://localhost:9002")
14 | }
15 | }
16 |
17 |
--------------------------------------------------------------------------------
/server/src/main/kotlin/com/hiper2d/config/WebSecurityConfig.kt:
--------------------------------------------------------------------------------
1 | package com.hiper2d.config
2 |
3 | import com.hiper2d.security.provider.AnyAuthenticationProvider
4 | import org.springframework.context.annotation.Configuration
5 | import org.springframework.http.HttpStatus
6 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder
7 | import org.springframework.security.config.annotation.web.builders.HttpSecurity
8 | import org.springframework.security.config.annotation.web.builders.WebSecurity
9 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
10 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
11 | import org.springframework.security.web.authentication.HttpStatusEntryPoint
12 | import org.springframework.security.web.csrf.CookieCsrfTokenRepository
13 | import org.springframework.security.web.util.matcher.AntPathRequestMatcher
14 |
15 | @Configuration
16 | @EnableWebSecurity
17 | class WebSecurityConfig(
18 | private val anyAuthenticationProvider: AnyAuthenticationProvider
19 | ): WebSecurityConfigurerAdapter() {
20 |
21 | override fun configure(auth: AuthenticationManagerBuilder) {
22 | // A custom provider which allows to authenticate with any Latin username/password
23 | auth.authenticationProvider(anyAuthenticationProvider)
24 | }
25 |
26 | override fun configure(http: HttpSecurity) {
27 | http
28 | .httpBasic()
29 | .and()
30 | .authorizeRequests()
31 | // Necessary when running the application with compiled client as static resources
32 | .antMatchers("/").permitAll()
33 | .anyRequest().authenticated()
34 | .and()
35 | .logout()
36 | .logoutRequestMatcher(AntPathRequestMatcher("/api/logout", "POST"))
37 | .and()
38 | .csrf()
39 | // Allow a JavaScript client to read the XSRF-TOKEN from cookie
40 | .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
41 | .and()
42 | // Use MVC CORS configuration
43 | .cors()
44 | .and()
45 | .exceptionHandling()
46 | // An AuthenticationEntryPoint that sends a generic HttpStatus as a response
47 | .authenticationEntryPoint(HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED))
48 | }
49 |
50 | override fun configure(web: WebSecurity) {
51 | // Everything below is necessary when running the application with compiled client as static resources
52 | web.ignoring()
53 | .mvcMatchers("/favicon.ico")
54 | .mvcMatchers("/*.css")
55 | .mvcMatchers("/*.js")
56 | }
57 | }
--------------------------------------------------------------------------------
/server/src/main/kotlin/com/hiper2d/controller/EchoController.kt:
--------------------------------------------------------------------------------
1 | package com.hiper2d.controller
2 |
3 | import org.springframework.web.bind.annotation.GetMapping
4 | import org.springframework.web.bind.annotation.RequestMapping
5 | import org.springframework.web.bind.annotation.RestController
6 |
7 | @RestController
8 | @RequestMapping("/api/echo")
9 | class EchoController {
10 |
11 | @GetMapping
12 | fun echo() = "hi"
13 | }
--------------------------------------------------------------------------------
/server/src/main/kotlin/com/hiper2d/controller/UserController.kt:
--------------------------------------------------------------------------------
1 | package com.hiper2d.controller
2 |
3 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken
4 | import org.springframework.security.core.context.SecurityContextHolder
5 | import org.springframework.web.bind.annotation.GetMapping
6 | import org.springframework.web.bind.annotation.PostMapping
7 | import org.springframework.web.bind.annotation.RequestMapping
8 | import org.springframework.web.bind.annotation.RestController
9 |
10 | @RestController
11 | @RequestMapping("/api/user")
12 | class UserController {
13 |
14 | @GetMapping
15 | fun getUser(): String? {
16 | val auth = SecurityContextHolder.getContext().authentication
17 | return if (auth is UsernamePasswordAuthenticationToken) {
18 | auth.principal as String
19 | } else {
20 | null
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/server/src/main/kotlin/com/hiper2d/security/provider/AnyAuthenticationProvider.kt:
--------------------------------------------------------------------------------
1 | package com.hiper2d.security.provider
2 |
3 | import org.springframework.security.authentication.AuthenticationProvider
4 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken
5 | import org.springframework.security.core.Authentication
6 | import org.springframework.stereotype.Component
7 |
8 | @Component
9 | class AnyAuthenticationProvider: AuthenticationProvider {
10 |
11 | override fun authenticate(token: Authentication?): Authentication? {
12 | val name: String? = token?.name
13 | val pass: String? = token?.credentials.toString()
14 | return if (name != null && pass != null) {
15 | UsernamePasswordAuthenticationToken(name, pass, emptyList())
16 | } else {
17 | null
18 | }
19 | }
20 |
21 | override fun supports(clazz: Class<*>?): Boolean {
22 | return true
23 | }
24 | }
--------------------------------------------------------------------------------
/server/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server.port: 9001
--------------------------------------------------------------------------------
/server/src/main/resources/log4j2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------