Search in sources :

Example 6 with RoleBean

use of io.apiman.manager.api.beans.idm.RoleBean in project apiman by apiman.

the class RoleResourceImpl method list.

/**
 * @see IRoleResource#list()
 */
@Override
public List<RoleBean> list() {
    // No permission check needed
    try {
        SearchCriteriaBean criteria = new SearchCriteriaBean();
        // $NON-NLS-1$
        criteria.setOrder("name", true);
        // Hide sensitive data and set only needed data for the UI
        if (securityContext.isAdmin()) {
            return query.findRoles(criteria).getBeans();
        } else {
            List<RoleBean> roles = new ArrayList<>();
            for (RoleBean role : query.findRoles(criteria).getBeans()) {
                roles.add(RestHelper.hideSensitiveDataFromRoleBean(securityContext, role));
            }
            return roles;
        }
    } catch (StorageException e) {
        throw new SystemErrorException(e);
    }
}
Also used : SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) SearchCriteriaBean(io.apiman.manager.api.beans.search.SearchCriteriaBean) NewRoleBean(io.apiman.manager.api.beans.idm.NewRoleBean) UpdateRoleBean(io.apiman.manager.api.beans.idm.UpdateRoleBean) RoleBean(io.apiman.manager.api.beans.idm.RoleBean) ArrayList(java.util.ArrayList) StorageException(io.apiman.manager.api.core.exceptions.StorageException)

Example 7 with RoleBean

use of io.apiman.manager.api.beans.idm.RoleBean in project apiman by apiman.

the class RoleResourceImpl method update.

/**
 * @see IRoleResource#update(java.lang.String, io.apiman.manager.api.beans.idm.UpdateRoleBean)
 */
@Override
public void update(String roleId, UpdateRoleBean bean) throws RoleNotFoundException, NotAuthorizedException {
    securityContext.checkAdminPermissions();
    try {
        RoleBean role = getRoleFromStorage(roleId);
        if (bean.getDescription() != null) {
            role.setDescription(bean.getDescription());
        }
        if (bean.getAutoGrant() != null) {
            role.setAutoGrant(bean.getAutoGrant());
        }
        if (bean.getName() != null) {
            role.setName(bean.getName());
        }
        if (bean.getPermissions() != null) {
            role.getPermissions().clear();
            role.getPermissions().addAll(bean.getPermissions());
        }
        storage.updateRole(role);
    } catch (StorageException e) {
        throw new SystemErrorException(e);
    }
}
Also used : SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) NewRoleBean(io.apiman.manager.api.beans.idm.NewRoleBean) UpdateRoleBean(io.apiman.manager.api.beans.idm.UpdateRoleBean) RoleBean(io.apiman.manager.api.beans.idm.RoleBean) StorageException(io.apiman.manager.api.core.exceptions.StorageException)

Example 8 with RoleBean

use of io.apiman.manager.api.beans.idm.RoleBean in project apiman by apiman.

the class JpaStorage method deleteRole.

/**
 * {@inheritDoc}
 */
@Override
public void deleteRole(RoleBean role) throws StorageException {
    try {
        EntityManager entityManager = getActiveEntityManager();
        RoleBean prole = get(role.getId(), RoleBean.class);
        // First delete all memberships in this role
        entityManager.createQuery("DELETE from RoleMembershipBean m " + "WHERE m.roleId = :roleId").setParameter("roleId", role.getId()).executeUpdate();
        // Then delete the role itself.
        super.delete(prole);
    } catch (Throwable t) {
        throw new StorageException(t);
    }
}
Also used : EntityManager(javax.persistence.EntityManager) RoleBean(io.apiman.manager.api.beans.idm.RoleBean) StorageException(io.apiman.manager.api.core.exceptions.StorageException)

Example 9 with RoleBean

use of io.apiman.manager.api.beans.idm.RoleBean in project apiman by apiman.

the class JpaStorage method getPermissions.

/**
 * {@inheritDoc}
 */
