use of jetbrains.buildServer.server.rest.errors.AuthorizationFailedException in project teamcity-rest by JetBrains.
the class VcsRootFinder method getPrefilteredItems.
@NotNull
@Override
public ItemHolder<SVcsRoot> getPrefilteredItems(@NotNull Locator locator) {
final String affectedProjectLocator = locator.getSingleDimensionValue(AFFECTED_PROJECT);
if (affectedProjectLocator != null) {
List<SProject> projects = myProjectFinder.getItems(affectedProjectLocator).myEntries;
projects.forEach(project -> myPermissionChecker.checkProjectPermission(Permission.VIEW_BUILD_CONFIGURATION_SETTINGS, project.getProjectId()));
return FinderDataBinding.getItemHolder(projects.stream().flatMap(p -> p.getVcsRoots().stream()).collect(Collectors.toSet()));
}
final String projectLocator = locator.getSingleDimensionValue(PROJECT);
if (projectLocator != null) {
List<SProject> projects = myProjectFinder.getItemsNotEmpty(projectLocator).myEntries;
projects.forEach(project -> myPermissionChecker.checkProjectPermission(Permission.VIEW_BUILD_CONFIGURATION_SETTINGS, project.getProjectId()));
// consistent with Project.java:183
return FinderDataBinding.getItemHolder(projects.stream().flatMap(p -> p.getOwnVcsRoots().stream()));
}
final List<SVcsRoot> allRegisteredVcsRoots = myVcsManager.getAllRegisteredVcsRoots();
final List<SVcsRoot> result = new ArrayList<SVcsRoot>(allRegisteredVcsRoots.size());
for (SVcsRoot root : allRegisteredVcsRoots) {
try {
checkPermission(Permission.VIEW_BUILD_CONFIGURATION_SETTINGS, root);
result.add(root);
} catch (AuthorizationFailedException e) {
// ignore
}
}
return getItemHolder(result);
}
use of jetbrains.buildServer.server.rest.errors.AuthorizationFailedException in project teamcity-rest by JetBrains.
the class PermissionChecker method checkPermission.
public void checkPermission(@NotNull final Permission permission, @NotNull final BuildPromotion buildPromotion) throws AuthorizationFailedException {
try {
final SBuildType buildType = buildPromotion.getBuildType();
checkProjectPermission(permission, buildType == null ? null : buildType.getProjectId(), null);
} catch (AccessDeniedException e) {
throw new AuthorizationFailedException(e.getMessage());
}
}
use of jetbrains.buildServer.server.rest.errors.AuthorizationFailedException in project teamcity-rest by JetBrains.
the class AggregatedBuildArtifactsElementBuilder method getBuildAggregatedArtifactElement.
@NotNull
public static Element getBuildAggregatedArtifactElement(@NotNull final String path, @NotNull final List<BuildPromotion> builds, @NotNull final ServiceLocator serviceLocator) {
final AggregatedBuildArtifactsElementBuilder result = new AggregatedBuildArtifactsElementBuilder();
int i = 0;
for (BuildPromotion buildPromotion : builds) {
try {
final Element artifactElement = BuildArtifactsFinder.getArtifactElement(buildPromotion, path, serviceLocator);
LOG.debug("Found artifact file with path '" + path + "' in " + i + "/" + builds.size() + " build: " + LogUtil.describe(buildPromotion));
result.add(artifactElement);
} catch (NotFoundException e) {
LOG.debug("Ignoring not found error in artifacts aggregation request: " + e.toString());
} catch (AuthorizationFailedException e) {
LOG.debug("Ignoring authentication error in artifacts aggregation request: " + e.toString());
}
i++;
}
return result.get();
}
use of jetbrains.buildServer.server.rest.errors.AuthorizationFailedException in project teamcity-rest by JetBrains.
the class AgentRequest method getCompatibleBuildTypes.
/**
* Experimental support to get currently compatible build types
*/
@GET
@Path("/{agentLocator}/compatibleBuildTypes")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Get build types compatible with the matching agent.", nickname = "getCompatibleBuildTypes")
public BuildTypes getCompatibleBuildTypes(@ApiParam(format = LocatorName.AGENT) @PathParam("agentLocator") String agentLocator, @QueryParam("fields") String fields) {
final SBuildAgent agent = myAgentFinder.getItem(agentLocator);
if (!AuthUtil.canViewAgentDetails(myBeanContext.getServiceLocator().getSingletonService(SecurityContext.class).getAuthorityHolder(), agent)) {
throw new AuthorizationFailedException("No permission to view agent details");
}
Fields fieldsDefinition = new Fields(Agent.COMPATIBLE_BUILD_TYPES + "(" + (StringUtil.isEmpty(fields) ? "$long" : fields) + ")");
return new Agent(agent, fieldsDefinition, myBeanContext).compatibleBuildTypes;
}
use of jetbrains.buildServer.server.rest.errors.AuthorizationFailedException in project teamcity-rest by JetBrains.
the class AgentRequest method geIncompatibleBuildTypes.
/**
* Experimental support to get currently incompatible build types with incompatibility reason
*/
@GET
@Path("/{agentLocator}/incompatibleBuildTypes")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Get build types incompatible with the matching agent.", nickname = "getIncompatibleBuildTypes")
public Compatibilities geIncompatibleBuildTypes(@ApiParam(format = LocatorName.AGENT) @PathParam("agentLocator") String agentLocator, @QueryParam("fields") String fields) {
final SBuildAgent agent = myAgentFinder.getItem(agentLocator);
if (!AuthUtil.canViewAgentDetails(myBeanContext.getServiceLocator().getSingletonService(SecurityContext.class).getAuthorityHolder(), agent)) {
throw new AuthorizationFailedException("No permission to view agent details");
}
Fields fieldsDefinition = new Fields(Agent.INCOMPATIBLE_BUILD_TYPES + "(" + (StringUtil.isEmpty(fields) ? "$long" : fields) + ")");
return new Agent(agent, fieldsDefinition, myBeanContext).incompatibleBuildTypes;
}
Aggregations