use of com.ctrip.framework.apollo.portal.entity.po.Permission in project apollo by ctripcorp.
the class RoleInitializationServiceTest method mockPermission.
private Permission mockPermission() {
Permission permission = new Permission();
permission.setPermissionType(PermissionType.MODIFY_NAMESPACE);
permission.setTargetId(RoleUtils.buildNamespaceTargetId(APP_ID, NAMESPACE));
return permission;
}
use of com.ctrip.framework.apollo.portal.entity.po.Permission in project apollo by ctripcorp.
the class DefaultRoleInitializationService method createPermission.
private Permission createPermission(String targetId, String permissionType, String operator) {
Permission permission = new Permission();
permission.setPermissionType(permissionType);
permission.setTargetId(targetId);
permission.setDataChangeCreatedBy(operator);
permission.setDataChangeLastModifiedBy(operator);
return permission;
}
use of com.ctrip.framework.apollo.portal.entity.po.Permission in project apollo by ctripcorp.
the class DefaultRoleInitializationService method initCreateAppRole.
@Transactional
public void initCreateAppRole() {
if (rolePermissionService.findRoleByRoleName(SystemRoleManagerService.CREATE_APPLICATION_ROLE_NAME) != null) {
return;
}
Permission createAppPermission = permissionRepository.findTopByPermissionTypeAndTargetId(PermissionType.CREATE_APPLICATION, SystemRoleManagerService.SYSTEM_PERMISSION_TARGET_ID);
if (createAppPermission == null) {
// create application permission init
createAppPermission = createPermission(SystemRoleManagerService.SYSTEM_PERMISSION_TARGET_ID, PermissionType.CREATE_APPLICATION, "apollo");
rolePermissionService.createPermission(createAppPermission);
}
// create application role init
Role createAppRole = createRole(SystemRoleManagerService.CREATE_APPLICATION_ROLE_NAME, "apollo");
rolePermissionService.createRoleWithPermissions(createAppRole, Sets.newHashSet(createAppPermission.getId()));
}
use of com.ctrip.framework.apollo.portal.entity.po.Permission in project apollo by ctripcorp.
the class DefaultRoleInitializationService method createAppMasterRole.
private void createAppMasterRole(String appId, String operator) {
Set<Permission> appPermissions = Stream.of(PermissionType.CREATE_CLUSTER, PermissionType.CREATE_NAMESPACE, PermissionType.ASSIGN_ROLE).map(permissionType -> createPermission(appId, permissionType, operator)).collect(Collectors.toSet());
Set<Permission> createdAppPermissions = rolePermissionService.createPermissions(appPermissions);
Set<Long> appPermissionIds = createdAppPermissions.stream().map(BaseEntity::getId).collect(Collectors.toSet());
// create app master role
Role appMasterRole = createRole(RoleUtils.buildAppMasterRoleName(appId), operator);
rolePermissionService.createRoleWithPermissions(appMasterRole, appPermissionIds);
}
use of com.ctrip.framework.apollo.portal.entity.po.Permission in project apollo by ctripcorp.
the class RolePermissionServiceTest method testCreatePermission.
@Test
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testCreatePermission() throws Exception {
String someTargetId = "someTargetId";
String somePermissionType = "somePermissionType";
Permission somePermission = assemblePermission(somePermissionType, someTargetId);
Permission created = rolePermissionService.createPermission(somePermission);
Permission createdFromDB = permissionRepository.findById(created.getId()).orElse(null);
assertEquals(somePermissionType, createdFromDB.getPermissionType());
assertEquals(someTargetId, createdFromDB.getTargetId());
}
Aggregations