Package org.sonatype.security.rest.model

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


  @Test
  public void createUserWithNoRoles()
      throws IOException
  {

    UserResource resource = new UserResource();

    resource.setFirstName("createUserWithNoRoles");
    resource.setUserId("createUserWithNoRoles");
    resource.setStatus("active");
    resource.setEmail("nexus@user.com");
    // no roles
    // resource.addRole( "role1" );

    Response response = this.messageUtil.sendMessage(Method.POST, resource);
View Full Code Here


  @Test
  public void updateUsersPasswordTest()
      throws IOException
  {

    UserResource resource = new UserResource();

    resource.setFirstName("updateUsersPasswordTest");
    resource.setUserId("updateUsersPasswordTest");
    resource.setStatus("active");
    resource.setEmail("nexus@user.com");
    resource.addRole("role1");

    resource = this.messageUtil.createUser(resource);

    resource.setPassword("SHOULD-FAIL");
    Response response = this.messageUtil.sendMessage(Method.PUT, resource);

    String responseText = response.getEntity().getText();
    Assert.assertFalse("Expected failure: Satus: " + response.getStatus() + "\n Response Text:" + responseText,
        response.getStatus().isSuccess());
View Full Code Here

      String responseText = response.getEntity().getText();
      Assert.fail("Could not create user: " + response.getStatus() + ":\n" + responseText);
    }

    // get the Resource object
    UserResource responseResource = this.getResourceFromResponse(response);

    // make sure the id != null
    Assert.assertNotNull("User ID shouldn't be null: "
        + response.getEntity().getText(), responseResource.getUserId());
    user.setUserId(responseResource.getUserId());

    Assert.assertEquals(responseResource.getFirstName(), user.getFirstName());
    Assert.assertEquals(responseResource.getLastName(), user.getLastName());
    Assert.assertEquals(responseResource.getUserId(), user.getUserId());
    Assert.assertEquals(responseResource.getStatus(), user.getStatus());
    Assert.assertEquals(responseResource.getEmail(), user.getEmail());
    Assert.assertEquals(user.getRoles(), responseResource.getRoles());

    new SecurityConfigUtil().verifyUser(user);

    return user;
  }
View Full Code Here

  public UserResource updateUser(UserResource user)
      throws IOException
  {
    Response response = null;
    UserResource responseResource;
    try {
      response = this.sendMessage(Method.PUT, user);
      assertThat(response, isSuccessful());
      responseResource = this.getResourceFromResponse(response);
    }
    finally {
      RequestFacade.releaseResponse(response);
    }

    // make sure the id != null

    Assert.assertEquals(responseResource.getFirstName(), user.getFirstName());
    Assert.assertEquals(responseResource.getLastName(), user.getLastName());
    Assert.assertEquals(responseResource.getUserId(), user.getUserId());
    Assert.assertEquals(responseResource.getStatus(), user.getStatus());
    Assert.assertEquals(responseResource.getEmail(), user.getEmail());
    Assert.assertEquals(user.getRoles(), responseResource.getRoles());

    new SecurityConfigUtil().verifyUser(user);

    return responseResource;
  }
View Full Code Here

   * @return returns the disabled user instance
   */
  public UserResource disableUser(String userId)
      throws IOException
  {
    UserResource user = getUser(userId);
    user.setStatus("disabled");
    updateUser(user);
    return user;
  }
View Full Code Here

        if (shouldBeAdmin) {
          globalConfig.setSecurityAnonymousAccessEnabled(true);
          SettingsMessageUtil.save(globalConfig);
        }

        UserResource user = getUser(globalConfig.getSecurityAnonymousUsername());

        if (shouldBeAdmin) {
          if (!user.getRoles().contains(ADMIN_ROLE)) {
            user.addRole(ADMIN_ROLE);
            updateUser(user);
          }
        }
        else {
          if (user.getRoles().contains(ADMIN_ROLE)) {
            user.removeRole(ADMIN_ROLE);
            updateUser(user);
          }
        }

        return null;
View Full Code Here

  }

  private void updateUserRole(String username, List<String> roleIds)
      throws Exception
  {
    UserResource resource = userUtil.getUser(username);

    resource.setRoles(roleIds);

    userUtil.updateUser(resource);
  }
View Full Code Here

  @Test
  public void userAccountCRU()
      throws Exception
  {
    UserResource resource = new UserResource();
    resource.setUserId("nxcm897");
    resource.setFirstName("NXCM 897");
    resource.setEmail("nxcm897@changeme.com");
    resource.setPassword("admin123");
    resource.addRole("ui-basic");
    resource.setStatus("active");

    this.userMsgUtil.createUser(resource);

    UserAccount dto = accountMsgUtil.readAccount("nxcm897");
    Assert.assertEquals("NXCM 897", dto.getFirstName());
View Full Code Here

  {
    UserResourceRequest resourceRequest = (UserResourceRequest) payload;
    UserResourceResponse result = null;

    if (resourceRequest != null) {
      UserResource resource = resourceRequest.getData();

      // the password can not be set on update, The only way to set a password is using the users_setpw resource
      if (StringUtils.isNotEmpty(resource.getPassword())) {
        throw new PlexusResourceException(
            Status.CLIENT_ERROR_BAD_REQUEST,
            this.getErrorResponse("*",
                "Updating a users password using this URI is not allowed."));
      }

      try {
        User user = restToSecurityModel(getSecuritySystem().getUser(resource.getUserId()), resource);

        validateUserContainment(user);

        getSecuritySystem().updateUser(user);

        result = new UserResourceResponse();

        result.setData(resourceRequest.getData());

        result.getData().setResourceURI(createChildReference(request, resource.getUserId()).toString());

      }
      catch (InvalidConfigurationException e) {
        // build and throw exception
        handleInvalidConfigurationException(e);
View Full Code Here

      throws ResourceException
  {
    UserListResourceResponse result = new UserListResourceResponse();

    for (User user : getSecuritySystem().searchUsers(new UserSearchCriteria(null, null, DEFAULT_SOURCE))) {
      UserResource res = securityToRestModel(user, request, true);

      if (res != null) {
        result.addData(res);
      }
    }
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.