Skip to content

Commit

Permalink
feat: upgrade to java 17 partial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tkuzynow committed Mar 29, 2024
1 parent 453d9c9 commit b0bc424
Show file tree
Hide file tree
Showing 38 changed files with 361 additions and 254 deletions.
59 changes: 52 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.12</version>
<version>3.0.6</version>
<relativePath/>
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>
<java.version>17</java.version>
<keycloak.version>17.0.0</keycloak.version>
<!-- force at least version 2.16 due to https://logging.apache.org/log4j/2.x/security.html -->
<log4j.version>2.19.0</log4j.version>
<openapi-generator-maven-plugin.version>6.2.1</openapi-generator-maven-plugin.version>
<openapi-generator-maven-plugin.version>6.6.0</openapi-generator-maven-plugin.version>
<springfox-boot-starter.version>3.0.0</springfox-boot-starter.version>
<jackson-databind-nullable.version>0.2.3</jackson-databind-nullable.version>
<spring-swagger-ui.version>2.10.0</spring-swagger-ui.version>
<spring-security-core.version>5.7.5</spring-security-core.version>
<spring-security-core.version>6.0.5</spring-security-core.version>
<ehcache.version>2.10.9.2</ehcache.version>
<javax.ws.rs-api.version>2.1.1</javax.ws.rs-api.version>
<java-jwt.version>3.12.1</java-jwt.version>
Expand All @@ -39,7 +39,9 @@
<liquibase-core.version>4.9.1</liquibase-core.version>
<hibernate.validator.version>8.0.0.Final</hibernate.validator.version>
<liquibase.maven.plugin.version>4.1.1</liquibase.maven.plugin.version>

<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<springfox.boot.starter.version>3.0.0</springfox.boot.starter.version>
</properties>

<dependencies>
Expand All @@ -60,11 +62,26 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
</dependency>

