From 0d495e125ad2b6511f2c59f3917c0731aa69d9b5 Mon Sep 17 00:00:00 2001 From: migudel <miguel.moras@estudiantes.uva.es> Date: Fri, 29 Nov 2024 22:54:59 +0100 Subject: [PATCH] =?UTF-8?q?Adaptaci=C3=B3n=20del=20header=20a=20sesiones?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- angular/RestClient/angular.json | 7 +- .../RestClient/environments/environment.ts | 8 +- angular/RestClient/package-lock.json | 28 ++-- angular/RestClient/package.json | 1 + angular/RestClient/src/app/app.config.ts | 11 +- angular/RestClient/src/app/app.routes.ts | 103 ++++++++++++--- .../src/app/auth/auth.interceptor.ts | 32 +++++ .../booking-list/booking-list.component.ts | 2 +- .../bookings/booking/booking.component.ts | 2 +- .../hotel/hotel-list/hotel-list.component.ts | 2 +- .../hotel-register.component.ts | 2 +- .../user/main-page/main-page.component.ts | 2 +- .../user-booking-list.component.ts | 2 +- .../core/navigation/navigation.component.css | 14 +- .../core/navigation/navigation.component.html | 106 +++++++-------- .../core/navigation/navigation.component.ts | 125 +++++++++++++++--- .../src/app/shared/booking-client.service.ts | 2 +- .../src/app/shared/hotel-client.service.ts | 2 +- .../src/app/shared/local-storage.service.ts | 21 +-- .../src/app/shared/session.service.spec.ts | 16 +++ .../src/app/shared/session.service.ts | 58 ++++++++ .../src/app/shared/user-client.service.ts | 2 +- .../src/{ => app}/types/Address.d.ts | 0 .../src/{ => app}/types/Booking.d.ts | 0 .../RestClient/src/{ => app}/types/Hotel.d.ts | 0 .../RestClient/src/{ => app}/types/Room.d.ts | 0 .../RestClient/src/{ => app}/types/User.d.ts | 0 .../RestClient/src/{ => app}/types/index.ts | 0 angular/RestClient/src/mocks/users.ts | 2 +- .../uva/monolith/config/SecurityConfig.java | 3 + .../filter/JwtAuthenticationFilter.java | 13 +- .../services/users/models/AuthResponse.java | 51 +++++++ .../services/users/services/UserService.java | 10 +- java/services/auth/pom.xml | 10 +- .../com/uva/authentication/api/UserAPI.java | 4 +- .../authentication/config/SecurityConfig.java | 17 --- .../controllers/AuthController.java | 6 +- .../authentication/models/AuthResponse.java | 51 ++++++- .../models/JwtAuthResponse.java | 14 ++ .../models/RegisterRequest.java | 2 + .../models/{ => remote}/Client.java | 10 +- .../models/{ => remote}/HotelManager.java | 9 +- .../models/{ => remote}/User.java | 2 +- .../models/{ => remote}/UserRol.java | 2 +- .../models/{ => remote}/UserStatus.java | 2 +- .../repositories/ClientRepository.java | 4 +- .../repositories/HotelManagerRepository.java | 4 +- .../repositories/UserRepository.java | 3 +- .../authentication/services/AuthService.java | 8 +- .../com/uva/authentication/utils/JwtUtil.java | 2 +- 50 files changed, 568 insertions(+), 209 deletions(-) create mode 100644 angular/RestClient/src/app/auth/auth.interceptor.ts create mode 100644 angular/RestClient/src/app/shared/session.service.spec.ts create mode 100644 angular/RestClient/src/app/shared/session.service.ts rename angular/RestClient/src/{ => app}/types/Address.d.ts (100%) rename angular/RestClient/src/{ => app}/types/Booking.d.ts (100%) rename angular/RestClient/src/{ => app}/types/Hotel.d.ts (100%) rename angular/RestClient/src/{ => app}/types/Room.d.ts (100%) rename angular/RestClient/src/{ => app}/types/User.d.ts (100%) rename angular/RestClient/src/{ => app}/types/index.ts (100%) create mode 100644 java/roomBooking/src/main/java/com/uva/monolith/services/users/models/AuthResponse.java delete mode 100644 java/services/auth/src/main/java/com/uva/authentication/config/SecurityConfig.java create mode 100644 java/services/auth/src/main/java/com/uva/authentication/models/JwtAuthResponse.java rename java/services/auth/src/main/java/com/uva/authentication/models/{ => remote}/Client.java (82%) rename java/services/auth/src/main/java/com/uva/authentication/models/{ => remote}/HotelManager.java (75%) rename java/services/auth/src/main/java/com/uva/authentication/models/{ => remote}/User.java (97%) rename java/services/auth/src/main/java/com/uva/authentication/models/{ => remote}/UserRol.java (54%) rename java/services/auth/src/main/java/com/uva/authentication/models/{ => remote}/UserStatus.java (65%) diff --git a/angular/RestClient/angular.json b/angular/RestClient/angular.json index 2fe5dbb..3276066 100644 --- a/angular/RestClient/angular.json +++ b/angular/RestClient/angular.json @@ -32,12 +32,7 @@ "scripts": [ "node_modules/jquery/dist/jquery.min.js", "node_modules/bootstrap/dist/js/bootstrap.min.js" - ], - "server": "src/main.server.ts", - "prerender": true, - "ssr": { - "entry": "server.ts" - } + ] }, "configurations": { "production": { diff --git a/angular/RestClient/environments/environment.ts b/angular/RestClient/environments/environment.ts index a58d68b..d82bc7f 100644 --- a/angular/RestClient/environments/environment.ts +++ b/angular/RestClient/environments/environment.ts @@ -1,9 +1,9 @@ -const monolithUrl = 'http://localhost:8080'; +const monolithUrl = 'localhost:8080'; export const environment = { production: true, authAPI: 'http://localhost:8101', - userAPI: `http://${monolithUrl}`, - hotelAPI: `http://${monolithUrl}`, - bookingAPI: `http://${monolithUrl}`, + userAPI: `http://${monolithUrl}/users`, + hotelAPI: `http://${monolithUrl}/hotels`, + bookingAPI: `http://${monolithUrl}/bookings`, }; diff --git a/angular/RestClient/package-lock.json b/angular/RestClient/package-lock.json index a5d201b..af24106 100644 --- a/angular/RestClient/package-lock.json +++ b/angular/RestClient/package-lock.json @@ -25,6 +25,7 @@ "bootstrap": "^3.4.0", "express": "^4.18.2", "jquery": "^3.4.1", + "jwt-decode": "^4.0.0", "rxjs": "~7.8.0", "tslib": "^2.3.0", "zone.js": "~0.14.10" @@ -5468,9 +5469,9 @@ "license": "ISC" }, "node_modules/bootstrap": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-3.4.0.tgz", - "integrity": "sha512-F1yTDO9OHKH0xjl03DsOe8Nu1OWBIeAugGMhy3UTIYDdbbIPesQIhCEbj+HEr6wqlwweGAlP8F3OBC6kEuhFuw==", + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-3.4.1.tgz", + "integrity": "sha512-yN5oZVmRCwe5aKwzRj6736nSmKDX7pLYwsXiCj/EYmo16hODaBiT4En5btW/jhBF/seV+XMx3aYwukYC3A49DA==", "license": "MIT", "engines": { "node": ">=6" @@ -6329,9 +6330,9 @@ } }, "node_modules/cross-spawn": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", - "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", "dev": true, "license": "MIT", "dependencies": { @@ -8555,9 +8556,9 @@ } }, "node_modules/jquery": { - "version": "3.4.1", - "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.4.1.tgz", - "integrity": "sha512-36+AdBzCL+y6qjw5Tx7HgzeGCzC81MDDgaUP8ld2zhx58HdqXGoBd+tHdrBMiyjGQs0Hxs/MLZTu/eHNJJuWPw==", + "version": "3.7.1", + "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.7.1.tgz", + "integrity": "sha512-m4avr8yL8kmFN8psrbFFFmB/If14iN5o9nw/NgnnM+kybDJpRsAynV2BsfpTYrTRysYUdADVD7CkUUizgkpLfg==", "license": "MIT" }, "node_modules/js-tokens": { @@ -8654,6 +8655,15 @@ ], "license": "MIT" }, + "node_modules/jwt-decode": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-4.0.0.tgz", + "integrity": "sha512-+KJGIyHgkGuIq3IEBNftfhW/LfWhXUIY6OmyVWjliu5KH1y0fw7VQ8YndE2O4qZdMSd9SqbnC8GOcZEy0Om7sA==", + "license": "MIT", + "engines": { + "node": ">=18" + } + }, "node_modules/karma": { "version": "6.4.4", "resolved": "https://registry.npmjs.org/karma/-/karma-6.4.4.tgz", diff --git a/angular/RestClient/package.json b/angular/RestClient/package.json index 262eacd..a17778b 100644 --- a/angular/RestClient/package.json +++ b/angular/RestClient/package.json @@ -28,6 +28,7 @@ "bootstrap": "^3.4.0", "express": "^4.18.2", "jquery": "^3.4.1", + "jwt-decode": "^4.0.0", "rxjs": "~7.8.0", "tslib": "^2.3.0", "zone.js": "~0.14.10" diff --git a/angular/RestClient/src/app/app.config.ts b/angular/RestClient/src/app/app.config.ts index 1f668ea..a7435ca 100644 --- a/angular/RestClient/src/app/app.config.ts +++ b/angular/RestClient/src/app/app.config.ts @@ -1,19 +1,22 @@ import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core'; import { provideRouter } from '@angular/router'; import { routes } from './app.routes'; -import { provideHttpClient, withFetch } from '@angular/common/http'; +import { + provideHttpClient, + withFetch, + withInterceptors, +} from '@angular/common/http'; import { provideAnimationsAsync } from '@angular/platform-browser/animations/async'; import { ReactiveFormsModule } from '@angular/forms'; // Added import for ReactiveFormsModule import { provideNativeDateAdapter } from '@angular/material/core'; -import { provideClientHydration } from '@angular/platform-browser'; +import { authRequest } from './auth/auth.interceptor'; export const appConfig: ApplicationConfig = { providers: [ provideNativeDateAdapter(), provideZoneChangeDetection({ eventCoalescing: true }), provideRouter(routes), - provideClientHydration(), - provideHttpClient(withFetch()), + provideHttpClient(withFetch(), withInterceptors([authRequest])), provideAnimationsAsync(), ReactiveFormsModule, ], diff --git a/angular/RestClient/src/app/app.routes.ts b/angular/RestClient/src/app/app.routes.ts index 51aacbb..5bb87ab 100644 --- a/angular/RestClient/src/app/app.routes.ts +++ b/angular/RestClient/src/app/app.routes.ts @@ -10,40 +10,109 @@ import { UserFormComponent } from './core/features/user/user-form/user-form.comp export const routes: Routes = [ { path: '', // Ruta principal - component: MainPageComponent, // Componente de la página principal + component: MainPageComponent, }, + // auth { - path: 'bookings/search', - component: BookingListComponent, + path: 'login', }, { - path: 'bookings/new', - component: BookingComponent, + path: 'register', }, + // Hoteles { - path: 'users/:id/bookings', - component: UserBookingListComponent, + path: 'hotels', // Ruta para la lista de hoteles }, { - path: 'hotels', - component: HotelListComponent, + path: 'hotels/register', // Registrar nuevo hotel }, { - path: 'hotels/new', - component: HotelRegisterComponent, + path: 'hotels/:id', // Hotel concreto }, { - path: 'hotels/:id', - component: HotelRegisterComponent, + path: 'hotels/:id/edit', // Modificar hotel }, + // Usuario { - path: 'users/:id', - component: UserFormComponent, + path: 'me', // Main }, { - path: 'register', - component: UserFormComponent, + path: 'me/edit', // Main + }, + // Usuario HOTEL admin + { + path: 'me/hotels', + }, + { + path: 'me/hotels/:id', + }, + { + path: 'me/hotels/:id/bookings', + }, + { + path: 'me/hotels/:id/rooms', + }, + { + path: 'me/hotels/:id/rooms/:id', + }, + { + path: 'me/hotels/:id/rooms/:id/bookings', }, + // Usuario Cliente + { + path: 'me/bookings', + }, + { + path: 'me/bookings/:id', + }, + { + path: 'me/bookings/new', + }, + // Administrador + { + path: 'admin', // Main + }, + { + path: 'admin/users', // Main + }, + { + path: 'admin/users/:id', // Main + }, + + // ! OTRO // NO MIRAR + + // { + // path: 'bookings/search', + // component: BookingListComponent, + // }, + // { + // path: 'bookings/new', + // component: BookingComponent, + // }, + // { + // path: 'users/:id/bookings', + // component: UserBookingListComponent, + // }, + // { + // path: 'hotels', + // component: HotelListComponent, + // }, + // { + // path: 'hotels/new', + // component: HotelRegisterComponent, + // }, + // { + // path: 'hotels/:id', + // component: HotelRegisterComponent, + // }, + // { + // path: 'users/:id', + // component: UserFormComponent, + // }, + // { + // path: 'register', + // component: UserFormComponent, + // }, { path: '**', redirectTo: '', diff --git a/angular/RestClient/src/app/auth/auth.interceptor.ts b/angular/RestClient/src/app/auth/auth.interceptor.ts new file mode 100644 index 0000000..63a139b --- /dev/null +++ b/angular/RestClient/src/app/auth/auth.interceptor.ts @@ -0,0 +1,32 @@ +import { HttpInterceptorFn } from '@angular/common/http'; +import { inject } from '@angular/core'; +import { LocalStorageService } from '../shared/local-storage.service'; + +const excluded = ['/login', '/register']; + +function isExcludedUrl(url: string) { + return excluded.some((excluded) => url.includes(excluded)); +} + +export const authRequest: HttpInterceptorFn = (req, next) => { + // Obtener el token desde localStorage (o cualquier otro mecanismo) + const storage = inject(LocalStorageService); // Obtener instancia del servicio + const token = storage.read<{ token: string }>('token'); + + if (isExcludedUrl(req.url) || !token) { + return next(req); // No modificar la solicitud + } + + // Clonar la solicitud y agregar el token al encabezado si existe + const authReq = token + ? req.clone({ + setHeaders: { + Authorization: `Bearer ${token.token}`, + 'Content-Type': 'application/json', + }, + }) + : req; + + // Pasar la solicitud modificada al siguiente manejador + return next(authReq); +}; diff --git a/angular/RestClient/src/app/core/features/bookings/booking-list/booking-list.component.ts b/angular/RestClient/src/app/core/features/bookings/booking-list/booking-list.component.ts index 5789a06..6fb9079 100644 --- a/angular/RestClient/src/app/core/features/bookings/booking-list/booking-list.component.ts +++ b/angular/RestClient/src/app/core/features/bookings/booking-list/booking-list.component.ts @@ -7,7 +7,7 @@ import { import { FormsModule } from '@angular/forms'; import { MatInputModule } from '@angular/material/input'; import { MatSelectModule } from '@angular/material/select'; -import { Hotel, Room, RoomType, roomTypeArray } from '../../../../../types'; +import { Hotel, Room, RoomType, roomTypeArray } from '../../../../types'; import { Router } from '@angular/router'; import { MatCardModule } from '@angular/material/card'; import { MatChipsModule } from '@angular/material/chips'; diff --git a/angular/RestClient/src/app/core/features/bookings/booking/booking.component.ts b/angular/RestClient/src/app/core/features/bookings/booking/booking.component.ts index 9b99737..6ad8c37 100644 --- a/angular/RestClient/src/app/core/features/bookings/booking/booking.component.ts +++ b/angular/RestClient/src/app/core/features/bookings/booking/booking.component.ts @@ -7,7 +7,7 @@ import { } from '@angular/forms'; import { ActivatedRoute, Router } from '@angular/router'; -import { Booking, User } from '../../../../../types'; +import { Booking, User } from '../../../../types'; import { LocalStorageService } from '../../../../shared/local-storage.service'; import { BookingClientService } from '../../../../shared/booking-client.service'; import { UserClientService } from '../../../../shared/user-client.service'; diff --git a/angular/RestClient/src/app/core/features/hotel/hotel-list/hotel-list.component.ts b/angular/RestClient/src/app/core/features/hotel/hotel-list/hotel-list.component.ts index 1bcaf64..d951865 100644 --- a/angular/RestClient/src/app/core/features/hotel/hotel-list/hotel-list.component.ts +++ b/angular/RestClient/src/app/core/features/hotel/hotel-list/hotel-list.component.ts @@ -1,6 +1,6 @@ import { Component } from '@angular/core'; import { RouterModule, Router } from '@angular/router'; -import { Hotel } from '../../../../../types'; +import { Hotel } from '../../../../types'; import { MatAccordion, MatExpansionPanel, diff --git a/angular/RestClient/src/app/core/features/hotel/hotel-register/hotel-register.component.ts b/angular/RestClient/src/app/core/features/hotel/hotel-register/hotel-register.component.ts index fad7415..9e2c2d4 100644 --- a/angular/RestClient/src/app/core/features/hotel/hotel-register/hotel-register.component.ts +++ b/angular/RestClient/src/app/core/features/hotel/hotel-register/hotel-register.component.ts @@ -13,7 +13,7 @@ import { MatFormFieldModule } from '@angular/material/form-field'; import { MatSelectModule } from '@angular/material/select'; import { MatSlideToggleModule } from '@angular/material/slide-toggle'; import { CommonModule } from '@angular/common'; -import { Address, Hotel, Room } from '../../../../../types'; +import { Address, Hotel, Room } from '../../../../types'; import { ActivatedRoute, Router } from '@angular/router'; import { HotelClientService } from '../../../../shared/hotel-client.service'; diff --git a/angular/RestClient/src/app/core/features/user/main-page/main-page.component.ts b/angular/RestClient/src/app/core/features/user/main-page/main-page.component.ts index c3506bb..14b5a9d 100644 --- a/angular/RestClient/src/app/core/features/user/main-page/main-page.component.ts +++ b/angular/RestClient/src/app/core/features/user/main-page/main-page.component.ts @@ -1,5 +1,5 @@ import { Component, OnInit } from '@angular/core'; -import { Client, User, UserStateFilter } from '../../../../../types'; +import { Client, User, UserStateFilter } from '../../../../types'; import { FormsModule } from '@angular/forms'; import { CommonModule } from '@angular/common'; import { RouterModule } from '@angular/router'; diff --git a/angular/RestClient/src/app/core/features/user/user-booking-list/user-booking-list.component.ts b/angular/RestClient/src/app/core/features/user/user-booking-list/user-booking-list.component.ts index 677a18d..878e644 100644 --- a/angular/RestClient/src/app/core/features/user/user-booking-list/user-booking-list.component.ts +++ b/angular/RestClient/src/app/core/features/user/user-booking-list/user-booking-list.component.ts @@ -1,6 +1,6 @@ import { Component } from '@angular/core'; -import { Booking, User } from '../../../../../types'; +import { Booking, User } from '../../../../types'; import { ActivatedRoute, RouterModule } from '@angular/router'; import { CommonModule } from '@angular/common'; import { FormsModule } from '@angular/forms'; diff --git a/angular/RestClient/src/app/core/navigation/navigation.component.css b/angular/RestClient/src/app/core/navigation/navigation.component.css index 200c21a..e3b01c1 100644 --- a/angular/RestClient/src/app/core/navigation/navigation.component.css +++ b/angular/RestClient/src/app/core/navigation/navigation.component.css @@ -4,7 +4,7 @@ nav { padding: 1em; } -ul { +ul.nav { list-style: none; padding: 0; display: flex; @@ -14,15 +14,15 @@ li { margin-right: 20px; } -a, -a:visited { +a.nav-link, +a.nav-link:visited { color: white; text-decoration: none; transform: scale(1); transition: transform 0.3s ease; } -a:hover { +a.nav-link:hover { font-weight: bold; text-decoration: underline; color: yellow; @@ -34,6 +34,12 @@ a:hover { font-weight: bold; } +a.simple, +a.simple:visited { + color: white; + text-decoration: none; +} + @keyframes escalar { 0% { transform: scale(1); diff --git a/angular/RestClient/src/app/core/navigation/navigation.component.html b/angular/RestClient/src/app/core/navigation/navigation.component.html index 6ba3f13..94a99ba 100644 --- a/angular/RestClient/src/app/core/navigation/navigation.component.html +++ b/angular/RestClient/src/app/core/navigation/navigation.component.html @@ -1,69 +1,71 @@ <nav> - <ul> - <li><a class="btn" [routerLink]="['/']">Home - Usuarios</a></li> + <ul class="nav"> + <li><a class="btn nav-link" [routerLink]="['/']">Home - Usuarios</a></li> <li> - <a class="btn" [routerLink]="['/hotels', 'new']">Registrar Hotel</a> + <a class="btn nav-link" [routerLink]="['/hotels', 'new']" + >Registrar Hotel</a + > </li> - <li><a class="btn" [routerLink]="['/hotels']">Hoteles</a></li> + <li><a class="btn nav-link" [routerLink]="['/hotels']">Hoteles</a></li> <li> - <a class="btn" [routerLink]="['/bookings', 'search']">Nueva Reserva</a> + <a class="btn nav-link" [routerLink]="['/bookings', 'search']" + >Nueva Reserva</a + > </li> - <li class="ml-auto"> + <!-- Solucionar que no va --> + <!-- <li class="ml-auto"> --> + <li style="margin-left: auto"> @if (isLogged){ <!-- Dropdown para usuario registrado --> - <div class="relative ml-6"> + + <div class="btn bg-blue-500 text-white rounded hover:bg-blue-600"> + <!-- mat-icon-button --> <button - (click)="toggleDropdown()" - class="flex items-center space-x-2 p-2 bg-blue-500 text-white rounded hover:bg-blue-600 focus:outline-none" + [matMenuTriggerFor]="sessionOptions" + class="flex items-center gap-3" > - <span>{{ userName }}</span> - <svg - xmlns="http://www.w3.org/2000/svg" - class="h-5 w-5" - viewBox="0 0 20 20" - fill="currentColor" - > - <path - fill-rule="evenodd" - d="M5.23 7.21a.75.75 0 011.06.02L10 10.94l3.71-3.71a.75.75 0 111.06 1.06l-4 4a.75.75 0 01-1.06 0l-4-4a.75.75 0 01.02-1.06z" - clip-rule="evenodd" - /> - </svg> - </button> + <span class="text-4xl">{{ user.name }}</span> - <!-- Menú desplegable --> - @if (dropdownOpen) { - <div - class="absolute right-0 mt-2 w-48 bg-slate-700 border border-gray-500 rounded shadow-lg" - > - <ul> - <li> - <a - class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" - [routerLink]="['/bookings']" - > - Mis Reservas - </a> - </li> - <li> - <a - class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" - > - <!-- (click)="logout()" --> - Cerrar Sesión - </a> - </li> - </ul> - </div> - } + @if (trigger?.menuOpen) { + <mat-icon class="text-4xl">arrow_drop_up</mat-icon> + }@else { + <mat-icon class="text-4xl">arrow_drop_down</mat-icon> + } + </button> </div> + <mat-menu #sessionOptions="matMenu" xPosition="before"> + @for (section of sections; track section.id) { @if (section.link) { + <a [routerLink]="section.link" class="simple"> + <button mat-menu-item> + <mat-icon>{{ section.icon }}</mat-icon> + <span class="text-2xl">{{ section.text }}</span> + </button> + </a> + } @else { + <button mat-menu-item> + <mat-icon>{{ section.icon }}</mat-icon> + <span class="text-2xl">{{ section.text }}</span> + </button> + } } + <button mat-menu-item (click)="logout()"> + <mat-icon>logout</mat-icon> + <span class="text-2xl">Cerrar sesión</span> + </button> + </mat-menu> } @else { - <a - class="btn bg-blue-500 text-white ml-6 hover:bg-blue-600" - [routerLink]="['/login']" - >Login</a + <div + class="btn bg-blue-500 text-white hover:bg-blue-600 ml-auto" + (click)="login()" > + <!-- <a class="simple" [routerLink]="['/login']"> --> + <a class="simple"> + <button class="flex items-center gap-3"> + <span class="text-4xl">Login</span> + <mat-icon>login</mat-icon> + </button> + </a> + </div> } </li> </ul> diff --git a/angular/RestClient/src/app/core/navigation/navigation.component.ts b/angular/RestClient/src/app/core/navigation/navigation.component.ts index 69efb6a..1e7a72d 100644 --- a/angular/RestClient/src/app/core/navigation/navigation.component.ts +++ b/angular/RestClient/src/app/core/navigation/navigation.component.ts @@ -1,31 +1,122 @@ -import { Component } from '@angular/core'; -import { Router, RouterModule } from '@angular/router'; +import { OnInit, Component, ViewChild } from '@angular/core'; +import { RouterModule } from '@angular/router'; +import { MatButtonModule } from '@angular/material/button'; +import { MatMenuModule, MatMenuTrigger } from '@angular/material/menu'; +import { MatIconModule } from '@angular/material/icon'; +import { User, UserRol } from '../../types'; +import { AuthInstance, SessionService } from '../../shared/session.service'; +import { UserClientService } from '../../shared/user-client.service'; import { AuthClientService } from '../../shared/auth-client.service'; + +var comp_id = 0; + +export function genId() { + const comp = 'navigation'; + return `${comp}-${comp_id++}`; +} + +interface Section { + id: string; + icon: string; + text: string; + link: string; + allowRoles?: UserRol[]; +} + @Component({ selector: 'app-navigation', standalone: true, - imports: [RouterModule], + imports: [RouterModule, MatButtonModule, MatMenuModule, MatIconModule], templateUrl: './navigation.component.html', styleUrl: './navigation.component.css', }) -export class NavigationComponent { - isLogged = true; - userName = 'User'; - dropdownOpen = false; +export class NavigationComponent implements OnInit { + @ViewChild(MatMenuTrigger) + trigger?: MatMenuTrigger; + isLogged = false; + user: AuthInstance = { + id: 0, + name: '', + email: '', + rol: 'CLIENT', + }; + sections: Section[] = []; + + constructor( + private sessionService: SessionService, + private auth: AuthClientService + ) {} + + ngOnInit() { + this.loadUser(); + } - constructor(private authClient: AuthClientService) {} + loadUser() { + const isLogged = this.sessionService.isValid(); + if (isLogged) { + this.user = this.sessionService.getSession(); + console.log({ user: this.user }); + this.sections = this.genSections(); + } + this.isLogged = isLogged; + } toggleDropdown() { - this.dropdownOpen = !this.dropdownOpen; - this.authClient.login('migudel@dev.com', 'NQSASorry').subscribe({ - next: (response) => { - console.log(response); - alert('OKEY! You are logged'); - }, - error: (error) => { - console.error(error); - alert('Error! You are not logged'); + if (this.trigger) { + if (this.trigger.menuOpen) this.trigger.closeMenu(); + else this.trigger.openMenu(); + } + } + + schemaSections: Section[] = [ + { + id: genId(), + icon: 'person', + text: 'Información personal', + link: '/me', + }, + { + id: genId(), + icon: 'calendar_today', + text: 'Reservas', + allowRoles: ['CLIENT'], + link: '/users/1/bookings', + // link: '/bookings', + }, + { + id: genId(), + icon: 'hotel', + text: 'Hoteles', + allowRoles: ['HOTEL_ADMIN'], + link: '/hotels', + }, + ]; + + genSections() { + return this.schemaSections.filter( + (section) => + this.user.rol === 'ADMIN' || // Es administrador del sistema + !section.allowRoles || + section.allowRoles.length === 0 || // No tiene limitación + section.allowRoles.includes(this.user.rol) // El rol del usuario es aceptado + ); + } + + login() { + const email = 'client@dev.com'; + this.auth.login(email, 'NQSASorry').subscribe({ + next: (data: any) => { + console.log(email, data); + this.sessionService.login(data); + this.loadUser(); }, }); } + + logout() { + if (confirm('You are trying to logout')) { + this.sessionService.logout(); + this.loadUser(); + } + } } diff --git a/angular/RestClient/src/app/shared/booking-client.service.ts b/angular/RestClient/src/app/shared/booking-client.service.ts index f05be5e..3e44163 100644 --- a/angular/RestClient/src/app/shared/booking-client.service.ts +++ b/angular/RestClient/src/app/shared/booking-client.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable } from 'rxjs'; import { environment } from '../../../environments/environment'; -import { Booking } from '../../types/Booking'; // Ajusta la ruta a tu modelo Booking +import { Booking } from '../types/Booking'; // Ajusta la ruta a tu modelo Booking @Injectable({ providedIn: 'root', diff --git a/angular/RestClient/src/app/shared/hotel-client.service.ts b/angular/RestClient/src/app/shared/hotel-client.service.ts index f38bb2a..87756a3 100644 --- a/angular/RestClient/src/app/shared/hotel-client.service.ts +++ b/angular/RestClient/src/app/shared/hotel-client.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { environment } from '../../../environments/environment'; import { HttpClient } from '@angular/common/http'; -import { Hotel, Room } from '../../types'; +import { Hotel, Room } from '../types'; @Injectable({ providedIn: 'root', diff --git a/angular/RestClient/src/app/shared/local-storage.service.ts b/angular/RestClient/src/app/shared/local-storage.service.ts index e1526f8..dc32865 100644 --- a/angular/RestClient/src/app/shared/local-storage.service.ts +++ b/angular/RestClient/src/app/shared/local-storage.service.ts @@ -1,32 +1,21 @@ -import { isPlatformBrowser } from '@angular/common'; -import { Inject, Injectable, PLATFORM_ID } from '@angular/core'; +import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) export class LocalStorageService { - // isBrowser: boolean; - - // constructor(@Inject(PLATFORM_ID) private platformId: Object) { - // this.isBrowser = isPlatformBrowser(this.platformId); - // } - - save(key: string, value: any) { - // if (!this.isBrowser) return; - localStorage.setItem(key, JSON.stringify(value)); + save(key: string, value: object) { + const content = JSON.stringify(value); + localStorage.setItem(key, content); } read<T>(key: string) { - // if (!this.isBrowser) return null; - const json = localStorage.getItem(key); const ret = json ? (JSON.parse(json) as T) : null; return ret; } consume<T>(key: string) { - // if (!this.isBrowser) return null; - const value = this.read<T>(key); if (value !== null) { this.remove(key); @@ -35,8 +24,6 @@ export class LocalStorageService { } remove(key: string) { - // if (!this.isBrowser) return; - localStorage.removeItem(key); } } diff --git a/angular/RestClient/src/app/shared/session.service.spec.ts b/angular/RestClient/src/app/shared/session.service.spec.ts new file mode 100644 index 0000000..4238e14 --- /dev/null +++ b/angular/RestClient/src/app/shared/session.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { SessionService } from './session.service'; + +describe('SessionService', () => { + let service: SessionService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(SessionService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/angular/RestClient/src/app/shared/session.service.ts b/angular/RestClient/src/app/shared/session.service.ts new file mode 100644 index 0000000..82e9daa --- /dev/null +++ b/angular/RestClient/src/app/shared/session.service.ts @@ -0,0 +1,58 @@ +import { Injectable } from '@angular/core'; +import { LocalStorageService } from './local-storage.service'; +import { UserRol } from '../types'; + +import { jwtDecode } from 'jwt-decode'; + +export interface AuthInstance { + id: number; + name: string; + email: string; + rol: UserRol; +} + +interface PersistenToken { + token: string; +} + +@Injectable({ + providedIn: 'root', +}) +export class SessionService { + constructor(private storage: LocalStorageService) {} + + private tokenKey = 'token'; + + login(session: PersistenToken) { + this.storage.save(this.tokenKey, session); + } + + logout() { + this.storage.remove(this.tokenKey); + } + + getToken() { + const savedToken = this.storage.read<PersistenToken>(this.tokenKey); + if (!savedToken) throw new Error('No session'); + return savedToken.token; + } + + getSession() { + const token = this.getToken(); + const r = jwtDecode<{ user: AuthInstance }>(token); + return r.user; + } + + isLogged() { + return !!this.storage.read<PersistenToken>(this.tokenKey); + } + + isValid() { + console.warn({ log: this.isLogged() }); + if (!this.isLogged()) return false; + const token = this.getToken(); + const r = jwtDecode(token); + // Validate if the token have been expired or not + return r.exp! > Math.floor(Date.now() / 1000); + } +} diff --git a/angular/RestClient/src/app/shared/user-client.service.ts b/angular/RestClient/src/app/shared/user-client.service.ts index 7383a72..2b2592e 100644 --- a/angular/RestClient/src/app/shared/user-client.service.ts +++ b/angular/RestClient/src/app/shared/user-client.service.ts @@ -1,7 +1,7 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { environment } from '../../../environments/environment'; -import { Client, User, UserState } from '../../types'; +import { Client, User, UserState } from '../types'; @Injectable({ providedIn: 'root', diff --git a/angular/RestClient/src/types/Address.d.ts b/angular/RestClient/src/app/types/Address.d.ts similarity index 100% rename from angular/RestClient/src/types/Address.d.ts rename to angular/RestClient/src/app/types/Address.d.ts diff --git a/angular/RestClient/src/types/Booking.d.ts b/angular/RestClient/src/app/types/Booking.d.ts similarity index 100% rename from angular/RestClient/src/types/Booking.d.ts rename to angular/RestClient/src/app/types/Booking.d.ts diff --git a/angular/RestClient/src/types/Hotel.d.ts b/angular/RestClient/src/app/types/Hotel.d.ts similarity index 100% rename from angular/RestClient/src/types/Hotel.d.ts rename to angular/RestClient/src/app/types/Hotel.d.ts diff --git a/angular/RestClient/src/types/Room.d.ts b/angular/RestClient/src/app/types/Room.d.ts similarity index 100% rename from angular/RestClient/src/types/Room.d.ts rename to angular/RestClient/src/app/types/Room.d.ts diff --git a/angular/RestClient/src/types/User.d.ts b/angular/RestClient/src/app/types/User.d.ts similarity index 100% rename from angular/RestClient/src/types/User.d.ts rename to angular/RestClient/src/app/types/User.d.ts diff --git a/angular/RestClient/src/types/index.ts b/angular/RestClient/src/app/types/index.ts similarity index 100% rename from angular/RestClient/src/types/index.ts rename to angular/RestClient/src/app/types/index.ts diff --git a/angular/RestClient/src/mocks/users.ts b/angular/RestClient/src/mocks/users.ts index ffdf8f2..f6fafe6 100644 --- a/angular/RestClient/src/mocks/users.ts +++ b/angular/RestClient/src/mocks/users.ts @@ -1,4 +1,4 @@ -import { Client, User } from '../types'; +import { Client, User } from '../app/types'; export const users: Client[] = [ { diff --git a/java/roomBooking/src/main/java/com/uva/monolith/config/SecurityConfig.java b/java/roomBooking/src/main/java/com/uva/monolith/config/SecurityConfig.java index 75a4664..5cc2695 100644 --- a/java/roomBooking/src/main/java/com/uva/monolith/config/SecurityConfig.java +++ b/java/roomBooking/src/main/java/com/uva/monolith/config/SecurityConfig.java @@ -2,6 +2,7 @@ package com.uva.monolith.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpMethod; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.web.SecurityFilterChain; @@ -24,6 +25,8 @@ public class SecurityConfig { public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { http.csrf(csrf -> csrf.disable()) .authorizeHttpRequests(authorize -> authorize + // Permitir OPTIONS sin autenticación + .requestMatchers(HttpMethod.OPTIONS, "/**").permitAll() // Acceso restringido a usuarios y administradores .requestMatchers("users", "users/**") .hasAnyRole(UserRol.ADMIN.toString(), UserRol.CLIENT.toString()) diff --git a/java/roomBooking/src/main/java/com/uva/monolith/filter/JwtAuthenticationFilter.java b/java/roomBooking/src/main/java/com/uva/monolith/filter/JwtAuthenticationFilter.java index 9a0b6f4..9b31d1a 100644 --- a/java/roomBooking/src/main/java/com/uva/monolith/filter/JwtAuthenticationFilter.java +++ b/java/roomBooking/src/main/java/com/uva/monolith/filter/JwtAuthenticationFilter.java @@ -25,6 +25,7 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.Filter; import java.io.IOException; import java.security.Key; +import java.time.LocalDateTime; import java.util.Collections; import java.util.Date; @@ -63,15 +64,15 @@ public class JwtAuthenticationFilter implements Filter { // Verifica que el token no esté expirado return claims.getExpiration().after(new Date()); } catch (ExpiredJwtException e) { - System.out.println("Token expirado: " + e.getMessage()); + System.out.println("[" + LocalDateTime.now().toString() + "] Token expirado: " + e.getMessage()); } catch (UnsupportedJwtException e) { - System.out.println("Token no soportado: " + e.getMessage()); + System.out.println("[" + LocalDateTime.now().toString() + "] Token no soportado: " + e.getMessage()); } catch (MalformedJwtException e) { - System.out.println("Token malformado: " + e.getMessage()); + System.out.println("[" + LocalDateTime.now().toString() + "] Token malformado: " + e.getMessage()); } catch (SignatureException e) { - System.out.println("Firma inválida: " + e.getMessage()); + System.out.println("[" + LocalDateTime.now().toString() + "] Firma inválida: " + e.getMessage()); } catch (IllegalArgumentException e) { - System.out.println("Token vacío o nulo: " + e.getMessage()); + System.out.println("[" + LocalDateTime.now().toString() + "] Token vacío o nulo: " + e.getMessage()); } return false; // Si ocurre cualquier excepción, el token es inválido @@ -96,6 +97,8 @@ public class JwtAuthenticationFilter implements Filter { HttpServletRequest httpRequest = (HttpServletRequest) request; String token = getTokenFromRequest(httpRequest); + System.out.println("[" + LocalDateTime.now().toString() + "] TOKEN " + token); + if (validateToken(token)) { String email = getEmailFromToken(token); diff --git a/java/roomBooking/src/main/java/com/uva/monolith/services/users/models/AuthResponse.java b/java/roomBooking/src/main/java/com/uva/monolith/services/users/models/AuthResponse.java new file mode 100644 index 0000000..8f33481 --- /dev/null +++ b/java/roomBooking/src/main/java/com/uva/monolith/services/users/models/AuthResponse.java @@ -0,0 +1,51 @@ +package com.uva.monolith.services.users.models; + +public class AuthResponse { + + private int id; + private String username; + private String email; + private String password; + private UserRol rol; + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public String getUsername() { + return this.username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getEmail() { + return this.email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPassword() { + return this.password; + } + + public void setPassword(String password) { + this.password = password; + } + + public UserRol getRol() { + return this.rol; + } + + public void setRol(UserRol rol) { + this.rol = rol; + } + +} diff --git a/java/roomBooking/src/main/java/com/uva/monolith/services/users/services/UserService.java b/java/roomBooking/src/main/java/com/uva/monolith/services/users/services/UserService.java index d25e835..193d736 100644 --- a/java/roomBooking/src/main/java/com/uva/monolith/services/users/services/UserService.java +++ b/java/roomBooking/src/main/java/com/uva/monolith/services/users/services/UserService.java @@ -4,11 +4,13 @@ import java.time.LocalDate; import java.util.List; import java.util.Optional; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.web.client.HttpClientErrorException; +import com.uva.monolith.services.users.models.AuthResponse; import com.uva.monolith.services.users.models.Client; import com.uva.monolith.services.users.models.User; import com.uva.monolith.services.users.models.UserStatus; @@ -36,8 +38,12 @@ public class UserService { return assertUser(userRepository.findById(id)); } - public User getUserByEmail(String email) { - return assertUser(userRepository.findByEmail(email)); + public AuthResponse getUserByEmail(String email) { + User u = assertUser(userRepository.findByEmail(email)); + AuthResponse auth = new AuthResponse(); + BeanUtils.copyProperties(u, auth); + auth.setUsername(u.getName()); + return auth; } public User addUser(User user) { diff --git a/java/services/auth/pom.xml b/java/services/auth/pom.xml index ab9de31..19b9923 100644 --- a/java/services/auth/pom.xml +++ b/java/services/auth/pom.xml @@ -49,10 +49,12 @@ <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-security</artifactId> - </dependency> + <!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-core --> + <dependency> + <groupId>org.springframework.security</groupId> + <artifactId>spring-security-core</artifactId> + <version>6.4.1</version> + </dependency> <dependency> <groupId>io.jsonwebtoken</groupId> <artifactId>jjwt-api</artifactId> diff --git a/java/services/auth/src/main/java/com/uva/authentication/api/UserAPI.java b/java/services/auth/src/main/java/com/uva/authentication/api/UserAPI.java index 7df746b..d4aa447 100644 --- a/java/services/auth/src/main/java/com/uva/authentication/api/UserAPI.java +++ b/java/services/auth/src/main/java/com/uva/authentication/api/UserAPI.java @@ -11,8 +11,8 @@ import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; import com.uva.authentication.models.RegisterRequest; -import com.uva.authentication.models.User; -import com.uva.authentication.models.UserRol; +import com.uva.authentication.models.remote.User; +import com.uva.authentication.models.remote.UserRol; import com.uva.authentication.utils.JwtUtil; @Component diff --git a/java/services/auth/src/main/java/com/uva/authentication/config/SecurityConfig.java b/java/services/auth/src/main/java/com/uva/authentication/config/SecurityConfig.java deleted file mode 100644 index 99715b0..0000000 --- a/java/services/auth/src/main/java/com/uva/authentication/config/SecurityConfig.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.uva.authentication.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.web.SecurityFilterChain; - -@Configuration -public class SecurityConfig { - - @Bean - public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { - http.csrf(crsf -> crsf.disable()) - .authorizeHttpRequests(auth -> auth.anyRequest().permitAll()); - return http.build(); - } -} diff --git a/java/services/auth/src/main/java/com/uva/authentication/controllers/AuthController.java b/java/services/auth/src/main/java/com/uva/authentication/controllers/AuthController.java index 72e4eab..23625a6 100644 --- a/java/services/auth/src/main/java/com/uva/authentication/controllers/AuthController.java +++ b/java/services/auth/src/main/java/com/uva/authentication/controllers/AuthController.java @@ -16,10 +16,10 @@ public class AuthController { private AuthService authService; @PostMapping("/login") - public ResponseEntity<String> login(@RequestBody LoginRequest loginRequest) { + public ResponseEntity<?> login(@RequestBody LoginRequest loginRequest) { try { String token = authService.login(loginRequest); - return ResponseEntity.ok(token); + return ResponseEntity.ok(new JwtAuthResponse(token)); } catch (HttpClientErrorException e) { if (e.getStatusCode() == HttpStatus.FORBIDDEN) { return new ResponseEntity<String>(e.getMessage(), HttpStatus.FORBIDDEN); @@ -29,7 +29,7 @@ public class AuthController { } @PostMapping("/register") - public ResponseEntity<String> register(@RequestBody RegisterRequest registerRequest) { + public ResponseEntity<?> register(@RequestBody RegisterRequest registerRequest) { try { LoginRequest loginRequest = new LoginRequest(); loginRequest.setEmail(registerRequest.getEmail()); diff --git a/java/services/auth/src/main/java/com/uva/authentication/models/AuthResponse.java b/java/services/auth/src/main/java/com/uva/authentication/models/AuthResponse.java index 0ec6ee5..e943a69 100644 --- a/java/services/auth/src/main/java/com/uva/authentication/models/AuthResponse.java +++ b/java/services/auth/src/main/java/com/uva/authentication/models/AuthResponse.java @@ -1,14 +1,53 @@ package com.uva.authentication.models; +import com.uva.authentication.models.remote.UserRol; + public class AuthResponse { - private String token; - public AuthResponse(String token) { - this.token = token; + private int id; + private String username; + private String email; + private String password; + private UserRol rol; + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public String getUsername() { + return this.username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getEmail() { + return this.email; } - // Getter - public String getToken() { - return token; + public void setEmail(String email) { + this.email = email; } + + public String getPassword() { + return this.password; + } + + public void setPassword(String password) { + this.password = password; + } + + public UserRol getRol() { + return this.rol; + } + + public void setRol(UserRol rol) { + this.rol = rol; + } + } diff --git a/java/services/auth/src/main/java/com/uva/authentication/models/JwtAuthResponse.java b/java/services/auth/src/main/java/com/uva/authentication/models/JwtAuthResponse.java new file mode 100644 index 0000000..a956695 --- /dev/null +++ b/java/services/auth/src/main/java/com/uva/authentication/models/JwtAuthResponse.java @@ -0,0 +1,14 @@ +package com.uva.authentication.models; + +public class JwtAuthResponse { + private String token; + + public JwtAuthResponse(String token) { + this.token = token; + } + + // Getter + public String getToken() { + return token; + } +} diff --git a/java/services/auth/src/main/java/com/uva/authentication/models/RegisterRequest.java b/java/services/auth/src/main/java/com/uva/authentication/models/RegisterRequest.java index d15ccb3..b3c98e8 100644 --- a/java/services/auth/src/main/java/com/uva/authentication/models/RegisterRequest.java +++ b/java/services/auth/src/main/java/com/uva/authentication/models/RegisterRequest.java @@ -1,5 +1,7 @@ package com.uva.authentication.models; +import com.uva.authentication.models.remote.UserRol; + public class RegisterRequest extends LoginRequest { private UserRol rol; private String name; diff --git a/java/services/auth/src/main/java/com/uva/authentication/models/Client.java b/java/services/auth/src/main/java/com/uva/authentication/models/remote/Client.java similarity index 82% rename from java/services/auth/src/main/java/com/uva/authentication/models/Client.java rename to java/services/auth/src/main/java/com/uva/authentication/models/remote/Client.java index 896fe93..69bb23c 100644 --- a/java/services/auth/src/main/java/com/uva/authentication/models/Client.java +++ b/java/services/auth/src/main/java/com/uva/authentication/models/remote/Client.java @@ -1,18 +1,10 @@ -package com.uva.authentication.models; - -import java.util.ArrayList; -import java.util.List; - -import com.fasterxml.jackson.annotation.JsonIgnore; +package com.uva.authentication.models.remote; import jakarta.persistence.Basic; -import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; -import jakarta.persistence.FetchType; -import jakarta.persistence.OneToMany; import jakarta.persistence.Table; @Entity diff --git a/java/services/auth/src/main/java/com/uva/authentication/models/HotelManager.java b/java/services/auth/src/main/java/com/uva/authentication/models/remote/HotelManager.java similarity index 75% rename from java/services/auth/src/main/java/com/uva/authentication/models/HotelManager.java rename to java/services/auth/src/main/java/com/uva/authentication/models/remote/HotelManager.java index 5cc75cb..584a336 100644 --- a/java/services/auth/src/main/java/com/uva/authentication/models/HotelManager.java +++ b/java/services/auth/src/main/java/com/uva/authentication/models/remote/HotelManager.java @@ -1,13 +1,6 @@ -package com.uva.authentication.models; +package com.uva.authentication.models.remote; -import java.util.ArrayList; -import java.util.List; -import com.fasterxml.jackson.annotation.JsonIgnore; - -import jakarta.persistence.CascadeType; import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.OneToMany; import jakarta.persistence.Table; @Entity diff --git a/java/services/auth/src/main/java/com/uva/authentication/models/User.java b/java/services/auth/src/main/java/com/uva/authentication/models/remote/User.java similarity index 97% rename from java/services/auth/src/main/java/com/uva/authentication/models/User.java rename to java/services/auth/src/main/java/com/uva/authentication/models/remote/User.java index ae4981a..a72ecfa 100644 --- a/java/services/auth/src/main/java/com/uva/authentication/models/User.java +++ b/java/services/auth/src/main/java/com/uva/authentication/models/remote/User.java @@ -1,4 +1,4 @@ -package com.uva.authentication.models; +package com.uva.authentication.models.remote; import com.fasterxml.jackson.annotation.JsonIgnore; diff --git a/java/services/auth/src/main/java/com/uva/authentication/models/UserRol.java b/java/services/auth/src/main/java/com/uva/authentication/models/remote/UserRol.java similarity index 54% rename from java/services/auth/src/main/java/com/uva/authentication/models/UserRol.java rename to java/services/auth/src/main/java/com/uva/authentication/models/remote/UserRol.java index 5944a68..fe4d90d 100644 --- a/java/services/auth/src/main/java/com/uva/authentication/models/UserRol.java +++ b/java/services/auth/src/main/java/com/uva/authentication/models/remote/UserRol.java @@ -1,4 +1,4 @@ -package com.uva.authentication.models; +package com.uva.authentication.models.remote; public enum UserRol { ADMIN, HOTEL_ADMIN, CLIENT diff --git a/java/services/auth/src/main/java/com/uva/authentication/models/UserStatus.java b/java/services/auth/src/main/java/com/uva/authentication/models/remote/UserStatus.java similarity index 65% rename from java/services/auth/src/main/java/com/uva/authentication/models/UserStatus.java rename to java/services/auth/src/main/java/com/uva/authentication/models/remote/UserStatus.java index cdf51ad..5dd62bc 100644 --- a/java/services/auth/src/main/java/com/uva/authentication/models/UserStatus.java +++ b/java/services/auth/src/main/java/com/uva/authentication/models/remote/UserStatus.java @@ -1,4 +1,4 @@ -package com.uva.authentication.models; +package com.uva.authentication.models.remote; public enum UserStatus { NO_BOOKINGS, WITH_ACTIVE_BOOKINGS, WITH_INACTIVE_BOOKINGS; diff --git a/java/services/auth/src/main/java/com/uva/authentication/repositories/ClientRepository.java b/java/services/auth/src/main/java/com/uva/authentication/repositories/ClientRepository.java index 11e4c12..3019f81 100644 --- a/java/services/auth/src/main/java/com/uva/authentication/repositories/ClientRepository.java +++ b/java/services/auth/src/main/java/com/uva/authentication/repositories/ClientRepository.java @@ -3,8 +3,8 @@ package com.uva.authentication.repositories; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; -import com.uva.authentication.models.Client; -import com.uva.authentication.models.User; +import com.uva.authentication.models.remote.Client; +import com.uva.authentication.models.remote.User; public interface ClientRepository extends JpaRepository<User, Integer> { Optional<Client> findByEmail(String email); diff --git a/java/services/auth/src/main/java/com/uva/authentication/repositories/HotelManagerRepository.java b/java/services/auth/src/main/java/com/uva/authentication/repositories/HotelManagerRepository.java index a1e0ba8..2d50305 100644 --- a/java/services/auth/src/main/java/com/uva/authentication/repositories/HotelManagerRepository.java +++ b/java/services/auth/src/main/java/com/uva/authentication/repositories/HotelManagerRepository.java @@ -3,8 +3,8 @@ package com.uva.authentication.repositories; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; -import com.uva.authentication.models.HotelManager; -import com.uva.authentication.models.User; +import com.uva.authentication.models.remote.HotelManager; +import com.uva.authentication.models.remote.User; public interface HotelManagerRepository extends JpaRepository<User, Integer> { Optional<HotelManager> findByEmail(String email); diff --git a/java/services/auth/src/main/java/com/uva/authentication/repositories/UserRepository.java b/java/services/auth/src/main/java/com/uva/authentication/repositories/UserRepository.java index c0695df..65f98ed 100644 --- a/java/services/auth/src/main/java/com/uva/authentication/repositories/UserRepository.java +++ b/java/services/auth/src/main/java/com/uva/authentication/repositories/UserRepository.java @@ -2,7 +2,8 @@ package com.uva.authentication.repositories; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; -import com.uva.authentication.models.User; + +import com.uva.authentication.models.remote.User; public interface UserRepository extends JpaRepository<User, Integer> { Optional<User> findByEmail(String email); diff --git a/java/services/auth/src/main/java/com/uva/authentication/services/AuthService.java b/java/services/auth/src/main/java/com/uva/authentication/services/AuthService.java index 3bc823b..e392a7b 100644 --- a/java/services/auth/src/main/java/com/uva/authentication/services/AuthService.java +++ b/java/services/auth/src/main/java/com/uva/authentication/services/AuthService.java @@ -8,12 +8,12 @@ import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.web.client.HttpClientErrorException; -import com.uva.authentication.models.Client; -import com.uva.authentication.models.HotelManager; import com.uva.authentication.models.LoginRequest; import com.uva.authentication.models.RegisterRequest; -import com.uva.authentication.models.User; -import com.uva.authentication.models.UserRol; +import com.uva.authentication.models.remote.Client; +import com.uva.authentication.models.remote.HotelManager; +import com.uva.authentication.models.remote.User; +import com.uva.authentication.models.remote.UserRol; import com.uva.authentication.repositories.ClientRepository; import com.uva.authentication.repositories.HotelManagerRepository; import com.uva.authentication.repositories.UserRepository; diff --git a/java/services/auth/src/main/java/com/uva/authentication/utils/JwtUtil.java b/java/services/auth/src/main/java/com/uva/authentication/utils/JwtUtil.java index 4ac6688..5182613 100644 --- a/java/services/auth/src/main/java/com/uva/authentication/utils/JwtUtil.java +++ b/java/services/auth/src/main/java/com/uva/authentication/utils/JwtUtil.java @@ -15,7 +15,7 @@ import java.util.function.Function; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; -import com.uva.authentication.models.User; +import com.uva.authentication.models.remote.User; @Component public class JwtUtil { -- GitLab