use of io.apiman.manager.api.beans.idm.NewRoleBean 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);
}
}
Aggregations