@Override
 public Identity getIdentity(Long id) {
   Account account = getAccountById(id);
   if (account == null || account.getKind().equalsIgnoreCase(ProjectConstants.TYPE)) {
     return null;
   }
   Credential credential =
       create()
           .selectFrom(CREDENTIAL)
           .where(
               CREDENTIAL
                   .KIND
                   .equalIgnoreCase(CredentialConstants.KIND_PASSWORD)
                   .and(CREDENTIAL.ACCOUNT_ID.eq(id))
                   .and(CREDENTIAL.STATE.equalIgnoreCase(CommonStatesConstants.ACTIVE)))
           .fetchAny();
   String accountId =
       (String)
           ApiContext.getContext()
               .getIdFormatter()
               .formatId(objectManager.getType(Account.class), account.getId());
   return new Identity(
       ProjectConstants.RANCHER_ID,
       accountId,
       account.getName(),
       null,
       null,
       credential == null ? null : credential.getPublicValue());
 }
 @Override
 public Account getAccountByKeys(String access, String secretKey) {
   try {
     Credential credential =
         create()
             .selectFrom(CREDENTIAL)
             .where(CREDENTIAL.STATE.eq(CommonStatesConstants.ACTIVE))
             .and(CREDENTIAL.PUBLIC_VALUE.eq(access))
             .and(CREDENTIAL.KIND.in(SUPPORTED_TYPES.get()))
             .fetchOne();
     if (credential == null) {
       return null;
     }
     boolean secretIsCorrect =
         ApiContext.getContext()
             .getTransformationService()
             .compare(secretKey, credential.getSecretValue());
     if (secretIsCorrect) {
       return create()
           .selectFrom(ACCOUNT)
           .where(
               ACCOUNT
                   .ID
                   .eq(credential.getAccountId())
                   .and(ACCOUNT.STATE.eq(CommonStatesConstants.ACTIVE)))
           .fetchOneInto(AccountRecord.class);
     } else {
       return null;
     }
   } catch (InvalidResultException e) {
     throw new ClientVisibleException(ResponseCodes.CONFLICT, "MultipleKeys");
   }
 }
 @Override
 public Account getAccountByLogin(String publicValue, String secretValue) {
   Credential credential =
       create()
           .selectFrom(CREDENTIAL)
           .where(CREDENTIAL.STATE.eq(CommonStatesConstants.ACTIVE))
           .and(
               CREDENTIAL
                   .PUBLIC_VALUE
                   .eq(publicValue)
                   .and(CREDENTIAL.KIND.equalIgnoreCase(CredentialConstants.KIND_PASSWORD)))
           .fetchOne();
   if (credential == null) {
     return null;
   }
   boolean secretIsCorrect =
       ApiContext.getContext()
           .getTransformationService()
           .compare(secretValue, credential.getSecretValue());
   if (secretIsCorrect) {
     return create()
         .selectFrom(ACCOUNT)
         .where(
             ACCOUNT
                 .ID
                 .eq(credential.getAccountId())
                 .and(ACCOUNT.STATE.eq(CommonStatesConstants.ACTIVE)))
         .fetchOneInto(AccountRecord.class);
   } else {
     return null;
   }
 }
Ejemplo n.º 4
0
  @Override
  public HandlerResult handle(ProcessState state, ProcessInstance process) {
    Account account = (Account) state.getResource();

    for (Certificate cert : getObjectManager().children(account, Certificate.class)) {
      if (cert.getRemoved() != null) {
        continue;
      }

      deactivateThenRemove(cert, state.getData());
    }

    for (Credential cred : getObjectManager().children(account, Credential.class)) {
      if (cred.getRemoved() != null) {
        continue;
      }

      deactivateThenRemove(cred, state.getData());
    }

    for (Host host : getObjectManager().children(account, Host.class)) {
      try {
        deactivateThenRemove(host, state.getData());
      } catch (ProcessCancelException e) {
        // ignore
      }
      purge(host, null);
    }

    for (PhysicalHost host : getObjectManager().children(account, PhysicalHost.class)) {
      try {
        getObjectProcessManager().executeStandardProcess(StandardProcess.REMOVE, host, null);
      } catch (ProcessCancelException e) {
        // ignore
      }
    }

    for (Agent agent : getObjectManager().children(account, Agent.class)) {
      if (agent.getRemoved() != null) {
        continue;
      }
      deactivateThenRemove(agent, state.getData());
    }

    for (Environment env : getObjectManager().children(account, Environment.class)) {
      if (env.getRemoved() != null) {
        continue;
      }
      objectProcessManager.scheduleStandardProcessAsync(StandardProcess.REMOVE, env, null);
    }

    for (Instance instance : instanceDao.listNonRemovedInstances(account, false)) {
      deleteAgentAccount(instance.getAgentId(), state.getData());

      try {
        objectProcessManager.scheduleStandardProcess(StandardProcess.REMOVE, instance, null);
      } catch (ProcessCancelException e) {
        objectProcessManager.scheduleProcessInstance(
            InstanceConstants.PROCESS_STOP,
            instance,
            CollectionUtils.asMap(InstanceConstants.REMOVE_OPTION, true));
      }
    }

    accountDao.deleteProjectMemberEntries(account);

    return null;
  }
Ejemplo n.º 5
0
 /** {@inheritDoc} */
 @Override
 public void from(io.cattle.platform.core.model.Credential from) {
   setId(from.getId());
   setName(from.getName());
   setAccountId(from.getAccountId());
   setKind(from.getKind());
   setUuid(from.getUuid());
   setDescription(from.getDescription());
   setState(from.getState());
   setCreated(from.getCreated());
   setRemoved(from.getRemoved());
   setRemoveTime(from.getRemoveTime());
   setData(from.getData());
   setPublicValue(from.getPublicValue());
   setSecretValue(from.getSecretValue());
   setRegistryId(from.getRegistryId());
 }