Beispiel #1
0
  @Path("{username}")
  public UserResource getUserByUsername(@Context UriInfo ui, @PathParam("username") String username)
      throws Exception {

    if ("me".equals(username)) {
      UserInfo user = SubjectUtils.getAdminUser();
      if ((user != null) && (user.getUuid() != null)) {
        return getSubResource(UserResource.class)
            .init(management.getAdminUserByUuid(user.getUuid()));
      }
      throw mappableSecurityException(
          "unauthorized", "No admin identity for access credentials provided");
    }

    return getSubResource(UserResource.class).init(management.getAdminUserByUsername(username));
  }
  @Test
  public void addExistingAdminUserToOrganization() throws Exception {

    Map<String, String> originalProperties = getRemoteTestProperties();

    try {
      Mailbox.clearAll();
      setTestProperty(PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false");
      setTestProperty(PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false");
      setTestProperty(PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "false");
      setTestProperty(PROPERTIES_SYSADMIN_EMAIL, "*****@*****.**");

      // svcSetup an admin user
      String adminUserEmail = "*****@*****.**";
      UserInfo adminUser =
          setup
              .getMgmtSvc()
              .createAdminUser(
                  adminUserEmail, adminUserEmail, adminUserEmail, "password1", true, false);
      assertNotNull(adminUser);
      Message[] msgs = getMessages("otherorg.com", "AdminUserFromOtherOrg", "password1");
      assertEquals(1, msgs.length);

      // add existing admin user to org
      // this should NOT send resetpwd  link in email to newly added org admin user(that
      // already exists in usergrid)
      // only "User Invited To Organization" email
      String adminToken = adminToken();
      JsonNode node =
          postAddAdminToOrg(
              "test-organization", "*****@*****.**", "password1", adminToken);
      String uuid = node.get("data").get("user").get("uuid").getTextValue();
      UUID userId = UUID.fromString(uuid);

      assertEquals(adminUser.getUuid(), userId);

      String resetpwd = "Password Reset";
      String invited = "User Invited To Organization";

      msgs = getMessages("otherorg.com", "AdminUserFromOtherOrg", "password1");

      // only 1 invited msg
      assertEquals(2, msgs.length);

      // email subject
      assertNotSame(resetpwd, msgs[1].getSubject());
      assertEquals(invited, msgs[1].getSubject());
    } finally {
      setTestProperties(originalProperties);
    }
  }