コード例 #1
0
 @GET
 @Produces(APPLICATION_JSON)
 public Response get(
     @Context HttpServletRequest request,
     @QueryParam("repositoryId") Integer repositoryId,
     @QueryParam("pullRequestId") Long pullRequestId)
     throws Exception {
   if (userManager.getRemoteUser(request) == null) {
     return status(UNAUTHORIZED).build();
   }
   List<PrnfsButton> buttons = newArrayList();
   final PrnfsSettings settings = getSettings();
   for (PrnfsButton candidate : settings.getButtons()) {
     UserKey userKey = userManager.getRemoteUserKey();
     PrnfsPullRequestAction pullRequestAction = PrnfsPullRequestAction.valueOf(BUTTON_TRIGGER);
     final PullRequest pullRequest = pullRequestService.getById(repositoryId, pullRequestId);
     Map<PrnfsVariable, Supplier<String>> variables =
         getVariables(settings, candidate.getFormIdentifier());
     if (allowedUseButton(
             candidate, userManager.isAdmin(userKey), userManager.isSystemAdmin(userKey))
         && triggeredByAction(settings, pullRequestAction, pullRequest, variables, request)) {
       buttons.add(candidate);
     }
   }
   return ok(gson.toJson(buttons), APPLICATION_JSON).build();
 }
コード例 #2
0
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    String user = userManager.getRemoteUsername();
    if (!userManager.isAdmin(user)) {
      resp.sendError(403, "Must be an administrator to configure Speakeasy");
      return;
    }

    webResourceManager.requireResource("com.atlassian.auiplugin:ajs");
    webResourceManager.requireResourcesForContext("speakeasy.admin");

    try {
      final Settings settings = speakeasyService.getSettings(user);
      resp.setContentType("text/html");
      render(
          "templates/admin.vm",
          ImmutableMap.<String, Object>builder()
              .put("user", user)
              .put("contextPath", req.getContextPath())
              .put(
                  "staticResourcesPrefix",
                  webResourceManager.getStaticResourcePrefix(UrlMode.RELATIVE))
              .put("settings", new JsRenderer(jsonMarshaller.marshal(settings)))
              .put("permissionsJson", new JsRenderer(jsonMarshaller.marshal(Permission.ALL)))
              .put("permissions", Permission.ALL)
              .build(),
          resp.getWriter());
    } catch (UnauthorizedAccessException e) {
      resp.sendError(403, e.getMessage());
    }
    resp.getWriter().close();
  }
コード例 #3
0
  @POST
  @Produces(APPLICATION_JSON)
  public Response post(
      @Context HttpServletRequest request,
      @QueryParam("repositoryId") Integer repositoryId,
      @QueryParam("pullRequestId") Long pullRequestId,
      @QueryParam("formIdentifier") final String formIdentifier)
      throws Exception {
    if (userManager.getRemoteUser(request) == null) {
      return status(UNAUTHORIZED).build();
    }

    final PrnfsSettings settings = getSettings();
    for (PrnfsNotification prnfsNotification : settings.getNotifications()) {
      PrnfsPullRequestAction pullRequestAction = PrnfsPullRequestAction.valueOf(BUTTON_TRIGGER);
      final PullRequest pullRequest = pullRequestService.getById(repositoryId, pullRequestId);
      Map<PrnfsVariable, Supplier<String>> variables = getVariables(settings, formIdentifier);
      PrnfsRenderer renderer =
          getRenderer(pullRequest, prnfsNotification, pullRequestAction, variables, request);
      if (prnfsPullRequestEventListener.notificationTriggeredByAction(
          prnfsNotification, pullRequestAction, renderer)) {
        prnfsPullRequestEventListener.notify(
            prnfsNotification, pullRequestAction, pullRequest, variables, renderer);
      }
    }
    return status(OK).build();
  }
  @Test
  public void test_getRemoteUser_success() {
    when(mockUserManager.getRemoteUsername()).thenReturn("someUser");
    when(mockUserAccessor.getUser("someUser")).thenReturn(new DefaultUser("someUser"));

    final User remoteUser = classUnderTest.getRemoteUser();

    assertThat(remoteUser.getName(), is("someUser"));
  }
  @Test
  public void test_canCreatePage_success() {
    final Page contentEntityObject = new Page();

    when(mockUserManager.getRemoteUsername()).thenReturn(SOME_USER1.getName());
    when(mockUserAccessor.getUser(SOME_USER1.getName())).thenReturn(SOME_USER1);
    when(mockPermissionManager.hasPermission(SOME_USER1, Permission.EDIT, contentEntityObject))
        .thenReturn(true);

    final boolean result = classUnderTest.canCreatePage(contentEntityObject);
    assertThat(result, is(true));
  }
  @Test
  public void test_canAttachFile_success() {
    ContentEntityObject contentEntityObject = new Page();

    when(mockUserManager.getRemoteUsername()).thenReturn(SOME_USER1.getName());
    when(mockUserAccessor.getUser(SOME_USER1.getName())).thenReturn(SOME_USER1);
    when(mockPermissionManager.hasCreatePermission(
            SOME_USER1, contentEntityObject, Attachment.class))
        .thenReturn(true);

    boolean result = classUnderTest.canAttachFile(contentEntityObject);

    assertThat(result, is(true));
  }
