javax.websocket.server.HandshakeRequest Java Examples
The following examples show how to use
javax.websocket.server.HandshakeRequest.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WsConfigurator.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
private EffectivePerson getEffectivePerson(HandshakeRequest request) { try { List<String> list = request.getParameterMap().get(HttpToken.X_Token); String token = null; if (ListTools.isNotEmpty(list)) { token = list.get(0); } if (StringUtils.isNotEmpty(token)) { HttpToken httpToken = new HttpToken(); return httpToken.who(token, Config.token().getCipher()); } } catch (Exception e) { e.printStackTrace(); } return EffectivePerson.anonymous(); }
Example #2
Source File: WsConfigurator.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
private EffectivePerson getEffectivePerson(HandshakeRequest request) { try { List<String> list = request.getParameterMap().get(HttpToken.X_Token); String token = null; if (ListTools.isNotEmpty(list)) { token = list.get(0); } if (StringUtils.isNotEmpty(token)) { HttpToken httpToken = new HttpToken(); return httpToken.who(token, Config.token().getCipher()); } } catch (Exception e) { e.printStackTrace(); } return EffectivePerson.anonymous(); }
Example #3
Source File: MCRWebsocketDefaultConfigurator.java From mycore with GNU General Public License v3.0 | 5 votes |
@Override public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) { HttpSession httpSession = (HttpSession) request.getHttpSession(); config.getUserProperties().put(MCRServlet.ATTR_MYCORE_SESSION, httpSession.getAttribute(MCRServlet.ATTR_MYCORE_SESSION)); config.getUserProperties().put(HTTP_SESSION, httpSession); }
Example #4
Source File: WebSocketUtil.java From scipio-erp with Apache License 2.0 | 5 votes |
/** Helper method for session configurator. WARN: subject to change */ public static void saveHttpSession(ServerEndpointConfig config, HandshakeRequest request) { // TODO: REVIEW: storing HttpSession here is probably not standard (?), though it may work on current version of Tomcat // see discussions on: https://stackoverflow.com/questions/17936440/accessing-httpsession-from-httpservletrequest-in-a-web-socket-serverendpoint // Client code should not assume the session is set this way - always go through getHttpSession config.getUserProperties().put(HttpSession.class.getName(), request.getHttpSession()); }
Example #5
Source File: RestrictedGuacamoleWebSocketTunnelEndpoint.java From guacamole-client with Apache License 2.0 | 5 votes |
@Override public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) { super.modifyHandshake(config, request, response); // Store tunnel request and tunnel request service for retrieval // upon WebSocket open Map<String, Object> userProperties = config.getUserProperties(); userProperties.clear(); userProperties.put(TUNNEL_REQUEST_PROPERTY, new WebSocketTunnelRequest(request)); userProperties.put(TUNNEL_REQUEST_SERVICE_PROPERTY, tunnelRequestServiceProvider.get()); }
Example #6
Source File: HttpChatSessionConfigurator.java From belling-admin with Apache License 2.0 | 5 votes |
@Override public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) { HttpSession httpSession = (HttpSession) request.getHttpSession(); if (null != httpSession) { config.getUserProperties().put(HttpSession.class.getName(), httpSession); } }
Example #7
Source File: Channels.java From symphonyx with Apache License 2.0 | 5 votes |
@Override public void modifyHandshake(final ServerEndpointConfig config, final HandshakeRequest request, final HandshakeResponse response) { final HttpSession httpSession = (HttpSession) request.getHttpSession(); config.getUserProperties().put(HttpSession.class.getName(), httpSession); }
Example #8
Source File: GuiceInjectorEndpointConfigurator.java From che with Eclipse Public License 2.0 | 5 votes |
@Override public void modifyHandshake( ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { HttpSession httpSession = (HttpSession) request.getHttpSession(); if (httpSession != null) { Object sessionSubject = httpSession.getAttribute("che_subject"); if (sessionSubject != null) { sec.getUserProperties().put("che_subject", sessionSubject); } } }
Example #9
Source File: AngularBeansServletContextListener.java From AngularBeans with GNU Lesser General Public License v3.0 | 5 votes |
private ServerEndpointConfig.Configurator configuratorFor(final String prefix, final boolean isRaw) { return new ServerEndpointConfig.Configurator() { @Override public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException { try { return endpointClass.getConstructor(SockJsServer.class, String.class, String.class) .newInstance(sockJsServer, context.getContextPath(), prefix); } catch (Exception e) { throw new RuntimeException(e); } } @Override public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { if (isRaw) { // We have no reliable key (like session id) to save // headers with for raw websocket requests return; } String path = request.getRequestURI().getPath(); Matcher matcher = SESSION_PATTERN.matcher(path); if (matcher.matches()) { String sessionId = matcher.group(1); saveHeaders(sessionId, request.getHeaders()); } } }; }
Example #10
Source File: WsConfigurator.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
@Override public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) { try { EffectivePerson effectivePerson = this.getEffectivePerson(request); config.getUserProperties().put(HttpToken.X_Person, effectivePerson); } catch (Exception e) { e.printStackTrace(); } }
Example #11
Source File: WsConfigurator.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
@Override public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) { try { EffectivePerson effectivePerson = this.getEffectivePerson(request); config.getUserProperties().put(HttpToken.X_Person, effectivePerson); } catch (Exception e) { e.printStackTrace(); } }
Example #12
Source File: GetHttpSessionConfigurator.java From AngularBeans with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) { HttpSession httpSession = (HttpSession) request.getHttpSession(); config.getUserProperties() .put(HttpSession.class.getName(), httpSession); }
Example #13
Source File: SockJsServlet.java From AngularBeans with GNU Lesser General Public License v3.0 | 5 votes |
private ServerEndpointConfig.Configurator configuratorFor(final String prefix, final boolean isRaw) { return new ServerEndpointConfig.Configurator() { @Override public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException { try { return endpointClass.getConstructor(SockJsServer.class, String.class, String.class) .newInstance(sockJsServer, getServletContext().getContextPath(), prefix); } catch (Exception e) { throw new RuntimeException(e); } } @Override public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { if (isRaw) { // We have no reliable key (like session id) to save // headers with for raw websocket requests return; } String path = request.getRequestURI().getPath(); Matcher matcher = SESSION_PATTERN.matcher(path); if (matcher.matches()) { String sessionId = matcher.group(1); saveHeaders(sessionId, request.getHeaders()); } } }; }
Example #14
Source File: ChatEndpointConfig.java From BotLibre with Eclipse Public License 1.0 | 5 votes |
@Override public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) { HttpSession httpSession = (HttpSession)request.getHttpSession(); if (httpSession == null) { return; } config.getUserProperties().put(HttpSession.class.getName(), httpSession); }
Example #15
Source File: WebsocketSecurityConfigurator.java From datawave with Apache License 2.0 | 5 votes |
@Override public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { super.modifyHandshake(sec, request, response); sec.getUserProperties().put(WebsocketSecurityInterceptor.SESSION_PRINCIPAL, request.getUserPrincipal()); sec.getUserProperties().put(WebsocketSecurityInterceptor.SESSION_SUBJECT, SecurityContextAssociation.getSubject()); sec.getUserProperties().put(WebsocketSecurityInterceptor.SESSION_CREDENTIAL, SecurityContextAssociation.getPrincipal()); Map<String,List<String>> headers = request.getHeaders(); if (headers != null) { List<String> loginHeader = headers.get(REQUEST_LOGIN_TIME_HEADER); if (loginHeader != null && !loginHeader.isEmpty()) { sec.getUserProperties().put(REQUEST_LOGIN_TIME_HEADER, loginHeader.get(0)); } } }
Example #16
Source File: ServerContainerInitializeListener.java From everrest with Eclipse Public License 2.0 | 5 votes |
private Configurator createConfigurator() { return new Configurator() { @Override public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { super.modifyHandshake(sec, request, response); final HttpSession httpSession = (HttpSession)request.getHttpSession(); if (httpSession != null) { sec.getUserProperties().put(HTTP_SESSION_ATTRIBUTE, httpSession); } final SecurityContext securityContext = createSecurityContext(request); sec.getUserProperties().put(SECURITY_CONTEXT, securityContext); } }; }
Example #17
Source File: WebsocketSessionConfigurator.java From uyuni with GNU General Public License v2.0 | 5 votes |
@Override public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) { HttpSession httpSession = (HttpSession)request.getHttpSession(); config.getUserProperties().put("webUserID", httpSession.getAttribute("webUserID")); }
Example #18
Source File: ServerContainerInitializeListener.java From everrest with Eclipse Public License 2.0 | 5 votes |
protected SecurityContext createSecurityContext(HandshakeRequest req) { final boolean isSecure = false; //todo: get somehow from request final Principal principal = req.getUserPrincipal(); if (principal == null) { return new SimpleSecurityContext(isSecure); } final String authenticationScheme = "BASIC"; //todo: get somehow from request final Set<String> userRoles = new LinkedHashSet<>(); for (String declaredRole : webApplicationDeclaredRoles.getDeclaredRoles()) { if (req.isUserInRole(declaredRole)) { userRoles.add(declaredRole); } } return new SimpleSecurityContext(new SimplePrincipal(principal.getName()), userRoles, authenticationScheme, isSecure); }
Example #19
Source File: RestrictedGuacamoleWebSocketTunnelEndpoint.java From guacamole-client with Apache License 2.0 | 5 votes |
@Override public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) { super.modifyHandshake(config, request, response); // Store tunnel request and tunnel request service for retrieval // upon WebSocket open Map<String, Object> userProperties = config.getUserProperties(); userProperties.clear(); userProperties.put(TUNNEL_REQUEST_PROPERTY, new WebSocketTunnelRequest(request)); userProperties.put(TUNNEL_REQUEST_SERVICE_PROPERTY, tunnelRequestServiceProvider.get()); }
Example #20
Source File: DefaultServerEndpointConfig.java From ameba with MIT License | 4 votes |
/** * <p>Constructor for DefaultServerEndpointConfig.</p> * * @param manager a manager * @param endpointClass a {@link java.lang.Class} endpoint class. * @param webSocketConf a {@link ameba.websocket.WebSocket} object. */ public DefaultServerEndpointConfig(final InjectionManager manager, Class endpointClass, final WebSocket webSocketConf) { path = webSocketConf.path(); subprotocols = Arrays.asList(webSocketConf.subprotocols()); encoders = Lists.newArrayList(webSocketConf.encoders()); decoders = Lists.newArrayList(webSocketConf.decoders()); for (Class<? extends Extension> extensionClass : webSocketConf.extensions()) { extensions.add(Injections.getOrCreate(manager, extensionClass)); } final WebSocketEndpointProvider provider = manager.getInstance(WebSocketEndpointProvider.class); final EndpointMeta endpointMeta = provider.parseMeta(endpointClass, webSocketConf); final ServerEndpointConfig.Configurator cfgr = Injections.getOrCreate(manager, webSocketConf.configurator()); serverEndpointConfigurator = new ServerEndpointConfig.Configurator() { @Override public String getNegotiatedSubprotocol(List<String> supported, List<String> requested) { return cfgr.getNegotiatedSubprotocol(supported, requested); } @Override public List<Extension> getNegotiatedExtensions(List<Extension> installed, List<Extension> requested) { return cfgr.getNegotiatedExtensions(installed, requested); } @Override public boolean checkOrigin(String originHeaderValue) { return cfgr.checkOrigin(originHeaderValue); } @Override public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { cfgr.modifyHandshake(sec, request, response); } @Override public <T> T getEndpointInstance(Class<T> eClass) throws InstantiationException { if (EndpointDelegate.class.equals(eClass)) { return eClass.cast(new EndpointDelegate(endpointMeta)); } return cfgr.getEndpointInstance(eClass); } }; }
Example #21
Source File: WebSocketConfig.java From mdw with Apache License 2.0 | 4 votes |
@Override public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { List<String> header = new ArrayList<>(); header.add(ApplicationContext.getHostname()); response.getHeaders().put("mdw-hostname", header); }
Example #22
Source File: DefaultServerEndpointConfigurator.java From tomcatsrc with Apache License 2.0 | 4 votes |
@Override public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { // NO-OP }
Example #23
Source File: WSEndpointConfigurator.java From diirt with MIT License | 4 votes |
@Override public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) { config.getUserProperties().put("session",request.getHttpSession()); }
Example #24
Source File: ExampleSessionConfigurator.java From scipio-erp with Apache License 2.0 | 4 votes |
@Override public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) { config.getUserProperties().put(HttpSession.class.getName(), request.getHttpSession()); }
Example #25
Source File: HttpSessionConfigurator.java From realtime-log with Apache License 2.0 | 4 votes |
@Override public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { HttpSession httpSession = (HttpSession) request.getHttpSession(); sec.getUserProperties().put(HttpSession.class.getName(), httpSession); }
Example #26
Source File: ServerEndpointRegistration.java From spring-analysis-note with MIT License | 4 votes |
@Override public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { super.modifyHandshake(this, request, response); }
Example #27
Source File: DefaultContainerConfigurator.java From quarkus-http with Apache License 2.0 | 4 votes |
@Override public void modifyHandshake(final ServerEndpointConfig sec, final HandshakeRequest request, final HandshakeResponse response) { }
Example #28
Source File: ServerEndpointRegistration.java From java-technology-stack with MIT License | 4 votes |
@Override public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { super.modifyHandshake(this, request, response); }
Example #29
Source File: GLSPConfigurator.java From graphical-lsp with Eclipse Public License 2.0 | 4 votes |
@Override public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { /* do nothing */ }
Example #30
Source File: GraphQLWSEndpointConfigurer.java From samples with MIT License | 4 votes |
@Override public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { endpoint.modifyHandshake(sec, request, response); }