use of org.osgi.service.useradmin.Group in project aries by apache.
the class UserAdmin method addMember.
/**
* @see org.osgi.jmx.service.useradmin.UserAdminMBean#addMember(java.lang.String, java.lang.String)
*/
public boolean addMember(String groupname, String rolename) throws IOException {
if (groupname == null) {
throw new IOException("Group name cannot be null");
}
if (rolename == null) {
throw new IOException("Role name cannot be null");
}
Role group = userAdmin.getRole(groupname);
Role member = userAdmin.getRole(rolename);
if (group == null) {
throw new IOException("Operation fails role with provided groupname = [" + groupname + "] doesn't exist");
}
validateRoleType(group, Role.GROUP);
return ((Group) group).addMember(member);
}
use of org.osgi.service.useradmin.Group in project aries by apache.
the class UserAdminTest method testRemoveMember.
/**
* Test method for {@link org.apache.aries.jmx.useradmin.UserAdmin#removeMember(java.lang.String, java.lang.String)}
* .
*
* @throws IOException
*/
@Test
public void testRemoveMember() throws IOException {
Group group1 = Mockito.mock(Group.class);
User user1 = Mockito.mock(User.class);
Mockito.when(userAdmin.getRole("group1")).thenReturn(group1);
Mockito.when(userAdmin.getRole("user1")).thenReturn(user1);
Mockito.when(group1.getType()).thenReturn(Role.GROUP);
Mockito.when(group1.removeMember(user1)).thenReturn(true);
boolean isAdded = mbean.removeMember("group1", "user1");
Assert.assertTrue(isAdded);
Mockito.verify(group1).removeMember(user1);
}
use of org.osgi.service.useradmin.Group in project aries by apache.
the class UserAdminTest method testAddMember.
/**
* Test method for {@link org.apache.aries.jmx.useradmin.UserAdmin#addMember(java.lang.String, java.lang.String)}.
*
* @throws IOException
*/
@Test
public void testAddMember() throws IOException {
Group group1 = Mockito.mock(Group.class);
User user1 = Mockito.mock(User.class);
Mockito.when(userAdmin.getRole("group1")).thenReturn(group1);
Mockito.when(userAdmin.getRole("user1")).thenReturn(user1);
Mockito.when(group1.getType()).thenReturn(Role.GROUP);
Mockito.when(group1.addMember(user1)).thenReturn(true);
boolean isAdded = mbean.addMember("group1", "user1");
Assert.assertTrue(isAdded);
Mockito.verify(group1).addMember(user1);
}
use of org.osgi.service.useradmin.Group in project felix by apache.
the class RoleRepositorySerializer method addGroups.
/**
* Adds all groups, based on the given stub groups.
*
* @param repository the repository to add the groups to, cannot be <code>null</code>;
* @param stubGroups the list with stub groups to replace, cannot be <code>null</code>.
* @throws IOException in case a referenced role was not found in the repository.
*/
private void addGroups(Map repository, List stubGroups) throws IOException {
// First create "empty" groups in the repository; we'll fill them in later on...
Iterator sgIter = stubGroups.iterator();
while (sgIter.hasNext()) {
StubGroupImpl stubGroup = (StubGroupImpl) sgIter.next();
Group group = (Group) RoleFactory.createRole(Role.GROUP, stubGroup.getName());
copyDictionary(stubGroup.getProperties(), group.getProperties());
copyDictionary(stubGroup.getCredentials(), group.getCredentials());
repository.put(group.getName(), group);
}
int origSize = stubGroups.size();
while (!stubGroups.isEmpty()) {
List copy = new ArrayList(stubGroups);
int size = copy.size();
for (int i = 0; i < size; i++) {
StubGroupImpl stubGroup = (StubGroupImpl) copy.get(i);
Group group = (Group) repository.get(stubGroup.getName());
if (group != null) {
resolveGroupMembers(stubGroup, group, repository);
stubGroups.remove(stubGroup);
}
}
// In case we didn't resolve any groups; we should fail...
if (origSize == stubGroups.size()) {
throw new IOException("Failed to resolve groups: " + stubGroups);
}
origSize = stubGroups.size();
}
}
use of org.osgi.service.useradmin.Group in project felix by apache.
the class RoleRepositoryFileStorePerformanceTest method createGroup.
private Group createGroup(int idx) {
String name = "Group" + idx;
Group result = RoleFactory.createGroup(name);
setCredentials(result);
setProperties(result);
return result;
}
Aggregations