Scaffold backend/frontend services, OIDC auth, and compose.yml

This commit is contained in:
nessar committed 2026-08-17 14:18:14 +02:00
1 parent 71a2b3081f
commit bdc2e1bc57
41 files changed
+3223

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
import { ApplicationConfig, provideBrowserGlobalErrorListeners, APP_INITIALIZER } from '@angular/core';
import { provideRouter } from '@angular/router';
import { provideHttpClient } from '@angular/common/http';
import { provideOAuthClient, OAuthService } from 'angular-oauth2-oidc';
import { routes } from './app.routes';
import { ConfigService } from './config.service';
export function initializeApp(configService: ConfigService, oauthService: OAuthService) {
return () => configService.loadConfig().then(() => {
oauthService.configure({
issuer: configService.oidcIssuer,
redirectUri: window.location.origin + '/',
clientId: configService.clientId,
responseType: 'code',
scope: 'openid profile email',
showDebugInformation: true,
requireHttps: false
});
return oauthService.loadDiscoveryDocumentAndTryLogin();
});
}
export const appConfig: ApplicationConfig = {
providers: [
provideBrowserGlobalErrorListeners(),
provideRouter(routes),
provideHttpClient(),
provideOAuthClient(),
{
provide: APP_INITIALIZER,
useFactory: initializeApp,
deps: [ConfigService, OAuthService],
multi: true
}
]
};
+332
View File
@@ -0,0 +1,332 @@
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');
:host {
display: block;
font-family: 'Outfit', sans-serif;
--bg-primary: #0a0b10;
--bg-card: rgba(18, 20, 29, 0.6);
--border-card: rgba(255, 255, 255, 0.08);
--color-primary: #6366f1;
--color-primary-glow: rgba(99, 102, 241, 0.3);
--color-secondary: #ec4899;
--color-text: #f3f4f6;
--color-text-muted: #9ca3af;
--color-success: #10b981;
}
.app-container {
min-height: 100vh;
background-color: var(--bg-primary);
color: var(--color-text);
display: flex;
align-items: center;
justify-content: center;
padding: 2rem;
position: relative;
overflow: hidden;
}
.background-decorations {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
pointer-events: none;
z-index: 0;
}
.blob {
position: absolute;
border-radius: 50%;
filter: blur(80px);
opacity: 0.15;
transition: all 1s ease-in-out;
}
.blob-1 {
width: 400px;
height: 400px;
background: var(--color-primary);
top: -10%;
right: 10%;
}
.blob-2 {
width: 500px;
height: 500px;
background: var(--color-secondary);
bottom: -10%;
left: -5%;
}
.main-card {
position: relative;
z-index: 1;
width: 100%;
max-width: 480px;
background: var(--bg-card);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
border: 1px solid var(--border-card);
border-radius: 24px;
padding: 3rem 2.5rem 2rem;
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
text-align: center;
}
.card-header {
margin-bottom: 2.5rem;
}
.logo-wrapper {
display: inline-flex;
align-items: center;
justify-content: center;
width: 64px;
height: 64px;
border-radius: 16px;
background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
margin-bottom: 1.5rem;
box-shadow: 0 8px 16px var(--color-primary-glow);
}
.logo-icon {
width: 32px;
height: 32px;
color: white;
}
h1 {
font-size: 2rem;
font-weight: 700;
margin: 0 0 0.5rem;
letter-spacing: -0.5px;
background: linear-gradient(to right, #ffffff, #d1d5db);
-webkit-background-clip: text;
background-clip: text;
-webkit-text-fill-color: transparent;
}
.subtitle {
color: var(--color-text-muted);
font-size: 0.95rem;
margin: 0;
line-height: 1.5;
}
.auth-state {
display: flex;
flex-direction: column;
align-items: center;
}
.shield-icon {
width: 80px;
height: 80px;
border-radius: 50%;
background: rgba(255, 255, 255, 0.03);
border: 1px solid rgba(255, 255, 255, 0.05);
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 1.5rem;
color: var(--color-primary);
}
.shield-icon svg {
width: 36px;
height: 36px;
}
.auth-state h2 {
font-size: 1.25rem;
font-weight: 600;
margin: 0 0 0.75rem;
}
.auth-state p {
color: var(--color-text-muted);
font-size: 0.9rem;
line-height: 1.6;
margin: 0 0 2rem;
}
.btn {
font-family: inherit;
font-weight: 600;
font-size: 0.95rem;
padding: 0.85rem 1.75rem;
border-radius: 12px;
border: none;
cursor: pointer;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
width: 100%;
}
.btn-primary {
background: var(--color-primary);
color: white;
}
.btn-glow {
box-shadow: 0 4px 20px var(--color-primary-glow);
}
.btn-glow:hover {
background-color: #4f46e5;
transform: translateY(-2px);
box-shadow: 0 8px 25px rgba(99, 102, 241, 0.5);
}
.btn-arrow {
width: 16px;
height: 16px;
transition: transform 0.2s ease;
}
.btn-glow:hover .btn-arrow {
transform: translateX(4px);
}
.user-profile {
display: flex;
align-items: center;
gap: 1rem;
background: rgba(255, 255, 255, 0.02);
border: 1px solid rgba(255, 255, 255, 0.05);
padding: 1.25rem;
border-radius: 16px;
width: 100%;
text-align: left;
margin-bottom: 2rem;
}
.avatar {
width: 48px;
height: 48px;
border-radius: 50%;
background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
color: white;
font-weight: 700;
font-size: 1.25rem;
display: flex;
align-items: center;
justify-content: center;
}
.user-details {
display: flex;
flex-direction: column;
gap: 0.25rem;
}
.user-details h3 {
font-size: 1.05rem;
font-weight: 600;
margin: 0;
}
.user-email {
color: var(--color-text-muted);
font-size: 0.8rem;
margin: 0;
}
.badge {
font-size: 0.75rem;
font-weight: 600;
padding: 0.2rem 0.6rem;
border-radius: 20px;
align-self: flex-start;
}
.badge-success {
background: rgba(16, 185, 129, 0.1);
color: var(--color-success);
border: 1px solid rgba(16, 185, 129, 0.2);
}
.api-demo-section {
background: rgba(255, 255, 255, 0.02);
border: 1px solid rgba(255, 255, 255, 0.05);
border-radius: 16px;
padding: 1.5rem;
width: 100%;
margin-bottom: 2rem;
text-align: left;
}
.api-demo-section h4 {
font-size: 1rem;
font-weight: 600;
margin: 0 0 0.5rem;
}
.api-demo-section p {
font-size: 0.8rem;
color: var(--color-text-muted);
line-height: 1.5;
margin: 0 0 1.25rem;
}
.btn-secondary {
background: rgba(255, 255, 255, 0.05);
border: 1px solid rgba(255, 255, 255, 0.1);
color: var(--color-text);
}
.btn-secondary:hover {
background: rgba(255, 255, 255, 0.1);
transform: translateY(-1px);
}
.api-response-wrapper {
margin-top: 1.25rem;
background: rgba(0, 0, 0, 0.2);
border-radius: 10px;
padding: 1rem;
border: 1px solid rgba(255, 255, 255, 0.03);
}
.response-label {
display: block;
font-size: 0.75rem;
color: var(--color-text-muted);
margin-bottom: 0.5rem;
}
.api-response-code {
font-family: monospace;
font-size: 0.85rem;
color: var(--color-success);
word-break: break-all;
}
.btn-outline {
background: transparent;
border: 1px solid rgba(255, 255, 255, 0.1);
color: var(--color-text-muted);
}
.btn-outline:hover {
border-color: rgba(255, 255, 255, 0.3);
color: var(--color-text);
transform: translateY(-1px);
}
.card-footer {
margin-top: 2.5rem;
border-top: 1px solid rgba(255, 255, 255, 0.05);
padding-top: 1.5rem;
}
.card-footer p {
color: rgba(255, 255, 255, 0.25);
font-size: 0.75rem;
margin: 0;
}
+79
View File
@@ -0,0 +1,79 @@
<div class="app-container">
<div class="background-decorations">
<div class="blob blob-1"></div>
<div class="blob blob-2"></div>
</div>
<main class="main-card">
<header class="card-header">
<div class="logo-wrapper">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="logo-icon">
<path d="m3 9 9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/>
<polyline points="9 22 9 12 15 12 15 22"/>
</svg>
</div>
<h1>LMNP Organizer</h1>
<p class="subtitle">Votre assistant de gestion et fiscalité immobilière</p>
</header>
<section class="card-body">
@if (!isLoggedIn) {
<div class="auth-state locked">
<div class="shield-icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<rect width="18" height="11" x="3" y="11" rx="2" ry="2"/>
<path d="M7 11V7a5 5 0 0 1 10 0v4"/>
</svg>
</div>
<h2>Connexion Sécurisée Requise</h2>
<p>Connectez-vous avec Keycloak / voidAuth pour accéder à votre espace de gestion locative.</p>
<button (click)="login()" class="btn btn-primary btn-glow">
<span>Se connecter avec OIDC</span>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="btn-arrow">
<path d="M5 12h14"/>
<path d="m12 5 7 7-7 7"/>
</svg>
</button>
</div>
} @else {
<div class="auth-state unlocked">
<div class="user-profile">
<div class="avatar">
{{ username.charAt(0).toUpperCase() }}
</div>
<div class="user-details">
<h3>{{ username }}</h3>
<p class="user-email">{{ email }}</p>
<span class="badge badge-success">Connecté</span>
</div>
</div>
<div class="api-demo-section">
<h4>Vérification API Sécurisée</h4>
<p>Testez la transmission et la validation du jeton JWT auprès du backend Java 25.</p>
<div class="api-actions">
<button (click)="callHelloApi()" class="btn btn-secondary">
Appeler /api/hello
</button>
</div>
@if (helloMessage()) {
<div class="api-response-wrapper">
<span class="response-label">Réponse du backend :</span>
<code class="api-response-code">{{ helloMessage() }}</code>
</div>
}
</div>
<button (click)="logout()" class="btn btn-outline">
Se déconnecter
</button>
</div>
}
</section>
<footer class="card-footer">
<p>LMNP Organizer &copy; 2026. Sécurisé avec OpenID Connect et Spring Boot 4.</p>
</footer>
</main>
</div>
+3
View File
@@ -0,0 +1,3 @@
import { Routes } from '@angular/router';
export const routes: Routes = [];
+153
View File
@@ -0,0 +1,153 @@
import { TestBed } from '@angular/core/testing';
import { App } from './app';
import { OAuthService } from 'angular-oauth2-oidc';
import { HttpClient } from '@angular/common/http';
import { of, throwError } from 'rxjs';
import { vi } from 'vitest';
describe('App', () => {
let mockOAuthService: any;
let mockHttpClient: any;
beforeEach(async () => {
mockOAuthService = {
hasValidAccessToken: () => false,
getIdentityClaims: () => null,
getAccessToken: () => 'mock-token',
initCodeFlow: () => {},
logOut: () => {}
};
mockHttpClient = {
get: () => of('Hello from mocked API!')
};
await TestBed.configureTestingModule({
imports: [App],
providers: [
{ provide: OAuthService, useValue: mockOAuthService },
{ provide: HttpClient, useValue: mockHttpClient }
]
}).compileComponents();
});
it('should create the app', () => {
const fixture = TestBed.createComponent(App);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});
it('should render title', async () => {
const fixture = TestBed.createComponent(App);
await fixture.whenStable();
const compiled = fixture.nativeElement as HTMLElement;
expect(compiled.querySelector('h1')?.textContent).toContain('LMNP Organizer');
});
it('should return login status based on OAuthService', () => {
const fixture = TestBed.createComponent(App);
const app = fixture.componentInstance;
mockOAuthService.hasValidAccessToken = () => true;
expect(app.isLoggedIn).toBe(true);
mockOAuthService.hasValidAccessToken = () => false;
expect(app.isLoggedIn).toBe(false);
});
it('should return username and email from identity claims', () => {
const fixture = TestBed.createComponent(App);
const app = fixture.componentInstance;
// Default username when no claims
expect(app.username).toBe('');
// Custom claims
mockOAuthService.getIdentityClaims = () => ({
preferred_username: 'Alice',
email: 'alice@example.com'
});
expect(app.username).toBe('Alice');
expect(app.email).toBe('alice@example.com');
});
it('should invoke OIDC login and logout flows', () => {
const fixture = TestBed.createComponent(App);
const app = fixture.componentInstance;
const loginSpy = vi.spyOn(mockOAuthService, 'initCodeFlow');
const logoutSpy = vi.spyOn(mockOAuthService, 'logOut');
app.login();
expect(loginSpy).toHaveBeenCalled();
app.logout();
expect(logoutSpy).toHaveBeenCalled();
});
it('should call hello API and set message on success', () => {
const fixture = TestBed.createComponent(App);
const app = fixture.componentInstance;
app.callHelloApi();
expect(app.helloMessage()).toBe('Hello from mocked API!');
});
it('should call hello API and handle error', () => {
const fixture = TestBed.createComponent(App);
const app = fixture.componentInstance;
mockHttpClient.get = () => throwError(() => ({ statusText: 'Unauthorized' }));
app.callHelloApi();
expect(app.helloMessage()).toBe('Failed to connect to backend: Unauthorized');
});
it('should render logged in state when user is authenticated', async () => {
const fixture = TestBed.createComponent(App);
const app = fixture.componentInstance;
// Log in
mockOAuthService.hasValidAccessToken = () => true;
mockOAuthService.getIdentityClaims = () => ({
preferred_username: 'Alice',
email: 'alice@example.com'
});
fixture.detectChanges();
await fixture.whenStable();
const compiled = fixture.nativeElement as HTMLElement;
expect(compiled.querySelector('.user-details h3')?.textContent).toContain('Alice');
expect(compiled.querySelector('.user-email')?.textContent).toContain('alice@example.com');
});
it('should render hello API response when API button is clicked', async () => {
const fixture = TestBed.createComponent(App);
const app = fixture.componentInstance;
// Log in
mockOAuthService.hasValidAccessToken = () => true;
mockOAuthService.getIdentityClaims = () => ({
preferred_username: 'Alice',
email: 'alice@example.com'
});
fixture.detectChanges();
await fixture.whenStable();
// Click button
const compiled = fixture.nativeElement as HTMLElement;
const button = compiled.querySelector('.api-actions button') as HTMLButtonElement;
button.click();
fixture.detectChanges();
await fixture.whenStable();
// Verify response message is shown
expect(app.helloMessage()).toBe('Hello from mocked API!');
fixture.detectChanges();
expect(compiled.querySelector('.api-response-code')?.textContent).toContain('Hello from mocked API!');
});
});
+53
View File
@@ -0,0 +1,53 @@
import { Component, signal } from '@angular/core';
import { OAuthService } from 'angular-oauth2-oidc';
import { HttpClient, HttpHeaders } from '@angular/common/http';
@Component({
selector: 'app-root',
imports: [],
templateUrl: './app.html',
styleUrl: './app.css'
})
export class App {
protected readonly title = signal('LMNP Organizer');
readonly helloMessage = signal<string>('');
constructor(private oauthService: OAuthService, private http: HttpClient) {}
get isLoggedIn(): boolean {
return this.oauthService.hasValidAccessToken();
}
get username(): string {
const claims: any = this.oauthService.getIdentityClaims();
if (!claims) return '';
return claims.preferred_username || claims.given_name || claims.name || 'User';
}
get email(): string {
const claims: any = this.oauthService.getIdentityClaims();
return claims?.email || '';
}
login() {
this.oauthService.initCodeFlow();
}
logout() {
this.oauthService.logOut();
}
callHelloApi() {
const headers = new HttpHeaders({
'Authorization': 'Bearer ' + this.oauthService.getAccessToken()
});
this.http.get('/api/hello', { headers, responseType: 'text' }).subscribe({
next: (msg) => this.helloMessage.set(msg),
error: (err) => {
console.error(err);
this.helloMessage.set('Failed to connect to backend: ' + err.statusText);
}
});
}
}
+32
View File
@@ -0,0 +1,32 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { lastValueFrom } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class ConfigService {
private config: any = null;
constructor(private http: HttpClient) {}
async loadConfig(): Promise<void> {
try {
this.config = await lastValueFrom(this.http.get('/config.json'));
} catch (e) {
console.warn('Could not load /config.json, using default dev values', e);
this.config = {
oidcIssuer: 'http://localhost:8090/realms/voidAuth',
clientId: 'lmnp-client'
};
}
}
get oidcIssuer(): string {
return this.config?.oidcIssuer || 'http://localhost:8090/realms/voidAuth';
}
get clientId(): string {
return this.config?.clientId || 'lmnp-client';
}
}
+13
View File
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>LmnpFrontend</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
</body>
</html>
+6
View File
@@ -0,0 +1,6 @@
import { bootstrapApplication } from '@angular/platform-browser';
import { appConfig } from './app/app.config';
import { App } from './app/app';
bootstrapApplication(App, appConfig)
.catch((err) => console.error(err));
+1
View File
@@ -0,0 +1 @@
/* You can add global styles to this file, and also import other style files */