use of org.eclipse.vorto.repository.domain.IRole in project vorto by eclipse.
the class EntityDTOConverter method createCollaborators.
public static Collection<Collaborator> createCollaborators(Map<User, Collection<IRole>> usersAndRoles) {
Collection<Collaborator> result = new TreeSet<>(Comparator.comparing(Collaborator::getUserId));
usersAndRoles.forEach((u, c) -> {
Collaborator collaborator = new Collaborator();
collaborator.setAuthenticationProviderId(u.getAuthenticationProviderId());
collaborator.setRoles(c.stream().map(IRole::getName).collect(Collectors.toSet()));
collaborator.setSubject(u.getSubject());
collaborator.setTechnicalUser(u.isTechnicalUser());
collaborator.setUserId(u.getUsername());
result.add(collaborator);
});
return result;
}
use of org.eclipse.vorto.repository.domain.IRole in project vorto by eclipse.
the class SearchTestInfrastructure method setupNamespaceMocking.
private void setupNamespaceMocking() throws OperationForbiddenException, DoesNotExistException {
when(namespaceService.resolveWorkspaceIdForNamespace(anyString())).thenReturn(Optional.of("playground"));
when(namespaceService.findNamespaceByWorkspaceId(anyString())).thenReturn(mockNamespace());
when(namespaceRepository.findAll()).thenReturn(Arrays.asList(mockNamespace()));
when(userNamespaceRoleService.hasRole(anyString(), any(), any())).thenReturn(true);
when(userNamespaceRoleService.getNamespaces(anyString(), anyString())).thenReturn(Arrays.asList(mockNamespace()));
List<String> workspaceIds = new ArrayList<>();
workspaceIds.add("playground");
when(namespaceService.findAllWorkspaceIds()).thenReturn(workspaceIds);
NamespaceRole role = new NamespaceRole();
role.setName("namespace_admin");
role.setPrivileges(7);
role.setRole(32);
Set<IRole> roles = new HashSet<>();
roles.add(role);
when(userNamespaceRoleService.getRoles(anyString(), anyString())).thenReturn(roles);
when(userNamespaceRoleService.getRoles(any(User.class), any(Namespace.class))).thenReturn(roles);
Set<Privilege> privileges = new HashSet<>(Arrays.asList(Privilege.DEFAULT_PRIVILEGES));
when(privilegeService.getPrivileges(anyLong())).thenReturn(privileges);
}
use of org.eclipse.vorto.repository.domain.IRole in project vorto by eclipse.
the class NamespaceController method getAllNamespacesForLoggedUser.
/**
* @return all namespaces the logged on user has access to.
*/
@RequestMapping(method = RequestMethod.GET, value = "/all")
@PreAuthorize("isAuthenticated()")
public ResponseEntity<Collection<NamespaceDto>> getAllNamespacesForLoggedUser() {
IUserContext userContext = UserContext.user(SecurityContextHolder.getContext().getAuthentication());
Collection<NamespaceDto> namespaces = new TreeSet<>(Comparator.comparing(NamespaceDto::getName));
try {
for (Map.Entry<Namespace, Map<User, Collection<IRole>>> entry : userNamespaceRoleService.getNamespacesCollaboratorsAndRoles(userContext.getUsername(), userContext.getUsername(), "namespace_admin").entrySet()) {
namespaces.add(EntityDTOConverter.createNamespaceDTO(entry.getKey(), entry.getValue()));
}
} catch (OperationForbiddenException ofe) {
return new ResponseEntity<>(namespaces, HttpStatus.FORBIDDEN);
} catch (DoesNotExistException d) {
return new ResponseEntity<>(namespaces, HttpStatus.NOT_FOUND);
}
return new ResponseEntity<>(namespaces, HttpStatus.OK);
}
use of org.eclipse.vorto.repository.domain.IRole in project vorto by eclipse.
the class IsReviewerCondition method passesCondition.
@Override
public boolean passesCondition(ModelInfo model, IUserContext user) {
IRole role = roleService.findAnyByName("model_reviewer").orElseThrow(() -> new IllegalStateException("model_reviewer role not found."));
User foundUser = userAccountService.getUser(user.getUsername());
return Objects.nonNull(foundUser) && hasRole(user, foundUser, role);
}
use of org.eclipse.vorto.repository.domain.IRole in project vorto by eclipse.
the class ReadOnlyRoleAccessPolicy method execute.
@Override
public void execute(ModelInfo model, IUserContext user, Map<String, Object> context) {
IModelPolicyManager policyManager = repositoryFactory.getPolicyManager(user.getWorkspaceId(), user.getAuthentication());
IRole role = roleToMakeReadOnly.get();
LOGGER.info(String.format("Setting read-only access to model [%s] for role [%s].", model.getId(), role.getName()));
Collection<PolicyEntry> policies = policyManager.getPolicyEntries(model.getId());
for (PolicyEntry policy : policies) {
if (policy.getPrincipalId().equals(role.getName()) && policy.getPrincipalType() == PrincipalType.Role) {
policyManager.makePolicyEntryReadOnly(model.getId(), policy);
break;
}
}
}
Aggregations