Add WebSocketSession attributes + initialization

In addition to adding the attributes, there is now mechanism for
initializing WebSocketSession instances from attributes of the
handshake request.
This commit is contained in:
Rossen Stoyanchev
2013-05-02 13:47:18 -04:00
parent 166ca7a5a3
commit 2a7935a913
24 changed files with 510 additions and 190 deletions

View File

@@ -16,6 +16,8 @@
package org.springframework.http.server;
import java.security.Principal;
import org.springframework.http.HttpInputMessage;
import org.springframework.http.HttpRequest;
import org.springframework.util.MultiValueMap;
@@ -33,4 +35,21 @@ public interface ServerHttpRequest extends HttpRequest, HttpInputMessage {
*/
MultiValueMap<String, String> getQueryParams();
/**
* Return a {@link java.security.Principal} instance containing the name of the
* authenticated user. If the user has not been authenticated, the method returns
* <code>null</code>.
*/
Principal getPrincipal();
/**
* Return the host name of the endpoint on the other end.
*/
String getRemoteHostName();
/**
* Return the IP address of the endpoint on the other end.
*/
String getRemoteAddress();
}

View File

@@ -26,6 +26,7 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.security.Principal;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashMap;
@@ -131,6 +132,21 @@ public class ServletServerHttpRequest implements ServerHttpRequest {
return this.headers;
}
@Override
public Principal getPrincipal() {
return this.servletRequest.getUserPrincipal();
}
@Override
public String getRemoteHostName() {
return this.servletRequest.getRemoteHost();
}
@Override
public String getRemoteAddress() {
return this.servletRequest.getRemoteAddr();
}
public Cookies getCookies() {
if (this.cookies == null) {
this.cookies = new Cookies();