public Builder copy(Account account) { sid = account.getSid(); parentSid = account.getParentSid(); organizationSid = account.getOrganizationSid(); type = account.getType(); uri = account.getUri(); authToken = account.getAuthToken(); emailAddress = account.getEmailAddress(); friendlyName = account.getFriendlyName(); role = account.getRole(); status = account.getStatus(); return this; }
public Account setEmailAddress(final String emailAddress) { return new Account(sid, dateCreated, DateTime.now(), emailAddress, friendlyName, parentSid, type, status, authToken, role, uri, organizationSid); }
/** * Checks if the operated account is a direct child of effective account * @return */ protected boolean isDirectChildOfAccount(final Account effectiveAccount, final Account operatedAccount) { return operatedAccount.getParentSid().equals(effectiveAccount.getSid()); }
public static String getAuthenticationHeader(Sid sid, DaoManager storage) { Account requestingAccount = storage.getAccountsDao().getAccount(sid); String authenticationHeader = null; if(requestingAccount != null) { String auth = requestingAccount.getSid() + ":" + requestingAccount.getAuthToken(); byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("ISO-8859-1"))); authenticationHeader = "Basic " + new String(encodedAuth); } return authenticationHeader; }
@Override public JsonElement serialize(final Account account, final Type type, final JsonSerializationContext context) { final JsonObject object = new JsonObject(); writeSid(account.getSid(), object); object.addProperty("organization", account.getOrganizationSid().toString()); writeFriendlyName(account.getFriendlyName(), object); writeEmailAddress(account, object); writeType(account.getType().toString(), object); writeStatus(account.getStatus().toString(), object); writeRoleInfo(account.getRole(), object); writeDateCreated(account.getDateCreated(), object); writeDateUpdated(account.getDateUpdated(), object); writeAuthToken(account, object); writeUri(account, object); writeSubResourceUris(account, object); return object; }
final Sid sid = userIdentityContext.getEffectiveAccount().getSid(); if (accountsDao.getAccount(account.getSid()) == null && !account.getEmailAddress().equalsIgnoreCase("administrator@company.com")) { if (parent.getStatus().equals(Account.Status.ACTIVE) && isSecuredByPermission("RestComm:Create:Accounts")) { if (!hasAccountRole(getAdministratorRole()) || !data.containsKey("Role")) { account = account.setRole(parent.getRole()); clientData.add("Login", username); clientData.add("Password", data.getFirst("Password")); clientData.add("FriendlyName", account.getFriendlyName()); clientData.add("AccountSid", account.getSid().toString()); Client client = clientDao.getClient(clientData.getFirst("Login"), account.getOrganizationSid()); if (client == null) { client = createClientFrom(account.getSid(), clientData); clientDao.addClient(client);
String operatingAccountSid = operatingAccount.getSid().toString(); String operatedAccountSid = operatedAccount.getSid().toString(); if (getAdministratorRole().equals(operatingAccount.getRole())) { if (operatedAccount.getParentSid() != null ) { if (operatedAccount.getParentSid().toString().equals(operatingAccountSid )) return AuthOutcome.OK; else if (accountsDao.getAccountLineage(operatedAccount).contains(operatingAccountSid))
/** * getOrganizationSidByAccountSid * * @param accountSid * @return Sid of Organization */ public static Sid getOrganizationSidByAccountSid(DaoManager storage, final Sid accountSid) { return storage.getAccountsDao().getAccount(accountSid).getOrganizationSid(); }
if (operatingAccount.getOrganizationSid().equals(organization.getSid())) { return status(BAD_REQUEST).entity("Account already in the requested Organization").build(); Account modifiedAccount = operatingAccount.setOrganizationSid(organization.getSid()); accountsDao.updateAccount(modifiedAccount); String msg = String.format("Parent Account %s migrated to Organization %s", modifiedAccount.getSid(), organization.getSid()); logger.debug(msg); List<Account> childAccounts = accountsDao.getChildAccounts(operatingAccount.getSid()); for (Account child : childAccounts) { if (!child.getOrganizationSid().equals(organization.getSid())) { Account modifiedChildAccount = child.setOrganizationSid(organization.getSid()); accountsDao.updateAccount(modifiedChildAccount); if (logger.isDebugEnabled()) { String msg = String.format("Child Account %s from Parent Account %s, migrated to Organization %s", modifiedChildAccount.getSid(), modifiedAccount.getSid(), organization.getSid()); logger.debug(msg);
/** * @param account * @throws IllegalStateException */ private void checkOrganization(Account account) throws IllegalStateException { Sid organizationSid = account.getOrganizationSid(); if(organizationSid == null){ String errorMsg = "there is no organization assosiate with this account: "+account.getSid(); logger.error(errorMsg); throw new IllegalStateException(errorMsg); } Organization organization = organizationsDao.getOrganization(organizationSid); if(organization == null || organization.getDomainName() == null || organization.getDomainName().trim().isEmpty()){ String errorMsg = "Invalid or Null Organization: "+organization +" for account: "+account.getSid(); logger.error(errorMsg); throw new IllegalStateException(errorMsg); } }
private String prefix(final Account account, MediaType responseType) { final StringBuilder buffer = new StringBuilder(); buffer.append("/").append(apiVersion).append("/Accounts"); if(responseType == APPLICATION_JSON_TYPE) { buffer.append(".json"); } buffer.append("/"+account.getSid().toString()); return buffer.toString(); }
lastAccount = daoManager.getAccountsDao().getAccount(currentAccount); if (lastAccount != null) { currentAccount = lastAccount.getParentSid(); } else { throw new RuntimeException("account not found!!!"); Sid organizationSid = lastAccount.getOrganizationSid(); profile = retrieveExplicitlyAssociatedProfile(organizationSid);
/** * update SIP client of the corresponding Account.Password and FriendlyName fields are synched. */ private void updateLinkedClient(Account account, MultivaluedMap<String, String> data) { logger.debug("checking linked client"); String email = account.getEmailAddress(); if (email != null && !email.equals("")) { logger.debug("account email is valid"); String username = email.split("@")[0]; Client client = clientDao.getClient(username, account.getOrganizationSid()); if (client != null) { logger.debug("client found"); // TODO: need to encrypt this password because it's // same with Account password. // Don't implement now. Opened another issue for it. if (data.containsKey("Password")) { // Md5Hash(data.getFirst("Password")).toString(); logger.debug("password changed"); String password = data.getFirst("Password"); client = client.setPassword(client.getLogin(), password, organizationsDao.getOrganization(account.getOrganizationSid()).getDomainName()); } if (data.containsKey("FriendlyName")) { logger.debug("friendlyname changed"); client = client.setFriendlyName(data.getFirst("FriendlyName")); } logger.debug("updating linked client"); clientDao.updateClient(client); } } }
Sid orgSid = new Sid(data.getFirst("OrganizationSid")); if(!orgSid.equals(parent.getOrganizationSid())){ organizationSid = organizationSid != null ? organizationSid : parent.getOrganizationSid(); final String password = data.getFirst("Password"); PasswordValidator validator = PasswordValidatorFactory.createDefault(); buffer.append("/").append(getApiVersion(null)).append("/Accounts/").append(sid.toString()); final URI uri = URI.create(buffer.toString()); return new Account(sid, now, now, emailAddress, friendlyName, accountSid, type, status, authToken, role, uri, organizationSid);
/** * Checks if the effective account is a super account (top level account) * @return */ protected boolean isSuperAdmin() { //SuperAdmin Account is the one the is //1. Has no parent, this is the top account //2. Is ACTIVE return (userIdentityContext.getEffectiveAccount().getParentSid() == null) && (userIdentityContext.getEffectiveAccount().getStatus().equals(Account.Status.ACTIVE)); }
/** * Switches an account status at dao level. * * If status is CLSOED, Removes all resources belonging to an account. * * If rcmlServerApi is not null it will * also send account-removal notifications to the rcmlserver * * @param account */ private void switchAccountStatus(Account account, Account.Status status) { if (logger.isDebugEnabled()) { logger.debug("Switching status for account:" + account.getSid() + ",status:" + status); } switch (status) { case CLOSED: sendRVDStatusNotification(account); // then proceed to dependency removal removeAccoundDependencies(account.getSid()); break; default: break; } // finally, set and persist account status account = account.setStatus(status); accountsDao.updateAccount(account); }
private void verify(AccountsDao dao) { if ( account != null ) { if ( challengedKey != null ) // Compare both the plaintext version of the token and md5'ed version of it if ( challengedKey.equals(account.getAuthToken()) || DigestUtils.md5Hex(challengedKey).equals(account.getAuthToken()) ) { verified = true; } } }
@Override public List<String> getAccountLineage(Account account) throws AccountHierarchyDepthCrossed { if (account == null) return null; List<String> lineage = new ArrayList<String>(); Sid parentSid = account.getParentSid(); if (parentSid != null) { lineage.add(parentSid.toString()); lineage.addAll(getAccountLineage(parentSid)); } return lineage; }