use of io.apiman.manager.api.beans.idm.RoleBean in project apiman by apiman.
the class StorageImportDispatcher method role.
/**
* @see io.apiman.manager.api.exportimport.read.IImportReaderDispatcher#role(io.apiman.manager.api.beans.idm.RoleBean)
*/
@Override
public void role(RoleBean role) {
try {
// $NON-NLS-1$
logger.info(Messages.i18n.format("StorageImportDispatcher.ImportingRole") + role.getName());
RoleBean roleBean = storage.getRole(role.getId());
if (roleBean != null) {
storage.updateRole(role);
} else {
storage.createRole(role);
}
} catch (StorageException e) {
error(e);
}
}
use of io.apiman.manager.api.beans.idm.RoleBean in project apiman by apiman.
the class RoleResourceImpl method create.
/**
* @see IRoleResource#create(io.apiman.manager.api.beans.idm.NewRoleBean)
*/
@Override
public RoleBean create(NewRoleBean bean) throws RoleAlreadyExistsException, NotAuthorizedException {
securityContext.checkAdminPermissions();
RoleBean role = new RoleBean();
role.setAutoGrant(bean.getAutoGrant());
role.setCreatedBy(securityContext.getCurrentUser());
role.setCreatedOn(new Date());
role.setDescription(bean.getDescription());
role.setId(BeanUtils.idFromName(bean.getName()));
role.setName(bean.getName());
role.setPermissions(bean.getPermissions());
try {
if (storage.getRole(role.getId()) != null) {
throw ExceptionFactory.roleAlreadyExistsException(role.getId());
}
storage.createRole(role);
return role;
} catch (StorageException e) {
throw new SystemErrorException(e);
}
}
use of io.apiman.manager.api.beans.idm.RoleBean in project apiman by apiman.
the class RestHelper method hideSensitiveDataFromRoleBean.
/**
* This method will hide sensitive data, such as created by, from the result
*
* @param securityContext the security context
* @param roleBean the role
* @return the role without sensitive data
*/
public static RoleBean hideSensitiveDataFromRoleBean(ISecurityContext securityContext, RoleBean roleBean) {
if (securityContext.isAdmin()) {
return roleBean;
} else {
RoleBean role = new RoleBean();
role.setId(roleBean.getId());
role.setName(roleBean.getName());
role.setPermissions(roleBean.getPermissions());
role.setAutoGrant(roleBean.getAutoGrant());
role.setDescription(roleBean.getDescription());
// check if the role was created by the current user
if (securityContext.getCurrentUser().equals(roleBean.getCreatedBy())) {
role.setCreatedBy(roleBean.getCreatedBy());
role.setCreatedOn(roleBean.getCreatedOn());
}
return role;
}
}
use of io.apiman.manager.api.beans.idm.RoleBean in project apiman by apiman.
the class OrganizationService method createOrg.
public OrganizationBean createOrg(NewOrganizationBean bean) throws OrganizationAlreadyExistsException, InvalidNameException {
FieldValidator.validateName(bean.getName());
List<RoleBean> autoGrantedRoles;
SearchCriteriaBean criteria = new SearchCriteriaBean();
criteria.setPage(1);
criteria.setPageSize(100);
// $NON-NLS-1$ //$NON-NLS-2$
criteria.addFilter("autoGrant", "true", SearchCriteriaFilterOperator.bool_eq);
try {
autoGrantedRoles = query.findRoles(criteria).getBeans();
} catch (StorageException e) {
throw new SystemErrorException(e);
}
if ("true".equals(System.getProperty("apiman.manager.require-auto-granted-org", "true"))) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
if (autoGrantedRoles.isEmpty()) {
// $NON-NLS-1$
throw new SystemErrorException(Messages.i18n.format("OrganizationResourceImpl.NoAutoGrantRoleAvailable"));
}
}
return tryAction(() -> {
OrganizationBean orgBean = new OrganizationBean();
orgBean.setName(bean.getName());
orgBean.setDescription(bean.getDescription());
orgBean.setId(BeanUtils.idFromName(bean.getName()));
orgBean.setCreatedOn(new Date());
orgBean.setCreatedBy(securityContext.getCurrentUser());
orgBean.setModifiedOn(new Date());
orgBean.setModifiedBy(securityContext.getCurrentUser());
// Store/persist the new organization
if (storage.getOrganization(orgBean.getId()) != null) {
throw ExceptionFactory.organizationAlreadyExistsException(bean.getName());
}
storage.createOrganization(orgBean);
storage.createAuditEntry(AuditUtils.organizationCreated(orgBean, securityContext));
// Auto-grant memberships in roles to the creator of the organization
for (RoleBean roleBean : autoGrantedRoles) {
String currentUser = securityContext.getCurrentUser();
String orgId = orgBean.getId();
RoleMembershipBean membership = RoleMembershipBean.create(currentUser, roleBean.getId(), orgId);
membership.setCreatedOn(new Date());
storage.createMembership(membership);
}
// $NON-NLS-1$
LOGGER.debug(String.format("Created organization %s: %s", orgBean.getName(), orgBean));
return orgBean;
});
}
use of io.apiman.manager.api.beans.idm.RoleBean 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