use of org.sonatype.nexus.common.stateguard.StateGuardLifecycleSupport.State.STARTED in project nexus-public by sonatype.
the class SelectorManagerImpl method browseActive.
@Override
@Guarded(by = STARTED)
public List<SelectorConfiguration> browseActive(final List<String> repositoryNames, final List<String> formats) {
AuthorizationManager authorizationManager;
User currentUser;
try {
authorizationManager = securitySystem.getAuthorizationManager(DEFAULT_SOURCE);
currentUser = securitySystem.currentUser();
} catch (NoSuchAuthorizationManagerException | UserNotFoundException e) {
log.warn("Unable to load active content selectors", e);
return Collections.emptyList();
}
if (currentUser == null) {
return Collections.emptyList();
}
List<String> roleIds = currentUser.getRoles().stream().map(RoleIdentifier::getRoleId).collect(toList());
List<Role> roles = getRoles(roleIds, authorizationManager, new ArrayList<>());
List<String> contentSelectorNames = roles.stream().map(Role::getPrivileges).flatMap(Collection::stream).map(id -> {
try {
return authorizationManager.getPrivilege(id);
} catch (NoSuchPrivilegeException e) {
log.debug("Unable to find privilege for id={}, continuing to check privileges", id, e);
return null;
}
}).filter(Objects::nonNull).filter(repositoryFormatOrNameMatcher(repositoryNames, formats)).map(this::getContentSelector).collect(toList());
return browse().stream().filter(selector -> contentSelectorNames.contains(selector.getName())).collect(toList());
}
use of org.sonatype.nexus.common.stateguard.StateGuardLifecycleSupport.State.STARTED in project nexus-public by sonatype.
the class SelectorManagerImpl method browseActive.
@Override
@Guarded(by = STARTED)
public List<SelectorConfiguration> browseActive(final Collection<String> repositoryNames, final Collection<String> formats) {
AuthorizationManager authorizationManager;
User currentUser;
try {
authorizationManager = securitySystem.getAuthorizationManager(DEFAULT_SOURCE);
currentUser = securitySystem.currentUser();
} catch (NoSuchAuthorizationManagerException | UserNotFoundException e) {
log.warn("Unable to load active content selectors", e);
return Collections.emptyList();
}
if (currentUser == null) {
return Collections.emptyList();
}
List<String> roleIds = currentUser.getRoles().stream().map(RoleIdentifier::getRoleId).collect(toList());
Set<String> privilegeIds = getRoles(roleIds, authorizationManager).stream().map(Role::getPrivileges).flatMap(Collection::stream).collect(Collectors.toSet());
List<String> contentSelectorNames = authorizationManager.getPrivileges(privilegeIds).stream().filter(repositoryFormatOrNameMatcher(repositoryNames, formats)).map(this::getContentSelector).collect(toList());
return browse().stream().filter(selector -> contentSelectorNames.contains(selector.getName())).collect(toList());
}
use of org.sonatype.nexus.common.stateguard.StateGuardLifecycleSupport.State.STARTED in project nexus-public by sonatype.
the class OrientBrowseNodeStore method deleteByRepository.
@Guarded(by = STARTED)
public void deleteByRepository(final String repositoryName) {
log.debug("Deleting all browse nodes for repository {}", repositoryName);
ProgressLogIntervalHelper progressLogger = new ProgressLogIntervalHelper(log, 60);
int deletedCount;
do {
deletedCount = inTxRetry(databaseInstance).call(db -> entityAdapter.deleteByRepository(db, repositoryName, deletePageSize));
progressLogger.info("Deleted {} browse nodes for repository {} in {}", deletedCount, repositoryName, progressLogger.getElapsed());
} while (deletedCount == deletePageSize);
progressLogger.flush();
log.debug("All browse nodes deleted for repository {} in {}", repositoryName, progressLogger.getElapsed());
}
use of org.sonatype.nexus.common.stateguard.StateGuardLifecycleSupport.State.STARTED in project nexus-public by sonatype.
the class OrientBrowseNodeStore method getByPath.
@Override
@Guarded(by = STARTED)
public Iterable<BrowseNode> getByPath(final Repository repository, final List<String> path, final int maxNodes) {
String repositoryName = repository.getName();
String format = repository.getFormat().getValue();
List<SelectorConfiguration> selectors = emptyList();
if (!hasBrowsePermission(repositoryName, format)) {
// user doesn't have repository-wide access so need to apply content selection
selectors = selectorManager.browseActive(asList(repositoryName), asList(format));
if (selectors.isEmpty()) {
// no browse permission and no selectors -> no results
return emptyList();
}
}
Map<String, Object> filterParameters = new HashMap<>();
String assetFilter = buildAssetFilter(repository, selectors, filterParameters);
BrowseNodeFilter filter = browseNodeFilters.getOrDefault(format, (node, name) -> true);
List<BrowseNode> results;
if (repository.getType() instanceof GroupType) {
BrowseNodeIdentity identity = browseNodeIdentities.getOrDefault(format, BrowseNode::getName);
Equivalence<OrientBrowseNode> browseNodeEquivalence = Equivalence.equals().onResultOf(identity::identity);
// overlay member results, first-one-wins if there are any nodes with the same name
results = members(repository).map(m -> getByPath(m.getName(), path, maxNodes, assetFilter, filterParameters)).flatMap(List::stream).map(browseNodeEquivalence::wrap).distinct().map(Wrapper::get).filter(node -> filter.test(node, repositoryName.equals(node.getRepositoryName()))).limit(maxNodes).collect(toList());
} else {
results = getByPath(repository.getName(), path, maxNodes, assetFilter, filterParameters).stream().filter(node -> filter.test(node, repositoryName.equals(node.getRepositoryName()))).collect(toList());
}
results.sort(getBrowseNodeComparator(format));
return results;
}
Aggregations