Example usage for javax.websocket Session getUserPrincipal

List of usage examples for javax.websocket Session getUserPrincipal

Introduction

In this page you can find the example usage for javax.websocket Session getUserPrincipal.

Prototype

Principal getUserPrincipal();

Source Link

Usage

From source file:cito.server.AbstractEndpoint.java

@OnClose
@Override/*from  w w  w. j ava2s  .  c om*/
public void onClose(Session session, CloseReason reason) {
    this.log.info("WebSocket connection closed. [id={},principle={},code={},reason={}]", session.getId(),
            session.getUserPrincipal(), reason.getCloseCode(), reason.getReasonPhrase());
    final WebSocketContext ctx = webSocketContext(this.beanManager);
    try (QuietClosable c = ctx.activate(session)) {
        this.registry.unregister(session);
        this.sessionEvent.select(cito.annotation.OnClose.Literal.onClose()).fire(session);
    }
    ctx.dispose(session);
}

From source file:cito.server.AbstractEndpoint.java

/**
 * //from  w  w w.j  a  v  a  2s.  c o  m
 * @param session
 * @param frame
 */
@OnMessage
public void message(Session session, Frame frame) {
    final String sessionId = session.getId();
    this.log.debug("Received message from client. [id={},principle={},command={}]", sessionId,
            session.getUserPrincipal(), frame.command());
    try (QuietClosable c = webSocketContext(this.beanManager).activate(session)) {
        final Message event = new Message(sessionId, frame);
        try (QuietClosable closable = ClientMessageProducer.set(event)) {
            this.relay.fromClient(event); // due to no @Observe @Priority we need to ensure the relay gets this first
            this.messageEvent.fire(event);
        }
    }
}

From source file:cito.server.AbstractEndpoint.java

@OnError
@Override//from www .j  a  v a2 s  .  co m
public void onError(Session session, Throwable cause) {
    final String errorId = RandomStringUtils.randomAlphanumeric(8).toUpperCase();
    this.log.warn("WebSocket error. [id={},principle={},errorId={}]", session.getId(),
            session.getUserPrincipal(), errorId, cause);
    try (QuietClosable c = webSocketContext(this.beanManager).activate(session)) {
        this.errorEvent.select(cito.annotation.OnError.Literal.onError()).fire(cause);
        final Frame errorFrame = Frame.error()
                .body(MediaType.TEXT_PLAIN_TYPE, format("%s [errorId=%s]", cause.getMessage(), errorId))
                .build();
        session.getBasicRemote().sendObject(errorFrame);
        session.close(
                new CloseReason(CloseCodes.PROTOCOL_ERROR, format("See server log. [errorId=%s]", errorId)));
    } catch (IOException | EncodeException e) {
        this.log.error("Unable to send error frame! [id={},principle={}]", session.getId(),
                session.getUserPrincipal(), e);
    }
}

From source file:cito.server.AbstractEndpoint.java

@OnOpen
@Override/*from   www  .  jav  a 2 s. co m*/
public void onOpen(Session session, EndpointConfig config) {
    final String httpSessionId = session.getRequestParameterMap().get("httpSessionId").get(0);
    this.log.info("WebSocket connection opened. [id={},httpSessionId={},principle={}]", session.getId(),
            httpSessionId, session.getUserPrincipal());
    final SecurityContext securityCtx = WebSocketConfigurator.removeSecurityContext(config.getUserProperties(),
            httpSessionId);
    SecurityContextProducer.set(session, securityCtx);
    try (QuietClosable c = webSocketContext(this.beanManager).activate(session)) {
        this.registry.register(session);
        this.sessionEvent.select(cito.annotation.OnOpen.Literal.onOpen()).fire(session);
    }

    this.rttService.start(session);
}