static private Optional<Jsr356HandshakePrincipal> unwrap(Session session) { Principal userPrincipal = session.getUserPrincipal(); if (userPrincipal != null && userPrincipal instanceof Jsr356HandshakePrincipal) { return Optional.of((Jsr356HandshakePrincipal)userPrincipal); } return Optional.empty(); }
@Override public void initializeNativeSession(Session session) { super.initializeNativeSession(session); this.uri = session.getRequestURI(); this.acceptedProtocol = session.getNegotiatedSubprotocol(); List<Extension> standardExtensions = getNativeSession().getNegotiatedExtensions(); if (!CollectionUtils.isEmpty(standardExtensions)) { this.extensions = new ArrayList<>(standardExtensions.size()); for (Extension standardExtension : standardExtensions) { this.extensions.add(new StandardToWebSocketExtensionAdapter(standardExtension)); } this.extensions = Collections.unmodifiableList(this.extensions); } else { this.extensions = Collections.emptyList(); } if (this.user == null) { this.user = session.getUserPrincipal(); } }
.pathInfo(pathInfo) .destroyable(false) .userPrincipal(session.getUserPrincipal()) .remoteInetSocketAddress(new Callable<InetSocketAddress>() { @Override
@Test @SuppressWarnings("resource") public void getPrincipalWithNativeSession() { TestPrincipal user = new TestPrincipal("joe"); Session nativeSession = Mockito.mock(Session.class); given(nativeSession.getUserPrincipal()).willReturn(user); StandardWebSocketSession session = new StandardWebSocketSession(this.headers, this.attributes, null, null); session.initializeNativeSession(nativeSession); assertSame(user, session.getPrincipal()); }
@Test @SuppressWarnings("resource") public void getPrincipalNone() { Session nativeSession = Mockito.mock(Session.class); given(nativeSession.getUserPrincipal()).willReturn(null); StandardWebSocketSession session = new StandardWebSocketSession(this.headers, this.attributes, null, null); session.initializeNativeSession(nativeSession); reset(nativeSession); assertNull(session.getPrincipal()); verifyNoMoreInteractions(nativeSession); }
@OnOpen public void start(Session wsSession) { current.set(wsSession); try { URI uri = wsSession.getRequestURI(); String path = uri.getPath(); log.fine("Establishing session for " + path); String contextPath = path.substring(0, path.lastIndexOf('/')); PluginContext context = WebPluginLifeCycle.getPluginContext(contextPath); if (context != null) { Boolean enabled = context.getProperty(WebPlugin.ENABLED); if (enabled != null && enabled) { log.fine("Using shell " + context); ShellFactory factory = context.getPlugin(ShellFactory.class); Principal user = wsSession.getUserPrincipal(); Shell shell = factory.create(user); CRaSHSession session = new CRaSHSession(wsSession, shell); sessions.put(wsSession.getId(), session); log.fine("Established session " + wsSession.getId()); } else { log.fine("Web plugin disabled"); } } else { log.fine("No shell found"); } } finally { current.set(null); } }
@Override public Principal getUserPrincipal() { return session.getUserPrincipal(); }
@Override public Principal getUserPrincipal() { return session.getUserPrincipal(); }
@Override public Principal getUserPrincipal() { return session.getUserPrincipal(); }
public Principal getUserPrincipal() { return session.getUserPrincipal(); }
public Principal getUserPrincipal(){ return session.getUserPrincipal(); }
/** * {@inheritDoc} */ @Override public void initializeNativeSession(Session session) { super.initializeNativeSession(session); if (this.user == null) { this.user = session.getUserPrincipal(); } }
public JavaxUpgradeHttpRequest(final Session session, EndpointConfig endpointConfig) { Map<String, Object> userProperties = session.getUserProperties(); if (userProperties == null || userProperties.isEmpty()) { // workaround for JBoss Wildfly 8.0.Final userProperties = endpointConfig.getUserProperties(); } this.httpSession = (HttpSession) userProperties.get("session"); this.headers = (Map<String, List<String>>) userProperties.get("headers"); this.queryString = session.getQueryString(); this.userPrincipal = session.getUserPrincipal(); Object requestURI = session.getRequestURI(); this.requestUri = requestURI != null ? requestURI.toString() : ""; this.parametersMap = new HashMap<>(); Map<String, List<String>> parameters = session.getRequestParameterMap(); if (parameters != null) { for (Map.Entry<String, List<String>> entry : parameters.entrySet()) { String name = entry.getKey(); List<String> value = entry.getValue(); parametersMap.put(name, value.toArray(new String[0])); } } }
@OnOpen public void open(Session session){ log.info("Session created: "+session.getId()); clients.add(session); try { session.getBasicRemote().sendText("welcome "+session.getUserPrincipal()); } catch (IOException e) { log.log(Level.WARNING,"Unable to send welcome message", e); } // TODO check privileges and close connection if invalid } @OnClose
public JavaxUpgradeHttpRequest(final Session session, EndpointConfig endpointConfig) { Map<String, Object> userProperties = session.getUserProperties(); if (userProperties == null || userProperties.isEmpty()) { // workaround for JBoss Wildfly 8.0.Final userProperties = endpointConfig.getUserProperties(); } this.httpSession = (HttpSession) userProperties.get("session"); this.headers = (Map<String, List<String>>) userProperties.get("headers"); this.queryString = session.getQueryString(); this.userPrincipal = session.getUserPrincipal(); Object requestURI = session.getRequestURI(); this.requestUri = requestURI != null ? requestURI.toString() : ""; this.parametersMap = new HashMap<>(); Map<String, List<String>> parameters = session.getRequestParameterMap(); if (parameters != null) { for (Map.Entry<String, List<String>> entry : parameters.entrySet()) { String name = entry.getKey(); List<String> value = entry.getValue(); parametersMap.put(name, value.toArray(new String[0])); } } }
@Override public void initializeNativeSession(Session session) { super.initializeNativeSession(session); this.uri = session.getRequestURI(); this.acceptedProtocol = session.getNegotiatedSubprotocol(); List<Extension> standardExtensions = getNativeSession().getNegotiatedExtensions(); if (!CollectionUtils.isEmpty(standardExtensions)) { this.extensions = new ArrayList<>(standardExtensions.size()); for (Extension standardExtension : standardExtensions) { this.extensions.add(new StandardToWebSocketExtensionAdapter(standardExtension)); } this.extensions = Collections.unmodifiableList(this.extensions); } else { this.extensions = Collections.emptyList(); } if (this.user == null) { this.user = session.getUserPrincipal(); } }
@Override public void initializeNativeSession(Session session) { super.initializeNativeSession(session); this.uri = session.getRequestURI(); this.acceptedProtocol = session.getNegotiatedSubprotocol(); List<Extension> standardExtensions = getNativeSession().getNegotiatedExtensions(); if (!CollectionUtils.isEmpty(standardExtensions)) { this.extensions = new ArrayList<>(standardExtensions.size()); for (Extension standardExtension : standardExtensions) { this.extensions.add(new StandardToWebSocketExtensionAdapter(standardExtension)); } this.extensions = Collections.unmodifiableList(this.extensions); } else { this.extensions = Collections.emptyList(); } if (this.user == null) { this.user = session.getUserPrincipal(); } }
@OnOpen public void start(Session wsSession) { current.set(wsSession); try { URI uri = wsSession.getRequestURI(); String path = uri.getPath(); log.fine("Establishing session for " + path); String contextPath = path.substring(0, path.lastIndexOf('/')); PluginContext context = WebPluginLifeCycle.getPluginContext(contextPath); if (context != null) { Boolean enabled = context.getProperty(WebPlugin.ENABLED); if (enabled != null && enabled) { log.fine("Using shell " + context); ShellFactory factory = context.getPlugin(ShellFactory.class); Principal user = wsSession.getUserPrincipal(); Shell shell = factory.create(user); CRaSHSession session = new CRaSHSession(wsSession, shell); sessions.put(wsSession.getId(), session); log.fine("Established session " + wsSession.getId()); } else { log.fine("Web plugin disabled"); } } else { log.fine("No shell found"); } } finally { current.set(null); } }
protected void in(PlatypusServerCore platypusCore, Session websocketSession, Consumer<com.eas.server.Session> aHandler) throws Exception { HandshakeRequest handshake = (HandshakeRequest) websocketSession.getUserProperties().get(JsServerModuleEndPointConfigurator.HANDSHAKE_REQUEST); String userName = websocketSession.getUserPrincipal() != null ? websocketSession.getUserPrincipal().getName() : null; Consumer<com.eas.server.Session> withPlatypusSession = (com.eas.server.Session aSession) -> { if (websocketSession.getUserPrincipal() != null) {// Additional properties can be obtained only for authorized users DatabasesClient.getUserProperties(platypusCore.getDatabasesClient(), userName, platypusCore.getQueueSpace(), (Map<String, String> aUserProps) -> {