Search in sources :

Example 6 with Role

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;
}
Also used : Role(com.ctrip.framework.apollo.portal.entity.po.Role) UserRole(com.ctrip.framework.apollo.portal.entity.po.UserRole) Date(java.util.Date) Role(com.ctrip.framework.apollo.portal.entity.po.Role) Autowired(org.springframework.beans.factory.annotation.Autowired) Multimap(com.google.common.collect.Multimap) Permission(com.ctrip.framework.apollo.portal.entity.po.Permission) UserInfo(com.ctrip.framework.apollo.portal.entity.bo.UserInfo) HashMultimap(com.google.common.collect.HashMultimap) Lists(com.google.common.collect.Lists) StreamSupport(java.util.stream.StreamSupport) RolePermissionService(com.ctrip.framework.apollo.portal.service.RolePermissionService) UserRole(com.ctrip.framework.apollo.portal.entity.po.UserRole) PortalConfig(com.ctrip.framework.apollo.portal.component.config.PortalConfig) RolePermission(com.ctrip.framework.apollo.portal.entity.po.RolePermission) Collection(java.util.Collection) Set(java.util.Set) ConsumerRoleRepository(com.ctrip.framework.apollo.openapi.repository.ConsumerRoleRepository) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) UserRoleRepository(com.ctrip.framework.apollo.portal.repository.UserRoleRepository) RolePermissionRepository(com.ctrip.framework.apollo.portal.repository.RolePermissionRepository) PermissionRepository(com.ctrip.framework.apollo.portal.repository.PermissionRepository) CollectionUtils(org.springframework.util.CollectionUtils) Preconditions(com.google.common.base.Preconditions) RoleRepository(com.ctrip.framework.apollo.portal.repository.RoleRepository) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) RolePermission(com.ctrip.framework.apollo.portal.entity.po.RolePermission) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with Role

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

Example 8 with Role

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

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

Example 10 with Role

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

Aggregations

Role (com.ctrip.framework.apollo.portal.entity.po.Role)20 Transactional (org.springframework.transaction.annotation.Transactional)9 Permission (com.ctrip.framework.apollo.portal.entity.po.Permission)8 UserRole (com.ctrip.framework.apollo.portal.entity.po.UserRole)7 ConsumerRole (com.ctrip.framework.apollo.openapi.entity.ConsumerRole)5 PortalConfig (com.ctrip.framework.apollo.portal.component.config.PortalConfig)4 UserInfo (com.ctrip.framework.apollo.portal.entity.bo.UserInfo)4 RolePermission (com.ctrip.framework.apollo.portal.entity.po.RolePermission)4 PermissionRepository (com.ctrip.framework.apollo.portal.repository.PermissionRepository)4 RolePermissionService (com.ctrip.framework.apollo.portal.service.RolePermissionService)4 Sets (com.google.common.collect.Sets)4 Date (java.util.Date)4 List (java.util.List)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 ConsumerRoleRepository (com.ctrip.framework.apollo.openapi.repository.ConsumerRoleRepository)3 RolePermissionRepository (com.ctrip.framework.apollo.portal.repository.RolePermissionRepository)3 RoleRepository (com.ctrip.framework.apollo.portal.repository.RoleRepository)3 UserRoleRepository (com.ctrip.framework.apollo.portal.repository.UserRoleRepository)3