10Duke Enterprise C++ SDK
Toggle main menu visibility
Loading...
Searching...
No Matches
StatefulCheckoutRequestTemplate.h
1
#ifndef TENDUKE_CLIENT_EE_STATEFULCHECKOUTREQUESTTEMPLATE_H
2
#define TENDUKE_CLIENT_EE_STATEFULCHECKOUTREQUESTTEMPLATE_H
3
4
#include "../authz/LicensingRequest.h"
5
#include "http/Unauthorized.h"
6
#include "log/log.h"
7
#include "oidc/session/OIDCSession.h"
8
9
namespace
tenduke
{
namespace
ee
{
namespace
licensing
{
namespace
impl
{
10
27
template
<
class
T>
28
class
StatefulCheckoutRequestTemplate
29
{
30
public
:
36
StatefulCheckoutRequestTemplate
(
37
std::unique_ptr<
::tenduke::ee::licensing::authzapi::LicensingRequest<T>
> request,
38
const
std::shared_ptr<::tenduke::oidc::OIDCSession> &oidc
39
) : oidc(oidc), request(std::move(request))
40
{}
41
48
T
execute
()
49
{
50
::tenduke::log::debug
(
"StatefulCheckoutRequest::execute() ensuring valid session..."
);
51
oidc->ensureValidSession();
52
53
// The response. Wrapped in pointer to workaround assignment issues to const fields
54
std::unique_ptr<T> response =
nullptr
;
55
56
try
{
57
::tenduke::log::debug
(
"StatefulCheckoutRequest::execute() ...executing the request..."
);
58
response.reset(
new
T(request->execute()));
59
}
60
// Since 10Duke Enterprise 5.0: The backend may be configured to throw HTTP 401 when the credentials are
61
// invalid or expired.
62
// Note that the client does not know the backend version nor the configuration, so the old handling below
63
// is retained, even though it might perform duplicate work.
64
catch
(const ::tenduke::http::Unauthorized &e) {
65
::tenduke::log::warning
(
"StatefulCheckoutRequest::execute() ...got HTTP 401."
);
66
return
reEstablishOIDCSessionAndRetry();
67
}
68
69
// Check if the request failed because credentials were invalid.
70
// On checkout, the /authz-API does not acknowledge missing/expired/removed request-authentication credentials.
71
// To detect this condition, we assume that if the request failed (all the items in the request failed),
72
// we do a heartbeat to the backend. If the heartbeat fails with HTTP 401, we refresh or re-login and
73
// re-try the request.
74
//
75
// This is the old functionality. See above for handling of the ::tenduke::http::Unauthorized.
76
if
(response->failed()) {
77
::tenduke::log::warning
(
"StatefulCheckoutRequest::execute() ...failed. Doing heartbeat to check backend state..."
);
78
79
if
(oidc->heartbeat()) {
80
::tenduke::log::info
(
"StatefulCheckoutRequest::execute() ...credentials were valid. Returning original response."
);
81
}
82
else
{
83
::tenduke::log::warning
(
" StatefulCheckoutRequest::execute()...credentials were defunct."
);
84
return
reEstablishOIDCSessionAndRetry();
85
}
86
}
87
else
{
88
::tenduke::log::debug
(
"StatefulCheckoutRequest::execute() ...succeeded"
);
89
}
90
91
return
*response;
92
}
93
94
protected
:
95
T reEstablishOIDCSessionAndRetry()
96
{
97
::tenduke::log::info
(
"StatefulCheckoutRequest::reEstablishOIDCSessionAndRetry() Re-estalishing OIDC session..."
);
98
oidc
->reEstablish();
99
100
::tenduke::log::info
(
"StatefulCheckoutRequest::reEstablishOIDCSessionAndRetry() ...OIDC session re-established. Re-executing original request..."
);
101
auto
response = request->execute();
102
103
::tenduke::log::info
(
"StatefulCheckoutRequest::reEstablishOIDCSessionAndRetry() ...ready, returning new response as-is."
);
104
return
response;
105
}
106
107
private
:
108
const
std::shared_ptr<::tenduke::oidc::OIDCSession>
oidc
;
109
const
std::unique_ptr<::tenduke::ee::licensing::authzapi::LicensingRequest<T>> request;
110
};
111
112
}}}}
113
114
115
#endif
//TENDUKE_CLIENT_EE_STATEFULCHECKOUTREQUESTTEMPLATE_H
tenduke::ee::licensing::authzapi::LicensingRequest
Licensing-related request.
Definition
LicensingRequest.h:13
tenduke::ee::licensing::impl::StatefulCheckoutRequestTemplate::StatefulCheckoutRequestTemplate
StatefulCheckoutRequestTemplate(std::unique_ptr<::tenduke::ee::licensing::authzapi::LicensingRequest< T > > request, const std::shared_ptr<::tenduke::oidc::OIDCSession > &oidc)
Constructs new instance.
Definition
StatefulCheckoutRequestTemplate.h:36
tenduke::ee::licensing::impl::StatefulCheckoutRequestTemplate::execute
T execute()
Executes the request.
Definition
StatefulCheckoutRequestTemplate.h:48
tenduke::ee::licensing::impl
Implementations of licensing related services.
Definition
DefaultLicenseTokens.h:13
tenduke::ee::licensing
Classes, functions and globals related to 10Duke Enterprise licensing.
Definition
AuthzLicensingClient.h:13
tenduke::ee
Classes, functions and globals of 10Duke Enterprise C++ Client.
Definition
APIRequest.h:4
tenduke::log::debug
void debug(const char *message)
Write message to global logger at DEBUG-level.
Definition
log.cpp:54
tenduke::log::warning
void warning(const char *message)
Write message to global logger at WARNING-level.
Definition
log.cpp:94
tenduke::log::info
void info(const char *message)
Write message to global logger at INFO-level.
Definition
log.cpp:74
tenduke::oidc
Implementation of OpenID Connect protocol.
Definition
AutoDiscovery.h:18
tenduke
Root for classes, functions and globals of 10Duke C++ Client.
Definition
APIRequest.h:4
client
enterprise
api
src
licensing
impl
StatefulCheckoutRequestTemplate.h
Generated by
1.17.0