@ -54,11 +54,14 @@ public class StandardWebSocketSession extends AbstractWebSocketSession<Session>
private final InetSocketAddress remoteAddress ;
private final InetSocketAddress remoteAddress ;
private final Principal user ;
private List < WebSocketExtension > extensions ;
private List < WebSocketExtension > extensions ;
/ * *
/ * *
* Class constructor .
* Class constructor .
*
* @param headers the headers of the handshake request
* @param headers the headers of the handshake request
* @param handshakeAttributes attributes from the HTTP handshake to make available
* @param handshakeAttributes attributes from the HTTP handshake to make available
* through the WebSocket session
* through the WebSocket session
@ -67,11 +70,30 @@ public class StandardWebSocketSession extends AbstractWebSocketSession<Session>
* /
* /
public StandardWebSocketSession ( HttpHeaders headers , Map < String , Object > handshakeAttributes ,
public StandardWebSocketSession ( HttpHeaders headers , Map < String , Object > handshakeAttributes ,
InetSocketAddress localAddress , InetSocketAddress remoteAddress ) {
InetSocketAddress localAddress , InetSocketAddress remoteAddress ) {
this ( headers , handshakeAttributes , localAddress , remoteAddress , null ) ;
}
/ * *
* Class constructor that associates a user with the WebSocket session .
*
* @param headers the headers of the handshake request
* @param handshakeAttributes attributes from the HTTP handshake to make available
* through the WebSocket session
* @param localAddress the address on which the request was received
* @param remoteAddress the address of the remote client
* @param user the user associated with the session ; can be left
* { @code null } in which case , we ' ll fallback on the user available via
* /
public StandardWebSocketSession ( HttpHeaders headers , Map < String , Object > handshakeAttributes ,
InetSocketAddress localAddress , InetSocketAddress remoteAddress , Principal user ) {
super ( handshakeAttributes ) ;
super ( handshakeAttributes ) ;
headers = ( headers ! = null ) ? headers : new HttpHeaders ( ) ;
headers = ( headers ! = null ) ? headers : new HttpHeaders ( ) ;
this . handshakeHeaders = HttpHeaders . readOnlyHttpHeaders ( headers ) ;
this . handshakeHeaders = HttpHeaders . readOnlyHttpHeaders ( headers ) ;
this . localAddress = localAddress ;
this . localAddress = localAddress ;
this . remoteAddress = remoteAddress ;
this . remoteAddress = remoteAddress ;
this . user = user ;
}
}
@Override
@Override
@ -93,6 +115,9 @@ public class StandardWebSocketSession extends AbstractWebSocketSession<Session>
@Override
@Override
public Principal getPrincipal ( ) {
public Principal getPrincipal ( ) {
if ( this . user ! = null ) {
return this . user ;
}
checkNativeSessionInitialized ( ) ;
checkNativeSessionInitialized ( ) ;
return getNativeSession ( ) . getUserPrincipal ( ) ;
return getNativeSession ( ) . getUserPrincipal ( ) ;
}
}