Search in sources :

Example 11 with Permission

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;
}
Also used : Permission(com.ctrip.framework.apollo.portal.entity.po.Permission)

Example 12 with 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;
}
Also used : Permission(com.ctrip.framework.apollo.portal.entity.po.Permission)

Example 13 with 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()));
}
Also used : Role(com.ctrip.framework.apollo.portal.entity.po.Role) Permission(com.ctrip.framework.apollo.portal.entity.po.Permission) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with Permission

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);
}
Also used : ConfigConsts(com.ctrip.framework.apollo.core.ConfigConsts) PortalConfig(com.ctrip.framework.apollo.portal.component.config.PortalConfig) PermissionType(com.ctrip.framework.apollo.portal.constant.PermissionType) Env(com.ctrip.framework.apollo.portal.environment.Env) SystemRoleManagerService(com.ctrip.framework.apollo.portal.service.SystemRoleManagerService) Role(com.ctrip.framework.apollo.portal.entity.po.Role) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) RoleType(com.ctrip.framework.apollo.portal.constant.RoleType) Permission(com.ctrip.framework.apollo.portal.entity.po.Permission) Collectors(java.util.stream.Collectors) RoleInitializationService(com.ctrip.framework.apollo.portal.service.RoleInitializationService) Sets(com.google.common.collect.Sets) BaseEntity(com.ctrip.framework.apollo.common.entity.BaseEntity) RoleUtils(com.ctrip.framework.apollo.portal.util.RoleUtils) HashSet(java.util.HashSet) List(java.util.List) Stream(java.util.stream.Stream) PermissionRepository(com.ctrip.framework.apollo.portal.repository.PermissionRepository) App(com.ctrip.framework.apollo.common.entity.App) RolePermissionService(com.ctrip.framework.apollo.portal.service.RolePermissionService) Transactional(org.springframework.transaction.annotation.Transactional) Role(com.ctrip.framework.apollo.portal.entity.po.Role) Permission(com.ctrip.framework.apollo.portal.entity.po.Permission)

Example 15 with Permission

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());
}
Also used : RolePermission(com.ctrip.framework.apollo.portal.entity.po.RolePermission) Permission(com.ctrip.framework.apollo.portal.entity.po.Permission) AbstractIntegrationTest(com.ctrip.framework.apollo.portal.AbstractIntegrationTest) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Aggregations

Permission (com.ctrip.framework.apollo.portal.entity.po.Permission)16 RolePermission (com.ctrip.framework.apollo.portal.entity.po.RolePermission)9 Role (com.ctrip.framework.apollo.portal.entity.po.Role)5 Transactional (org.springframework.transaction.annotation.Transactional)5 AbstractIntegrationTest (com.ctrip.framework.apollo.portal.AbstractIntegrationTest)4 Test (org.junit.Test)4 Sql (org.springframework.test.context.jdbc.Sql)4 HashSet (java.util.HashSet)2 App (com.ctrip.framework.apollo.common.entity.App)1 BaseEntity (com.ctrip.framework.apollo.common.entity.BaseEntity)1 ConfigConsts (com.ctrip.framework.apollo.core.ConfigConsts)1 ConsumerRole (com.ctrip.framework.apollo.openapi.entity.ConsumerRole)1 PortalConfig (com.ctrip.framework.apollo.portal.component.config.PortalConfig)1 PermissionType (com.ctrip.framework.apollo.portal.constant.PermissionType)1 RoleType (com.ctrip.framework.apollo.portal.constant.RoleType)1 UserRole (com.ctrip.framework.apollo.portal.entity.po.UserRole)1 Env (com.ctrip.framework.apollo.portal.environment.Env)1 PermissionRepository (com.ctrip.framework.apollo.portal.repository.PermissionRepository)1 RoleInitializationService (com.ctrip.framework.apollo.portal.service.RoleInitializationService)1 RolePermissionService (com.ctrip.framework.apollo.portal.service.RolePermissionService)1