Search in sources :

Example 1 with NewRoleBean

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);
    }
}
Also used : SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) NewRoleBean(io.apiman.manager.api.beans.idm.NewRoleBean) UpdateRoleBean(io.apiman.manager.api.beans.idm.UpdateRoleBean) RoleBean(io.apiman.manager.api.beans.idm.RoleBean) StorageException(io.apiman.manager.api.core.exceptions.StorageException) Date(java.util.Date)

Aggregations

NewRoleBean (io.apiman.manager.api.beans.idm.NewRoleBean)1 RoleBean (io.apiman.manager.api.beans.idm.RoleBean)1 UpdateRoleBean (io.apiman.manager.api.beans.idm.UpdateRoleBean)1 StorageException (io.apiman.manager.api.core.exceptions.StorageException)1 SystemErrorException (io.apiman.manager.api.rest.exceptions.SystemErrorException)1 Date (java.util.Date)1