use of io.apiman.manager.api.beans.idm.PermissionType in project apiman by apiman.
the class EsMarshalling method marshall.
/**
* Marshals the given bean into the given map.
* @param bean the bean
* @return the content builder
* @throws StorageException when a storage problem occurs while storing a bean
*/
public static XContentBuilder marshall(RoleBean bean) throws StorageException {
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
preMarshall(bean);
builder.startObject().field("id", bean.getId()).field("name", bean.getName()).field("description", bean.getDescription()).field("createdBy", bean.getCreatedBy()).field("createdOn", bean.getCreatedOn().getTime()).field("autoGrant", bean.getAutoGrant());
Set<PermissionType> permissions = bean.getPermissions();
if (permissions != null && !permissions.isEmpty()) {
builder.array("permissions", permissions.toArray(new PermissionType[permissions.size()]));
}
builder.endObject();
postMarshall(bean);
return builder;
} catch (IOException e) {
throw new StorageException(e);
}
}
use of io.apiman.manager.api.beans.idm.PermissionType in project apiman by apiman.
the class IndexedPermissions method index.
/**
* Index the permissions.
* @param bean
*/
private void index(Set<PermissionBean> permissions) {
for (PermissionBean permissionBean : permissions) {
PermissionType permissionName = permissionBean.getName();
String orgQualifier = permissionBean.getOrganizationId();
String qualifiedPermission = createQualifiedPermissionKey(permissionName, orgQualifier);
organizations.add(orgQualifier);
qualifiedPermissions.add(qualifiedPermission);
Set<String> orgs = permissionToOrgsMap.computeIfAbsent(permissionName, k -> new HashSet<>());
orgs.add(orgQualifier);
}
}
use of io.apiman.manager.api.beans.idm.PermissionType 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.PermissionType in project apiman by apiman.
the class EsStorage method getPermissions.
/**
* @see io.apiman.manager.api.core.IStorageQuery#getPermissions(java.lang.String)
*/
@Override
public Set<PermissionBean> getPermissions(String userId) throws StorageException {
try {
@SuppressWarnings("nls") QueryBuilder qb = QueryBuilders.termQuery("userId", userId);
SearchSourceBuilder builder = new SearchSourceBuilder().query(qb).size(500);
// $NON-NLS-1$
List<SearchHit> hits = listEntities(INDEX_MANAGER_POSTFIX_ROLE_MEMBERSHIP, builder);
Set<PermissionBean> rval = new HashSet<>(hits.size());
if (!hits.isEmpty()) {
for (SearchHit hit : hits) {
Map<String, Object> source = hit.getSourceAsMap();
// $NON-NLS-1$
String roleId = String.valueOf(source.get("roleId"));
// $NON-NLS-1$
String qualifier = String.valueOf(source.get("organizationId"));
RoleBean role = getRole(roleId);
if (role != null) {
for (PermissionType permission : role.getPermissions()) {
PermissionBean p = new PermissionBean();
p.setName(permission);
p.setOrganizationId(qualifier);
rval.add(p);
}
}
}
}
return rval;
} catch (Exception e) {
throw new StorageException(e);
}
}
Aggregations