Package org.sonatype.security.rest.model

Examples of org.sonatype.security.rest.model.UserResource


  public void resetTestUserPrivs()
      throws Exception
  {
    TestContainer.getInstance().getTestContext().useAdminForRequests();

    UserResource testUser = this.userUtil.getUser(TEST_USER_NAME);
    testUser.getRoles().clear();
    testUser.addRole("anonymous");
    this.userUtil.updateUser(testUser);
  }
View Full Code Here


  protected ArrayList<String> getUserPrivs(String userId)
      throws IOException
  {
    TestContainer.getInstance().getTestContext().useAdminForRequests();

    UserResource user = this.userUtil.getUser(userId);
    ArrayList<String> privs = new ArrayList<String>();

    for (Iterator iter = user.getRoles().iterator(); iter.hasNext(); ) {
      String roleId = (String) iter.next();
      RoleResource role = this.roleUtil.getRole(roleId);

      for (Iterator roleIter = role.getPrivileges().iterator(); roleIter.hasNext(); ) {
        String privId = (String) roleIter.next();
View Full Code Here

  {
    TestContainer.getInstance().getTestContext().useAdminForRequests();

    for (RoleResource roleResource : roleUtil.getList()) {
      if (roleResource.getName().equals(roleName)) {
        UserResource testUser = this.userUtil.getUser(userId);
        testUser.addRole(roleResource.getId());
        this.userUtil.updateUser(testUser);
        break;
      }
    }
  }
View Full Code Here

  {
    // use admin
    TestContainer.getInstance().getTestContext().useAdminForRequests();

    // add it
    UserResource testUser = this.userUtil.getUser(userId);
    testUser.addRole(roleId);
    this.userUtil.updateUser(testUser);
  }
View Full Code Here

      // save it
      role = this.roleUtil.createRole(role);
    }

    // add it
    UserResource testUser = this.userUtil.getUser(userId);
    testUser.getRoles().clear();
    testUser.addRole(role.getId());
    this.userUtil.updateUser(testUser);
  }
View Full Code Here

    if (role == null) {
      Assert.fail("Role not found: " + roleId);
    }

    // add it
    UserResource testUser = this.userUtil.getUser(userId);
    testUser.getRoles().clear();
    testUser.addRole(role.getId());
    this.userUtil.updateUser(testUser);
  }
View Full Code Here

    }
    else {
      RoleMessageUtil.update(role);
    }

    UserResource testUser = this.userUtil.getUser(userId);
    testUser.addRole(role.getId());
    this.userUtil.updateUser(testUser);
  }
View Full Code Here

  protected void removePrivilege(String userId, String privilege)
      throws IOException
  {
    TestContainer.getInstance().getTestContext().useAdminForRequests();

    UserResource testUser = this.userUtil.getUser(userId);
    testUser.removeRole(privilege + "-role");
    this.userUtil.updateUser(testUser);
  }
View Full Code Here

  public void verifyUsers(List<UserResource> users)
      throws IOException
  {

    for (Iterator<UserResource> outterIter = users.iterator(); outterIter.hasNext(); ) {
      UserResource userResource = outterIter.next();

      CUser secUser = getCUser(userResource.getUserId());

      Assert.assertNotNull("Cannot find user: " + userResource.getUserId(), secUser);

      CUser user = UserConverter.toCUser(userResource);

      Assert.assertTrue(new UserComparator().compare(user, secUser) == 0);
View Full Code Here

  {
    TestContext testContext = TestContainer.getInstance().getTestContext();
    testContext.useAdminForRequests();

    // create user,
    UserResource resource = new UserResource();
    resource.setUserId(USER_ID);
    resource.setFirstName("Marvin Velo");
    resource.setEmail("velo@earth.com");
    resource.setStatus("active");
    resource.addRole("nx-admin");
    userUtil.createUser(resource);

    // get email
    // two e-mails (first confirming user creating and second with users pw)
    emailServerHelper.waitForMail(2);
    Thread.sleep(1000); //w8 a few more

    MimeMessage[] msgs = emailServerHelper.getReceivedMessages();
    String password = null;
    StringBuilder emailsContent = new StringBuilder();

    /// make sure we have at least 1 message
    Assert.assertTrue("No emails recieved.", msgs.length > 0);

    for (MimeMessage mimeMessage : msgs) {
      emailsContent.append(GreenMailUtil.getHeaders(mimeMessage)).append('\n');

      // Sample body: Your new password is ********
      String body = GreenMailUtil.getBody(mimeMessage);
      emailsContent.append(body).append('\n').append('\n');

      int index = body.indexOf("Your new password is ");
      int passwordStartIndex = index + "Your new password is ".length();
      if (index != -1) {
        password = body.substring(passwordStartIndex, body.indexOf('\n', passwordStartIndex)).trim();
        log.debug("New password:\n" + password);
        break;
      }
    }

    Assert.assertNotNull(password, "Didn't recieve a password.  Got the following messages:\n" + emailsContent);

    // login with generated password
    testContext.setUsername(USER_ID);
    testContext.setPassword(password);
    Status status = UserCreationUtil.login();
    Assert.assertTrue(status.isSuccess());

    // set new password
    String newPassword = "velo123";
    status = ChangePasswordUtils.changePassword(USER_ID, password, newPassword);
    Assert.assertTrue(status.isSuccess());

    // check if the user is 'active'
    testContext.useAdminForRequests();
    UserResource user = userUtil.getUser(USER_ID);
    Assert.assertEquals(user.getStatus(), "active");

    // login with new password
    testContext.setUsername(USER_ID);
    testContext.setPassword(newPassword);
    status = UserCreationUtil.login();
View Full Code Here

TOP

Related Classes of org.sonatype.security.rest.model.UserResource

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.