Package org.sonatype.security.rest.model

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


      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.",
          getErrorResponse("roles", "User requires one or more roles."));
    }

    try {
      // this will throw if we cannot find the user, in that case we will create one.
      getSecuritySystem().setUsersRoles(userToRole.getUserId(), userToRole.getSource(), roleIdentifiers);
    }
    catch (InvalidConfigurationException e) {
      this.handleInvalidConfigurationException(e);
    }
    catch (UserNotFoundException e) {
View Full Code Here


    return roleIdentifiers;
  }

  private UserToRoleResource securityToRestModel(String userId, String source, Set<RoleIdentifier> roleIds) {
    UserToRoleResource resource = new UserToRoleResource();

    resource.setUserId(userId);

    resource.setSource(source);

    List<String> roles = new ArrayList<String>();

    for (RoleIdentifier roleId : roleIds) {
      roles.add(roleId.getRoleId());
    }

    resource.setRoles(roles);

    return resource;
  }
View Full Code Here

    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);
View Full Code Here

    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

    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);
      Assert.fail("Expected ResourceException");
    }
View Full Code Here

    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

    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");

    try {
      resource.put(null, request, response, requestRequest);
      Assert.fail("Expected PlexusResourceException");
    }
View Full Code Here

    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));

    // check config
    CUserRoleMapping mapping = this.getConfig().readUserRoleMapping("jcoder", REALM_KEY);
View Full Code Here

    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));

    // check config
    CUserRoleMapping mapping = this.getConfig().readUserRoleMapping("cdugas", REALM_KEY);
View Full Code Here

    Response response = new Response(request);
    request.getAttributes().put(UserToRolePlexusResource.USER_ID_KEY, "FOO-USER");
    request.getAttributes().put(UserToRolePlexusResource.SOURCE_ID_KEY, REALM_KEY);

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

    try {
      resource.delete(null, request, response);
    }
    catch (ResourceException e) {
View Full Code Here

TOP

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

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.