Package org.sonatype.security.rest.model

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


  @GET
  public UserResourceResponse get(Context context, Request request, Response response, Variant variant)
      throws ResourceException
  {

    UserResourceResponse result = new UserResourceResponse();

    try {
      result.setData(securityToRestModel(getSecuritySystem().getUser(getUserId(request)), request, false));

    }
    catch (UserNotFoundException e) {
      throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, e.getMessage());
    }
View Full Code Here


  @POST
  public UserResourceResponse put(Context context, Request request, Response response, Object payload)
      throws ResourceException
  {
    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

  @POST
  public UserResourceResponse post(Context context, Request request, Response response, Object payload)
      throws ResourceException
  {
    UserResourceRequest requestResource = (UserResourceRequest) payload;
    UserResourceResponse result = null;

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

      try {
        User user = restToSecurityModel(null, resource);

        validateUserContainment(user);

        String password = resource.getPassword();
        getSecuritySystem().addUser(user, password);

        result = new UserResourceResponse();

        // Update the status, as that may have changed
        resource.setStatus(user.getStatus().name());

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

        result.setData(resource);

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

    this.validateXmlHasNoPackageNames(resourceRequest);
  }

  @Test
  public void testUserResourceResponse() {
    UserResourceResponse resourceResponse = new UserResourceResponse();

    UserResource user1 = new UserResource();
    user1.setResourceURI("ResourceURI1");
    user1.setEmail("Email1");
    user1.setUserId("UserId1");
    user1.setFirstName("Name1");
    user1.setStatus("Status1");
    user1.addRole("role1");
    user1.addRole("role2");
    resourceResponse.setData(user1);

    this.marshalUnmarchalThenCompare(resourceResponse);
    this.validateXmlHasNoPackageNames(resourceResponse);
  }
View Full Code Here

TOP

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

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.