All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.n2oapp.framework.boot.N2oWebSocketHandshakeHandlerConfiguration Maven / Gradle / Ivy

There is a newer version: 7.28.1
Show newest version
package net.n2oapp.framework.boot;

import com.sun.security.auth.UserPrincipal;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;

import java.security.Principal;
import java.util.Map;
import java.util.UUID;

@AutoConfiguration
public class N2oWebSocketHandshakeHandlerConfiguration {

    @Bean
    @ConditionalOnMissingBean(DefaultHandshakeHandler.class)
    public DefaultHandshakeHandler handshakeHandler() {
        return new DefaultHandshakeHandler() {
            @Override
            protected Principal determineUser(ServerHttpRequest request, WebSocketHandler wsHandler, Map attributes) {
                return new UserPrincipal(UUID.randomUUID().toString());
            }
        };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy