Search in sources :

Example 1 with RoleScope

use of io.gravitee.repository.management.model.RoleScope in project gravitee-management-rest-api by gravitee-io.

the class MembershipServiceImpl method deleteMember.

@Override
public void deleteMember(MembershipReferenceType referenceType, String referenceId, String userId) {
    try {
        LOGGER.debug("Delete member {} for {} {}", userId, referenceType, referenceId);
        if (!MembershipReferenceType.GROUP.equals(referenceType)) {
            RoleScope roleScope = getScopeByMembershipReferenceType(referenceType);
            RoleEntity roleEntity = this.getRole(referenceType, referenceId, userId, roleScope);
            if (roleEntity != null && PRIMARY_OWNER.name().equals(roleEntity.getName())) {
                throw new SinglePrimaryOwnerException(referenceType.equals(API) ? RoleScope.API : RoleScope.APPLICATION);
            }
        }
        Membership membership = new Membership(userId, referenceId, referenceType);
        membershipRepository.delete(membership);
        createAuditLog(MEMBERSHIP_DELETED, new Date(), membership, null);
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to delete member {} for {} {}", userId, referenceType, referenceId, ex);
        throw new TechnicalManagementException("An error occurs while trying to delete member " + userId + " for " + referenceType + " " + referenceId, ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) RoleScope(io.gravitee.repository.management.model.RoleScope) Membership(io.gravitee.repository.management.model.Membership)

Example 2 with RoleScope

use of io.gravitee.repository.management.model.RoleScope in project gravitee-management-rest-api by gravitee-io.

the class RoleServiceImpl method update.

@Override
public RoleEntity update(final UpdateRoleEntity roleEntity) {
    if (isReserved(roleEntity.getName())) {
        throw new RoleReservedNameException(SystemRole.ADMIN.name());
    }
    RoleScope scope = convert(roleEntity.getScope());
    try {
        Optional<Role> optRole = roleRepository.findById(scope, roleEntity.getName());
        if (!optRole.isPresent()) {
            throw new RoleNotFoundException(scope, roleEntity.getName());
        }
        Role role = optRole.get();
        Role updatedRole = convert(roleEntity);
        updatedRole.setCreatedAt(role.getCreatedAt());
        RoleEntity entity = convert(roleRepository.update(updatedRole));
        auditService.createPortalAuditLog(Collections.singletonMap(ROLE, role.getScope() + ":" + role.getName()), ROLE_UPDATED, updatedRole.getUpdatedAt(), role, updatedRole);
        if (entity.isDefaultRole()) {
            toggleDefaultRole(scope, entity.getName());
        }
        return entity;
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to update role {}", roleEntity.getName(), ex);
        throw new TechnicalManagementException("An error occurs while trying to update role " + roleEntity.getName(), ex);
    }
}
Also used : Role(io.gravitee.repository.management.model.Role) UpdateRoleEntity(io.gravitee.management.model.UpdateRoleEntity) NewRoleEntity(io.gravitee.management.model.NewRoleEntity) RoleEntity(io.gravitee.management.model.RoleEntity) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) RoleScope(io.gravitee.repository.management.model.RoleScope) RoleReservedNameException(io.gravitee.management.service.exceptions.RoleReservedNameException) RoleNotFoundException(io.gravitee.management.service.exceptions.RoleNotFoundException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 3 with RoleScope

use of io.gravitee.repository.management.model.RoleScope in project gravitee-management-rest-api by gravitee-io.

the class RoleServiceImpl method findDefaultRoleByScopes.

@Override
public List<RoleEntity> findDefaultRoleByScopes(RoleScope... scopes) {
    try {
        LOGGER.debug("Find default Roles by scope");
        List<RoleEntity> roles = new ArrayList<>();
        for (RoleScope scope : scopes) {
            roles.addAll(roleRepository.findByScope(scope).stream().filter(Role::isDefaultRole).map(this::convert).collect(Collectors.toList()));
        }
        return roles;
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to find default roles by scope", ex);
        throw new TechnicalManagementException("An error occurs while trying to find default roles by scope", ex);
    }
}
Also used : UpdateRoleEntity(io.gravitee.management.model.UpdateRoleEntity) NewRoleEntity(io.gravitee.management.model.NewRoleEntity) RoleEntity(io.gravitee.management.model.RoleEntity) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) RoleScope(io.gravitee.repository.management.model.RoleScope) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Aggregations

TechnicalException (io.gravitee.repository.exceptions.TechnicalException)3 RoleScope (io.gravitee.repository.management.model.RoleScope)3 NewRoleEntity (io.gravitee.management.model.NewRoleEntity)2 RoleEntity (io.gravitee.management.model.RoleEntity)2 UpdateRoleEntity (io.gravitee.management.model.UpdateRoleEntity)2 TechnicalManagementException (io.gravitee.management.service.exceptions.TechnicalManagementException)2 RoleNotFoundException (io.gravitee.management.service.exceptions.RoleNotFoundException)1 RoleReservedNameException (io.gravitee.management.service.exceptions.RoleReservedNameException)1 Membership (io.gravitee.repository.management.model.Membership)1 Role (io.gravitee.repository.management.model.Role)1