Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit 6a51aa7

Browse files
FF-103 Logic for UserRegistration. (#32)
* WIP writing logic for UserRegistration. * FF-103 wrote logic and unit tests. * Added additional ExpectionHandler, and HealthCheck change. * FF-103 added configuration key for password check. * FF-103 Running cucumber tests works. * FF-103 Reworked server response to use httpStatus messages instead of strings. * FF-103 Implemented changes requested by @qvalentin, fixed some bugs. * Fixed Maven Test Execution. * updated version and date. Co-authored-by: open-schnick <[email protected]>
1 parent 8f0a85d commit 6a51aa7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+473
-170
lines changed

.run/JUnit Tests.run.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<component name="ProjectRunConfigurationManager">
22
<configuration default="false" name="Run only Unit Tests" type="JUnit" factoryName="JUnit">
33
<useClassPathOnly />
4-
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" />
54
<option name="ALTERNATIVE_JRE_PATH" value="11" />
65
<option name="PACKAGE_NAME" value="" />
76
<option name="MAIN_CLASS_NAME" value="" />

pom.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
<parent>
66
<groupId>org.springframework.boot</groupId>
77
<artifactId>spring-boot-starter-parent</artifactId>
8-
<version>2.4.0</version>
8+
<version>2.3.5.RELEASE</version>
99
<relativePath/> <!-- lookup parent from repository -->
1010
</parent>
1111
<groupId>de.filefighter</groupId>
1212
<artifactId>rest</artifactId>
13-
<version>0.0.3</version>
13+
<version>0.0.4</version>
1414
<name>RestApi</name>
1515
<description>RestApi for FileFighter</description>
1616

@@ -49,6 +49,11 @@
4949
<version>1.18.16</version>
5050
</dependency>
5151

52+
<dependency>
53+
<groupId>org.apache.httpcomponents</groupId>
54+
<artifactId>httpclient</artifactId>
55+
</dependency>
56+
5257
<!-- TESTING -->
5358
<dependency>
5459
<groupId>org.junit.jupiter</groupId>

src/main/java/de/filefighter/rest/RestApplication.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,11 @@
44
import org.springframework.boot.SpringApplication;
55
import org.springframework.boot.autoconfigure.SpringBootApplication;
66
import org.springframework.boot.context.properties.EnableConfigurationProperties;
7-
import org.springframework.context.annotation.Bean;
8-
import org.springframework.web.client.RestTemplate;
97

108
@SpringBootApplication
119
@EnableConfigurationProperties(FileFighterProperties.class)
1210
public class RestApplication {
13-
public static void main(String[] args) {
14-
SpringApplication.run(RestApplication.class, args);
15-
}
16-
17-
@Bean
18-
public RestTemplate getRestTemplate() {
19-
return new RestTemplate();
20-
}
11+
public static void main(String[] args) {
12+
SpringApplication.run(RestApplication.class, args);
13+
}
2114
}

src/main/java/de/filefighter/rest/configuration/FileFighterProperties.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package de.filefighter.rest.configuration;
22

3-
import lombok.Data;
43
import org.springframework.boot.context.properties.ConfigurationProperties;
54
import org.springframework.context.annotation.Configuration;
65

@@ -13,6 +12,7 @@ public class FileFighterProperties {
1312
*/
1413
private String version = "undefined";
1514
private String date = "undefined";
15+
private boolean disablePasswordCheck = false;
1616

1717
public String getVersion() {
1818
return version;
@@ -29,4 +29,12 @@ public String getDate() {
2929
public void setDate(String date) {
3030
this.date = date;
3131
}
32-
}
32+
33+
public boolean isDisablePasswordCheck() {
34+
return disablePasswordCheck;
35+
}
36+
37+
public void setDisablePasswordCheck(boolean disablePasswordCheck) {
38+
this.disablePasswordCheck = disablePasswordCheck;
39+
}
40+
}

src/main/java/de/filefighter/rest/configuration/PrepareDataBase.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ CommandLineRunner veryImportantFileFighterStartScript() {
4545
System.out.println(" | _| | | | | | __/ | _| | | | (_| | | | | | | |_ | __/ | | ");
4646
System.out.println(" |_| |_| |_| \\___| |_| |_| \\__, | |_| |_| \\__| \\___| |_| ");
4747
System.out.println(" |___/ ");
48-
System.out.println(" Version v"+version+" Last updated at "+date+" ");
48+
System.out.println(" Version v" + version + " Last updated at " + date + " ");
4949
System.out.println(" Developed by Gimleux, Valentin, Open-Schnick. ");
5050
System.out.println(" Development Blog: https://filefighter.github.io ");
5151
System.out.println(" The code can be found at: https://www.github.com/filefighter ");
@@ -102,7 +102,7 @@ CommandLineRunner initUserDataBaseDev(UserRepository repository) {
102102
.lowercaseUsername("user")
103103
.password("1234")
104104
.refreshToken("rft1234")
105-
.groupIds(new long[]{0})
105+
.groupIds(new long[]{1})
106106
.build()) +
107107
repository.save(UserEntity
108108
.builder()
@@ -155,7 +155,7 @@ CommandLineRunner initFileSystemDataBaseDev(FileSystemRepository repository) {
155155
.name("root")
156156
.size(420)
157157
.typeId(FileSystemType.FOLDER.getId())
158-
.visibleForGroupIds(new long[]{-1,0,1})
158+
.visibleForGroupIds(new long[]{-1, 0, 1})
159159
.build()) +
160160
repository.save(FileSystemEntity.builder()
161161
.createdByUserId(0)

src/main/java/de/filefighter/rest/configuration/RestConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class RestConfiguration {
1616
public static final String FS_BASE_URI = "/filesystem/";
1717
public static final String FS_PATH_HEADER = "X-FF-PATH";
1818
public static final String USER_BASE_URI = "/users/";
19+
public static final String DEFAULT_ERROR_PATH = "/error";
1920

2021
@Bean
2122
public WebMvcConfigurer configurer(){

src/main/java/de/filefighter/rest/domain/common/Utils.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,42 @@
22

33
import de.filefighter.rest.rest.exceptions.RequestDidntMeetFormalRequirementsException;
44

5+
import java.io.BufferedReader;
6+
import java.io.File;
7+
import java.io.FileReader;
8+
import java.io.IOException;
9+
import java.util.ArrayList;
10+
import java.util.List;
11+
512
public class Utils {
613

7-
public static boolean stringIsValid(String s){
14+
private Utils() {
15+
// Prevent Instantiation
16+
}
17+
18+
public static boolean stringIsValid(String s) {
819
return !(null == s || s.isEmpty() || s.isBlank());
920
}
1021

11-
public static String validateAuthorizationHeader(String header, String testString){
12-
if(!stringIsValid(testString))
22+
public static String validateAuthorizationHeader(String header, String testString) {
23+
if (!stringIsValid(testString))
1324
throw new RequestDidntMeetFormalRequirementsException("Header does not contain a valid String.");
1425

1526
if (!testString.matches("^" + header + "[^\\s](.*)$"))
1627
throw new RequestDidntMeetFormalRequirementsException("Header does not contain '" + header + "', or format is invalid.");
1728
String[] split = testString.split(header);
1829
return split[1];
1930
}
31+
32+
public static List<String> getLinesFromFile(File file) {
33+
ArrayList<String> lines = new ArrayList<>();
34+
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
35+
while (br.ready()) {
36+
lines.add(br.readLine().replace(" ",""));
37+
}
38+
} catch (IOException e) {
39+
e.printStackTrace();
40+
}
41+
return lines;
42+
}
2043
}

src/main/java/de/filefighter/rest/domain/health/business/SystemHealthBusinessService.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class SystemHealthBusinessService {
1515
private final UserBusinessService userBusinessService;
1616
private final AccessTokenBusinessService accessTokenBusinessService;
1717
private final long serverStartedAt;
18+
private DataIntegrity cachedIntegrity = DataIntegrity.STABLE;
1819

1920
@Value("${filefighter.version}")
2021
String version;
@@ -41,13 +42,19 @@ private DataIntegrity calculateDataIntegrity() {
4142

4243
// Risk / Unstable Cases.
4344
if(userCount < accessTokenCount){
44-
return DataIntegrity.POSSIBLE_RISK;
45+
this.triggerIntegrityChange(DataIntegrity.POSSIBLE_RISK);
4546
}
4647

47-
return DataIntegrity.STABLE;
48+
return cachedIntegrity;
4849
}
4950

5051
public long getCurrentEpochSeconds(){
5152
return Instant.now().getEpochSecond();
5253
}
54+
55+
public void triggerIntegrityChange(DataIntegrity integrity) {
56+
if(cachedIntegrity.getCode() < integrity.getCode()){
57+
this.cachedIntegrity = integrity;
58+
}
59+
}
5360
}

src/main/java/de/filefighter/rest/domain/health/data/SystemHealth.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ public class SystemHealth {
1616
private final String version;
1717

1818
public enum DataIntegrity {
19-
STABLE, POSSIBLE_RISK, UNSTABLE
19+
STABLE(0), POSSIBLE_RISK(1), UNSTABLE(2);
20+
21+
private final int code;
22+
23+
DataIntegrity(int code) {
24+
this.code = code;
25+
}
26+
27+
public int getCode() {
28+
return code;
29+
}
2030
}
2131
}

src/main/java/de/filefighter/rest/domain/token/business/AccessTokenBusinessService.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import de.filefighter.rest.domain.token.data.dto.AccessToken;
44
import de.filefighter.rest.domain.token.data.persistance.AccessTokenEntity;
55
import de.filefighter.rest.domain.token.data.persistance.AccessTokenRepository;
6-
import de.filefighter.rest.domain.token.exceptions.AccessTokenNotFoundException;
76
import de.filefighter.rest.domain.user.data.dto.User;
87
import de.filefighter.rest.domain.user.exceptions.UserNotAuthenticatedException;
98
import de.filefighter.rest.rest.exceptions.RequestDidntMeetFormalRequirementsException;
@@ -12,7 +11,6 @@
1211
import java.time.Instant;
1312
import java.util.UUID;
1413

15-
import static de.filefighter.rest.configuration.RestConfiguration.AUTHORIZATION_BASIC_PREFIX;
1614
import static de.filefighter.rest.configuration.RestConfiguration.AUTHORIZATION_BEARER_PREFIX;
1715
import static de.filefighter.rest.domain.common.Utils.stringIsValid;
1816
import static de.filefighter.rest.domain.common.Utils.validateAuthorizationHeader;
@@ -91,7 +89,7 @@ public AccessToken validateAccessTokenValue(String accessTokenValue) {
9189
return accessTokenDtoService.createDto(accessTokenEntity);
9290
}
9391

94-
public String generateRandomTokenValue() {
92+
public static String generateRandomTokenValue() {
9593
return UUID.randomUUID().toString();
9694
}
9795

0 commit comments

Comments
 (0)