[EDIT] MODIFICACION DE INTERCEPTOR PARA WEBSOCKET

parent 6cf8a188
......@@ -3,6 +3,7 @@ package web.multitask.trismegistoservices.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.ChannelRegistration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
......@@ -20,8 +21,16 @@ public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.enableSimpleBroker("/topic");
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.setPoolSize(1);
taskScheduler.setThreadNamePrefix("wss-heartbeat-thread-");
taskScheduler.initialize();
registry.enableSimpleBroker("/topic")
.setHeartbeatValue(new long[]{10000, 10000})
.setTaskScheduler(taskScheduler);
registry.setApplicationDestinationPrefixes("/ws");
}
@Override
......
......@@ -31,17 +31,16 @@ public class AuthChannelInterceptorAdapter implements ChannelInterceptor {
assert accessor != null;
if (StompCommand.CONNECT == accessor.getCommand()) {
LinkedMultiValueMap<String, String> map = (LinkedMultiValueMap<String, String>) accessor.getHeader("nativeHeaders");
String authorization = Objects.requireNonNull(Objects.requireNonNull(map).get("Authorization")).get(0);
assert authorization != null;
final String token = authorization.split(" ")[1];
if(token != null && jwtTokenUtil.validateToken(token)){
JSONObject jsonToken = new JSONObject(jwtTokenUtil.getDataToken(token));
UserDetails userDetails = userRepo.findByUsername(jsonToken.getString("username"));
// LinkedMultiValueMap<String, String> map = (LinkedMultiValueMap<String, String>) accessor.getHeader("nativeHeaders");
// String authorization = Objects.requireNonNull(Objects.requireNonNull(map).get("Authorization")).get(0);
// assert authorization != null;
// final String token = authorization.split(" ")[1];
// if(token != null && jwtTokenUtil.validateToken(token)){
// JSONObject jsonToken = new JSONObject(jwtTokenUtil.getDataToken(token));
UserDetails userDetails = userRepo.findByUsername("admin");
final UsernamePasswordAuthenticationToken user = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
accessor.setUser(user);
}
// }
}
return message;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment