/** * Constructor using the specified allowed origin values. * @see #setAllowedOrigins(Collection) */ public OriginHandshakeInterceptor(Collection<String> allowedOrigins) { setAllowedOrigins(allowedOrigins); }
/** * Default constructor that auto-detects and instantiates a * {@link RequestUpgradeStrategy} suitable for the runtime container. * @throws IllegalStateException if no {@link RequestUpgradeStrategy} can be found. */ protected AbstractHandshakeHandler() { this(initRequestUpgradeStrategy()); }
private HandshakeHandler getOrCreateHandshakeHandler() { return (this.handshakeHandler != null ? this.handshakeHandler : new DefaultHandshakeHandler()); }
protected HandshakeInterceptor[] getInterceptors() { List<HandshakeInterceptor> interceptors = new ArrayList<>(this.interceptors.size() + 1); interceptors.addAll(this.interceptors); interceptors.add(new OriginHandshakeInterceptor(this.allowedOrigins)); return interceptors.toArray(new HandshakeInterceptor[0]); }
@Test public void applyAfterHandshakeOnly() { HandshakeInterceptorChain chain = new HandshakeInterceptorChain(interceptors, wsHandler); chain.applyAfterHandshake(request, response, null); verifyNoMoreInteractions(i1, i2, i3); }
@Override public void stop() { if (isRunning()) { this.running = false; if (this.handshakeHandler instanceof Lifecycle) { ((Lifecycle) this.handshakeHandler).stop(); } } }
@Override public void setServletContext(ServletContext servletContext) { RequestUpgradeStrategy strategy = getRequestUpgradeStrategy(); if (strategy instanceof ServletContextAware) { ((ServletContextAware) strategy).setServletContext(servletContext); } }
@Override protected void initServletContext(ServletContext servletContext) { for (Object handler : getUrlMap().values()) { if (handler instanceof ServletContextAware) { ((ServletContextAware) handler).setServletContext(servletContext); } } }
protected boolean isWebSocketVersionSupported(WebSocketHttpHeaders httpHeaders) { String version = httpHeaders.getSecWebSocketVersion(); String[] supportedVersions = getSupportedVersions(); for (String supportedVersion : supportedVersions) { if (supportedVersion.trim().equals(version)) { return true; } } return false; }
@Nullable private HttpSession getSession(ServerHttpRequest request) { if (request instanceof ServletServerHttpRequest) { ServletServerHttpRequest serverRequest = (ServletServerHttpRequest) request; return serverRequest.getServletRequest().getSession(isCreateSession()); } return null; }
public WebSocketHttpRequestHandler(WebSocketHandler wsHandler) { this(wsHandler, new DefaultHandshakeHandler()); }
protected HandshakeInterceptor[] getInterceptors() { List<HandshakeInterceptor> interceptors = new ArrayList<>(this.interceptors.size() + 1); interceptors.addAll(this.interceptors); interceptors.add(new OriginHandshakeInterceptor(this.allowedOrigins)); return interceptors.toArray(new HandshakeInterceptor[0]); }
@Override public void start() { if (!isRunning()) { this.running = true; if (this.handshakeHandler instanceof Lifecycle) { ((Lifecycle) this.handshakeHandler).start(); } } }
@Bean public DefaultHandshakeHandler handshakeHandler() { return new DefaultHandshakeHandler(requestUpgradeStrategy()); }
@Test(expected = IllegalArgumentException.class) public void invalidInput() { new OriginHandshakeInterceptor(null); }
@Override protected void registerStompEndpoints(StompEndpointRegistry registry) { // Can't rely on classpath detection RequestUpgradeStrategy upgradeStrategy = new TomcatRequestUpgradeStrategy(); registry.addEndpoint("/stomp") .setHandshakeHandler(new DefaultHandshakeHandler(upgradeStrategy)) .setAllowedOrigins("*"); }