use of com.ctrip.framework.apollo.portal.entity.po.Permission in project apollo by ctripcorp.
the class DefaultRolePermissionService method createPermissions.
/**
* Create permissions, note that permissionType + targetId should be unique
*/
@Transactional
public Set<Permission> createPermissions(Set<Permission> permissions) {
Multimap<String, String> targetIdPermissionTypes = HashMultimap.create();
for (Permission permission : permissions) {
targetIdPermissionTypes.put(permission.getTargetId(), permission.getPermissionType());
}
for (String targetId : targetIdPermissionTypes.keySet()) {
Collection<String> permissionTypes = targetIdPermissionTypes.get(targetId);
List<Permission> current = permissionRepository.findByPermissionTypeInAndTargetId(permissionTypes, targetId);
Preconditions.checkState(CollectionUtils.isEmpty(current), "Permission with permissionType %s targetId %s already exists!", permissionTypes, targetId);
}
Iterable<Permission> results = permissionRepository.saveAll(permissions);
return StreamSupport.stream(results.spliterator(), false).collect(Collectors.toSet());
}
use of com.ctrip.framework.apollo.portal.entity.po.Permission in project apollo by ctripcorp.
the class DefaultRolePermissionService method createPermission.
/**
* Create permission, note that permissionType + targetId should be unique
*/
@Transactional
public Permission createPermission(Permission permission) {
String permissionType = permission.getPermissionType();
String targetId = permission.getTargetId();
Permission current = permissionRepository.findTopByPermissionTypeAndTargetId(permissionType, targetId);
Preconditions.checkState(current == null, "Permission with permissionType %s targetId %s already exists!", permissionType, targetId);
return permissionRepository.save(permission);
}
use of com.ctrip.framework.apollo.portal.entity.po.Permission 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.Permission 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.Permission 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