use of org.springframework.web.socket.server.support.DefaultHandshakeHandler in project spring-framework by spring-projects.
the class DefaultHandshakeHandlerTests method setup.
@Before
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
this.handshakeHandler = new DefaultHandshakeHandler(this.upgradeStrategy);
}
use of org.springframework.web.socket.server.support.DefaultHandshakeHandler in project steve by RWTH-i5-IDSG.
the class WebSocketConfiguration method registerWebSocketHandlers.
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
policy.setMaxTextMessageBufferSize(MAX_MSG_SIZE);
policy.setMaxTextMessageSize(MAX_MSG_SIZE);
policy.setIdleTimeout(IDLE_TIMEOUT);
List<AbstractWebSocketEndpoint> endpoints = getEndpoints();
String[] protocols = endpoints.stream().map(e -> e.getVersion().getValue()).toArray(String[]::new);
OcppWebSocketUpgrader upgradeStrategy = new OcppWebSocketUpgrader(policy, endpoints, chargePointRepository, notificationService, chargePointHelperService);
DefaultHandshakeHandler handler = new DefaultHandshakeHandler(upgradeStrategy);
handler.setSupportedProtocols(protocols);
for (AbstractWebSocketEndpoint endpoint : endpoints) {
registry.addHandler(endpoint, "/websocket/CentralSystemService/*").setHandshakeHandler(handler).setAllowedOrigins("*");
}
}
use of org.springframework.web.socket.server.support.DefaultHandshakeHandler in project cetc by DiscoverForever.
the class WebsocketConfiguration method defaultHandshakeHandler.
private DefaultHandshakeHandler defaultHandshakeHandler() {
return new DefaultHandshakeHandler() {
@Override
protected Principal determineUser(ServerHttpRequest request, WebSocketHandler wsHandler, Map<String, Object> attributes) {
Principal principal = request.getPrincipal();
if (principal == null) {
Collection<SimpleGrantedAuthority> authorities = new ArrayList<>();
authorities.add(new SimpleGrantedAuthority(AuthoritiesConstants.ANONYMOUS));
principal = new AnonymousAuthenticationToken("WebsocketConfiguration", "anonymous", authorities);
}
return principal;
}
};
}
use of org.springframework.web.socket.server.support.DefaultHandshakeHandler in project ArTEMiS by ls1intum.
the class WebsocketConfiguration method defaultHandshakeHandler.
private DefaultHandshakeHandler defaultHandshakeHandler() {
return new DefaultHandshakeHandler() {
@Override
protected Principal determineUser(ServerHttpRequest request, WebSocketHandler wsHandler, Map<String, Object> attributes) {
Principal principal = request.getPrincipal();
if (principal == null) {
Collection<SimpleGrantedAuthority> authorities = new ArrayList<>();
authorities.add(new SimpleGrantedAuthority(AuthoritiesConstants.ANONYMOUS));
principal = new AnonymousAuthenticationToken("WebsocketConfiguration", "anonymous", authorities);
}
return principal;
}
};
}
use of org.springframework.web.socket.server.support.DefaultHandshakeHandler in project spring-framework by spring-projects.
the class WebMvcStompWebSocketEndpointRegistrationTests method handshakeHandlerAndInterceptorWithAllowedOrigins.
@Test
public void handshakeHandlerAndInterceptorWithAllowedOrigins() {
WebMvcStompWebSocketEndpointRegistration registration = new WebMvcStompWebSocketEndpointRegistration(new String[] { "/foo" }, this.handler, this.scheduler);
DefaultHandshakeHandler handshakeHandler = new DefaultHandshakeHandler();
HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
String origin = "https://mydomain.com";
registration.setHandshakeHandler(handshakeHandler).addInterceptors(interceptor).setAllowedOrigins(origin);
MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
assertThat(mappings.size()).isEqualTo(1);
Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next();
assertThat(entry.getValue()).isEqualTo(Arrays.asList("/foo"));
WebSocketHttpRequestHandler requestHandler = (WebSocketHttpRequestHandler) entry.getKey();
assertThat(requestHandler.getWebSocketHandler()).isNotNull();
assertThat(requestHandler.getHandshakeHandler()).isSameAs(handshakeHandler);
assertThat(requestHandler.getHandshakeInterceptors().size()).isEqualTo(2);
assertThat(requestHandler.getHandshakeInterceptors().get(0)).isEqualTo(interceptor);
assertThat(requestHandler.getHandshakeInterceptors().get(1).getClass()).isEqualTo(OriginHandshakeInterceptor.class);
}
Aggregations