public Credentials getBasicCredentials()

in services/src/main/java/org/apache/custos/service/credential/store/CredentialStoreService.java [455:511]


    public Credentials getBasicCredentials(TokenRequest request) {
        try {
            String token = request.getToken();
            Credential credential = credentialManager.decodeToken(token);

            if (credential == null || credential.getId() == null) {
                LOGGER.error("Invalid access token");
                throw new EntityNotFoundException("Invalid access token");
            }

            CredentialEntity entity = repository.findByClientId(credential.getId());
            if (entity == null) {
                LOGGER.error("Could not find the credential entity with the Id: {}", credential.getId());
                throw new EntityNotFoundException("Could not find the credential entity with the Id: " + credential.getId());
            }

            String subPath = BASE_PATH + entity.getOwnerId();
            List<String> paths = vaultTemplate.list(subPath);
            Credentials.Builder credentialsBuilder = Credentials.newBuilder();

            if (paths != null && !paths.isEmpty()) {
                for (String key : paths) {
                    String path = subPath + "/" + key;
                    VaultResponseSupport<Credential> crRe = vaultTemplate.read(path, Credential.class);
                    if (crRe == null || crRe.getData() == null || crRe.getData().getSecret() == null) {
                        LOGGER.error("Cannot find Credential with the Id: " + credential.getId() + " in the Secret store");
                        throw new EntityNotFoundException("Cannot find Credential with the Id: " + credential.getId() + " in the Secret store");
                    }

                    if (key.equals(Type.CUSTOS.name())) {
                        if (!crRe.getData().getSecret().equals(credential.getSecret())) {
                            String msg = "Invalid secret for id" + credential.getId();
                            LOGGER.error(msg);
                            throw new AuthenticationException(msg);
                        }

                        credentialsBuilder.setCustosClientId(crRe.getData().getId())
                                .setCustosClientSecret(crRe.getData().getSecret())
                                .setCustosClientIdIssuedAt(entity.getIssuedAt().getTime())
                                .setCustosClientSecretExpiredAt(entity.getClientSecretExpiredAt());

                    } else if (key.equals(Type.IAM.name())) {
                        credentialsBuilder.setIamClientId(crRe.getData().getId()).setIamClientSecret(crRe.getData().getSecret());

                    } else if (key.equals(Type.CILOGON.name())) {
                        credentialsBuilder.setCiLogonClientId(crRe.getData().getId()).setCiLogonClientSecret(crRe.getData().getSecret());
                    }
                }
            }
            return credentialsBuilder.build();

        } catch (Exception ex) {
            String msg = "Operation failed " + ex;
            LOGGER.error(msg);
            throw new InternalServerException(msg, ex);
        }
    }