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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations