Code moving and fix login component style.
This commit is contained in:
@@ -29,10 +29,6 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-security</artifactId>
|
<artifactId>spring-boot-starter-security</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>jakarta.servlet</groupId>
|
|
||||||
<artifactId>jakarta.servlet-api</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.auth0</groupId>
|
<groupId>com.auth0</groupId>
|
||||||
<artifactId>java-jwt</artifactId>
|
<artifactId>java-jwt</artifactId>
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
package org.sportshub.application.security;
|
package org.sportshub.exposition.configuration.security;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.springframework.http.HttpHeaders.AUTHORIZATION;
|
import static org.springframework.http.HttpHeaders.AUTHORIZATION;
|
||||||
import static org.springframework.util.ObjectUtils.isEmpty;
|
import static org.springframework.util.ObjectUtils.isEmpty;
|
||||||
|
import org.sportshub.application.security.JwtService;
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
package org.sportshub.exposition.configuration;
|
package org.sportshub.exposition.configuration.security;
|
||||||
|
|
||||||
import static org.springframework.http.HttpMethod.GET;
|
import static org.springframework.http.HttpMethod.GET;
|
||||||
import static org.springframework.http.HttpMethod.OPTIONS;
|
import static org.springframework.http.HttpMethod.OPTIONS;
|
||||||
import static org.springframework.http.HttpMethod.POST;
|
import static org.springframework.http.HttpMethod.POST;
|
||||||
import static org.springframework.security.config.http.SessionCreationPolicy.STATELESS;
|
import static org.springframework.security.config.http.SessionCreationPolicy.STATELESS;
|
||||||
import org.sportshub.application.security.JwtAuthenticationFilter;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.security.config.Customizer;
|
import org.springframework.security.config.Customizer;
|
||||||
@@ -12,8 +11,6 @@ import org.springframework.security.config.annotation.method.configuration.Enabl
|
|||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
||||||
import org.springframework.security.web.SecurityFilterChain;
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||||
|
|
||||||
@@ -2,6 +2,8 @@ package org.sportshub.exposition.user;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.sportshub.application.security.annotation.AllowedToAdmins;
|
||||||
|
import org.sportshub.application.security.annotation.AllowedToAnonymous;
|
||||||
import org.sportshub.application.user.UserUseCases;
|
import org.sportshub.application.user.UserUseCases;
|
||||||
import org.sportshub.domain.user.model.User;
|
import org.sportshub.domain.user.model.User;
|
||||||
import org.sportshub.domain.user.model.UserAuthenticationData;
|
import org.sportshub.domain.user.model.UserAuthenticationData;
|
||||||
@@ -24,12 +26,14 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
|
@AllowedToAnonymous
|
||||||
public LoginResponse login(@RequestBody LoginRequest request) {
|
public LoginResponse login(@RequestBody LoginRequest request) {
|
||||||
UserAuthenticationData userAuthenticationData = userUseCases.authenticate(request.id(), request.password());
|
UserAuthenticationData userAuthenticationData = userUseCases.authenticate(request.id(), request.password());
|
||||||
return new LoginResponse(userAuthenticationData);
|
return new LoginResponse(userAuthenticationData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
|
@AllowedToAdmins
|
||||||
public List<User> findAll() {
|
public List<User> findAll() {
|
||||||
return userUseCases.findAll();
|
return userUseCases.findAll();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
<form (ngSubmit)="onSubmit()" [formGroup]="loginForm" ngNativeValidate>
|
<form (ngSubmit)="onSubmit()" class="shadowed" [formGroup]="loginForm" ngNativeValidate>
|
||||||
<div>
|
<div>
|
||||||
<label for="id">Identifier</label>
|
<label for="id">Identifier</label>
|
||||||
<input id="id" name="id" formControlName="id"/>
|
<input id="id" name="id" formControlName="id" class="input" required/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label for="password">Password</label>
|
<label for="password">Password</label>
|
||||||
<input id="password" name="password" type="password" formControlName="password"/>
|
<input id="password" name="password" type="password" formControlName="password" class="input" required/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<button type="submit">Validate</button>
|
<button type="submit" class="btn">Validate</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
:host {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
form {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
border: solid 1px #e8e8e8;
|
||||||
|
padding: 1em;
|
||||||
|
border-radius: .5em;
|
||||||
|
gap: 1em;
|
||||||
|
|
||||||
|
div {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: left;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,7 +27,9 @@ export class LoginComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onSubmit(): void {
|
onSubmit(): void {
|
||||||
const loginRequest: LoginRequest = this.loginForm.value;
|
if (this.loginForm.valid) {
|
||||||
this.loginService.login(loginRequest);
|
const loginRequest: LoginRequest = this.loginForm.value;
|
||||||
|
this.loginService.login(loginRequest);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
<a class="title" routerLink="/">SportsHub</a>
|
<a class="title" routerLink="/">SportsHub</a>
|
||||||
<div id="menu">
|
<div id="menu">
|
||||||
<a routerLink="/login" *ngIf="(isAuthenticated$ | async) === false">
|
<a routerLink="/login" *ngIf="(isAuthenticated$ | async) === false" class="btn">
|
||||||
<mat-icon>login</mat-icon>
|
<mat-icon>login</mat-icon>
|
||||||
Login
|
Login
|
||||||
</a>
|
</a>
|
||||||
<a routerLink="/logout" *ngIf="isAuthenticated$ | async" class="logout">
|
<a routerLink="/logout" *ngIf="isAuthenticated$ | async" class="btn logout">
|
||||||
<mat-icon>logout</mat-icon>
|
<mat-icon>logout</mat-icon>
|
||||||
Logout
|
Logout
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@@ -24,14 +24,6 @@
|
|||||||
|
|
||||||
a {
|
a {
|
||||||
flex: 0 1;
|
flex: 0 1;
|
||||||
background-color: #008cff;
|
|
||||||
color: white;
|
|
||||||
border-radius: .5em;
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
padding: .5em 1em;
|
|
||||||
text-decoration: none;
|
|
||||||
gap: .5em;
|
gap: .5em;
|
||||||
|
|
||||||
&.logout {
|
&.logout {
|
||||||
|
|||||||
@@ -2,3 +2,25 @@
|
|||||||
|
|
||||||
html, body { height: 100%; }
|
html, body { height: 100%; }
|
||||||
body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; }
|
body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; }
|
||||||
|
|
||||||
|
.shadowed {
|
||||||
|
box-shadow: 0 3px 1px -2px #0003,0 2px 2px #00000024,0 1px 5px #0000001f;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
background-color: #008cff;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
border-radius: .4em;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
padding: .5em 1em;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input {
|
||||||
|
padding: .5em;
|
||||||
|
border-radius: .4em;
|
||||||
|
border: 1px solid #d2d2d2
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user