Search in sources :

Example 16 with RoleBean

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

the class RoleResourceImpl method get.

/**
 * @see IRoleResource#get(java.lang.String)
 */
@Override
public RoleBean get(String roleId) throws RoleNotFoundException {
    // No permission check needed
    try {
        getStorage().beginTx();
        RoleBean role = getRoleFromStorage(roleId);
        // Hide sensitive data and set only needed data for the UI
        return RestHelper.hideSensitiveDataFromRoleBean(securityContext, role);
    } catch (StorageException e) {
        throw new SystemErrorException(e);
    } finally {
        getStorage().rollbackTx();
    }
}
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 17 with RoleBean

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

the class OrganizationResourceImpl method listMembers.

/**
 * @see IOrganizationResource#listMembers(java.lang.String)
 */
@Override
public List<MemberBean> listMembers(String organizationId) throws OrganizationNotFoundException, NotAuthorizedException {
    // Only members are allowed to see other members
    if (!securityContext.isMemberOf(organizationId)) {
        throw ExceptionFactory.notAuthorizedException();
    }
    get(organizationId);
    try {
        Set<RoleMembershipBean> memberships = query.getOrgMemberships(organizationId);
        TreeMap<String, MemberBean> members = new TreeMap<>();
        storage.beginTx();
        for (RoleMembershipBean membershipBean : memberships) {
            String userId = membershipBean.getUserId();
            String roleId = membershipBean.getRoleId();
            RoleBean role = storage.getRole(roleId);
            // Role does not exist!
            if (role == null) {
                continue;
            }
            MemberBean member = members.get(userId);
            if (member == null) {
                UserBean user = storage.getUser(userId);
                member = new MemberBean();
                member.setEmail(user.getEmail());
                member.setUserId(userId);
                member.setUserName(user.getFullName());
                member.setRoles(new ArrayList<>());
                members.put(userId, member);
            }
            MemberRoleBean mrb = new MemberRoleBean();
            mrb.setRoleId(roleId);
            mrb.setRoleName(role.getName());
            member.getRoles().add(mrb);
            if (member.getJoinedOn() == null || membershipBean.getCreatedOn().compareTo(member.getJoinedOn()) < 0) {
                member.setJoinedOn(membershipBean.getCreatedOn());
            }
        }
        return new ArrayList<>(members.values());
    } catch (StorageException e) {
        throw new SystemErrorException(e);
    } finally {
        storage.rollbackTx();
    }
}
Also used : SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) MemberRoleBean(io.apiman.manager.api.beans.members.MemberRoleBean) RoleBean(io.apiman.manager.api.beans.idm.RoleBean) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) RoleMembershipBean(io.apiman.manager.api.beans.idm.RoleMembershipBean) MemberBean(io.apiman.manager.api.beans.members.MemberBean) UserBean(io.apiman.manager.api.beans.idm.UserBean) MemberRoleBean(io.apiman.manager.api.beans.members.MemberRoleBean) StorageException(io.apiman.manager.api.core.exceptions.StorageException)

Example 18 with RoleBean

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

the class SearchResourceImpl method searchRoles.

/**
 * @see ISearchResource#searchRoles(SearchCriteriaBean)
 */
@Override
public SearchResultsBean<RoleBean> searchRoles(SearchCriteriaBean criteria) throws InvalidSearchCriteriaException {
    // No permission check needed
    try {
        // Hide sensitive data and set only needed data for the UI
        SearchCriteriaUtil.validateSearchCriteria(criteria);
        List<RoleBean> roles = new ArrayList<>();
        for (RoleBean bean : getQuery().findRoles(criteria).getBeans()) {
            roles.add(RestHelper.hideSensitiveDataFromRoleBean(securityContext, bean));
        }
        SearchResultsBean<RoleBean> result = new SearchResultsBean<>();
        result.setBeans(roles);
        result.setTotalSize(roles.size());
        return result;
    } catch (StorageException e) {
        throw new SystemErrorException(e);
    }
}
Also used : SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) RoleBean(io.apiman.manager.api.beans.idm.RoleBean) ArrayList(java.util.ArrayList) StorageException(io.apiman.manager.api.core.exceptions.StorageException)

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