Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
61 changes: 40 additions & 21 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>2.7.17</version>
<version>3.3.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand All @@ -20,7 +20,9 @@
<inceptionYear>2023</inceptionYear>

<properties>
<java.version>1.8</java.version>
<java.version>21</java.version>
<testcontainers.version>1.19.8</testcontainers.version>
<spring-framework.version>6.2.0-M3</spring-framework.version>
</properties>

<licenses>
Expand Down Expand Up @@ -52,7 +54,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>2.7.6</version>
<version>3.2.6</version>
</dependency>

<!-- Tests -->
Expand All @@ -70,25 +72,24 @@
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<version>5.7.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.17.6</version>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.17.6</version>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<version>1.17.6</version>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>

Expand All @@ -110,7 +111,7 @@
<dependency>
<groupId>com.giffing.bucket4j.spring.boot.starter</groupId>
<artifactId>bucket4j-spring-boot-starter</artifactId>
<version>0.8.1</version>
<version>0.12.7</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -119,26 +120,26 @@
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>2.9.3</version>
<version>3.1.8</version>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>jcache</artifactId>
<version>2.9.3</version>
<version>3.1.8</version>
</dependency>

<!-- Docs -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.7.0</version>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.5.0</version>
</dependency>

<!-- Mapper -->
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>3.1.1</version>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>com.github.java-json-tools</groupId>
Expand All @@ -148,7 +149,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>32.0.0-jre</version>
<version>33.2.1-jre</version>
</dependency>

<!-- Validation -->
Expand All @@ -157,13 +158,6 @@
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>

<!-- Hibernate -->
<dependency>
<groupId>com.vladmihalcea</groupId>
<artifactId>hibernate-types-52</artifactId>
<version>2.21.1</version>
</dependency>

<!-- Database/Postgres -->
<dependency>
<groupId>org.postgresql</groupId>
Expand Down Expand Up @@ -232,4 +226,29 @@
</plugins>
</build>

