public List<CMISConnection> getUserConnections() {
    String currentUser = authenticationService.getCurrentUserName();
    if (currentUser == null) {
      throw new IllegalStateException("No current user!");
    }

    lock.writeLock().lock();
    try {
      List<CMISConnection> result = new ArrayList<CMISConnection>();

      for (CMISConnection conn : userConnections.values()) {
        int idx = conn.getInternalId().indexOf(RESERVED_ID_CHAR);
        if (idx > -1) {
          if (currentUser.equals(conn.getInternalId().substring(idx + 1))) {
            result.add(conn);
          }
        }
      }

      Collections.sort(result);
      return Collections.unmodifiableList(result);
    } finally {
      lock.writeLock().unlock();
    }
  }
  @Override
  public CMISConnection createSharedConnection(CMISServer server, String connectionId) {
    if (connectionId == null
        || connectionId.length() == 0
        || connectionId.indexOf(RESERVED_ID_CHAR) > -1
        || DEFAULT_CONNECTION_ID.equals(connectionId)) {
      throw new IllegalArgumentException("Invalid connection id!");
    }

    CMISConnection connection;

    lock.writeLock().lock();
    try {
      if (sharedConnections.containsKey(connectionId)) {
        throw new IllegalStateException("Connection id is already in use!");
      }

      connection = createConnection(server, connectionId, true);

      sharedConnections.put(connection.getInternalId(), connection);
    } finally {
      lock.writeLock().unlock();
    }

    return connection;
  }
  public void removeConnection(CMISConnection connection) {
    if (connection == null || connection.getInternalId() == null) {
      return;
    }

    lock.writeLock().lock();
    try {
      if (connection.isShared()) {
        sharedConnections.remove(connection.getInternalId());
      } else {
        userConnections.remove(connection.getInternalId());
      }
    } finally {
      lock.writeLock().unlock();
    }
  }