Search in sources :

Example 1 with PermissionChecker

use of jetbrains.buildServer.server.rest.data.PermissionChecker in project teamcity-rest by JetBrains.

the class BuildTypeUtil method checkCanUseBuildTypeAsDependency.

public static void checkCanUseBuildTypeAsDependency(final String buildTypeExternalId, final ServiceLocator serviceLocator) {
    // see also TW-39209
    if (!TeamCityProperties.getBooleanOrTrue("rest.dependency.checkPermissionsOnChange")) {
        return;
    }
    final PermissionChecker permissionChecker = serviceLocator.getSingletonService(PermissionChecker.class);
    if (permissionChecker.isPermissionGranted(Permission.VIEW_PROJECT, null)) {
        return;
    }
    final SBuildType buildType = serviceLocator.getSingletonService(ProjectManager.class).findBuildTypeByExternalId(buildTypeExternalId);
    if (buildType == null) {
        if (TeamCityProperties.getBoolean("rest.dependency.allowMissingBuildTypeDependency")) {
            return;
        }
        throw new BadRequestException("Cannot find build type with id '" + buildTypeExternalId + "'");
    }
    permissionChecker.checkProjectPermission(Permission.VIEW_PROJECT, buildType.getProjectId());
}
Also used : PermissionChecker(jetbrains.buildServer.server.rest.data.PermissionChecker) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException)

Example 2 with PermissionChecker

use of jetbrains.buildServer.server.rest.data.PermissionChecker in project teamcity-rest by JetBrains.

the class LicensingData method initLicensingPolicyDependantFields.

private void initLicensingPolicyDependantFields(@NotNull LicenseKeysManager licenseKeysManager, @NotNull Fields fields, @NotNull BeanContext beanContext) {
    final LicensingPolicyEx licensingPolicy = licenseKeysManager.getLicensingPolicy();
    final PermissionChecker permissionChecker = beanContext.getSingletonService(PermissionChecker.class);
    licenseUseExceeded = ValueWithDefault.decideDefaultIgnoringAccessDenied(fields.isIncluded("licenseUseExceeded"), () -> {
        permissionChecker.checkGlobalPermission(Permission.MANAGE_SERVER_LICENSES);
        return licensingPolicy.isMaxNumberOfBuildTypesExceeded();
    });
    agentsLeft = ValueWithDefault.decideIncludeByDefault(myFields.isIncluded("agentsLeft"), () -> {
        if (permissionChecker.hasGlobalPermission(Permission.MANAGE_SERVER_LICENSES) || permissionChecker.hasGlobalPermission(Permission.VIEW_AGENT_DETAILS))
            return licensingPolicy.getAgentsLicensesLeft();
        return null;
    });
    buildTypesLeft = ValueWithDefault.decideDefaultIgnoringAccessDenied(fields.isIncluded("buildTypesLeft"), () -> {
        permissionChecker.checkGlobalPermission(Permission.MANAGE_SERVER_LICENSES);
        int result = licensingPolicy.getBuildTypesLicensesLeft();
        return result == -1 ? null : result;
    });
}
Also used : PermissionChecker(jetbrains.buildServer.server.rest.data.PermissionChecker) LicensingPolicyEx(jetbrains.buildServer.serverSide.LicensingPolicyEx)

Example 3 with PermissionChecker

use of jetbrains.buildServer.server.rest.data.PermissionChecker in project teamcity-rest by JetBrains.

the class ServerRequestTest method setUp.

@Override
@BeforeMethod
public void setUp() throws Exception {
    super.setUp();
    BeanContext ctx = BaseFinderTest.getBeanContext(myFixture);
    PermissionChecker checker = new PermissionChecker(myServer.getSecurityContext(), myProjectManager);
    myFixture.addService(checker);
    myRequest = new ServerRequest();
    myRequest.initForTests(ctx.getServiceLocator(), ctx.getApiUrlBuilder(), new BeanFactory(null), ctx, checker);
}
Also used : BeanContext(jetbrains.buildServer.server.rest.util.BeanContext) PermissionChecker(jetbrains.buildServer.server.rest.data.PermissionChecker) BeanFactory(jetbrains.buildServer.server.rest.util.BeanFactory) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with PermissionChecker

use of jetbrains.buildServer.server.rest.data.PermissionChecker in project teamcity-rest by JetBrains.

the class BaseResolverTest method setUp.

@Override
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception {
    super.setUp();
    myDataFetchingEnvironment = new MockDataFetchingEnvironment();
    myFixture.addService(myProjectManager);
    myPermissionChecker = new PermissionChecker(myServer.getSecurityContext(), myProjectManager);
    myFixture.addService(myPermissionChecker);
    myProjectFinder = new ProjectFinder(myProjectManager, myPermissionChecker, myServer);
    myFixture.addService(myProjectFinder);
}
Also used : PermissionChecker(jetbrains.buildServer.server.rest.data.PermissionChecker) ProjectFinder(jetbrains.buildServer.server.rest.data.ProjectFinder) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

PermissionChecker (jetbrains.buildServer.server.rest.data.PermissionChecker)4 BeforeMethod (org.testng.annotations.BeforeMethod)2 ProjectFinder (jetbrains.buildServer.server.rest.data.ProjectFinder)1 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)1 BeanContext (jetbrains.buildServer.server.rest.util.BeanContext)1 BeanFactory (jetbrains.buildServer.server.rest.util.BeanFactory)1 LicensingPolicyEx (jetbrains.buildServer.serverSide.LicensingPolicyEx)1