Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
e6a3de1
Add TestController class
Dec 25, 2020
ed73a4e
Add thymeleaf dependency
Dec 26, 2020
01befd4
Change field isActivated to enabled
Dec 26, 2020
3719d32
Add NotificationEmail model
Dec 26, 2020
b3fc69c
Add findByEmail method
Dec 26, 2020
68db166
Add findByToken method
Dec 26, 2020
27150ae
Enable Async computation
Dec 26, 2020
37674bc
Add AuthController class
Dec 26, 2020
3c4b506
Add custom exception CModelException
Dec 26, 2020
b6084c2
Add RegisterRequest class in dto package
Dec 26, 2020
25278c5
Add SecurityConfig class
Dec 26, 2020
f429e70
Add service package
Dec 26, 2020
0e7bf37
Add notification mail template
Dec 26, 2020
591e8f8
Add mail properties
Dec 26, 2020
3ce83ea
Add and implement login method
Dec 26, 2020
d2e45d5
Add LoginRequest container
Dec 26, 2020
3f22da7
Add AuthenticationResponse container
Dec 26, 2020
d91c3fa
Add configureGlobal and authenticationManagerBean methods
Dec 26, 2020
654089d
Add JWT dependencies
Dec 26, 2020
4ebda7b
Add and implement UserDetailsServiceImpl
Dec 26, 2020
040030d
Add login method
Dec 26, 2020
0e593f5
Add JwtProvider
Dec 26, 2020
95301ff
Edit the security configuration of the app
Dec 26, 2020
6fbf231
Add JwtAuthenticationFilter class
Dec 26, 2020
520d859
Add token validation
Dec 26, 2020
2684949
Change project structure
Dec 26, 2020
426d981
Update database
Dec 26, 2020
1f2b852
Add getInitialSetOfRoles method
Dec 26, 2020
6918da4
Move and rename NotificationEmail to dto package
Dec 26, 2020
6e437ec
Change login certificate
Dec 27, 2020
56387e1
Merge pull request #3 from Tumilok/login2
tumilok Dec 27, 2020
4abb851
Refactor field name from username to email
Dec 27, 2020
a3d65e0
Add two parameter constructor in CModelException
Dec 27, 2020
d0071f5
Introduce a minor refactorization
Dec 27, 2020
a12e8f2
Add UserDetailsImpl class
Dec 27, 2020
4b10b76
Edit UserDetailsServiceImpl class
Dec 27, 2020
cfe0c42
Remove Equals and Hashcode from Role model
Dec 27, 2020
9c9ae01
Change Role object creation from constr to builder
Dec 27, 2020
2d9a6ca
Introduce authorization to the TestController
Dec 27, 2020
8659dc5
Add equals and hashcode with excluded filed users
Dec 27, 2020
34d02c4
Add verification of email's affiliation
Dec 27, 2020
f95ac65
Fix with introduction of UserDetailsImpl class
Dec 27, 2020
4e3cf8a
Fix typo in the exception message
Dec 27, 2020
47d436e
Fix injection of fields to constructor
Dec 27, 2020
bc0e626
Add JwtConfig class which uses .properties file
Dec 27, 2020
55dcea0
Comment all the tests due to model changes
Dec 27, 2020
d68c6c6
Add expirationTimeInDays filed
Dec 27, 2020
ae7951b
Add JWT properties
Dec 27, 2020
872acb9
finished refresh token implementation
sswrk Mar 2, 2021
aab2bea
Merge pull request #4 from Tumilok/auth-szymon
sswrk Mar 2, 2021
cbf54d0
Add SwaggerConfigurations class
tumilok Mar 2, 2021
6f8150a
Change pom.xml file
tumilok Mar 2, 2021
d4901c2
Adjust the swagger changes
tumilok Mar 2, 2021
10fa706
Merge branch 'auth' of https://github.com/Tumilok/c-model-server into…
tumilok Mar 2, 2021
469cdd1
Merge pull request #6 from Tumilok/swagger-documentation
tumilok Mar 2, 2021
384d809
added simulation post and get by id
sswrk Mar 3, 2021
abfed7e
Enable cross origin
tumilok Mar 3, 2021
d3b05b2
Merge branch 'auth' of https://github.com/Tumilok/c-model-server into…
tumilok Mar 3, 2021
e1f577f
added rest get mappings for all simulations with or without pagination
sswrk Mar 3, 2021
268f50c
made fields in SimulationService final
sswrk Mar 4, 2021
3940fed
Merge pull request #7 from Tumilok/rest-api
sswrk Mar 4, 2021
dbfcf71
Fix getInitialSetOfRoles method
tumilok Mar 17, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 109 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,74 +10,168 @@
</parent>
<groupId>pl.edu.agh.racing</groupId>
<artifactId>c-model</artifactId>
<version>0.0.1</version>
<version>0.0.3</version>
<name>c-model</name>
<description>Demo project for Spring Boot</description>
<description>C-Model app for AGH Racing Aerodynamics team</description>

