Search in sources :

Example 1 with AuthorizationFailedException

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);
}
Also used : java.util(java.util) AuthorizationFailedException(jetbrains.buildServer.server.rest.errors.AuthorizationFailedException) LocatorName(jetbrains.buildServer.server.rest.swagger.constants.LocatorName) LocatorResource(jetbrains.buildServer.server.rest.swagger.annotations.LocatorResource) BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) ParametersProvider(jetbrains.buildServer.parameters.ParametersProvider) EntityId(jetbrains.buildServer.serverSide.identifiers.EntityId) AbstractMapParametersProvider(jetbrains.buildServer.parameters.impl.AbstractMapParametersProvider) VcsRoot(jetbrains.buildServer.server.rest.model.change.VcsRoot) ProjectManager(jetbrains.buildServer.serverSide.ProjectManager) LogUtil(jetbrains.buildServer.serverSide.impl.LogUtil) VcsSettings(jetbrains.vcs.api.VcsSettings) Logger(com.intellij.openapi.diagnostic.Logger) VcsSupportCore(jetbrains.buildServer.vcs.VcsSupportCore) PagerData(jetbrains.buildServer.server.rest.model.PagerData) TeamCityProperties(jetbrains.buildServer.serverSide.TeamCityProperties) SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) Constants(jetbrains.buildServer.server.rest.request.Constants) VcsRootIdentifiersManager(jetbrains.buildServer.serverSide.identifiers.VcsRootIdentifiersManager) Collectors(java.util.stream.Collectors) APIController(jetbrains.buildServer.server.rest.APIController) Nullable(org.jetbrains.annotations.Nullable) CommonLocatorDimensionsList(jetbrains.buildServer.server.rest.swagger.constants.CommonLocatorDimensionsList) LocatorDimension(jetbrains.buildServer.server.rest.swagger.annotations.LocatorDimension) Permission(jetbrains.buildServer.serverSide.auth.Permission) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) VcsMappingElement(jetbrains.vcs.api.services.tc.VcsMappingElement) SProject(jetbrains.buildServer.serverSide.SProject) NotNull(org.jetbrains.annotations.NotNull) VcsManager(jetbrains.buildServer.vcs.VcsManager) PersonalSupportBatchService(jetbrains.vcs.api.services.tc.PersonalSupportBatchService) BuildProject(jetbrains.buildServer.BuildProject) SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) AuthorizationFailedException(jetbrains.buildServer.server.rest.errors.AuthorizationFailedException) SProject(jetbrains.buildServer.serverSide.SProject) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with AuthorizationFailedException

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());
    }
}
Also used : AuthorizationFailedException(jetbrains.buildServer.server.rest.errors.AuthorizationFailedException)

Example 3 with AuthorizationFailedException

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();
}
Also used : BuildPromotion(jetbrains.buildServer.serverSide.BuildPromotion) AuthorizationFailedException(jetbrains.buildServer.server.rest.errors.AuthorizationFailedException) Element(jetbrains.buildServer.util.browser.Element) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with AuthorizationFailedException

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;
}
Also used : SBuildAgent(jetbrains.buildServer.serverSide.SBuildAgent) Fields(jetbrains.buildServer.server.rest.model.Fields) AuthorizationFailedException(jetbrains.buildServer.server.rest.errors.AuthorizationFailedException) SecurityContext(jetbrains.buildServer.serverSide.auth.SecurityContext) SBuildAgent(jetbrains.buildServer.serverSide.SBuildAgent) ApiOperation(io.swagger.annotations.ApiOperation)

Example 5 with AuthorizationFailedException

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;
}
Also used : SBuildAgent(jetbrains.buildServer.serverSide.SBuildAgent) Fields(jetbrains.buildServer.server.rest.model.Fields) AuthorizationFailedException(jetbrains.buildServer.server.rest.errors.AuthorizationFailedException) SecurityContext(jetbrains.buildServer.serverSide.auth.SecurityContext) SBuildAgent(jetbrains.buildServer.serverSide.SBuildAgent) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

AuthorizationFailedException (jetbrains.buildServer.server.rest.errors.AuthorizationFailedException)9 ApiOperation (io.swagger.annotations.ApiOperation)4 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)4 Fields (jetbrains.buildServer.server.rest.model.Fields)3 SecurityContext (jetbrains.buildServer.serverSide.auth.SecurityContext)3 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)2 BuildTypeOrTemplate (jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate)2 SBuildAgent (jetbrains.buildServer.serverSide.SBuildAgent)2 SProject (jetbrains.buildServer.serverSide.SProject)2 Permission (jetbrains.buildServer.serverSide.auth.Permission)2 NotNull (org.jetbrains.annotations.NotNull)2 Logger (com.intellij.openapi.diagnostic.Logger)1 java.util (java.util)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 HttpSession (javax.servlet.http.HttpSession)1 BuildProject (jetbrains.buildServer.BuildProject)1 ParametersProvider (jetbrains.buildServer.parameters.ParametersProvider)1