Java Code Examples for org.apache.solr.common.SolrException.ErrorCode#FORBIDDEN

The following examples show how to use org.apache.solr.common.SolrException.ErrorCode#FORBIDDEN . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TermsComponent.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
protected void checkShardsWhitelist(final ResponseBuilder rb, final List<String> lst) {
  final List<String> urls = new LinkedList<String>();
  for (final String ele : lst) {
    urls.addAll(StrUtils.splitSmart(ele, '|'));
  }
  
  if (whitelistHostChecker.isWhitelistHostCheckingEnabled() && rb.req.getCore().getCoreContainer().getZkController() == null && !whitelistHostChecker.hasExplicitWhitelist()) {
    throw new SolrException(ErrorCode.FORBIDDEN, "TermsComponent "+HttpShardHandlerFactory.INIT_SHARDS_WHITELIST
        +" not configured but required when using the '"+ShardParams.SHARDS+"' parameter with the TermsComponent."
        +HttpShardHandlerFactory.SET_SOLR_DISABLE_SHARDS_WHITELIST_CLUE);
  } else {
    ClusterState cs = null;
    if (rb.req.getCore().getCoreContainer().getZkController() != null) {
      cs = rb.req.getCore().getCoreContainer().getZkController().getClusterState();
    }
    whitelistHostChecker.checkWhitelist(cs, urls.toString(), urls);
  }
}
 
Example 2
Source File: RestManager.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Deletes a managed resource if it is not being used by any Solr components. 
 */
public synchronized void deleteManagedResource(ManagedResource res) {
  String resourceId = res.getResourceId();
  ManagedResourceRegistration existingReg = registry.registered.get(resourceId);
  int numObservers = existingReg.observers.size();
  if (numObservers > 0) {
    String errMsg = 
        String.format(Locale.ROOT,
            "Cannot delete managed resource %s as it is being used by %d Solr components",
            resourceId, numObservers);
    throw new SolrException(ErrorCode.FORBIDDEN, errMsg);
  }
  
  registry.registered.remove(resourceId);
  managed.remove(resourceId);
  try {
    res.onResourceDeleted();
  } catch (IOException e) {
    // the resource is already deleted so just log this
    log.error("Error when trying to clean-up after deleting {}",resourceId, e);
  }
}
 
Example 3
Source File: DistributedZkUpdateProcessor.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void processDelete(DeleteUpdateCommand cmd) throws IOException {
  clusterState = zkController.getClusterState();

  if (isReadOnly()) {
    throw new SolrException(ErrorCode.FORBIDDEN, "Collection " + collection + " is read-only.");
  }

  super.processDelete(cmd);
}
 
Example 4
Source File: DistributedZkUpdateProcessor.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void processMergeIndexes(MergeIndexesCommand cmd) throws IOException {
  clusterState = zkController.getClusterState();

  if (isReadOnly()) {
    throw new SolrException(ErrorCode.FORBIDDEN, "Collection " + collection + " is read-only.");
  }
  super.processMergeIndexes(cmd);
}
 
Example 5
Source File: DistributedZkUpdateProcessor.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void processRollback(RollbackUpdateCommand cmd) throws IOException {
  clusterState = zkController.getClusterState();

  if (isReadOnly()) {
    throw new SolrException(ErrorCode.FORBIDDEN, "Collection " + collection + " is read-only.");
  }
  super.processRollback(cmd);
}
 
Example 6
Source File: ReplicationHandler.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
protected String validateFilenameOrError(String filename) {
  if (filename != null) {
    Path filePath = Paths.get(filename);
    filePath.forEach(subpath -> {
      if ("..".equals(subpath.toString())) {
        throw new SolrException(ErrorCode.FORBIDDEN, "File name cannot contain ..");
      }
    });
    if (filePath.isAbsolute()) {
      throw new SolrException(ErrorCode.FORBIDDEN, "File name must be relative");
    }
    return filename;
  } else return null;
}
 
Example 7
Source File: RAMDirectoryFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
protected LockFactory createLockFactory(String rawLockType) throws IOException {
  if (!(rawLockType == null || DirectoryFactory.LOCK_TYPE_SINGLE.equalsIgnoreCase(rawLockType.trim()))) {
    throw new SolrException(ErrorCode.FORBIDDEN,
        "RAMDirectory can only be used with the '" +
            DirectoryFactory.LOCK_TYPE_SINGLE+"' lock factory type.");
  }
  return new SingleInstanceLockFactory();
}
 
Example 8
Source File: ByteBuffersDirectoryFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
protected LockFactory createLockFactory(String rawLockType) throws IOException {
  if (!(rawLockType == null || DirectoryFactory.LOCK_TYPE_SINGLE.equalsIgnoreCase(rawLockType.trim()))) {
    throw new SolrException(ErrorCode.FORBIDDEN,
        "ByteBuffersDirectory can only be used with the '"+DirectoryFactory.LOCK_TYPE_SINGLE+"' lock factory type.");
  }
  return new SingleInstanceLockFactory();
}