<properties>
<java.version>11</java.version>
<org.mapstruct.version>1.4.2.Final</org.mapstruct.version>
<org.mapstruct.version>1.4.2.Final</org.mapstruct.version>
<org.projectlombok.version>1.18.16</org.projectlombok.version>
<lombok-mapstruct-binding.version>0.2.0</lombok-mapstruct-binding.version>
</properties>

<dependencies>

<!-- Spring Boot Data Jpa dependency. Used to build the database -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<!-- Spring Boot Security dependency. Used to secure the app -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>

<!-- Spring Boot Web dependency. Used to create a web app -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- Spring Boot Thymeleaf dependency. Used to inject java code into HTML files -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

<!-- Spring Boot Mail dependency. Used to send mails -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>

<!-- MySQL Connector dependency. Used to connect app with MySQL database -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>

<!-- Lombok dependency. Used to reduce the amount of code -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>

<!-- Validation api dependency. Used to validate data in database -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>

<!-- JWT related dependencies. Used in the implementation of authentication. -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>0.11.2</version>
</dependency>

<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>0.11.2</version>
</dependency>

<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<version>0.11.2</version>
</dependency>

<!-- Spring Fox and Swagger dependencies. Used to document the api's -->

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>

<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>
<!-- Spring Boot Test dependency. Used to test the app -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- Spring Boot Security Test dependency. Used to test security of the app -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>

