Package org.jwebsocket.token

Examples of org.jwebsocket.token.Token


    // don't send session-id on good bye, neither required nor desired
    sendToken(aConnector, aConnector, lGoodBye);
  }

  private void login(WebSocketConnector aConnector, Token aToken) {
    Token lResponse = createResponse(aToken);

    String lUsername = aToken.getString("username");
    // TODO: Add authentication and password check
    String lPassword = aToken.getString("password");
    String lGroup = aToken.getString("group");

    if (log.isDebugEnabled()) {
      log.debug("Processing 'login' (username='" + lUsername + "', group='" + lGroup + "') from '" + aConnector + "'...");
    }

    if (lUsername != null) {
      lResponse.put("username", lUsername);
      // lResponse.put("usid", getSessionId(aConnector));
      lResponse.put("sourceId", aConnector.getId());
      // set shared variables
      setUsername(aConnector, lUsername);
      setGroup(aConnector, lGroup);
    } else {
      lResponse.put("code", -1);
      lResponse.put("msg", "missing arguments for 'login' command");
    }

    // send response to client
    sendToken(aConnector, aConnector, lResponse);
View Full Code Here


      broadcastLoginEvent(aConnector);
    }
  }

  private void logout(WebSocketConnector aConnector, Token aToken) {
    Token lResponse = createResponse(aToken);

    if (log.isDebugEnabled()) {
      log.debug("Processing 'logout' (username='" + getUsername(aConnector) + "') from '" + aConnector + "'...");
    }

    if (getUsername(aConnector) != null) {
      // send good bye token as response to client
      sendGoodBye(aConnector, CloseReason.CLIENT);
      // and broadcast the logout event
      broadcastLogoutEvent(aConnector);
      // resetting the username is the only required signal for logout
      // lResponse.put("usid", getSessionId(aConnector));
      lResponse.put("sourceId", aConnector.getId());
      removeUsername(aConnector);
      removeGroup(aConnector);
    } else {
      lResponse.put("code", -1);
      lResponse.put("msg", "not logged in");
      sendToken(aConnector, aConnector, lResponse);
    }
  }
View Full Code Here

    if (!SecurityFactory.checkRight(getUsername(aConnector), NS_SYSTEM_DEFAULT + ".send")) {
      sendToken(aConnector, aConnector, createAccessDenied(aToken));
      return;
    }

    Token lResponse = createResponse(aToken);

    WebSocketConnector lTargetConnector;
    String lTargetId = aToken.getString("unid");
    if (lTargetId != null) {
      lTargetConnector = getNode(lTargetId);
View Full Code Here

    if (!SecurityFactory.checkRight(getUsername(aConnector), NS_SYSTEM_DEFAULT + ".broadcast")) {
      sendToken(aConnector, aConnector, createAccessDenied(aToken));
      return;
    }

    Token lResponse = createResponse(aToken);

    if (log.isDebugEnabled()) {
      log.debug("Processing 'broadcast' (username='"
          + getUsername(aConnector) + "') from '"
          + aConnector + "'...");
View Full Code Here

  /**
   *
   * @param aToken
   */
  private void echo(WebSocketConnector aConnector, Token aToken) {
    Token lResponseToken = createResponse(aToken);

    String lData = aToken.getString("data");
    if (lData != null) {
      if (log.isDebugEnabled()) {
        log.debug("echo " + lData);
      }
    } else {
      lResponseToken.put("code", -1);
      lResponseToken.put("msg", "missing 'data' argument for 'echo' command");
    }
    sendToken(aConnector, aConnector, lResponseToken);
  }
View Full Code Here

      log.debug("Processing 'Ping' (echo='" + lEcho + "') from '"
          + aConnector + "'...");
    }

    if (lEcho.equalsIgnoreCase("true")) {
      Token lResponseToken = createResponse(aToken);
      // TODO: here could optionally send a time stamp
      // TODO: implement response time on client!
      // lResponseToken.put("","");
      sendToken(aConnector, aConnector, lResponseToken);
    }
View Full Code Here

   *
   * @param aConnector
   * @param aToken
   */
  public void getClients(WebSocketConnector aConnector, Token aToken) {
    Token lResponseToken = createResponse(aToken);

    if (log.isDebugEnabled()) {
      log.debug("Processing 'getClients' from '"
          + aConnector + "'...");
    }

    if (getUsername(aConnector) != null) {
      String lGroup = aToken.getString("group");
      Integer lMode = aToken.getInteger("mode", 0);
      FastMap lFilter = new FastMap();
      lFilter.put(BaseConnector.VAR_USERNAME, ".*");
      List<String> listOut = new FastList<String>();
      for (WebSocketConnector lConnector : getServer().selectConnectors(lFilter).values()) {
        listOut.add(getUsername(lConnector) + "@"
            + lConnector.getRemotePort());
      }
      lResponseToken.put("clients", listOut);
      lResponseToken.put("count", listOut.size());
    } else {
      lResponseToken.put("code", -1);
      lResponseToken.put("msg", "not logged in");
    }

    sendToken(aConnector, aConnector, lResponseToken);
  }
View Full Code Here

   * allocates a "non-interruptable" communication channel between two clients.
   * @param aConnector
   * @param aToken
   */
  public void allocChannel(WebSocketConnector aConnector, Token aToken) {
    Token lResponseToken = createResponse(aToken);

    if (log.isDebugEnabled()) {
      log.debug("Processing 'allocChannel' from '"
          + aConnector + "'...");
    }
View Full Code Here

   * deallocates a "non-interruptable" communication channel between two clients.
   * @param aConnector
   * @param aToken
   */
  public void deallocChannel(WebSocketConnector aConnector, Token aToken) {
    Token lResponseToken = createResponse(aToken);

    if (log.isDebugEnabled()) {
      log.debug("Processing 'deallocChannel' from '"
          + aConnector + "'...");
    }
View Full Code Here

    try {
      if (server != null) {
        // convert request arguments to token
        FastMap<String, String[]> lParms = new FastMap(request.getParameterMap());
        Token lToken = new Token();
        for (String lParm : lParms.keySet()) {
          String[] lValues = lParms.get(lParm);
          if (lValues != null && lValues.length > 0) {
            lToken.put(lParm, lValues[0]);
          }
        }
        ServletConnector lConn = new ServletConnector(request, response);
        server.getPlugInChain().processToken(lConn, lToken);
        out.println(lConn.getPlainResponse());
View Full Code Here

TOP

Related Classes of org.jwebsocket.token.Token

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.