use of com.ctrip.framework.apollo.portal.entity.po.Role in project apollo by ctripcorp.
the class DefaultRolePermissionService method createRoleWithPermissions.
/**
* Create role with permissions, note that role name should be unique
*/
@Transactional
public Role createRoleWithPermissions(Role role, Set<Long> permissionIds) {
Role current = findRoleByRoleName(role.getRoleName());
Preconditions.checkState(current == null, "Role %s already exists!", role.getRoleName());
Role createdRole = roleRepository.save(role);
if (!CollectionUtils.isEmpty(permissionIds)) {
Iterable<RolePermission> rolePermissions = permissionIds.stream().map(permissionId -> {
RolePermission rolePermission = new RolePermission();
rolePermission.setRoleId(createdRole.getId());
rolePermission.setPermissionId(permissionId);
rolePermission.setDataChangeCreatedBy(createdRole.getDataChangeCreatedBy());
rolePermission.setDataChangeLastModifiedBy(createdRole.getDataChangeLastModifiedBy());
return rolePermission;
}).collect(Collectors.toList());
rolePermissionRepository.saveAll(rolePermissions);
}
return createdRole;
}
use of com.ctrip.framework.apollo.portal.entity.po.Role in project apollo by ctripcorp.
the class DefaultRoleInitializationService method createNamespaceRole.
private void createNamespaceRole(String appId, String namespaceName, String permissionType, String roleName, String operator) {
Permission permission = createPermission(RoleUtils.buildNamespaceTargetId(appId, namespaceName), permissionType, operator);
Permission createdPermission = rolePermissionService.createPermission(permission);
Role role = createRole(roleName, operator);
rolePermissionService.createRoleWithPermissions(role, Sets.newHashSet(createdPermission.getId()));
}
use of com.ctrip.framework.apollo.portal.entity.po.Role in project apollo by ctripcorp.
the class DefaultRoleInitializationService method createRole.
private Role createRole(String roleName, String operator) {
Role role = new Role();
role.setRoleName(roleName);
role.setDataChangeCreatedBy(operator);
role.setDataChangeLastModifiedBy(operator);
return role;
}
use of com.ctrip.framework.apollo.portal.entity.po.Role in project apollo by ctripcorp.
the class DefaultRoleInitializationService method createManageAppMasterRole.
@Transactional
private void createManageAppMasterRole(String appId, String operator) {
Permission permission = createPermission(appId, PermissionType.MANAGE_APP_MASTER, operator);
rolePermissionService.createPermission(permission);
Role role = createRole(RoleUtils.buildAppRoleName(appId, PermissionType.MANAGE_APP_MASTER), operator);
Set<Long> permissionIds = new HashSet<>();
permissionIds.add(permission.getId());
rolePermissionService.createRoleWithPermissions(role, permissionIds);
}
use of com.ctrip.framework.apollo.portal.entity.po.Role in project apollo by ctripcorp.
the class DefaultRoleInitializationService method createNamespaceEnvRole.
private void createNamespaceEnvRole(String appId, String namespaceName, String permissionType, String env, String roleName, String operator) {
Permission permission = createPermission(RoleUtils.buildNamespaceTargetId(appId, namespaceName, env), permissionType, operator);
Permission createdPermission = rolePermissionService.createPermission(permission);
Role role = createRole(roleName, operator);
rolePermissionService.createRoleWithPermissions(role, Sets.newHashSet(createdPermission.getId()));
}
Aggregations