Skip to content

Commit

Permalink
Google Java Format
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Jan 15, 2024
1 parent f1c9c2b commit c12d25d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.twtw.backend.config.socket;

import com.twtw.backend.global.properties.RabbitMQProperties;

import lombok.RequiredArgsConstructor;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.messaging.simp.config.ChannelRegistration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.twtw.backend.config.socket;

import com.twtw.backend.config.security.jwt.TokenProvider;

import lombok.RequiredArgsConstructor;

import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.messaging.Message;
Expand All @@ -28,21 +30,26 @@ public Message<?> preSend(final Message<?> message, final MessageChannel channel
final StompHeaderAccessor acessor = StompHeaderAccessor.wrap(message);

if (StompCommand.CONNECT == acessor.getCommand()) {
final Optional<String> headerValue = Optional.ofNullable(acessor.getFirstNativeHeader(AUTHORIZATION_HEADER));
resolveToken(headerValue).ifPresent(header -> {
tokenProvider.validateToken(header);
SecurityContextHolder.getContext().setAuthentication(tokenProvider.getAuthentication(header));
});
final Optional<String> headerValue =
Optional.ofNullable(acessor.getFirstNativeHeader(AUTHORIZATION_HEADER));
resolveToken(headerValue)
.ifPresent(
header -> {
tokenProvider.validateToken(header);
SecurityContextHolder.getContext()
.setAuthentication(tokenProvider.getAuthentication(header));
});
}
return message;
}

private Optional<String> resolveToken(final Optional<String> headerValue) {
return headerValue.map(header -> {
if (header.startsWith(BEARER_PREFIX)) {
return header.substring(7);
}
return header;
});
return headerValue.map(
header -> {
if (header.startsWith(BEARER_PREFIX)) {
return header.substring(7);
}
return header;
});
}
}

0 comments on commit c12d25d

Please sign in to comment.