use of com.b2international.snowowl.core.identity.Role in project snow-owl by b2ihealthcare.
the class CommitInfoRequestTest method searchCommitInfoByBranch.
@Test
public void searchCommitInfoByBranch() {
final String oid = UUID.randomUUID().toString();
final String shortName = "Resource6";
final String comment = "Code system for commit info 6";
final String branchName = "Test6";
final String term = "Test Description 6";
createCodeSystem(shortName, oid, comment);
final String branchPath = createBranch(String.format("%s/%s", BRANCH, shortName), branchName);
createDescription(ResourceURI.branch(CodeSystem.RESOURCE_TYPE, shortName, branchName), term, comment);
// Search as admin
assertEquals(1, RepositoryRequests.commitInfos().prepareSearchCommitInfo().filterByBranch(branchPath).build(REPOSITORY_ID).execute(bus).getSync().getTotal());
final Permission userPermission = Permission.requireAll(Permission.OPERATION_BROWSE, String.format("%s*", shortName));
final List<Role> roles = List.of(new Role("Editor", List.of(userPermission)));
final String userName = "User6";
final User user = new User(userName, roles);
final IEventBus authorizedBus = new AuthorizedEventBus(bus, ImmutableMap.of(AuthorizedRequest.AUTHORIZATION_HEADER, Services.service(JWTGenerator.class).generate(user)));
// Search as user with limited permissions
assertEquals(1, RepositoryRequests.commitInfos().prepareSearchCommitInfo().filterByBranch(branchPath).build(REPOSITORY_ID).execute(authorizedBus).getSync().getTotal());
}
use of com.b2international.snowowl.core.identity.Role in project snow-owl by b2ihealthcare.
the class LdapIdentityProvider method searchUsers.
@Override
public Promise<Users> searchUsers(Collection<String> usernames, int limit) {
final ImmutableList.Builder<User> resultBuilder = ImmutableList.builder();
final String uidProp = conf.getUserIdProperty();
InitialLdapContext context = null;
NamingEnumeration<SearchResult> searchResultEnumeration = null;
try {
context = createLdapContext();
Collection<LdapRole> ldapRoles = getAllLdapRoles(context);
searchResultEnumeration = context.search(conf.getBaseDn(), conf.getUserFilter(), createSearchControls(ATTRIBUTE_DN, uidProp));
for (final SearchResult searchResult : ImmutableList.copyOf(Iterators.forEnumeration(searchResultEnumeration))) {
final Attributes attributes = searchResult.getAttributes();
if (hasAttribute(attributes, uidProp)) {
final String userName = (String) attributes.get(uidProp).get();
final List<Role> userRoles = ldapRoles.stream().filter(role -> role.getUniqueMembers().contains(searchResult.getNameInNamespace())).map(role -> new Role(role.getName(), role.getPermissions())).collect(Collectors.toList());
resultBuilder.add(new User(userName, userRoles));
}
}
final List<User> users = resultBuilder.build().stream().sorted((u1, u2) -> u1.getUsername().compareTo(u2.getUsername())).filter(user -> usernames.isEmpty() || usernames.contains(user.getUsername())).limit(limit).collect(Collectors.toList());
return Promise.immediate(new Users(users, limit, users.size()));
} catch (final NamingException e) {
LOG.error("Couldn't search users/roles due to LDAP communication error: {}", e.getMessage(), e);
throw new SnowowlRuntimeException(e);
} finally {
closeNamingEnumeration(searchResultEnumeration);
closeLdapContext(context);
}
}
use of com.b2international.snowowl.core.identity.Role in project snow-owl by b2ihealthcare.
the class CommitInfoRequestTest method searchCommitOnSubBranch.
@Test
public void searchCommitOnSubBranch() {
// Search with no branch filter, to test security filter for user with limited resources
final String oid = UUID.randomUUID().toString();
final String shortName = "Resource7";
final String comment = "Code system for commit info 7";
final String branchName = "Test7";
final String commitComment = "Create Description 7";
final String term = "Test Description 7";
// Commit on resource branch
createCodeSystem(shortName, oid, comment);
createDescription(ResourceURI.of(CodeSystem.RESOURCE_TYPE, shortName), term, commitComment);
// Commit on version branch
final String branchPath = createBranch(String.format("%s/%s", BRANCH, shortName), branchName);
createDescription(ResourceURI.branch(CodeSystem.RESOURCE_TYPE, shortName, branchName), term, commitComment);
// Commit on deeper branch
final String newBranchName = String.format("%s/%s", branchName, branchName);
createBranch(branchPath, branchName);
createDescription(ResourceURI.branch(CodeSystem.RESOURCE_TYPE, shortName, newBranchName), term, commitComment);
final Permission userPermission = Permission.requireAll(Permission.OPERATION_BROWSE, String.format("%s*", shortName));
final List<Role> roles = List.of(new Role("Editor", List.of(userPermission)));
final String userName = "User7";
final User user = new User(userName, roles);
final IEventBus authorizedBus = new AuthorizedEventBus(bus, ImmutableMap.of(AuthorizedRequest.AUTHORIZATION_HEADER, Services.service(JWTGenerator.class).generate(user)));
// Search as user with permission only to access the resource and one sub branch
assertEquals(2, RepositoryRequests.commitInfos().prepareSearchCommitInfo().filterByComment(commitComment).build(REPOSITORY_ID).execute(authorizedBus).getSync().getTotal());
// Search as admin user with permission to access all
assertEquals(3, RepositoryRequests.commitInfos().prepareSearchCommitInfo().filterByComment(commitComment).build(REPOSITORY_ID).execute(bus).getSync().getTotal());
}
Aggregations