Package org.sonatype.security.model

Examples of org.sonatype.security.model.CUserRoleMapping


    jcoderBefore.addRole("developer");

    Assert.assertNull(resource.put(null, request, response, requestRequest));

    // check config
    CUserRoleMapping mapping = this.getConfig().readUserRoleMapping("jcoder", REALM_KEY);
    Assert.assertEquals(1, mapping.getRoles().size());
    Assert.assertTrue(mapping.getRoles().contains("developer"));

    // now delete
    resource.delete(null, request, response);

    // check config
View Full Code Here


    cdugasBefore.addRole("developer");

    Assert.assertNull(resource.put(null, request, response, requestRequest));

    // check config
    CUserRoleMapping mapping = this.getConfig().readUserRoleMapping("cdugas", REALM_KEY);
    Assert.assertEquals(1, mapping.getRoles().size());
    Assert.assertTrue(mapping.getRoles().contains("developer"));

    // now delete
    resource.delete(null, request, response);

    // check config
View Full Code Here

    getConfiguration().addUserRoleMapping(roleMapping);

  }

  private CUserRoleMapping buildUserRoleMapping(String userId, Set<String> roles) {
    CUserRoleMapping roleMapping = new CUserRoleMapping();

    roleMapping.setUserId(userId);
    roleMapping.setSource(SecurityXmlUserManager.SOURCE);
    roleMapping.setRoles(new ArrayList<String>(roles));

    return roleMapping;

  }
View Full Code Here

  public void updateUser(CUser user)
      throws InvalidConfigurationException, UserNotFoundException
  {
    Set<String> roles = Sets.newHashSet();
    try {
      CUserRoleMapping userRoleMapping = this.readUserRoleMapping(user.getId(), SecurityXmlUserManager.SOURCE);
      roles.addAll(userRoleMapping.getRoles());
    }
    catch (NoSuchRoleMappingException e) {
      this.log.debug("User: {} has no roles", user.getId());
    }
    this.updateUser(user, new HashSet<String>(roles));
View Full Code Here

  }

  private CUserRoleMapping readCUserRoleMapping(String userId, String source)
      throws NoSuchRoleMappingException
  {
    CUserRoleMapping mapping = getConfiguration().getUserRoleMappingByUserId(userId, source);

    if (mapping != null) {
      return mapping;
    }
    else {
View Full Code Here

    Assert.assertEquals(user.getFirstName(), "Test");
    Assert.assertEquals(user.getLastName(), "User");
    Assert.assertEquals(user.getPassword(), "b2a0e378437817cebdf753d7dff3dd75483af9e0");
    Assert.assertEquals(user.getStatus(), "active");

    CUserRoleMapping mapping = config.readUserRoleMapping("test-user", "default");

    Assert.assertTrue(mapping.getRoles().contains("role1"));
    Assert.assertTrue(mapping.getRoles().contains("role2"));
    Assert.assertEquals(2, mapping.getRoles().size());
  }
View Full Code Here

    Assert.assertEquals(user.getFirstName(), "Test");
    Assert.assertEquals(user.getLastName(), "User With Empty Role");
    Assert.assertEquals(user.getPassword(), "b2a0e378437817cebdf753d7dff3dd75483af9e0");
    Assert.assertEquals(user.getStatus(), "active");

    CUserRoleMapping mapping = config.readUserRoleMapping("test-user-with-empty-role", "default");

    Assert.assertTrue(mapping.getRoles().contains("empty-role"));
    Assert.assertTrue(mapping.getRoles().contains("role1"));
    Assert.assertTrue(mapping.getRoles().contains("role2"));
    Assert.assertEquals(3, mapping.getRoles().size());

    // try to update empty role
    config.updateUserRoleMapping(mapping);
    config.save();
    config.clearCache();

    // make sure we still have the role mappings
    mapping = config.readUserRoleMapping("test-user-with-empty-role", "default");

    Assert.assertTrue(mapping.getRoles().contains("empty-role"));
    Assert.assertTrue(mapping.getRoles().contains("role1"));
    Assert.assertTrue(mapping.getRoles().contains("role2"));
    Assert.assertEquals(3, mapping.getRoles().size());
  }
View Full Code Here

    Assert.assertEquals(5, config.listUserRoleMappings().size());

    // get the test-user and add a role
    CUser user = config.readUser("test-user");

    CUserRoleMapping roleMapping = config.readUserRoleMapping("test-user", "default");
    List<String> roles = roleMapping.getRoles();
    roles.add("role3");

    // update the user
    config.updateUser(user, new HashSet<String>(roles));
View Full Code Here

  public void updateUser(CUser user)
      throws InvalidConfigurationException, UserNotFoundException
  {
    Set<String> roles = new HashSet<String>();
    try {
      CUserRoleMapping userRoleMapping = this.readUserRoleMapping(user.getId(), SecurityXmlUserManager.SOURCE);
      roles.addAll(userRoleMapping.getRoles());
    }
    catch (NoSuchRoleMappingException e) {
      this.log.debug("User: {} has no roles", user.getId());
    }
    this.updateUser(user, new HashSet<String>(roles));
View Full Code Here

    delegate.addUser(cu);
    id2users.put(cu.getId(), cu);
  }

  public void addUserRoleMapping(final CUserRoleMapping cUserRoleMapping) {
    final CUserRoleMapping curm = cUserRoleMapping.clone();
    delegate.addUserRoleMapping(curm);
    id2roleMappings.put(getUserRoleMappingKey(curm.getUserId(), curm.getSource()), curm);
  }
View Full Code Here

TOP

Related Classes of org.sonatype.security.model.CUserRoleMapping

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.