<repositories>
<repository>
<id>maven_central</id>
<name>Maven Central</name>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.oauth2.server.resource.OAuth2ResourceServerConfigurer;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
Expand Down Expand Up @@ -36,31 +38,27 @@ public class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
return http
.headers(req ->
req.frameOptions().sameOrigin()
.headers(req -> req
.frameOptions((HeadersConfigurer.FrameOptionsConfig::sameOrigin))
)
.cors()
.and()
.csrf().disable()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests(req -> req
.csrf((AbstractHttpConfigurer::disable))
.sessionManagement((session) -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(req -> req
// API Docs
.antMatchers(HttpMethod.GET, "/v3/api-docs", "/v3/api-docs/**").permitAll()
.requestMatchers(HttpMethod.GET, "/v3/api-docs", "/v3/api-docs/**").permitAll()
// Errors
.antMatchers(HttpMethod.GET, "/error").permitAll()
.requestMatchers(HttpMethod.GET, "/error").permitAll()
// Auth
.antMatchers(HttpMethod.POST, "/api/v1/auth/**").permitAll()
.requestMatchers(HttpMethod.POST, "/api/v1/auth/**").permitAll()
// API
.antMatchers(HttpMethod.GET, "/api/**").permitAll()
.antMatchers(HttpMethod.PATCH, "/api/**").hasAnyRole("ADMIN", "MAINTAINER")
.antMatchers(HttpMethod.POST, "/api/**").hasAnyRole("ADMIN", "MAINTAINER")
.antMatchers(HttpMethod.DELETE, "/api/**").hasAnyRole("ADMIN", "MAINTAINER")
.requestMatchers(HttpMethod.GET, "/api/**").permitAll()
.requestMatchers(HttpMethod.PATCH, "/api/**").hasAnyRole("ADMIN", "MAINTAINER")
.requestMatchers(HttpMethod.POST, "/api/**").hasAnyRole("ADMIN", "MAINTAINER")
.requestMatchers(HttpMethod.DELETE, "/api/**").hasAnyRole("ADMIN", "MAINTAINER")
// Others endpoints
.anyRequest().permitAll()
)
.oauth2ResourceServer(OAuth2ResourceServerConfigurer::jwt)
.oauth2ResourceServer((oauth2) -> oauth2.jwt(Customizer.withDefaults()))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import com.lucasjosino.hawapi.exceptions.auth.UserUnauthorizedException;
import com.lucasjosino.hawapi.exceptions.specification.OperatorNotFoundException;
import com.lucasjosino.hawapi.models.http.ExceptionResponse;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.MethodArgumentNotValidException;
Expand All @@ -23,7 +25,6 @@
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Map;
Expand Down Expand Up @@ -75,7 +76,7 @@ public ResponseEntity<Object> handleBadRequestException(
protected ResponseEntity<Object> handleMethodArgumentNotValid(
MethodArgumentNotValidException ex,
HttpHeaders headers,
HttpStatus status,
HttpStatusCode status,
WebRequest request
) {
Optional<ObjectError> error = ex.getBindingResult().getAllErrors().stream().findFirst();
Expand All @@ -92,7 +93,6 @@ protected ResponseEntity<Object> handleMethodArgumentNotValid(
return handleBadRequestException(new BadRequestException(message), servletRequest);
}


@ExceptionHandler(SaveConflictException.class)
public ResponseEntity<Object> handleConflictException(
SaveConflictException ex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

import javax.annotation.PostConstruct;
import jakarta.annotation.PostConstruct;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import javax.validation.Valid;
import jakarta.validation.Valid;

/**
* A base auth controller interface with all required endpoints.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import jakarta.validation.Valid;

import java.io.IOException;
import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import jakarta.validation.Valid;

import java.io.IOException;
import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import jakarta.validation.Valid;

import java.io.IOException;
import java.util.List;
import java.util.UUID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import jakarta.validation.Valid;

import java.io.IOException;
import java.util.List;
import java.util.UUID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequestWrapper;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.Collections;
import java.util.Enumeration;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.lucasjosino.hawapi.filters.http;

import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;
import org.springframework.web.filter.UrlHandlerFilter;

import java.io.IOException;

/**
* Request filter to handle url trailing slash forwarding using {@link UrlHandlerFilter}
*
* @author Lucas Josino
* @since 1.3.0
*/
@Component
@SuppressWarnings("NullableProblems")
public class TrailingSlashHandlerFilter extends OncePerRequestFilter {

@Override
protected void doFilterInternal(
HttpServletRequest request,
HttpServletResponse response,
FilterChain filterChain
) throws ServletException, IOException {
UrlHandlerFilter filter = UrlHandlerFilter.trimTrailingSlash("/**").andHandleRequest().build();
filter.doFilter(request, response, filterChain);
}
}
13 changes: 7 additions & 6 deletions src/main/java/com/lucasjosino/hawapi/models/ActorModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import com.lucasjosino.hawapi.models.base.BaseModel;
import org.hibernate.annotations.Type;
import jakarta.persistence.*;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;

import javax.persistence.*;
import java.time.LocalDate;
import java.util.List;
import java.util.Set;
Expand All @@ -21,7 +22,7 @@ public class ActorModel extends BaseModel {
@Column(name = "last_name", nullable = false)
private String lastName;

@Type(type = "list-array")
@JdbcTypeCode(SqlTypes.ARRAY)
@Column(columnDefinition = "varchar[]")
private List<String> nicknames;

Expand All @@ -39,11 +40,11 @@ public class ActorModel extends BaseModel {
@Column
private String nationality;

@Type(type = "list-array")
@JdbcTypeCode(SqlTypes.ARRAY)
@Column(columnDefinition = "varchar[]")
private List<String> seasons;

@Type(type = "list-array")
@JdbcTypeCode(SqlTypes.ARRAY)
@Column(columnDefinition = "varchar[]")
private List<String> awards;

Expand All @@ -54,7 +55,7 @@ public class ActorModel extends BaseModel {
@JoinColumn(name = "actor_uuid", referencedColumnName = "uuid", insertable = false, updatable = false)
private Set<ActorSocialModel> socials;

@Type(type = "list-array")
@JdbcTypeCode(SqlTypes.ARRAY)
@Column(columnDefinition = "text[]")
private List<String> images;

Expand Down
Loading