@Override public void execute() { List<Role> roles; if (getId() != null && getId() > 0L) { roles = Collections.singletonList(roleService.findRole(getId())); } else if (StringUtils.isNotBlank(getName())) { roles = roleService.findRolesByName(getName()); } else if (getRoleType() != null) { roles = roleService.findRolesByType(getRoleType()); } else { roles = roleService.listRoles(); } setupResponse(roles); } }
public boolean isDisabled() { return roleService.isEnabled(); }
public Short getAccountType() { return RoleType.getAccountTypeByRole(roleService.findRole(roleId), accountType); }
@Override public void execute() { Role role = roleService.findRole(getRoleId()); if (role == null) { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Invalid role id provided"); } CallContext.current().setEventDetails("Role: " + getRoleName() + ", type:" + getRoleType() + ", description: " + getRoleDescription()); role = roleService.updateRole(role, getRoleName(), getRoleType(), getRoleDescription()); setupResponse(role); } }
@Override public void execute() { final Role role = roleService.findRole(getRoleId()); boolean result = false; if (role == null) { final List<RolePermission> rolePermissionsOrder = new ArrayList<>(); for (Long rolePermissionId : getRulePermissionOrder()) { final RolePermission rolePermission = roleService.findRolePermission(rolePermissionId); if (rolePermission == null) { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Provided role permission(s) do not exist"); result = roleService.updateRolePermission(role, rolePermissionsOrder); } else if (getRuleId() != null && getRulePermission() != null) { if (getRulePermissionOrder() != null) { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Parameters permission and ruleid must be mutually exclusive with ruleorder"); RolePermission rolePermission = roleService.findRolePermission(getRuleId()); if (rolePermission == null) { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Invalid rule id provided"); result = roleService.updateRolePermission(role, rolePermission, getRulePermission());
final Role accountRole = roleService.findRole(account.getRoleId()); if (accountRole == null || accountRole.getId() < 1L) { denyApiAccess(commandName); for (final RolePermission permission : roleService.findAllPermissionsBy(accountRole.getId())) { if (permission.getRule().matches(commandName)) { if (RolePermission.Permission.ALLOW.equals(permission.getPermission())) {
@Override public void execute() { Role role = roleService.findRole(getRoleId()); if (role == null) { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Cannot find the role with provided id"); } CallContext.current().setEventDetails("Role id: " + role.getId()); boolean result = roleService.deleteRole(role); SuccessResponse response = new SuccessResponse(getCommandName()); response.setSuccess(result); setResponseObject(response); } }
@Override public void execute() { final Role role = roleService.findRole(getRoleId()); if (role == null) { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Invalid role id provided"); } CallContext.current().setEventDetails("Role id: " + role.getId() + ", rule:" + getRule() + ", permission: " + getPermission() + ", description: " + getDescription()); final RolePermission rolePermission = roleService.createRolePermission(role, getRule(), getPermission(), getDescription()); if (rolePermission == null) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create role permission"); } setupResponse(rolePermission, role); } }
@Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException { final List<RolePermission> rolePermissions = roleService.findAllPermissionsBy(getRoleId()); setupResponse(rolePermissions, getRoleId()); } }
final List<Role> roles = cmd.roleService.listRoles(); final boolean roleNotFound = roles.stream().filter(r -> r.getId() == roleId).count() == 0; if (roleNotFound) {
@Override public void execute() { CallContext.current().setEventDetails("Role: " + getRoleName() + ", type:" + getRoleType() + ", description: " + getRoleDescription()); final Role role = roleService.createRole(getRoleName(), getRoleType(), getRoleDescription()); if (role == null) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create role"); } setupResponse(role); } }
public Short getAccountType() { return RoleType.getAccountTypeByRole(roleService.findRole(roleId), accountType); }
@Test public void testUpdateSuccess() { when(roleService.findRole(updateRoleCmd.getRoleId())).thenReturn(role); when(role.getId()).thenReturn(1L); when(role.getUuid()).thenReturn("12345-abcgdkajd"); when(role.getDescription()).thenReturn("Defualt user"); when(role.getName()).thenReturn("User"); when(role.getRoleType()).thenReturn(RoleType.User); when(roleService.updateRole(role,updateRoleCmd.getRoleName(),updateRoleCmd.getRoleType(),updateRoleCmd.getRoleDescription())).thenReturn(role); when(role.getId()).thenReturn(1L); when(role.getDescription()).thenReturn("Description Initial"); when(role.getName()).thenReturn("User"); updateRoleCmd.execute(); RoleResponse response = (RoleResponse) updateRoleCmd.getResponseObject(); assertEquals((String)ReflectionTestUtils.getField(response, "roleName"),role.getName()); assertEquals((String)ReflectionTestUtils.getField(response, "roleDescription"),role.getDescription()); } }
public Short getAccountType() { return RoleType.getAccountTypeByRole(roleService.findRole(roleId), accountType); }
public boolean isDisabled() { return !roleService.isEnabled(); }
private void setupResponse(final List<RolePermission> rolePermissions, final Long roleId) { final Role roleProvided = roleService.findRole(roleId); final ListResponse<RolePermissionResponse> response = new ListResponse<>(); final List<RolePermissionResponse> rolePermissionResponses = new ArrayList<>(); for (final RolePermission rolePermission : rolePermissions) { final RolePermissionResponse rolePermissionResponse = new RolePermissionResponse(); Role role = roleProvided; if (role == null) { role = roleService.findRole(rolePermission.getRoleId()); } rolePermissionResponse.setRoleId(role.getUuid()); rolePermissionResponse.setRoleName(role.getName()); rolePermissionResponse.setId(rolePermission.getUuid()); rolePermissionResponse.setRule(rolePermission.getRule()); rolePermissionResponse.setRulePermission(rolePermission.getPermission()); rolePermissionResponse.setDescription(rolePermission.getDescription()); rolePermissionResponse.setObjectName("rolepermission"); rolePermissionResponses.add(rolePermissionResponse); } response.setResponses(rolePermissionResponses); response.setResponseName(getCommandName()); setResponseObject(response); }
@Override public void execute() { Map<String, Object> capabilities = _mgr.listCapabilities(this); CapabilitiesResponse response = new CapabilitiesResponse(); response.setSecurityGroupsEnabled((Boolean)capabilities.get("securityGroupsEnabled")); response.setDynamicRolesEnabled(roleService.isEnabled()); response.setCloudStackVersion((String)capabilities.get("cloudStackVersion")); response.setUserPublicTemplateEnabled((Boolean)capabilities.get("userPublicTemplateEnabled")); response.setSupportELB((String)capabilities.get("supportELB")); response.setProjectInviteRequired((Boolean)capabilities.get("projectInviteRequired")); response.setAllowUsersCreateProjects((Boolean)capabilities.get("allowusercreateprojects")); response.setDiskOffMinSize((Long)capabilities.get("customDiskOffMinSize")); response.setDiskOffMaxSize((Long)capabilities.get("customDiskOffMaxSize")); response.setRegionSecondaryEnabled((Boolean)capabilities.get("regionSecondaryEnabled")); response.setKVMSnapshotEnabled((Boolean)capabilities.get("KVMSnapshotEnabled")); response.setAllowUserViewDestroyedVM((Boolean)capabilities.get("allowUserViewDestroyedVM")); response.setAllowUserExpungeRecoverVM((Boolean)capabilities.get("allowUserExpungeRecoverVM")); if (capabilities.containsKey("apiLimitInterval")) { response.setApiLimitInterval((Integer)capabilities.get("apiLimitInterval")); } if (capabilities.containsKey("apiLimitMax")) { response.setApiLimitMax((Integer)capabilities.get("apiLimitMax")); } response.setObjectName("capability"); response.setResponseName(getCommandName()); this.setResponseObject(response); } }
public static AccountResponse newAccountResponse(ResponseView view, AccountJoinVO ve) { AccountResponse response = s_accountJoinDao.newAccountResponse(view, ve); // Populate account role information if (ve.getRoleId() != null) { Role role = s_roleService.findRole(ve.getRoleId()); if (role != null) { response.setRoleId(role.getUuid()); response.setRoleType(role.getRoleType()); response.setRoleName(role.getName()); } } return response; }
public static UserResponse newUserResponse(UserAccountJoinVO usr, Long domainId) { UserResponse response = s_userAccountJoinDao.newUserResponse(usr); if(!AccountManager.UseSecretKeyInResponse.value()){ response.setSecretKey(null); } // Populate user account role information if (usr.getAccountRoleId() != null) { Role role = s_roleService.findRole( usr.getAccountRoleId()); if (role != null) { response.setRoleId(role.getUuid()); response.setRoleType(role.getRoleType()); response.setRoleName(role.getName()); } } if (domainId != null && usr.getDomainId() != domainId) response.setIsCallerChildDomain(true); else response.setIsCallerChildDomain(false); return response; }