Example usage for org.springframework.http.server ServerHttpRequest getPrincipal

List of usage examples for org.springframework.http.server ServerHttpRequest getPrincipal

Introduction

In this page you can find the example usage for org.springframework.http.server ServerHttpRequest getPrincipal.

Prototype

@Nullable
Principal getPrincipal();

Source Link

Document

Return a java.security.Principal instance containing the name of the authenticated user.

Usage

From source file:opensnap.config.CustomHandshakeHandler.java

@Override
protected Principal determineUser(ServerHttpRequest request, WebSocketHandler wsHandler,
        Map<String, Object> attributes) {
    Principal principal = request.getPrincipal();
    if (principal == null) {
        principal = new UsernamePasswordAuthenticationToken("anonymous", "jdqsjkdjsqkjd",
                Arrays.asList(new SimpleGrantedAuthority("ANONYMOUS")));
    }/*from  w  w w.  j  a va2 s .  c o  m*/
    return principal;
}

From source file:org.springframework.web.socket.server.support.AbstractHandshakeHandler.java

/**
 * A method that can be used to associate a user with the WebSocket session
 * in the process of being established. The default implementation calls
 * {@link ServerHttpRequest#getPrincipal()}
 * <p>Subclasses can provide custom logic for associating a user with a session,
 * for example for assigning a name to anonymous users (i.e. not fully authenticated).
 * @param request the handshake request//ww  w . ja v  a  2s  .c om
 * @param wsHandler the WebSocket handler that will handle messages
 * @param attributes handshake attributes to pass to the WebSocket session
 * @return the user for the WebSocket session, or {@code null} if not available
 */
@Nullable
protected Principal determineUser(ServerHttpRequest request, WebSocketHandler wsHandler,
        Map<String, Object> attributes) {

    return request.getPrincipal();
}

From source file:org.springframework.web.socket.server.support.DefaultHandshakeHandler.java

/**
 * A method that can be used to associate a user with the WebSocket session
 * in the process of being established. The default implementation calls
 * {@link org.springframework.http.server.ServerHttpRequest#getPrincipal()}
 * <p>Subclasses can provide custom logic for associating a user with a session,
 * for example for assigning a name to anonymous users (i.e. not fully
 * authenticated).//from w w  w.j  a  v  a  2 s .  c  o  m
 * @param request the handshake request
 * @param wsHandler the WebSocket handler that will handle messages
 * @param attributes handshake attributes to pass to the WebSocket session
 * @return the user for the WebSocket session, or {@code null} if not available
 */
protected Principal determineUser(ServerHttpRequest request, WebSocketHandler wsHandler,
        Map<String, Object> attributes) {

    return request.getPrincipal();
}