use of com.ctrip.framework.apollo.portal.entity.po.Role in project apollo by ctripcorp.
the class AppController method findAppsByOwner.
@GetMapping("/by-owner")
public List<App> findAppsByOwner(@RequestParam("owner") String owner, Pageable page) {
Set<String> appIds = Sets.newHashSet();
List<Role> userRoles = rolePermissionService.findUserRoles(owner);
for (Role role : userRoles) {
String appId = RoleUtils.extractAppIdFromRoleName(role.getRoleName());
if (appId != null) {
appIds.add(appId);
}
}
return appService.findByAppIds(appIds, page);
}
use of com.ctrip.framework.apollo.portal.entity.po.Role in project apollo by ctripcorp.
the class ConsumerService method assignAppRoleToConsumer.
@Transactional
public ConsumerRole assignAppRoleToConsumer(String token, String appId) {
Long consumerId = getConsumerIdByToken(token);
if (consumerId == null) {
throw new BadRequestException("Token is Illegal");
}
Role masterRole = rolePermissionService.findRoleByRoleName(RoleUtils.buildAppMasterRoleName(appId));
if (masterRole == null) {
throw new BadRequestException("App's role does not exist. Please check whether app has created.");
}
long roleId = masterRole.getId();
ConsumerRole managedModifyRole = consumerRoleRepository.findByConsumerIdAndRoleId(consumerId, roleId);
if (managedModifyRole != null) {
return managedModifyRole;
}
String operator = userInfoHolder.getUser().getUserId();
ConsumerRole consumerRole = createConsumerRole(consumerId, roleId, operator);
return consumerRoleRepository.save(consumerRole);
}
use of com.ctrip.framework.apollo.portal.entity.po.Role 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.Role 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.Role in project apollo by ctripcorp.
the class RolePermissionServiceTest method assembleRole.
private Role assembleRole(String roleName) {
Role role = new Role();
role.setRoleName(roleName);
role.setDataChangeCreatedBy(someCreatedBy);
role.setDataChangeLastModifiedBy(someLastModifiedBy);
return role;
}
Aggregations