Skip to content

Commit 82f1890

Browse files
authored
Merge pull request #76 from coderPaddyS/Adriano/finish
Finish javadocs
2 parents b63f3d6 + 6ba1283 commit 82f1890

File tree

11 files changed

+131
-35
lines changed

11 files changed

+131
-35
lines changed

backend/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,4 @@
168168
</plugins>
169169
</build>
170170

171-
</project>
171+
</project>

backend/src/main/java/de/itermori/pse/kitroomfinder/backend/BackendApplication.java

+11
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,22 @@
55
import org.springframework.boot.autoconfigure.SpringBootApplication;
66
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
77

8+
/**
9+
* The main class.
10+
*
11+
* @author Lukas Zetto
12+
* @author Adriano Castro
13+
* @version 1.0
14+
*/
815
@EnableEncryptableProperties
916
@EnableJpaRepositories(basePackages = "de.itermori.pse.kitroomfinder.backend.repositories")
1017
@SpringBootApplication()
1118
public class BackendApplication {
1219

20+
/**
21+
* The main method.
22+
* @param args The arguments.
23+
*/
1324
public static void main(String[] args) {
1425
SpringApplication.run(BackendApplication.class, args);
1526
}

backend/src/main/java/de/itermori/pse/kitroomfinder/backend/ErrorHandling.java

+14
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,21 @@
99
import java.util.List;
1010
import java.util.stream.Collectors;
1111

12+
/**
13+
* Handles GraphQL errors.
14+
*
15+
* @author Lukas Zetto
16+
* @version 1.0
17+
*/
1218
@Component
1319
public class ErrorHandling implements GraphQLErrorHandler {
20+
21+
/**
22+
* Processes GraphQL errors.
23+
*
24+
* @param errors The GraphQL errors.
25+
* @return The processed errors.
26+
*/
1427
@Override
1528
public List<GraphQLError> processErrors(List<GraphQLError> errors) {
1629
if (errors == null || errors.isEmpty()) {
@@ -28,4 +41,5 @@ private GraphQLError unwrapError(GraphQLError error) {
2841
} else
2942
return error;
3043
}
44+
3145
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
package de.itermori.pse.kitroomfinder.backend.exceptions;
22

3+
/**
4+
* Exception class for handling bad tokens.
5+
*
6+
* @author Lukas Zetto
7+
* @version 1.0
8+
*/
39
public class BadTokenException extends RuntimeException {
410

11+
/**
12+
* {@inheritDoc}
13+
*/
514
@Override
615
public String getMessage() {
716
return "invalid Token";
817
}
18+
919
}

backend/src/main/java/de/itermori/pse/kitroomfinder/backend/exceptions/NoSuchAliasSuggestionException.java

+9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
package de.itermori.pse.kitroomfinder.backend.exceptions;
22

3+
/**
4+
* Exception class for handling case when no alias suggestion with provided name exists.
5+
*
6+
* @author Adriano Castro
7+
* @version 1.0
8+
*/
39
public class NoSuchAliasSuggestionException extends RuntimeException {
410

11+
/**
12+
* {@inheritDoc}
13+
*/
514
@Override
615
public String getMessage() {
716
return "No such alias suggestion exists in the database";

backend/src/main/java/de/itermori/pse/kitroomfinder/backend/exceptions/UserNotFoundException.java

+9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
package de.itermori.pse.kitroomfinder.backend.exceptions;
22

3+
/**
4+
* Exception class for handling case when provided user is not registered yet.
5+
*
6+
* @author Lukas Zetto
7+
* @version 1.0
8+
*/
39
public class UserNotFoundException extends RuntimeException{
410

11+
/**
12+
* {@inheritDoc}
13+
*/
514
@Override
615
public String getMessage() {
716
return "User not registered yet";

backend/src/main/java/de/itermori/pse/kitroomfinder/backend/security/JWTFilter.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818

1919
import static java.util.function.Predicate.not;
2020

21+
/**
22+
* Filter that manages the authentication and authorization.
23+
*
24+
* @author Lukas Zetto
25+
* @version 1.0
26+
*/
2127
@Component
2228
public class JWTFilter extends OncePerRequestFilter {
2329
private static final String AUTHORIZATION_HEADER = "Authorization";
@@ -51,5 +57,5 @@ private Optional<String> getToken(HttpServletRequest request) {
5157
.filter(Matcher::find)
5258
.map(matcher -> matcher.group(1));
5359
}
54-
}
5560

61+
}
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,56 @@
11
package de.itermori.pse.kitroomfinder.backend.security;
22

33
import de.itermori.pse.kitroomfinder.backend.models.User;
4-
import javassist.Loader;
4+
import java.util.Set;
5+
import java.util.stream.Collectors;
6+
import java.util.stream.Stream;
57
import lombok.Builder;
68
import lombok.Getter;
79
import org.springframework.security.core.GrantedAuthority;
810
import org.springframework.security.core.authority.SimpleGrantedAuthority;
911
import org.springframework.security.web.authentication.WebAuthenticationDetails;
1012
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;
1113

12-
import java.util.Set;
13-
import java.util.stream.Collectors;
14-
import java.util.stream.Stream;
15-
14+
/**
15+
* Token that carries the authorities of the authenticated user.
16+
*
17+
* @author Lukas Zetto
18+
* @version 1.0
19+
*/
1620
@Getter
1721
public class JWTPreAuthenticationToken extends PreAuthenticatedAuthenticationToken {
22+
1823
private static final long serialVersionUID = 34737835684569L;
1924

25+
/**
26+
* Constructor: Demands for the initialization a {@link User} and a {@link WebAuthenticationDetails}.
27+
*
28+
* @param principal The user.
29+
* @param details The web authentication details.
30+
*/
2031
@Builder
2132
public JWTPreAuthenticationToken(User principal, WebAuthenticationDetails details) {
2233
super(principal, null, parseAuthorities(principal.getAuthorities()));
2334
super.setDetails(details);
2435
}
2536

37+
/**
38+
*
39+
* {@inheritDoc}
40+
*/
2641
@Override
2742
public Object getCredentials() {
2843
return null;
2944
}
3045

3146
private static Set<GrantedAuthority> parseAuthorities(String authorities) {
3247
return Stream.of(authorities.split(","))
33-
.map(authority -> buildSimpleGrantedAuthority(authority))
48+
.map(JWTPreAuthenticationToken::buildSimpleGrantedAuthority)
3449
.collect(Collectors.toSet());
3550
}
3651

3752
private static SimpleGrantedAuthority buildSimpleGrantedAuthority(String authority) {
3853
return new SimpleGrantedAuthority(authority);
3954
}
55+
4056
}

backend/src/main/java/de/itermori/pse/kitroomfinder/backend/security/WebSecurityConfig.java

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package de.itermori.pse.kitroomfinder.backend.security;
22

3-
import java.util.Arrays;
43
import java.util.List;
54
import lombok.RequiredArgsConstructor;
65
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -13,21 +12,28 @@
1312
import org.springframework.security.config.http.SessionCreationPolicy;
1413
import org.springframework.security.web.authentication.preauth.RequestHeaderAuthenticationFilter;
1514
import org.springframework.web.cors.CorsConfiguration;
16-
import org.springframework.web.cors.CorsConfigurationSource;
1715
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
1816
import org.springframework.web.filter.CorsFilter;
1917

20-
import static org.springframework.security.config.Customizer.withDefaults;
21-
18+
/**
19+
* Configuration class which defines the standard rights
20+
* for the methods in the resolver package and for the filter.
21+
*
22+
* @author Lukas Zetto
23+
* @version 1.0
24+
*/
2225
@Configuration
2326
@EnableWebSecurity
2427
@EnableGlobalMethodSecurity(prePostEnabled = true)
2528
@RequiredArgsConstructor
2629
@EnableConfigurationProperties()
2730
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
28-
private final JWTFilter jwtFilter;
2931

32+
private final JWTFilter jwtFilter;
3033

34+
/**
35+
* {@inheritDoc}
36+
*/
3137
@Override
3238
protected void configure(HttpSecurity http) throws Exception {
3339
http
@@ -39,6 +45,10 @@ protected void configure(HttpSecurity http) throws Exception {
3945
.addFilterBefore(jwtFilter, RequestHeaderAuthenticationFilter.class);
4046
}
4147

48+
/**
49+
* Configures CORS.
50+
* @return The CORS filter.
51+
*/
4252
@Bean
4353
public CorsFilter corsConfigurationSource() {
4454
CorsConfiguration configuration = new CorsConfiguration();
@@ -49,4 +59,5 @@ public CorsFilter corsConfigurationSource() {
4959
source.registerCorsConfiguration("/**", configuration);
5060
return new CorsFilter(source);
5161
}
62+
5263
}

backend/src/test/java/de/itermori/pse/kitroomfinder/backend/BackendApplicationTests.java

-13
This file was deleted.

backend/src/test/java/de/itermori/pse/kitroomfinder/backend/queryTests/UtilTests.java

+32-9
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,23 @@
55
import com.graphql.spring.boot.test.GraphQLResponse;
66
import com.graphql.spring.boot.test.GraphQLTestTemplate;
77
import io.micrometer.core.instrument.util.IOUtils;
8-
import org.json.JSONException;
9-
import org.skyscreamer.jsonassert.JSONAssert;
10-
import org.springframework.beans.factory.annotation.Autowired;
11-
import org.springframework.core.io.ClassPathResource;
12-
138
import java.io.IOException;
149
import java.nio.charset.StandardCharsets;
1510
import java.util.Calendar;
1611
import java.util.Date;
12+
import org.json.JSONException;
13+
import org.skyscreamer.jsonassert.JSONAssert;
14+
import org.springframework.core.io.ClassPathResource;
1715

1816
import static java.lang.String.format;
1917
import static org.assertj.core.api.Assertions.assertThat;
2018

19+
/**
20+
* Utility class that provides utility methods for the test classes.
21+
*
22+
* @author Lukas Zetto
23+
* @version 1.0
24+
*/
2125
public class UtilTests {
2226

2327
static final String GRAPHQL_QUERY_REQUEST_PATH = "graphql/resolver/query/request/%s.graphql";
@@ -32,11 +36,30 @@ private static String read(String location) throws IOException {
3236
StandardCharsets.UTF_8);
3337
}
3438

35-
public static void validate(GraphQLTestTemplate graphQLTestTemplate, String testname) throws IOException, JSONException {
39+
/**
40+
* Validates a GraphQL query.
41+
*
42+
* @param graphQLTestTemplate The GraphQL test template.
43+
* @param testname The name of the GraphQL query.
44+
* @throws IOException When the validation of the GraphQL query fails.
45+
* @throws JSONException When the validation of the GraphQL query fails.
46+
*/
47+
public static void validate(GraphQLTestTemplate graphQLTestTemplate, String testname)
48+
throws IOException, JSONException {
3649
compare(graphQLTestTemplate, testname);
3750
}
3851

39-
public static void validate(GraphQLTestTemplate graphQLTestTemplate, String testname, String user) throws IOException, JSONException {
52+
/**
53+
* Validates a GraphQL query.
54+
*
55+
* @param graphQLTestTemplate The GraphQL test template.
56+
* @param testname The name of the GraphQL query.
57+
* @param user The name of the user.
58+
* @throws IOException When the validation of the GraphQL query fails.
59+
* @throws JSONException When the validation of the GraphQL query fails.
60+
*/
61+
public static void validate(GraphQLTestTemplate graphQLTestTemplate, String testname, String user)
62+
throws IOException, JSONException {
4063
String token = JWT
4164
.create()
4265
.withIssuer("my-graphql-api")
@@ -48,10 +71,10 @@ public static void validate(GraphQLTestTemplate graphQLTestTemplate, String test
4871
compare(graphQLTestTemplate, testname);
4972
}
5073

51-
private static void compare(GraphQLTestTemplate graphQLTestTemplate, String testname) throws IOException, JSONException {
74+
private static void compare(GraphQLTestTemplate graphQLTestTemplate, String testname)
75+
throws IOException, JSONException {
5276
String expectedResultBody = read(format(GRAPHQL_QUERY_RESPONSE_PATH, testname));
5377
GraphQLResponse response = graphQLTestTemplate.postForResource(format(GRAPHQL_QUERY_REQUEST_PATH, testname));
54-
String test = response.getRawResponse().getBody();
5578
assertThat(response.isOk()).isTrue();
5679
JSONAssert.assertEquals(expectedResultBody, response.getRawResponse().getBody(), true);
5780
}

0 commit comments

Comments
 (0)