Search in sources :

Example 6 with IRole

use of org.eclipse.vorto.repository.domain.IRole in project vorto by eclipse.

the class RemoveRoleAccessPolicy method execute.

@Override
public void execute(ModelInfo model, IUserContext user, Map<String, Object> context) {
    IModelPolicyManager policyManager = repositoryFactory.getPolicyManager(user.getWorkspaceId(), user.getAuthentication());
    IRole role = roleToRemove.get();
    LOGGER.info("Removing full access of model to " + role.getName() + " for " + model.getId());
    Collection<PolicyEntry> policies = policyManager.getPolicyEntries(model.getId());
    for (PolicyEntry policy : policies) {
        if (policy.getPrincipalId().equals(role.getName()) && policy.getPrincipalType() == PrincipalType.Role) {
            policyManager.removePolicyEntry(model.getId(), policy);
            break;
        }
    }
}
Also used : IRole(org.eclipse.vorto.repository.domain.IRole) PolicyEntry(org.eclipse.vorto.repository.core.PolicyEntry) IModelPolicyManager(org.eclipse.vorto.repository.core.IModelPolicyManager)

Example 7 with IRole

use of org.eclipse.vorto.repository.domain.IRole in project vorto by eclipse.

the class UserDBAuthoritiesExtractor method getGrantedAuthorities.

protected List<GrantedAuthority> getGrantedAuthorities(Map<String, Object> map, String userAttr) {
    String username = (String) map.get(userAttr);
    User user = userService.getUser(username);
    if (user == null) {
        return Collections.emptyList();
    }
    Set<IRole> allRoles = getAllRoles(user);
    if (allRoles.isEmpty()) {
        allRoles.add(roleService.findAnyByName("user").orElseThrow(() -> new IllegalStateException("Role 'user' is not present.")));
    }
    return SpringUserUtils.toAuthorityList(allRoles);
}
Also used : User(org.eclipse.vorto.repository.domain.User) IRole(org.eclipse.vorto.repository.domain.IRole)

Aggregations

IRole (org.eclipse.vorto.repository.domain.IRole)7 User (org.eclipse.vorto.repository.domain.User)3 TreeSet (java.util.TreeSet)2 IModelPolicyManager (org.eclipse.vorto.repository.core.IModelPolicyManager)2 PolicyEntry (org.eclipse.vorto.repository.core.PolicyEntry)2 Namespace (org.eclipse.vorto.repository.domain.Namespace)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 IUserContext (org.eclipse.vorto.repository.core.IUserContext)1 NamespaceRole (org.eclipse.vorto.repository.domain.NamespaceRole)1 Privilege (org.eclipse.vorto.repository.domain.Privilege)1 DoesNotExistException (org.eclipse.vorto.repository.services.exceptions.DoesNotExistException)1 OperationForbiddenException (org.eclipse.vorto.repository.services.exceptions.OperationForbiddenException)1 Collaborator (org.eclipse.vorto.repository.web.api.v1.dto.Collaborator)1 NamespaceDto (org.eclipse.vorto.repository.web.api.v1.dto.NamespaceDto)1 Matchers.anyString (org.mockito.Matchers.anyString)1 ResponseEntity (org.springframework.http.ResponseEntity)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1