/**
  * @param packet
  * @throws Exception
  */
 private void handleAppendAddRecord(final ReplicationAddMessage packet) throws Exception {
   Journal journalToUse = getJournal(packet.getJournalID());
   if (packet.getRecord() == ADD_OPERATION_TYPE.UPDATE) {
     if (ReplicationEndpoint.trace) {
       ActiveMQServerLogger.LOGGER.trace("Endpoint appendUpdate id = " + packet.getId());
     }
     journalToUse.appendUpdateRecord(
         packet.getId(), packet.getJournalRecordType(), packet.getRecordData(), noSync);
   } else {
     if (ReplicationEndpoint.trace) {
       ActiveMQServerLogger.LOGGER.trace("Endpoint append id = " + packet.getId());
     }
     journalToUse.appendAddRecord(
         packet.getId(), packet.getJournalRecordType(), packet.getRecordData(), noSync);
   }
 }
  @Override
  public boolean validateUserAndRole(
      final String user,
      final String password,
      final Set<Role> roles,
      final CheckType checkType,
      final String address,
      final RemotingConnection connection) {
    X509Certificate[] certificates = null;
    if (connection.getTransportConnection() instanceof NettyConnection) {
      certificates =
          CertificateUtil.getCertsFromChannel(
              ((NettyConnection) connection.getTransportConnection()).getChannel());
    }
    Subject localSubject;
    try {
      localSubject = getAuthenticatedSubject(user, password, certificates);
    } catch (LoginException e) {
      ActiveMQServerLogger.LOGGER.debug("Couldn't validate user", e);
      return false;
    }

    boolean authorized = false;

    if (localSubject != null) {
      Set<RolePrincipal> rolesWithPermission = getPrincipalsInRole(checkType, roles);

      // Check the caller's roles
      Set<RolePrincipal> rolesForSubject = localSubject.getPrincipals(RolePrincipal.class);
      if (rolesForSubject.size() > 0 && rolesWithPermission.size() > 0) {
        Iterator<RolePrincipal> rolesForSubjectIter = rolesForSubject.iterator();
        while (!authorized && rolesForSubjectIter.hasNext()) {
          Iterator<RolePrincipal> rolesWithPermissionIter = rolesWithPermission.iterator();
          while (!authorized && rolesWithPermissionIter.hasNext()) {
            Principal role = rolesWithPermissionIter.next();
            authorized = rolesForSubjectIter.next().equals(role);
          }
        }
      }

      if (trace) {
        ActiveMQServerLogger.LOGGER.trace(
            "user " + (authorized ? " is " : " is NOT ") + "authorized");
      }
    }

    return authorized;
  }
  public boolean send(final StompConnection connection, final StompFrame frame) {
    if (ActiveMQServerLogger.LOGGER.isTraceEnabled()) {
      ActiveMQServerLogger.LOGGER.trace("sent " + frame);
    }

    invokeInterceptors(this.outgoingInterceptors, frame, connection);

    synchronized (connection) {
      if (connection.isDestroyed()) {
        ActiveMQStompProtocolLogger.LOGGER.connectionClosed(connection);
        return false;
      }

      try {
        connection.physicalSend(frame);
      } catch (Exception e) {
        ActiveMQStompProtocolLogger.LOGGER.errorSendingFrame(e, frame);
        return false;
      }
      return true;
    }
  }
Exemplo n.º 4
0
  @Override
  public boolean page(
      ServerMessage message,
      final Transaction tx,
      RouteContextList listCtx,
      final ReadLock managerLock)
      throws Exception {

    if (!running) {
      throw new IllegalStateException("PagingStore(" + getStoreName() + ") not initialized");
    }

    boolean full = isFull();

    if (addressFullMessagePolicy == AddressFullMessagePolicy.DROP
        || addressFullMessagePolicy == AddressFullMessagePolicy.FAIL) {
      if (full) {
        if (!printedDropMessagesWarning) {
          printedDropMessagesWarning = true;

          ActiveMQServerLogger.LOGGER.pageStoreDropMessages(storeName, sizeInBytes.get(), maxSize);
        }

        if (message.isLargeMessage()) {
          ((LargeServerMessage) message).deleteFile();
        }

        if (addressFullMessagePolicy == AddressFullMessagePolicy.FAIL) {
          throw ActiveMQMessageBundle.BUNDLE.addressIsFull(address.toString());
        }

        // Address is full, we just pretend we are paging, and drop the data
        return true;
      } else {
        return false;
      }
    } else if (addressFullMessagePolicy == AddressFullMessagePolicy.BLOCK) {
      return false;
    }

    // We need to ensure a read lock, as depage could change the paging state
    lock.readLock().lock();

    try {
      // First check done concurrently, to avoid synchronization and increase throughput
      if (!paging) {
        return false;
      }
    } finally {
      lock.readLock().unlock();
    }

    managerLock.lock();
    try {
      lock.writeLock().lock();

      try {
        if (!paging) {
          return false;
        }

        if (!message.isDurable()) {
          // The address should never be transient when paging (even for non-persistent messages
          // when paging)
          // This will force everything to be persisted
          message.forceAddress(address);
        }

        final long transactionID = tx == null ? -1 : tx.getID();
        PagedMessage pagedMessage =
            new PagedMessageImpl(message, routeQueues(tx, listCtx), transactionID);

        if (message.isLargeMessage()) {
          ((LargeServerMessage) message).setPaged();
        }

        int bytesToWrite = pagedMessage.getEncodeSize() + Page.SIZE_RECORD;

        if (currentPageSize.addAndGet(bytesToWrite) > pageSize
            && currentPage.getNumberOfMessages() > 0) {
          // Make sure nothing is currently validating or using currentPage
          openNewPage();
          currentPageSize.addAndGet(bytesToWrite);
        }

        if (tx != null) {
          installPageTransaction(tx, listCtx);
        }

        // the apply counter will make sure we write a record on journal
        // especially on the case for non transactional sends and paging
        // doing this will give us a possibility of recovering the page counters
        applyPageCounters(tx, getCurrentPage(), listCtx);

        currentPage.write(pagedMessage);

        if (tx == null && syncNonTransactional && message.isDurable()) {
          sync();
        }

        if (isTrace) {
          ActiveMQServerLogger.LOGGER.trace(
              "Paging message "
                  + pagedMessage
                  + " on pageStore "
                  + this.getStoreName()
                  + " pageId="
                  + currentPage.getPageId());
        }

        return true;
      } finally {
        lock.writeLock().unlock();
      }
    } finally {
      managerLock.unlock();
    }
  }
 /** @param packet */
 private void handleLargeMessageBegin(final ReplicationLargeMessageBeginMessage packet) {
   final long id = packet.getMessageId();
   createLargeMessage(id, false);
   ActiveMQServerLogger.LOGGER.trace("Receiving Large Message " + id + " on backup");
 }