Package org.sonatype.security.rest.model

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


    XStreamRepresentation representation = new XStreamRepresentation(xstream, "", mediaType);

    String serviceURI = USER_ROLES_SERVICE_PART + "/" + source + "/" + resource.getUserId();

    UserToRoleResourceRequest repoResponseRequest = new UserToRoleResourceRequest();
    repoResponseRequest.setData(resource);

    // now set the payload
    representation.setPayload(repoResponseRequest);

    LOG.debug("sendMessage: {}", representation.getText());
View Full Code Here


    this.setReadable(true);
  }

  @Override
  public Object getPayloadInstance() {
    return new UserToRoleResourceRequest();
  }
View Full Code Here

  @Override
  @PUT
  public Object put(Context context, Request request, Response response, Object payload)
      throws ResourceException
  {
    UserToRoleResourceRequest mappingRequest = (UserToRoleResourceRequest) payload;

    if (mappingRequest.getData() == null) {
      throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST,
          "User Role Mapping was not found in the Request.");
    }

    String userId = this.getUserId(request);
    String sourceId = this.getSourceId(request);

    // check if the user exists
    try {
      if (this.getSecuritySystem().getUser(userId, sourceId) == null) {
        throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "User with id '" + userId + "' not found.");
      }
    }
    catch (UserNotFoundException e) {
      throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "User with id '" + userId + "' not found.");
    }
    catch (NoSuchUserManagerException e) {
      this.getLogger().warn(e.getMessage(), e);
      throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "User with id '" + userId + "' not found.");
    }

    // get the dto
    UserToRoleResource userToRole = mappingRequest.getData();

    Set<RoleIdentifier> roleIdentifiers = this.restToSecurityModel(userToRole);

    if (roleIdentifiers.size() == 0) {
      throw new PlexusResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Configuration error.",
View Full Code Here

    String sourceId = this.getSourceId(request);

    try {
      Set<RoleIdentifier> roleIds = getSecuritySystem().getUsersRoles(userId, sourceId);

      UserToRoleResourceRequest resp = new UserToRoleResourceRequest();

      resp.setData(securityToRestModel(userId, sourceId, roleIds));

      return resp;
    }
    catch (UserNotFoundException e) {
      throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "Could not find user '" + userId + "'.");
View Full Code Here

    request.getAttributes().put(UserToRolePlexusResource.USER_ID_KEY, "jcoder");
    request.getAttributes().put(UserToRolePlexusResource.SOURCE_ID_KEY, MockUserManager.SOURCE);

    PlexusResource userToRoleResource = this.lookup(PlexusResource.class, "UserSearchPlexusResource");

    UserToRoleResourceRequest payload = new UserToRoleResourceRequest();
    payload.setData(new UserToRoleResource());
    payload.getData().setUserId("jcoder");
    payload.getData().setSource(MockUserManager.SOURCE);
    payload.getData().getRoles().add("admin");

    userToRoleResource.put(null, request, response, null);

    // the xml user should have the original roles the mock users should only have admin.
View Full Code Here

    Request request = new Request();
    Response response = new Response(request);
    request.getAttributes().put(UserToRolePlexusResource.USER_ID_KEY, "jcoder");
    request.getAttributes().put(UserToRolePlexusResource.SOURCE_ID_KEY, REALM_KEY);

    UserToRoleResourceRequest requestRequest = new UserToRoleResourceRequest();
    UserToRoleResource jcoderBefore = new UserToRoleResource();
    requestRequest.setData(jcoderBefore);
    jcoderBefore.setUserId("jcoder");
    jcoderBefore.setSource(REALM_KEY);
    jcoderBefore.addRole("developer");

    Assert.assertNull(resource.put(null, request, response, requestRequest));
View Full Code Here

    Request request = new Request();
    Response response = new Response(request);
    request.getAttributes().put(UserToRolePlexusResource.USER_ID_KEY, "jcoder");
    request.getAttributes().put(UserToRolePlexusResource.SOURCE_ID_KEY, REALM_KEY);

    UserToRoleResourceRequest requestRequest = new UserToRoleResourceRequest();
    UserToRoleResource jcoderBefore = new UserToRoleResource();
    requestRequest.setData(jcoderBefore);
    jcoderBefore.setUserId("jcoder");
    jcoderBefore.setSource(REALM_KEY);

    try {
      resource.put(null, request, response, requestRequest);
View Full Code Here

    Request request = new Request();
    Response response = new Response(request);
    request.getAttributes().put(UserToRolePlexusResource.USER_ID_KEY, "cdugas");
    request.getAttributes().put(UserToRolePlexusResource.SOURCE_ID_KEY, REALM_KEY);

    UserToRoleResourceRequest requestRequest = new UserToRoleResourceRequest();
    UserToRoleResource cdugasBefore = new UserToRoleResource();
    requestRequest.setData(cdugasBefore);
    cdugasBefore.setUserId("cdugas");
    cdugasBefore.setSource(REALM_KEY);
    cdugasBefore.addRole("developer");

    Assert.assertNull(resource.put(null, request, response, requestRequest));
View Full Code Here

    Request request = new Request();
    Response response = new Response(request);
    request.getAttributes().put(UserToRolePlexusResource.USER_ID_KEY, "cdugas");
    request.getAttributes().put(UserToRolePlexusResource.SOURCE_ID_KEY, REALM_KEY);

    UserToRoleResourceRequest requestRequest = new UserToRoleResourceRequest();
    UserToRoleResource cdugasBefore = new UserToRoleResource();
    requestRequest.setData(cdugasBefore);
    cdugasBefore.setUserId("cdugas");
    cdugasBefore.setSource(REALM_KEY);
    cdugasBefore.addRole("developerINVALID");
    cdugasBefore.addRole("repomaintainerINVALID");
View Full Code Here

    Request request = new Request();
    Response response = new Response(request);
    request.getAttributes().put(UserToRolePlexusResource.USER_ID_KEY, "jcoder");
    request.getAttributes().put(UserToRolePlexusResource.SOURCE_ID_KEY, REALM_KEY);

    UserToRoleResourceRequest requestRequest = new UserToRoleResourceRequest();
    UserToRoleResource jcoderBefore = new UserToRoleResource();
    requestRequest.setData(jcoderBefore);
    jcoderBefore.setUserId("jcoder");
    jcoderBefore.setSource(REALM_KEY);
    jcoderBefore.addRole("developer");

    Assert.assertNull(resource.put(null, request, response, requestRequest));
View Full Code Here

TOP

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

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.