public static Long getRoleByAccountType(final Long roleId, final Short accountType) { if (roleId == null && accountType != null) { RoleType defaultRoleType = RoleType.getByAccountType(accountType); if (defaultRoleType != null && defaultRoleType != RoleType.Unknown) { return defaultRoleType.getId(); } } return roleId; }
public AccountVO(final String accountName, final long domainId, final String networkDomain, final short type, final String uuid) { this.accountName = accountName; this.domainId = domainId; this.networkDomain = networkDomain; this.type = type; this.state = State.enabled; this.uuid = uuid; this.roleId = RoleType.getRoleByAccountType(null, type); }
pstmt.setLong(4, RoleType.User.getId()); }else{ pstmt.setLong(4, acct.getRoleId());
@Test public void testGetRoleByAccountTypeForDefaultAccountTypes() { Assert.assertEquals(RoleType.getRoleByAccountType(null, Account.ACCOUNT_TYPE_ADMIN), (Long) RoleType.Admin.getId()); Assert.assertEquals(RoleType.getRoleByAccountType(null, Account.ACCOUNT_TYPE_NORMAL), (Long) RoleType.User.getId()); Assert.assertEquals(RoleType.getRoleByAccountType(null, Account.ACCOUNT_TYPE_DOMAIN_ADMIN), (Long) RoleType.DomainAdmin.getId()); Assert.assertEquals(RoleType.getRoleByAccountType(null, Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN), (Long) RoleType.ResourceAdmin.getId()); Assert.assertEquals(RoleType.getRoleByAccountType(null, Account.ACCOUNT_TYPE_PROJECT), null); }
acnt.setState(Account.State.enabled); acnt.setDomainId(1); acnt.setType(RoleType.User.getAccountType()); acnt.setRoleId(RoleType.User.getId()); acnt = acntDao.persist(acnt);
@Test public void testValidRoleTypeFromString() { for (RoleType roleType : RoleType.values()) { Assert.assertEquals(RoleType.fromString(roleType.name()), roleType); } }
@Test public void testGetAccountTypeByRole() { Role role = Mockito.mock(Role.class); Mockito.when(role.getRoleType()).thenReturn(RoleType.Admin); Mockito.when(role.getId()).thenReturn(100L); Assert.assertEquals(RoleType.getAccountTypeByRole(role, null), (Short) RoleType.Admin.getAccountType()); } }
public static Short getAccountTypeByRole(final Role role, final Short accountType) { if (role != null && role.getId() > 0L) { return role.getRoleType().getAccountType(); } return accountType; } }
@Override public RoleType getRoleType(Account account) { if (account == null) { return RoleType.Unknown; } return RoleType.getByAccountType(account.getType()); }
public Short getAccountType() { return RoleType.getAccountTypeByRole(roleService.findRole(roleId), accountType); }
protected DynamicRoleBasedAPIAccessChecker() { super(); for (RoleType roleType : RoleType.values()) { annotationRoleBasedApisMap.put(roleType, new HashSet<String>()); } }
public RoleType getRoleType() { return RoleType.fromString(roleType); }
try { UserAccount userAccount = _accountService .createUserAccount(admin, "", ldapUser.getFirstname(), ldapUser.getLastname(), ldapUser.getEmail(), null, admin, Account.ACCOUNT_TYPE_DOMAIN_ADMIN, RoleType.DomainAdmin.getId(), domainId, null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), User.Source.LDAP); response.setAdminId(String.valueOf(userAccount.getAccountId()));
roleIsAllowed = false; for (final RoleType allowedRole : allowedRoles) { if (allowedRole.getAccountType() == caller.getType()) { roleIsAllowed = true; break;
@Test public void testGetByAccountType() { Assert.assertEquals(RoleType.getByAccountType(Account.ACCOUNT_TYPE_NORMAL), RoleType.User); Assert.assertEquals(RoleType.getByAccountType(Account.ACCOUNT_TYPE_ADMIN), RoleType.Admin); Assert.assertEquals(RoleType.getByAccountType(Account.ACCOUNT_TYPE_DOMAIN_ADMIN), RoleType.DomainAdmin); Assert.assertEquals(RoleType.getByAccountType(Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN), RoleType.ResourceAdmin); Assert.assertEquals(RoleType.getByAccountType(Account.ACCOUNT_TYPE_PROJECT), RoleType.Unknown); }
public Short getAccountType() { return RoleType.getAccountTypeByRole(roleService.findRole(roleId), accountType); }
public StaticRoleBasedAPIAccessChecker() { super(); for (RoleType roleType : RoleType.values()) { commandsPropertiesRoleBasedApisMap.put(roleType, new HashSet<String>()); annotationRoleBasedApisMap.put(roleType, new HashSet<String>()); } }
public RoleType getRoleType() { if (!Strings.isNullOrEmpty(roleType)) { return RoleType.fromString(roleType); } return null; }
private void migrateAccountsToDefaultRoles(final Connection conn) { try (final PreparedStatement selectStatement = conn.prepareStatement("SELECT `id`, `type` FROM `cloud`.`account`;"); final ResultSet selectResultSet = selectStatement.executeQuery()) { while (selectResultSet.next()) { final Long accountId = selectResultSet.getLong(1); final Short accountType = selectResultSet.getShort(2); final Long roleId = RoleType.getByAccountType(accountType).getId(); if (roleId < 1L || roleId > 4L) { s_logger.warn("Skipping role ID migration due to invalid role_id resolved for account id=" + accountId); continue; } try (final PreparedStatement updateStatement = conn.prepareStatement("UPDATE `cloud`.`account` SET account.role_id = ? WHERE account.id = ? ;")) { updateStatement.setLong(1, roleId); updateStatement.setLong(2, accountId); updateStatement.executeUpdate(); } catch (SQLException e) { s_logger.error("Failed to update cloud.account role_id for account id:" + accountId + " with exception: " + e.getMessage()); throw new CloudRuntimeException("Exception while updating cloud.account role_id", e); } } } catch (SQLException e) { throw new CloudRuntimeException("Exception while migrating existing account table's role_id column to a role based on account type", e); } s_logger.debug("Done migrating existing accounts to use one of default roles based on account type"); }