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