@Override
public Set<PermissionBean> getPermissions(String userId) throws StorageException {
    try {
        List<RoleMembershipBean> resultList = getCriteriaBuilderFactory().create(getActiveEntityManager(), RoleMembershipBean.class).where("userId").eq(userId).setMaxResults(// I think this is set arbitrarily?
        500).getResultList();
        List<String> roleIds = resultList.stream().map(RoleMembershipBean::getRoleId).collect(Collectors.toList());
        Map<String, RoleBean> roleMap = getRolesById(roleIds).stream().collect(Collectors.toMap(e -> e.getId(), e -> e));
        Set<PermissionBean> permissions = new HashSet<>(resultList.size());
        for (RoleMembershipBean membership : resultList) {
            String qualifier = membership.getOrganizationId();
            for (PermissionType permission : roleMap.get(membership.getRoleId()).getPermissions()) {
                PermissionBean p = new PermissionBean();
                p.setName(permission);
                p.setOrganizationId(qualifier);
                permissions.add(p);
            }
        }
        return permissions;
    } catch (Throwable t) {
        LOGGER.error(t.getMessage(), t);
        throw new StorageException(t);
    }
}
Also used : PermissionConstraint(io.apiman.manager.api.beans.idm.PermissionConstraint) RoleBean_(io.apiman.manager.api.beans.idm.RoleBean_) ApiGatewayBean(io.apiman.manager.api.beans.apis.ApiGatewayBean) ApiPlanSummaryBean(io.apiman.manager.api.beans.summary.ApiPlanSummaryBean) StorageException(io.apiman.manager.api.core.exceptions.StorageException) ApiVersionBean(io.apiman.manager.api.beans.apis.ApiVersionBean) NoResultException(javax.persistence.NoResultException) IDataEncrypter(io.apiman.common.util.crypt.IDataEncrypter) ApiDefinitionBean(io.apiman.manager.api.beans.apis.ApiDefinitionBean) UserBean(io.apiman.manager.api.beans.idm.UserBean) SearchCriteriaFilterOperator(io.apiman.manager.api.beans.search.SearchCriteriaFilterOperator) ApiBean(io.apiman.manager.api.beans.apis.ApiBean) DeveloperBean(io.apiman.manager.api.beans.developers.DeveloperBean) ByteArrayInputStream(java.io.ByteArrayInputStream) Locale(java.util.Locale) CriteriaBuilder(com.blazebit.persistence.CriteriaBuilder) PagingBean(io.apiman.manager.api.beans.search.PagingBean) Map(java.util.Map) DiscoverabilityEntity(io.apiman.manager.api.beans.idm.DiscoverabilityEntity) ApimanLoggerFactory(io.apiman.common.logging.ApimanLoggerFactory) OrganizationBean(io.apiman.manager.api.beans.orgs.OrganizationBean) GatewayType(io.apiman.manager.api.beans.gateways.GatewayType) ApiEntryBean(io.apiman.manager.api.beans.summary.ApiEntryBean) Transactional(javax.transaction.Transactional) Set(java.util.Set) UserBean_(io.apiman.manager.api.beans.idm.UserBean_) GatewaySummaryBean(io.apiman.manager.api.beans.summary.GatewaySummaryBean) PermissionBean(io.apiman.manager.api.beans.idm.PermissionBean) PluginSummaryBean(io.apiman.manager.api.beans.summary.PluginSummaryBean) Collectors(java.util.stream.Collectors) ApiVersionSummaryBean(io.apiman.manager.api.beans.summary.ApiVersionSummaryBean) ApiSummaryBean(io.apiman.manager.api.beans.summary.ApiSummaryBean) ClientSummaryBean(io.apiman.manager.api.beans.summary.ClientSummaryBean) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Query(javax.persistence.Query) IApimanLogger(io.apiman.common.logging.IApimanLogger) ApiPlanBean(io.apiman.manager.api.beans.apis.ApiPlanBean) PolicySummaryBean(io.apiman.manager.api.beans.summary.PolicySummaryBean) OrganizationBean_(io.apiman.manager.api.beans.orgs.OrganizationBean_) AuditEntryBean(io.apiman.manager.api.beans.audit.AuditEntryBean) RoleMembershipBean(io.apiman.manager.api.beans.idm.RoleMembershipBean) PostConstruct(javax.annotation.PostConstruct) SearchCriteriaBean(io.apiman.manager.api.beans.search.SearchCriteriaBean) ApplicationScoped(javax.enterprise.context.ApplicationScoped) ClientBean_(io.apiman.manager.api.beans.clients.ClientBean_) PermissionType(io.apiman.manager.api.beans.idm.PermissionType) OrganizationSummaryBean(io.apiman.manager.api.beans.summary.OrganizationSummaryBean) PlanVersionSummaryBean(io.apiman.manager.api.beans.summary.PlanVersionSummaryBean) DiscoverabilityLevel(io.apiman.manager.api.beans.idm.DiscoverabilityLevel) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PluginBean(io.apiman.manager.api.beans.plugins.PluginBean) Alternative(javax.enterprise.inject.Alternative) PlanBean(io.apiman.manager.api.beans.plans.PlanBean) PlanSummaryBean(io.apiman.manager.api.beans.summary.PlanSummaryBean) ApiStatus(io.apiman.manager.api.beans.apis.ApiStatus) PolicyBean(io.apiman.manager.api.beans.policies.PolicyBean) TypedQuery(javax.persistence.TypedQuery) AuditEntryBean_(io.apiman.manager.api.beans.audit.AuditEntryBean_) ArrayList(java.util.ArrayList) AuditEntityType(io.apiman.manager.api.beans.audit.AuditEntityType) ContractBean(io.apiman.manager.api.beans.contracts.ContractBean) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ClientBean(io.apiman.manager.api.beans.clients.ClientBean) DataEncryptionContext(io.apiman.common.util.crypt.DataEncryptionContext) PlanBean_(io.apiman.manager.api.beans.plans.PlanBean_) DeleteCriteriaBuilder(com.blazebit.persistence.DeleteCriteriaBuilder) RoleBean(io.apiman.manager.api.beans.idm.RoleBean) IStorageQuery(io.apiman.manager.api.core.IStorageQuery) QualifiedType(org.jdbi.v3.core.qualifier.QualifiedType) PolicyTemplateUtil(io.apiman.manager.api.core.util.PolicyTemplateUtil) OrderByBean(io.apiman.manager.api.beans.search.OrderByBean) PlanVersionBean(io.apiman.manager.api.beans.plans.PlanVersionBean) MetadataBean(io.apiman.manager.api.beans.system.MetadataBean) ClientVersionSummaryBean(io.apiman.manager.api.beans.summary.ClientVersionSummaryBean) Iterator(java.util.Iterator) GatewayBean(io.apiman.manager.api.beans.gateways.GatewayBean) ClientStatus(io.apiman.manager.api.beans.clients.ClientStatus) SearchResultsBean(io.apiman.manager.api.beans.search.SearchResultsBean) ContractSummaryBean(io.apiman.manager.api.beans.summary.ContractSummaryBean) ApiMapper(io.apiman.manager.api.beans.summary.mappers.ApiMapper) PolicyDefinitionBean(io.apiman.manager.api.beans.policies.PolicyDefinitionBean) IStorage(io.apiman.manager.api.core.IStorage) ClientVersionBean(io.apiman.manager.api.beans.clients.ClientVersionBean) IOException(java.io.IOException) EntityManager(javax.persistence.EntityManager) ApiRegistryBean(io.apiman.manager.api.beans.summary.ApiRegistryBean) PolicyBean_(io.apiman.manager.api.beans.policies.PolicyBean_) Consumer(java.util.function.Consumer) DownloadBean(io.apiman.manager.api.beans.download.DownloadBean) PolicyType(io.apiman.manager.api.beans.policies.PolicyType) PolicyDefinitionSummaryBean(io.apiman.manager.api.beans.summary.PolicyDefinitionSummaryBean) PlanStatus(io.apiman.manager.api.beans.plans.PlanStatus) Collections(java.util.Collections) InputStream(java.io.InputStream) PermissionType(io.apiman.manager.api.beans.idm.PermissionType) RoleBean(io.apiman.manager.api.beans.idm.RoleBean) RoleMembershipBean(io.apiman.manager.api.beans.idm.RoleMembershipBean) PermissionBean(io.apiman.manager.api.beans.idm.PermissionBean) StorageException(io.apiman.manager.api.core.exceptions.StorageException) HashSet(java.util.HashSet)

