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
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.api.twitter.security.configuration;

import com.api.twitter.security.domain.service.UserCredentialsService;
import com.api.twitter.security.domain.service.TokenService;
import com.api.twitter.security.domain.service.UserCredentialsService;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
Expand All @@ -17,12 +16,14 @@

@Component
public class SecurityAuthenticationFilter extends OncePerRequestFilter {
@Autowired
private TokenService tokenService;

@Autowired
private UserCredentialsService userCredentialsService;

public SecurityAuthenticationFilter(TokenService tokenService, UserCredentialsService userCredentialsService) {
this.tokenService = tokenService;
this.userCredentialsService = userCredentialsService;
}

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
String token = recoverToken(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.time.LocalDateTime;
import java.time.ZoneOffset;

@Getter
@Service
public class JWTService implements TokenService {
@Value(value = "${api.security.token.secret}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.api.twitter.security.domain.service;

import com.api.twitter.security.application.dto.UserLoginRequest;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

@Component
@Service
public interface TokenService {
public String generateToken(UserLoginRequest userLoginRequest);

Expand Down
43 changes: 30 additions & 13 deletions src/main/resources/application-dev.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
server:
port: ${PORT:8080}

spring:
datasource:
url: jdbc:h2:mem:dev
username: dev
password: dev
application:
name: twitter-api
title: "Twitter API"
version: ${APP_VERSION:"x.x.x"}
url: ${SERVER_URL:http://localhost:8080/}
datasource:
url: ${DB_URL}
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
driver-class-name: org.postgresql.Driver

cache:
type: REDIS

jpa:
hibernate:
ddl-auto: none
show-sql: true
data:
redis:
url: ${REDIS_URL:redis://localhost:6379}
web:
pageable:
max-page-size: 50

h2:
console:
enabled: true
api:
security:
token:
secret: ${JWT_SECRET:secret}
issuer: ${JWT_ISSUER:issuer}
expiration-seconds: ${JWT_EXPIRATION_SECONDS:3600}

flyway:
enabled: true
springdoc:
writer-with-default-pretty-printer: true
swagger-ui:
syntaxHighlight:
activated: true
7 changes: 4 additions & 3 deletions src/main/resources/application-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ spring:
title: "Twitter API"
version: ${APP_VERSION:"x.x.x"}
url: ${SERVER_URL:http://localhost:8080/}

datasource:
url: jdbc:h2:mem:testdb
driver-class-name: org.h2.Driver
username: test
password: test
driver-class-name: org.h2.Driver
jpa:
hibernate:
ddl-auto: 'create-drop'
Expand All @@ -29,6 +30,6 @@ springdoc:
api:
security:
token:
secret: secret
issuer: issuer
secret: "secret"
issuer: "issuer"
expiration-seconds: 3600