コード例 #7
0
 private PrnfsRenderer getRenderer(
     final PullRequest pullRequest,
     PrnfsNotification prnfsNotification,
     PrnfsPullRequestAction pullRequestAction,
     Map<PrnfsVariable, Supplier<String>> variables,
     HttpServletRequest request) {
   StashUser stashUser =
       userService.getUserBySlug(userManager.getRemoteUser(request).getUsername());
   return new PrnfsRenderer(
       pullRequest,
       pullRequestAction,
       stashUser,
       repositoryService,
       propertiesService,
       prnfsNotification,
       variables);
 }
コード例 #8
0
  private Person generatePerson(String username) {
    String product = applicationProperties.getDisplayName();
    Person person = new Person();

    // don't want to get a default UserProfile when the "user" is anon or the product,
    // and anyway there could be a user with the username "anonymous" or "Confluence" etc
    if (i18nResolver.getText("upm.auditLog.anonymous").equals(username)
        || product.equals(username)) {
      person.setName(username);
    } else {
      UserProfile userProfile = userManager.getUserProfile(username);
      final String userFullname = userProfile == null ? null : userProfile.getFullName();
      person.setName((userFullname != null) ? userFullname : username);
      URI userUri = uriBuilder.buildAbsoluteProfileUri(userProfile);
      if (userUri != null) {
        person.setUrl(userUri.toString());
      }
    }
    return person;
  }
コード例 #9
0
  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException {
    if (userManager != null) {
      // validation user permissions
      if (!CommonJiraPluginUtils.isAnAuthorizedJiraAdministrator(req, userManager)) {
        CommonJiraPluginUtils.unauthorize(res, templateRenderer);
        return;
      }

      // load resources and show template
      loadWebResources();

      // store if has data
      if (req.getParameterMap().size() > 0) {

        String jiraUser = userManager.getRemoteUsername(req);
        String ciUser = req.getParameter("ciUser");
        String ciUrl = req.getParameter("ciUrl");
        String ciAccessKeyId = req.getParameter("ciAccessKeyId");
        String ciSecretKey = req.getParameter("ciSecretKey");

        if (pluginConfigService.hasConfiguration()) {
          aIMSService.deleteAccessKeyId();
        }

        PluginConfig pluginConfig =
            pluginConfigService.createOrUpdateConfiguration(
                jiraUser, ciUser, ciUrl, ciAccessKeyId, ciSecretKey);

        if (pluginConfig != null) {
          res.setContentType("application/json");
          JSONObject obj = new JSONObject();
          obj.put("success", "true");
          res.getWriter().write(obj.toString());
        } else {
          res.sendError(HttpServletResponse.SC_BAD_REQUEST);
        }
      }
    }
  }
コード例 #10
0
  protected ModelAndView onSubmit(
      HttpServletRequest request,
      HttpServletResponse response,
      Object command,
      BindException errors)
      throws Exception {
    String remoteUser = userManager.getRemoteUsername(request);

    MigrateDirectoryUsersCommand migrateUsersCommand = (MigrateDirectoryUsersCommand) command;

    migrateUsers(
        migrateUsersCommand.getFromDirectoryId(),
        migrateUsersCommand.getToDirectoryId(),
        remoteUser,
        migrateUsersCommand,
        errors);

    if (errors.hasErrors()) {
      return showForm(request, response, errors, referenceData(request));
    }
    return showForm(request, response, errors, referenceData(request));
  }
コード例 #11
0
 public void logI18nMessage(final String key, final String... params) {
   logI18nMessageWithUsername(key, checkAnonymous(userManager.getRemoteUsername()), params);
 }