Example 10 with RoleBean

use of io.apiman.manager.api.beans.idm.RoleBean in project apiman by apiman.

the class StorageExporter method exportRoles.

private void exportRoles() {
    try {
        Iterator<RoleBean> iter;
        iter = storage.getAllRoles();
        writer.startRoles();
        while (iter.hasNext()) {
            RoleBean bean = iter.next();
            // $NON-NLS-1$
            logger.info(Messages.i18n.format("StorageExporter.ExportingRole") + bean);
            writer.writeRole(bean);
        }
        writer.endRoles();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : RoleBean(io.apiman.manager.api.beans.idm.RoleBean)

Aggregations

RoleBean (io.apiman.manager.api.beans.idm.RoleBean)18 StorageException (io.apiman.manager.api.core.exceptions.StorageException)13 SystemErrorException (io.apiman.manager.api.rest.exceptions.SystemErrorException)9 NewRoleBean (io.apiman.manager.api.beans.idm.NewRoleBean)5 RoleMembershipBean (io.apiman.manager.api.beans.idm.RoleMembershipBean)5 UpdateRoleBean (io.apiman.manager.api.beans.idm.UpdateRoleBean)5 ArrayList (java.util.ArrayList)5 MemberRoleBean (io.apiman.manager.api.beans.members.MemberRoleBean)4 SearchCriteriaBean (io.apiman.manager.api.beans.search.SearchCriteriaBean)4 PermissionType (io.apiman.manager.api.beans.idm.PermissionType)3 UserBean (io.apiman.manager.api.beans.idm.UserBean)3 OrganizationBean (io.apiman.manager.api.beans.orgs.OrganizationBean)3 PermissionBean (io.apiman.manager.api.beans.idm.PermissionBean)2 IOException (java.io.IOException)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 EntityManager (javax.persistence.EntityManager)2 CriteriaBuilder (com.blazebit.persistence.CriteriaBuilder)1 DeleteCriteriaBuilder (com.blazebit.persistence.DeleteCriteriaBuilder)1 ApimanLoggerFactory (io.apiman.common.logging.ApimanLoggerFactory)1