diff --git a/src/plugins/axivion/dashboard/concat.cpp b/src/plugins/axivion/dashboard/concat.cpp index 1da7f2b081f..7d0ad6f7285 100644 --- a/src/plugins/axivion/dashboard/concat.cpp +++ b/src/plugins/axivion/dashboard/concat.cpp @@ -16,6 +16,9 @@ #include +namespace Axivion::Internal::Dto +{ + template static Output concat(const std::initializer_list &args) { @@ -43,3 +46,5 @@ QByteArray concat_bytes(const std::initializer_list &args) { return concat(args); } + +} // namespace Axivion::Internal::Dto diff --git a/src/plugins/axivion/dashboard/concat.h b/src/plugins/axivion/dashboard/concat.h index 591b4ffeca3..33429e3bf42 100644 --- a/src/plugins/axivion/dashboard/concat.h +++ b/src/plugins/axivion/dashboard/concat.h @@ -22,9 +22,12 @@ #include #include +namespace Axivion::Internal::Dto +{ std::string concat(const std::initializer_list &args); QString concat(const std::initializer_list &args); QByteArray concat_bytes(const std::initializer_list &args); +} // namespace Axivion::Internal::Dto diff --git a/src/plugins/axivion/dashboard/dto.cpp b/src/plugins/axivion/dashboard/dto.cpp index 607c227816c..1720087f2c8 100644 --- a/src/plugins/axivion/dashboard/dto.cpp +++ b/src/plugins/axivion/dashboard/dto.cpp @@ -749,10 +749,10 @@ namespace Axivion::Internal::Dto { // version - constexpr std::array ApiVersion::number{7,6,2,12725}; - const QLatin1String ApiVersion::string{"7.6.2.12725"}; - const QLatin1String ApiVersion::name{"7.6.2"}; - const QLatin1String ApiVersion::timestamp{"2023-08-07 14:38:01 +00:00"}; + constexpr std::array ApiVersion::number{7,6,3,12797}; + const QLatin1String ApiVersion::string{"7.6.3.12797"}; + const QLatin1String ApiVersion::name{"7.6.3"}; + const QLatin1String ApiVersion::timestamp{"2023-08-30 15:49:00 +00:00"}; // AnalyzedFileDto @@ -1011,6 +1011,50 @@ namespace Axivion::Internal::Dto { return serialize_bytes(*this); } + // CsrfTokenDto + + static const QLatin1String csrfTokenKeyCsrfToken{"csrfToken"}; + + template<> + class de_serializer final + { + public: + // throws Axivion::Internal::Dto::invalid_dto_exception + static CsrfTokenDto deserialize(const QJsonValue &json) { + const QJsonObject jo = toJsonObject(json); + return { + deserialize_field(jo, csrfTokenKeyCsrfToken) + }; + } + + static QJsonValue serialize(const CsrfTokenDto &value) { + QJsonObject jo; + serialize_field(jo, csrfTokenKeyCsrfToken, value.csrfToken); + return { jo }; + } + + de_serializer() = delete; + ~de_serializer() = delete; + }; + + // throws Axivion::Internal::Dto::invalid_dto_exception + CsrfTokenDto CsrfTokenDto::deserialize(const QByteArray &json) + { + return deserialize_bytes(json); + } + + CsrfTokenDto::CsrfTokenDto( + QString csrfToken + ) : + csrfToken(std::move(csrfToken)) + { } + + // throws Axivion::Internal::Dto::invalid_dto_exception + QByteArray CsrfTokenDto::serialize() const + { + return serialize_bytes(*this); + } + // EntityDto static const QLatin1String entityKeyId{"id"}; @@ -2186,7 +2230,7 @@ namespace Axivion::Internal::Dto { deserialize_field(jo, analysisVersionKeyDate), deserialize_field>(jo, analysisVersionKeyLabel), deserialize_field(jo, analysisVersionKeyIndex), - deserialize_field>(jo, analysisVersionKeyName), + deserialize_field(jo, analysisVersionKeyName), deserialize_field(jo, analysisVersionKeyMillis), deserialize_field(jo, analysisVersionKeyIssueCounts), deserialize_field>(jo, analysisVersionKeyToolsVersion), @@ -2223,7 +2267,7 @@ namespace Axivion::Internal::Dto { QString date, std::optional label, qint32 index, - std::optional name, + QString name, qint64 millis, Any issueCounts, std::optional toolsVersion, @@ -2614,6 +2658,7 @@ namespace Axivion::Internal::Dto { static const QLatin1String dashboardInfoKeyUserNamedFiltersUrl{"userNamedFiltersUrl"}; static const QLatin1String dashboardInfoKeySupportAddress{"supportAddress"}; static const QLatin1String dashboardInfoKeyIssueFilterHelp{"issueFilterHelp"}; + static const QLatin1String dashboardInfoKeyCsrfTokenUrl{"csrfTokenUrl"}; template<> class de_serializer final @@ -2628,7 +2673,7 @@ namespace Axivion::Internal::Dto { deserialize_field>(jo, dashboardInfoKeyDashboardVersionNumber), deserialize_field(jo, dashboardInfoKeyDashboardBuildDate), deserialize_field>(jo, dashboardInfoKeyUsername), - deserialize_field(jo, dashboardInfoKeyCsrfTokenHeader), + deserialize_field>(jo, dashboardInfoKeyCsrfTokenHeader), deserialize_field(jo, dashboardInfoKeyCsrfToken), deserialize_field>(jo, dashboardInfoKeyCheckCredentialsUrl), deserialize_field>(jo, dashboardInfoKeyNamedFiltersUrl), @@ -2636,7 +2681,8 @@ namespace Axivion::Internal::Dto { deserialize_field>(jo, dashboardInfoKeyUserApiTokenUrl), deserialize_field>(jo, dashboardInfoKeyUserNamedFiltersUrl), deserialize_field>(jo, dashboardInfoKeySupportAddress), - deserialize_field>(jo, dashboardInfoKeyIssueFilterHelp) + deserialize_field>(jo, dashboardInfoKeyIssueFilterHelp), + deserialize_field>(jo, dashboardInfoKeyCsrfTokenUrl) }; } @@ -2656,6 +2702,7 @@ namespace Axivion::Internal::Dto { serialize_field(jo, dashboardInfoKeyUserNamedFiltersUrl, value.userNamedFiltersUrl); serialize_field(jo, dashboardInfoKeySupportAddress, value.supportAddress); serialize_field(jo, dashboardInfoKeyIssueFilterHelp, value.issueFilterHelp); + serialize_field(jo, dashboardInfoKeyCsrfTokenUrl, value.csrfTokenUrl); return { jo }; } @@ -2675,7 +2722,7 @@ namespace Axivion::Internal::Dto { std::optional dashboardVersionNumber, QString dashboardBuildDate, std::optional username, - QString csrfTokenHeader, + std::optional csrfTokenHeader, QString csrfToken, std::optional checkCredentialsUrl, std::optional namedFiltersUrl, @@ -2683,7 +2730,8 @@ namespace Axivion::Internal::Dto { std::optional userApiTokenUrl, std::optional userNamedFiltersUrl, std::optional supportAddress, - std::optional issueFilterHelp + std::optional issueFilterHelp, + std::optional csrfTokenUrl ) : mainUrl(std::move(mainUrl)), dashboardVersion(std::move(dashboardVersion)), @@ -2698,7 +2746,8 @@ namespace Axivion::Internal::Dto { userApiTokenUrl(std::move(userApiTokenUrl)), userNamedFiltersUrl(std::move(userNamedFiltersUrl)), supportAddress(std::move(supportAddress)), - issueFilterHelp(std::move(issueFilterHelp)) + issueFilterHelp(std::move(issueFilterHelp)), + csrfTokenUrl(std::move(csrfTokenUrl)) { } // throws Axivion::Internal::Dto::invalid_dto_exception diff --git a/src/plugins/axivion/dashboard/dto.h b/src/plugins/axivion/dashboard/dto.h index bdede500c39..97ca5d602dc 100644 --- a/src/plugins/axivion/dashboard/dto.h +++ b/src/plugins/axivion/dashboard/dto.h @@ -317,6 +317,34 @@ namespace Axivion::Internal::Dto virtual QByteArray serialize() const override; }; + /** + * CSRF token + * + * @since 7.7.0 + */ + class CsrfTokenDto : public Serializable + { + public: + + /** + *

