Package org.sonar.server.user

Examples of org.sonar.server.user.UserSession


    checkPermission();
    ruleDeleter.delete(ruleKey);
  }

  private void checkPermission() {
    UserSession userSession = UserSession.get();
    userSession.checkLoggedIn();
    userSession.checkGlobalPermission(GlobalPermissions.QUALITY_PROFILE_ADMIN);
  }
View Full Code Here


  static void checkSystemAdminUser() {
    checkProjectAdminUser(null);
  }

  static void checkProjectAdminUser(@Nullable String componentKey) {
    UserSession currentSession = UserSession.get();
    currentSession.checkLoggedIn();
    if (componentKey == null) {
      currentSession.checkGlobalPermission(GlobalPermissions.SYSTEM_ADMIN);
    } else {
      if (!currentSession.hasGlobalPermission(GlobalPermissions.SYSTEM_ADMIN) && !currentSession.hasProjectPermission(UserRole.ADMIN, componentKey)) {
        throw new ForbiddenException("Insufficient privileges");
      }
    }
  }
View Full Code Here

  }

  @Override
  public void handle(Request request, Response response) {
    String fileKey = request.mandatoryParam(PARAM_KEY);
    UserSession userSession = UserSession.get();

    JsonWriter json = response.newJsonWriter();
    json.beginObject();

    DbSession session = dbClient.openSession(false);
    try {
      ComponentDto component = dbClient.componentDao().getNullableByKey(session, fileKey);
      if (component == null) {
        throw new NotFoundException(String.format("Component '%s' does not exist", fileKey));
      }
      userSession.checkComponentPermission(UserRole.USER, fileKey);

      List<Period> periodList = periods(component.projectUuid(), session);
      Integer periodIndex = request.paramAsInt(PARAM_PERIOD);
      Date periodDate = periodDate(periodIndex, periodList);
View Full Code Here

      }
    }
  }

  private void checkPermission(boolean preview){
    UserSession userSession = UserSession.get();
    boolean hasScanPerm = userSession.hasGlobalPermission(GlobalPermissions.SCAN_EXECUTION);
    boolean hasPreviewPerm = userSession.hasGlobalPermission(GlobalPermissions.DRY_RUN_EXECUTION);
    if (!hasPreviewPerm && !hasScanPerm) {
      throw new ForbiddenException("You're not authorized to execute any SonarQube analysis. Please contact your SonarQube administrator.");
    }
    if (!preview && !hasScanPerm) {
      throw new ForbiddenException("You're only authorized to execute a local (dry run) SonarQube analysis without pushing the results to the SonarQube server. " +
View Full Code Here

    return false;
  }

  private boolean canExecuteTransition(Issue issue, final String transition) {
    final DefaultIssue defaultIssue = (DefaultIssue) issue;
    final UserSession userSession = UserSession.get();
    return Iterables.find(workflow.outTransitions(issue), new Predicate<Transition>() {
      @Override
      public boolean apply(Transition input) {
        return input.key().equals(transition) &&
          (StringUtils.isBlank(input.requiredProjectPermission()) ||
          userSession.hasProjectPermission(input.requiredProjectPermission(), defaultIssue.projectKey()));
      }
    }, null) != null;
  }
View Full Code Here

      .setHandler(this);
  }

  @Override
  public void handle(Request request, Response response) throws Exception {
    UserSession userSession = UserSession.get();
    boolean hasScanPerm = userSession.hasGlobalPermission(GlobalPermissions.SCAN_EXECUTION);
    boolean hasDryRunPerm = userSession.hasGlobalPermission(GlobalPermissions.DRY_RUN_EXECUTION);

    DbSession session = dbClient.openSession(false);
    try {
      GlobalReferentials ref = new GlobalReferentials();
      addMetrics(ref, session);
View Full Code Here

    return issueFilterService.find(id, UserSession.get());
  }

  public boolean isUserAuthorized(DefaultIssueFilter issueFilter) {
    try {
      UserSession userSession = UserSession.get();
      String user = issueFilterService.getLoggedLogin(userSession);
      issueFilterService.verifyCurrentUserCanReadFilter(issueFilter, user);
      return true;
    } catch (Exception e) {
      return false;
View Full Code Here

    StickyFacetBuilder assigneeFacetBuilder = new StickyFacetBuilder(esQuery, assigneeFilters);
    BoolFilterBuilder facetFilter = assigneeFacetBuilder.getStickyFacetFilter(fieldName);
    FilterAggregationBuilder facetTopAggregation = assigneeFacetBuilder.buildTopFacetAggregation(fieldName, facetName, facetFilter, DEFAULT_ISSUE_FACET_SIZE);
    List<String> assignees = Lists.newArrayList(query.assignees());

    UserSession session = UserSession.get();
    if (session.isLoggedIn()) {
      assignees.add(session.login());
    }
    facetTopAggregation = assigneeFacetBuilder.addSelectedItemsToFacet(fieldName, facetName, facetTopAggregation, assignees.toArray());

    // Add missing facet for unassigned issues
    facetTopAggregation.subAggregation(
View Full Code Here

  IssueFilterWriter writer = new IssueFilterWriter();

  @Test
  public void write_filter() throws Exception {
    UserSession userSession = MockUserSession.set();
    test(userSession,
      new DefaultIssueFilter()
        .setId(13L)
        .setName("Blocker issues")
        .setDescription("All Blocker Issues")
View Full Code Here

    );
  }

  @Test
  public void can_modify_if_logged_user_own_filter() throws Exception {
    UserSession userSession = MockUserSession.set().setLogin("simon");
    test(userSession,
      new DefaultIssueFilter()
        .setId(13L)
        .setName("Blocker issues")
        .setDescription("All Blocker Issues")
View Full Code Here

TOP

Related Classes of org.sonar.server.user.UserSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.