Skip to content

Commit

Permalink
Upgrade to Spring v 3.1.0-M2.
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamed-taman committed Apr 12, 2023
1 parent 32257c5 commit f28976b
Show file tree
Hide file tree
Showing 22 changed files with 500 additions and 1,040 deletions.
2 changes: 1 addition & 1 deletion README.md

Large diffs are not rendered by default.

549 changes: 108 additions & 441 deletions frontend/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@
"tslint": "~6.1.3",
"typescript": "~4.3.5"
}
}
}
73 changes: 17 additions & 56 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0-M2</version>
<version>3.1.0-M2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand Down Expand Up @@ -58,27 +58,23 @@
</licenses>

<properties>
<maven.compiler.release>18</maven.compiler.release>
<maven.compiler.source>18</maven.compiler.source>
<maven.compiler.target>18</maven.compiler.target>
<maven.compiler.release>20</maven.compiler.release>
<maven.compiler.source>20</maven.compiler.source>
<maven.compiler.target>20</maven.compiler.target>
<java.version>20</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<!-- Dependencies versions properties -->
<maven.surefire.plugin.version>3.0.0-M5</maven.surefire.plugin.version>
<maven.failsafe.plugin.version>3.0.0-M5</maven.failsafe.plugin.version>
<io.jsonwebtoken.version>0.11.2</io.jsonwebtoken.version>
<org.mapstruct.version>1.5.0.RC1</org.mapstruct.version>
<org.springdoc.version>2.0.0-M1</org.springdoc.version>
<lombok.version>1.18.22</lombok.version>
<opencsv.version>5.6</opencsv.version>
<maven.surefire.plugin.version>3.0.0</maven.surefire.plugin.version>
<maven.failsafe.plugin.version>3.0.0</maven.failsafe.plugin.version>
<io.jsonwebtoken.version>0.11.5</io.jsonwebtoken.version>
<org.mapstruct.version>1.5.3.Final</org.mapstruct.version>
<org.springdoc.version>2.1.0</org.springdoc.version>
<opencsv.version>5.7.1</opencsv.version>
<hipster-core.version>1.0.1</hipster-core.version>
<datasource-proxy-sbs.version>1.8.0</datasource-proxy-sbs.version>
<commons-fileupload.version>1.4</commons-fileupload.version>
<commons-io.version>2.11.0</commons-io.version>
<datasource-proxy-sbs.version>1.8.1</datasource-proxy-sbs.version>
<commons-collections4.version>4.4</commons-collections4.version>
<hibernate-core-jakarta.version>5.6.5.Final</hibernate-core-jakarta.version>
<jackson-databind.version>2.13.2.2</jackson-databind.version>
</properties>

<dependencies>
Expand All @@ -92,18 +88,6 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core-jakarta</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core-jakarta</artifactId>
<version>${hibernate-core-jakarta.version}</version>
</dependency>

<dependency>
Expand All @@ -124,38 +108,12 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!--
To fix CVE-2020-36518
https://advisory.checkmarx.net/advisory/vulnerability/CVE-2020-36518/
-->
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${org.springdoc.version}</version>
<!--
To fix CVE-2020-36518
https://advisory.checkmarx.net/advisory/vulnerability/CVE-2020-36518/
-->
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-databind.version}</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -192,7 +150,7 @@
<version>${io.jsonwebtoken.version}</version>
<scope>runtime</scope>
</dependency>
<!-- Start - JWT library for authentication libraries -->
<!-- End - JWT library for authentication libraries -->
<!-- End - Security dependencies -->

<!-- Start - Development and Ops dependencies, and third parties libraries -->
Expand All @@ -207,11 +165,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<!-- Lombok to automate setter/getter generation -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<optional>true</optional>
</dependency>

Expand Down Expand Up @@ -302,6 +260,9 @@
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<enablePreview>true</enablePreview>
<compilerArgs>
<arg>-Xlint</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.siriusxi.htec.fa.api.model.request.AuthRequest;
import org.siriusxi.htec.fa.api.model.request.CreateUserRequest;
import org.siriusxi.htec.fa.api.model.response.UserView;
import org.siriusxi.htec.fa.domain.User;
import org.siriusxi.htec.fa.infra.mapper.UserMapper;
import org.siriusxi.htec.fa.infra.security.jwt.JwtTokenHelper;
import org.siriusxi.htec.fa.service.UserService;
import org.springframework.http.HttpHeaders;
Expand All @@ -34,57 +34,49 @@
// TODO: add refresh token method, change password.
@Log4j2
@Tag(name = "Authentication",
description = "A set of public APIs, for managing user authentication, and the registration.")
description = "A set of public APIs, for managing user authentication, and the registration.")
@RestController
@RequestMapping("public")
@RequiredArgsConstructor
public class AuthController {

private final AuthenticationManager authenticationManager;
private final UserService userService;
private final UserMapper userMapper;

public AuthController(AuthenticationManager authenticationManager,
UserService userService,
UserMapper userMapper) {
this.authenticationManager = authenticationManager;
this.userService = userService;
this.userMapper = userMapper;
}


@Operation(description = """
An API call to authenticate user before using the system,
and if successful a valid token is returned.
""")
An API call to authenticate user before using the system,
and if successful a valid token is returned.
""")
@PostMapping(value = "login")
public ResponseEntity<UserView> authenticate(@RequestBody @Valid AuthRequest request) {
try {
var authenticate = authenticationManager
.authenticate(new UsernamePasswordAuthenticationToken(
request.username(),
request.password()));
.authenticate(new UsernamePasswordAuthenticationToken(
request.username(),
request.password()));

User user = (User) authenticate.getPrincipal();

return ResponseEntity.ok()
.header(HttpHeaders.AUTHORIZATION,
JwtTokenHelper.generateAccessToken(
user.getId(),
user.getUsername()))
.body(userMapper.toView(user));
.header(HttpHeaders.AUTHORIZATION,
JwtTokenHelper.generateAccessToken(
user.getId(),
user.getUsername()))
.body(userService.mapper().toView(user));
} catch (BadCredentialsException ex) {
throw new HttpClientErrorException(UNAUTHORIZED, UNAUTHORIZED.getReasonPhrase());
}
}

@Operation(description = """
An API call, to register the user,
to be able to authenticate and use the system.
""")
An API call, to register the user,
to be able to authenticate and use the system.
""")
@PostMapping(value = "register")
public UserView register(@RequestBody @Valid CreateUserRequest userRequest) {

log.debug("User to be created: {}", userRequest);
return userService.create(userRequest);
}

}
Loading

0 comments on commit f28976b

Please sign in to comment.