Skip to content

Commit e285e08

Browse files
committed
fix: #202 fix logout process
1 parent 58cb25c commit e285e08

File tree

8 files changed

+12
-69
lines changed

8 files changed

+12
-69
lines changed

commons/src/main/java/pl/sknikod/kodemycommons/security/JwtAuthorizationFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected void doFilterInternal(
5454
@NonNull FilterChain filterChain
5555
) throws ServletException, IOException {
5656
extractBearer(request)
57-
.flatMapTry(jwtProvider::parseToken)
57+
.flatMap(jwtProvider::parseToken)
5858
.map(this::toUserPrincipal)
5959
.onFailure(th -> log.debug("Authenticate failure", th))
6060
.onSuccess(user -> authenticate(request, user));

commons/src/main/java/pl/sknikod/kodemycommons/security/JwtProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public Deserialize(UUID bearerId, Long id, String username, Integer state, Set<S
204204
@Setter
205205
@NoArgsConstructor
206206
public abstract static class Properties {
207-
private String secretKey = "";
207+
private String secretKey;
208208
private Integer bearerExpirationMin = 15;
209209
private Integer delegationExpirationMin = 60;
210210
}

kodemy-api-gateway/src/main/java/pl/sknikod/kodemygateway/util/LogoutGatewayFilterFactory.java renamed to kodemy-api-gateway/src/main/java/pl/sknikod/kodemygateway/util/LogoutRelayGatewayFilterFactory.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121

2222
@Component
2323
@Slf4j
24-
public class LogoutGatewayFilterFactory extends AbstractGatewayFilterFactory<Object> {
24+
public class LogoutRelayGatewayFilterFactory extends AbstractGatewayFilterFactory<Object> {
2525

26-
public LogoutGatewayFilterFactory() {
26+
public LogoutRelayGatewayFilterFactory() {
2727
super(Object.class);
2828
}
2929

3030
@Override
3131
public GatewayFilter apply(Object config) {
32-
return new LogoutGatewayFilter();
32+
return new LogoutRelayFilter();
3333
}
3434

3535
@Getter
@@ -41,10 +41,7 @@ public static class Config {
4141
}
4242

4343
@RequiredArgsConstructor
44-
private static final class LogoutGatewayFilter implements GatewayFilter, Ordered {
45-
private static final String ACCESS_TOKEN_COOKIE = "AUTH_CONTEXT";
46-
private static final String REFRESH_TOKEN_COOKIE = "AUTH_PERSIST";
47-
44+
private static final class LogoutRelayFilter implements GatewayFilter, Ordered {
4845
@Override
4946
public int getOrder() {
5047
return NettyWriteResponseFilter.WRITE_RESPONSE_FILTER_ORDER;
@@ -67,7 +64,8 @@ private void modifyHeaders(ServerHttpResponse response) {
6764
}
6865
response.getHeaders().addAll(
6966
HttpHeaders.SET_COOKIE,
70-
List.of(createExpiredCookie(ACCESS_TOKEN_COOKIE).toString(), createExpiredCookie(REFRESH_TOKEN_COOKIE).toString())
67+
List.of(createExpiredCookie(AuthCookies.ACCESS_TOKEN).toString(),
68+
createExpiredCookie(AuthCookies.REFRESH_TOKEN).toString())
7169
);
7270
}
7371

kodemy-api-gateway/src/main/java/pl/sknikod/kodemygateway/util/RewriteCookieToBearerGatewayFilterFactory.java

Lines changed: 0 additions & 52 deletions
This file was deleted.

kodemy-api-gateway/src/main/resources/application.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ spring:
1111
predicates:
1212
- Path=/api/auth/logout
1313
filters:
14-
- Logout
14+
- LogoutRelay
1515

1616
- id: oauth2_auth
1717
uri: ${service.baseUrl.auth}

kodemy-auth/src/main/resources/application-local.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ service:
3232
app:
3333
security:
3434
jwt:
35-
bearer-expiration-min: 2
35+
bearer-expiration-min: 60
3636
oauth2:
3737
baseUrl:
3838
front: http://localhost:3000

kodemy-backend/src/main/java/pl/sknikod/kodemybackend/configuration/SecurityConfiguration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
44
import lombok.AllArgsConstructor;
5+
import lombok.NoArgsConstructor;
56
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
67
import org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration;
78
import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -65,6 +66,7 @@ public JwtAuthorizationFilter jwtAuthorizationFilter(JwtProvider jwtProvider) {
6566
}
6667

6768
@Component
69+
@NoArgsConstructor
6870
@ConfigurationProperties(prefix = "app.security.jwt")
6971
public static class JwtProperties extends JwtProvider.Properties {
7072
}

kodemy-backend/src/main/resources/application-local.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ service:
2121
baseUrl:
2222
auth: http://localhost:8080
2323

24-
app:
25-
security:
26-
jwt:
27-
bearer-expiration-min: 60
28-
2924
eureka:
3025
client:
3126
enabled: false

0 commit comments

Comments
 (0)