public GetAllCredentialsResponse getAllCredentialsFromToken()

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


    public GetAllCredentialsResponse getAllCredentialsFromToken(TokenRequest request) {
        try {
            String token = request.getToken();
            Credential credential = credentialManager.decodeJWTToken(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("Client not found");
                throw new EntityNotFoundException("Client not found");
            }

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

            List<CredentialMetadata> credentialMetadata = new ArrayList<>();


            if (paths != null && !paths.isEmpty()) {
                for (String key : paths) {
                    if (isMainType(key)) {
                        String path = subPath + "/" + key;
                        VaultResponseSupport<Credential> crRe = vaultTemplate.read(path, Credential.class);
                        if (crRe != null && crRe.getData() != null) {
                            CredentialMetadata metadata = convertToCredentialMetadata(crRe.getData(), entity.getOwnerId(), key);
                            if (key.equals(Type.CUSTOS.name())) {
                                metadata = metadata.toBuilder()
                                        .setClientIdIssuedAt(entity.getIssuedAt().getTime())
                                        .setClientSecretExpiredAt(entity.getClientSecretExpiredAt())
                                        .build();
                            }
                            credentialMetadata.add(metadata);
                        }
                    }
                }
            }
            return GetAllCredentialsResponse.newBuilder().addAllSecretList(credentialMetadata).build();

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