<!-- H2 database dependency. Used to create an inmemory database during database tests -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.200</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source> <!-- depending on your project -->
<target>${java.version}</target> <!-- depending on your project -->
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${org.projectlombok.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>${lombok-mapstruct-binding.version}</version>
</path>
<!-- other annotation processors -->
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
Expand All @@ -87,6 +181,10 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
<exclude>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/pl/edu/agh/racing/cmodel/CModelApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Import;
import org.springframework.scheduling.annotation.EnableAsync;
import pl.edu.agh.racing.cmodel.swagger.SwaggerConfiguration;

@SpringBootApplication
@EnableAsync
@Import(SwaggerConfiguration.class)
public class CModelApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package pl.edu.agh.racing.cmodel.controller;

import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import pl.edu.agh.racing.cmodel.dto.request.RefreshTokenRequest;
import pl.edu.agh.racing.cmodel.dto.response.AuthenticationResponse;
import pl.edu.agh.racing.cmodel.dto.request.LoginRequest;
import pl.edu.agh.racing.cmodel.dto.request.RegisterRequest;
import pl.edu.agh.racing.cmodel.service.AuthService;
import pl.edu.agh.racing.cmodel.service.RefreshTokenService;

import javax.validation.Valid;

import static org.springframework.http.HttpStatus.OK;

@CrossOrigin(maxAge = 3600)
@RestController
@RequestMapping("/api/auth")
@AllArgsConstructor
public class AuthController {

private final AuthService authService;
private final RefreshTokenService refreshTokenService;

@PostMapping("/signup")
public ResponseEntity<String> signup(@RequestBody RegisterRequest registerRequest) {
authService.signup(registerRequest);
return new ResponseEntity<>("User Registration Successful",
OK);
}

@GetMapping("/accountVerification/{token}")
public ResponseEntity<String> verifyAccount(@PathVariable String token) {
authService.verifyAccount(token);
return new ResponseEntity<>("Account Has Activated Successfully", OK);
}

@PostMapping("/login")
public AuthenticationResponse login(@RequestBody LoginRequest loginRequest) {
return authService.login(loginRequest);
}

@PostMapping("refresh/token")
public AuthenticationResponse refreshTokens(@Valid @RequestBody RefreshTokenRequest refreshTokenRequest) {
return authService.refreshToken(refreshTokenRequest);
}

@PostMapping("/logout")
public ResponseEntity<String> logout(@Valid @RequestBody RefreshTokenRequest refreshTokenRequest) {
refreshTokenService.deleteRefreshToken(refreshTokenRequest.getRefreshToken());
return ResponseEntity.status(OK).body("Refresh Token Deleted Successfully!!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package pl.edu.agh.racing.cmodel.controller;

import lombok.AllArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import pl.edu.agh.racing.cmodel.dto.SimulationDto;
import pl.edu.agh.racing.cmodel.service.SimulationService;

import java.util.List;

@RestController
@RequestMapping("/api/simulations")
@AllArgsConstructor
@CrossOrigin(maxAge = 3600)
public class SimulationController {

private final SimulationService simulationService;

@PostMapping
public ResponseEntity<Void> createSimulation(@RequestBody SimulationDto simulationDto){
simulationService.save(simulationDto);
return new ResponseEntity<>(HttpStatus.CREATED);
}

@GetMapping
public ResponseEntity<List<SimulationDto>> getAllSimulations(){
return ResponseEntity.status(HttpStatus.OK).body(simulationService.getAllSimulations());
}

@GetMapping("/pages/{pageNumber}")
public ResponseEntity<List<SimulationDto>> getAllSimulationsWithPagination(@PathVariable int pageNumber){
return ResponseEntity.status(HttpStatus.OK).body(simulationService.getAllSimulationWithPagination(pageNumber));
}

@GetMapping("/by-id/{simulationId}")
public ResponseEntity<SimulationDto> getSimulationById(@PathVariable Long simulationId){
return ResponseEntity.status(HttpStatus.OK).body(simulationService.getSimulationById(simulationId));
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package pl.edu.agh.racing.cmodel.controller;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/test")
public class TestController {

@GetMapping("/all")
public String allAccess() {
return "Public Content.";
}

@GetMapping("/newbie")
@PreAuthorize("hasRole('NEWBIE') or hasRole('USER') or hasRole('MODERATOR') or hasRole('ADMIN')")
public String newbieAccess() {
return "Newbie Content.";
}

@GetMapping("/user")
@PreAuthorize("hasRole('USER') or hasRole('MODERATOR') or hasRole('ADMIN')")
public String userAccess() {
return "User Content.";
}

@GetMapping("/moderator")
@PreAuthorize("hasRole('MODERATOR') or hasRole('ADMIN')")
public String moderatorAccess() {
return "Moderator Content.";
}

@GetMapping("/admin")
@PreAuthorize("hasRole('ADMIN')")
public String adminAccess() {
return "Admin Content.";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package pl.edu.agh.racing.cmodel.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class NotificationEmailDto {
private String subject;
private String recipient;
private String body;
}
28 changes: 28 additions & 0 deletions src/main/java/pl/edu/agh/racing/cmodel/dto/SimulationDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package pl.edu.agh.racing.cmodel.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.Instant;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class SimulationDto {
private Long id;
private String name;
private String fw;
private String rw;
private String s;
private String diff;
private String u;
private String n;
private Double df;
private Double d;
private Double balance;
private Double mrfChlodnica;
private Long statusId;
private Instant createDateTime;
private Instant updateDateTime;
}
Loading