<!-- Spring dependencies -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${spring-security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${spring-security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>${spring-security-core.version}</version>
<version>${spring-security.version}</version>
</dependency>

<!-- caching dependencies -->
Expand Down Expand Up @@ -103,6 +120,28 @@
<version>${jackson-databind-nullable.version}</version>
</dependency>

<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.3.0</version>
</dependency>
<!-- SpringFox: generate YAML file from POJOs and generate documentation -->
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>2.2.15</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>${springfox.boot.starter.version}</version>
</dependency>
<dependency>
<groupId>io.swagger.parser.v3</groupId>
<artifactId>swagger-parser</artifactId>
<version>2.1.15</version>
</dependency>

<!-- json dependencies -->
<dependency>
<groupId>org.json</groupId>
Expand Down Expand Up @@ -201,6 +240,7 @@
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>


<!-- Test dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -263,7 +303,10 @@
<version>${log4j.version}</version>
</dependency>


<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
</dependency>

</dependencies>

Expand Down Expand Up @@ -306,7 +349,9 @@
<configOptions>
<interfaceOnly>true</interfaceOnly>
<sourceFolder>/</sourceFolder>
<useSpringBoot3>true</useSpringBoot3>
</configOptions>

<inputSpec>${project.basedir}/api/videoservice.yaml</inputSpec>
<generatorName>spring</generatorName>
<apiPackage>${project.groupId}.${project.artifactId}.generated.api.controller
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public ResponseEntity<Object> handleNoSuchElementException(
* @param request web request
* @return response entity
*/
@Override
@NonNull
protected ResponseEntity<Object> handleHttpMessageNotReadable(
final @NonNull HttpMessageNotReadableException ex,
Expand All @@ -85,7 +84,6 @@ protected ResponseEntity<Object> handleHttpMessageNotReadable(
* @param request web request
* @return response entity
*/
@Override
@NonNull
protected ResponseEntity<Object> handleMethodArgumentNotValid(
final @NonNull MethodArgumentNotValidException ex,
Expand Down Expand Up @@ -148,7 +146,7 @@ public ResponseEntity<Object> handleInternal(
LogService.logWarning(ex);

return handleExceptionInternal(
EMPTY_EXCEPTION, null, new HttpHeaders(), ex.getStatus(), request);
EMPTY_EXCEPTION, null, new HttpHeaders(), ex.getStatusCode(), request);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
package de.caritas.cob.videoservice.api.authorization;

import com.google.common.collect.Lists;
import java.util.List;
import java.util.stream.Stream;
import lombok.Getter;

/** Definition of all authorities and of the role-authority-mapping. */
@Getter
public enum Authority {
CONSULTANT(UserRole.CONSULTANT, "AUTHORIZATION_CONSULTANT_DEFAULT"),
USER(UserRole.USER, "AUTHORIZATION_USER_DEFAULT"),

JITSI_TECHNICAL(UserRole.JITSI_TECHNICAL, "AUTHORIZATION_JITSI_TECHNICAL_DEFAULT");

private final UserRole role;
private final String authorityName;
private final List<String> authorities;

Authority(final UserRole role, final String authorityName) {
this.role = role;
this.authorityName = authorityName;
this.authorities = Lists.newArrayList(authorityName);
}

/**
Expand All @@ -30,12 +34,13 @@ public static Authority fromRoleName(String roleName) {
.orElse(null);
}

/**
* Returns the authority name for the given {@link Authority}.
*
* @return authority name for the given {@link Authority}
*/
public String getAuthority() {
return this.authorityName;
public static class AuthorityValue {

private AuthorityValue() {}

public static final String PREFIX = "AUTHORIZATION_";
public static final String CONSULTANT = PREFIX + "CONSULTANT_DEFAULT";
public static final String USER = PREFIX + "USER_DEFAULT";
public static final String JITSI_TECHNICAL = PREFIX + "JITSI_TECHNICAL_DEFAULT";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@
@Component
public class RoleAuthorizationAuthorityMapper implements GrantedAuthoritiesMapper {

/**
* Maps all {@link Authority} definitions to the corresponding roles.
*
* @param authorities all given authorities
* @return mapped role authorities collections
*/
@Override
public Collection<? extends GrantedAuthority> mapAuthorities(
Collection<? extends GrantedAuthority> authorities) {
Expand All @@ -31,11 +25,12 @@ public Collection<? extends GrantedAuthority> mapAuthorities(
return mapAuthorities(roleNames);
}

private Set<GrantedAuthority> mapAuthorities(Set<String> roleNames) {
public Set<GrantedAuthority> mapAuthorities(Set<String> roleNames) {
return roleNames.stream()
.map(Authority::fromRoleName)
.filter(Objects::nonNull)
.map(Authority::getAuthority)
.map(Authority::getAuthorities)
.flatMap(Collection::parallelStream)
.map(SimpleGrantedAuthority::new)
.collect(Collectors.toSet());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import de.caritas.cob.videoservice.api.tenant.TenantContext;
import de.caritas.cob.videoservice.generated.api.controller.VideocallsApi;
import io.swagger.annotations.Api;
import jakarta.validation.Valid;
import java.util.UUID;
import javax.validation.Valid;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package de.caritas.cob.videoservice.api.model;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.Table;
import java.time.LocalDateTime;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.caritas.cob.videoservice.api.service.httpheader;

import jakarta.servlet.http.HttpServletRequest;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
import java.time.Duration;
import java.time.LocalDateTime;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.hc.client5.http.classic.HttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.client5.http.protocol.RedirectStrategy;
import org.apache.http.impl.client.LaxRedirectStrategy;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -50,7 +51,9 @@ public MessageControllerApi getMessageControllerApi() {
final HttpComponentsClientHttpRequestFactory factory =
new HttpComponentsClientHttpRequestFactory();
final HttpClient httpClient =
HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();
HttpClientBuilder.create()
.setRedirectStrategy((RedirectStrategy) new LaxRedirectStrategy())
.build();
factory.setHttpClient(httpClient);
restTemplate.setRequestFactory(factory);
de.caritas.cob.videoservice.messageservice.generated.ApiClient apiClient =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import de.caritas.cob.videoservice.api.service.LogService;
import de.caritas.cob.videoservice.api.service.statistics.event.StatisticsEvent;
import jakarta.validation.constraints.NotNull;
import java.nio.charset.StandardCharsets;
import javax.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.MessageBuilder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package de.caritas.cob.videoservice.api.tenant;

import jakarta.servlet.http.HttpServletRequest;
import java.util.Map;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.keycloak.KeycloakSecurityContext;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package de.caritas.cob.videoservice.api.tenant;

import de.caritas.cob.videoservice.api.service.httpheader.TenantHeaderSupplier;
import jakarta.servlet.http.HttpServletRequest;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
import lombok.AllArgsConstructor;
import lombok.NonNull;
import org.springframework.stereotype.Component;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import de.caritas.cob.videoservice.api.service.TenantService;
import de.caritas.cob.videoservice.filter.SubdomainExtractor;
import jakarta.servlet.http.HttpServletRequest;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
import lombok.AllArgsConstructor;
import lombok.NonNull;
import org.springframework.stereotype.Component;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.caritas.cob.videoservice.api.tenant;

import jakarta.servlet.http.HttpServletRequest;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
import org.keycloak.representations.AccessToken;
import org.springframework.stereotype.Component;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.caritas.cob.videoservice.api.tenant;

import jakarta.servlet.http.HttpServletRequest;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;

public interface TenantResolver {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import static com.google.common.collect.Lists.newArrayList;

import jakarta.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import de.caritas.cob.videoservice.api.authorization.VideoUser;
import de.caritas.cob.videoservice.api.exception.KeycloakException;
import jakarta.servlet.http.HttpServletRequest;
import java.security.Principal;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.keycloak.KeycloakSecurityContext;
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
import org.springframework.beans.factory.annotation.Qualifier;
Expand Down
Loading

0 comments on commit b0bc424

Please sign in to comment.