The value expected to be sent along the ``csrfTokenHeader`` for all HTTP requests that are not GET, HEAD, OPTIONS or TRACE. + * + *

Note, that this does not replace authentication of subsequent requests. Also the token is combined with the authentication + * data, so will not work when authenticating as another user. Its lifetime is limited, so when creating a very long-running + * application you should consider refreshing this token from time to time. + */ + QString csrfToken; + + // Throws Axivion::Internal::Dto::invalid_dto_exception + static CsrfTokenDto deserialize(const QByteArray &json); + + CsrfTokenDto( + QString csrfToken + ); + + virtual QByteArray serialize() const override; + }; + /** * A Project Entity such as a Class, a Method, a File or a Module * or the System Entity. @@ -1261,21 +1289,10 @@ namespace Axivion::Internal::Dto qint32 index; /** - *

The legacy display name of a version. - * - *

It is not recommended to use this anymore. It contains the - * date of the analysis version creation in an arbitrary time zone which is not - * indicated in the timestamp. In recent versions most probably UTC is used but - * this can change at any time - which would be regarded as a non-breaking - * change. - * - *

Instead, clients should craft their own display name from the other - * available properties (date, label) and maybe adjust displayed dates - * according to their system timezone. - * - * @deprecated + *

The display name of the analysis version consisting of the date formatted with the + * preferred time zone of the user making the request and the label in parentheses. */ - std::optional name; + QString name; /** *

Analysis version timestamp in milliseconds @@ -1333,7 +1350,7 @@ namespace Axivion::Internal::Dto QString date, std::optional label, qint32 index, - std::optional name, + QString name, qint64 millis, Any issueCounts, std::optional toolsVersion, @@ -1708,8 +1725,12 @@ namespace Axivion::Internal::Dto /** *

The HTTP-Request Header expected present for all HTTP requests that are not GET, HEAD, OPTIONS or TRACE. + * + *

Deprecated since 7.7.0: the header name is always ``AX-CSRF-Token``. + * + * @deprecated */ - QString csrfTokenHeader; + std::optional csrfTokenHeader; /** *

The value expected to be sent along the ``csrfTokenHeader`` for all HTTP requests that are not GET, HEAD, OPTIONS or TRACE. @@ -1767,6 +1788,13 @@ namespace Axivion::Internal::Dto */ std::optional issueFilterHelp; + /** + *

Endoint for creating new CSRF tokens. + * + * @since 7.7.0 + */ + std::optional csrfTokenUrl; + // Throws Axivion::Internal::Dto::invalid_dto_exception static DashboardInfoDto deserialize(const QByteArray &json); @@ -1776,7 +1804,7 @@ namespace Axivion::Internal::Dto std::optional dashboardVersionNumber, QString dashboardBuildDate, std::optional username, - QString csrfTokenHeader, + std::optional csrfTokenHeader, QString csrfToken, std::optional checkCredentialsUrl, std::optional namedFiltersUrl, @@ -1784,7 +1812,8 @@ namespace Axivion::Internal::Dto std::optional userApiTokenUrl, std::optional userNamedFiltersUrl, std::optional supportAddress, - std::optional issueFilterHelp + std::optional issueFilterHelp, + std::optional csrfTokenUrl ); virtual QByteArray serialize() const override;