Remove refreshing token 48/23148/1
authorJose Bollo <jose.bollo@iot.bzh>
Fri, 15 Nov 2019 14:33:26 +0000 (15:33 +0100)
committerJose Bollo <jose.bollo@iot.bzh>
Mon, 25 Nov 2019 10:48:31 +0000 (11:48 +0100)
The token is no more generated by the binder
but by some external component.

Bug-AGL: SPEC-2968

Change-Id: I2c6221034272ab097e21e7727e4840b6b47bd0dc
Signed-off-by: Jose Bollo <jose.bollo@iot.bzh>
src/afb-context.c
src/afb-context.h
src/afb-hook-flags.c
src/afb-hook.c
src/afb-hook.h
src/afb-monitor.c
src/afb-session.c
src/afb-session.h
src/afb-trace.c
src/afb-xreq.c
src/tests/session/test-session.c

index 6057e69..33cca0e 100644 (file)
@@ -77,7 +77,6 @@ int afb_context_connect(struct afb_context *context, const char *uuid, const cha
        init_context(context, session, token);
        if (created) {
                context->created = 1;
-               /* context->refreshing = 1; */
        }
        return 0;
 }
@@ -93,10 +92,6 @@ int afb_context_connect_validated(struct afb_context *context, const char *uuid)
 void afb_context_disconnect(struct afb_context *context)
 {
        if (context->session && !context->super) {
-               if (context->refreshing && !context->refreshed) {
-                       afb_session_new_token (context->session);
-                       context->refreshed = 1;
-               }
                if (context->closing && !context->closed) {
                        afb_context_change_loa(context, 0);
                        afb_context_set(context, NULL, NULL);
@@ -111,12 +106,6 @@ const char *afb_context_sent_token(struct afb_context *context)
 {
        if (context->session == NULL || context->closing || context->super)
                return NULL;
-       if (!context->refreshing)
-               return NULL;
-       if (!context->refreshed) {
-               afb_session_new_token (context->session);
-               context->refreshed = 1;
-       }
        return afb_session_token(context->session);
 }
 
@@ -157,20 +146,6 @@ void afb_context_close(struct afb_context *context)
        context->closing = 1;
 }
 
-void afb_context_refresh(struct afb_context *context)
-{
-       if (context->super)
-               afb_context_refresh(context->super);
-       else {
-               assert(context->validated);
-               context->refreshing = 1;
-               if (!context->refreshed) {
-                       afb_session_new_token (context->session);
-                       context->refreshed = 1;
-               }
-       }
-}
-
 int afb_context_check(struct afb_context *context)
 {
        if (context->super)
index 21af4b2..2d44611 100644 (file)
@@ -32,8 +32,6 @@ struct afb_context
                        unsigned created: 1;
                        unsigned validated: 1;
                        unsigned invalidated: 1;
-                       unsigned refreshing: 1;
-                       unsigned refreshed: 1;
                        unsigned closing: 1;
                        unsigned closed: 1;
                };
@@ -55,7 +53,6 @@ extern int afb_context_set(struct afb_context *context, void *value, void (*free
 extern void *afb_context_make(struct afb_context *context, int replace, void *(*make_value)(void *closure), void (*free_value)(void *item), void *closure);
 
 extern void afb_context_close(struct afb_context *context);
-extern void afb_context_refresh(struct afb_context *context);
 extern int afb_context_check(struct afb_context *context);
 extern int afb_context_check_loa(struct afb_context *context, unsigned loa);
 extern int afb_context_change_loa(struct afb_context *context, unsigned loa);
index 874d21b..9a7cf6e 100644 (file)
@@ -140,7 +140,6 @@ static struct flag session_flags[] = { /* must be sorted by names */
                { "common",             afb_hook_flags_session_common },
                { "create",             afb_hook_flag_session_create },
                { "destroy",            afb_hook_flag_session_destroy },
-               { "renew",              afb_hook_flag_session_renew },
                { "unref",              afb_hook_flag_session_unref },
 };
 
index f8b593d..6b1ab10 100644 (file)
@@ -1544,11 +1544,6 @@ static void hook_session_destroy_cb(void *closure, const struct afb_hookid *hook
        _hook_session_(session, "destroy");
 }
 
-static void hook_session_renew_cb(void *closure, const struct afb_hookid *hookid, struct afb_session *session)
-{
-       _hook_session_(session, "renew -> token=%s", afb_session_token(session));
-}
-
 static void hook_session_addref_cb(void *closure, const struct afb_hookid *hookid, struct afb_session *session)
 {
        _hook_session_(session, "addref");
@@ -1563,7 +1558,6 @@ static struct afb_hook_session_itf hook_session_default_itf = {
        .hook_session_create = hook_session_create_cb,
        .hook_session_close = hook_session_close_cb,
        .hook_session_destroy = hook_session_destroy_cb,
-       .hook_session_renew = hook_session_renew_cb,
        .hook_session_addref = hook_session_addref_cb,
        .hook_session_unref = hook_session_unref_cb
 };
@@ -1605,11 +1599,6 @@ void afb_hook_session_destroy(struct afb_session *session)
        _HOOK_SESSION_(destroy, session);
 }
 
-void afb_hook_session_renew(struct afb_session *session)
-{
-       _HOOK_SESSION_(renew, session);
-}
-
 void afb_hook_session_addref(struct afb_session *session)
 {
        _HOOK_SESSION_(addref, session);
index 9131621..290bf74 100644 (file)
@@ -415,12 +415,10 @@ extern void afb_hook_unref_evt(struct afb_hook_evt *hook);
 #define afb_hook_flag_session_create                   0x000001
 #define afb_hook_flag_session_close                    0x000002
 #define afb_hook_flag_session_destroy                  0x000004
-#define afb_hook_flag_session_renew                    0x000008
-#define afb_hook_flag_session_addref                   0x000010
-#define afb_hook_flag_session_unref                    0x000020
+#define afb_hook_flag_session_addref                   0x000008
+#define afb_hook_flag_session_unref                    0x000010
 
-#define afb_hook_flags_session_common  (afb_hook_flag_session_create|afb_hook_flag_session_close\
-                                       |afb_hook_flag_session_renew)
+#define afb_hook_flags_session_common  (afb_hook_flag_session_create|afb_hook_flag_session_close)
 #define afb_hook_flags_session_all     (afb_hook_flags_session_common|afb_hook_flag_session_destroy\
                                        |afb_hook_flag_session_addref|afb_hook_flag_session_unref)
 
@@ -428,7 +426,6 @@ struct afb_hook_session_itf {
        void (*hook_session_create)(void *closure, const struct afb_hookid *hookid, struct afb_session *session);
        void (*hook_session_close)(void *closure, const struct afb_hookid *hookid, struct afb_session *session);
        void (*hook_session_destroy)(void *closure, const struct afb_hookid *hookid, struct afb_session *session);
-       void (*hook_session_renew)(void *closure, const struct afb_hookid *hookid, struct afb_session *session);
        void (*hook_session_addref)(void *closure, const struct afb_hookid *hookid, struct afb_session *session);
        void (*hook_session_unref)(void *closure, const struct afb_hookid *hookid, struct afb_session *session);
 };
@@ -436,7 +433,6 @@ struct afb_hook_session_itf {
 extern void afb_hook_session_create(struct afb_session *session);
 extern void afb_hook_session_close(struct afb_session *session);
 extern void afb_hook_session_destroy(struct afb_session *session);
-extern void afb_hook_session_renew(struct afb_session *session);
 extern void afb_hook_session_addref(struct afb_session *session);
 extern void afb_hook_session_unref(struct afb_session *session);
 
index 15dd1a4..13687d3 100644 (file)
@@ -297,7 +297,6 @@ static struct json_object *get_apis(struct json_object *spec)
 
 static const char _verbosity_[] = "verbosity";
 static const char _apis_[] = "apis";
-static const char _refresh_token_[] = "refresh-token";
 
 static void f_get(afb_req_t req)
 {
@@ -373,7 +372,6 @@ static void f_trace(afb_req_t req)
 static void f_session(afb_req_t req)
 {
        struct json_object *r = NULL;
-       int refresh = 0;
        struct afb_xreq *xreq = xreq_from_req_x2(req);
 
        /* check right to call it */
@@ -382,11 +380,6 @@ static void f_session(afb_req_t req)
                return;
        }
 
-       /* renew the token if required */
-       wrap_json_unpack(afb_req_json(req), "{s?:b}", _refresh_token_, &refresh);
-       if (refresh)
-               afb_context_refresh(&xreq->context);
-
        /* make the result */
        wrap_json_pack(&r, "{s:s,s:s,s:i,s:i}",
                        "uuid", afb_session_uuid(xreq->context.session),
index fe5aa4a..8fa4434 100644 (file)
@@ -545,29 +545,6 @@ int afb_session_check_token (struct afb_session *session, const char *token)
        return r;
 }
 
-/* generate a new token and update client context */
-void afb_session_new_token (struct afb_session *session)
-{
-       int rc;
-       uuid_stringz_t uuid;
-       struct afb_token *previous, *next;
-       session_lock(session);
-       uuid_new_stringz(uuid);
-       rc = afb_token_get(&next, uuid);
-       if (rc < 0)
-               ERROR("can't renew token");
-       else {
-               previous = session->token;
-               session->token = next;
-               session_update_expiration(session, NOW);
-#if WITH_AFB_HOOK
-               afb_hook_session_renew(session);
-#endif
-               afb_token_unref(previous);
-       }
-       session_unlock(session);
-}
-
 /* Returns the uuid of 'session' */
 const char *afb_session_uuid (struct afb_session *session)
 {
index 71b1556..f6e848c 100644 (file)
@@ -41,7 +41,6 @@ extern void afb_session_close(struct afb_session *session);
 extern int afb_session_is_closed (struct afb_session *session);
 
 extern int afb_session_check_token(struct afb_session *session, const char *token);
-extern void afb_session_new_token(struct afb_session *session);
 extern const char *afb_session_token(struct afb_session *session);
 extern int afb_session_timeout(struct afb_session *session);
 extern int afb_session_what_remains(struct afb_session *session);
index 0de78da..5e349c7 100644 (file)
@@ -866,11 +866,6 @@ static void hook_session_destroy(void *closure, const struct afb_hookid *hookid,
        hook_session(closure, hookid, session, "destroy", NULL);
 }
 
-static void hook_session_renew(void *closure, const struct afb_hookid *hookid, struct afb_session *session)
-{
-       hook_session(closure, hookid, session, "renew", "{ss}", "token", afb_session_token(session));
-}
-
 static void hook_session_addref(void *closure, const struct afb_hookid *hookid, struct afb_session *session)
 {
        hook_session(closure, hookid, session, "addref", NULL);
@@ -885,7 +880,6 @@ static struct afb_hook_session_itf hook_session_itf = {
        .hook_session_create = hook_session_create,
        .hook_session_close = hook_session_close,
        .hook_session_destroy = hook_session_destroy,
-       .hook_session_renew = hook_session_renew,
        .hook_session_addref = hook_session_addref,
        .hook_session_unref = hook_session_unref
 };
index 17a603c..8542741 100644 (file)
@@ -760,9 +760,6 @@ static int xreq_session_check_apply_v1(struct afb_xreq *xreq, int sessionflags)
                }
        }
 
-       if ((sessionflags & AFB_SESSION_RENEW_X1) != 0) {
-               afb_context_refresh(&xreq->context);
-       }
        if ((sessionflags & AFB_SESSION_CLOSE_X1) != 0) {
                afb_context_change_loa(&xreq->context, 0);
                afb_context_close(&xreq->context);
@@ -798,9 +795,6 @@ static int xreq_session_check_apply_v2(struct afb_xreq *xreq, uint32_t sessionfl
                return -1;
        }
 
-       if ((sessionflags & AFB_SESSION_REFRESH_X2) != 0) {
-               afb_context_refresh(&xreq->context);
-       }
        if ((sessionflags & AFB_SESSION_CLOSE_X2) != 0) {
                afb_context_close(&xreq->context);
        }
index fdbb043..444475e 100644 (file)
@@ -61,12 +61,6 @@ START_TEST (check_creation)
        ck_assert(afb_session_check_token(s, GOOD_UUID));
        ck_assert(afb_session_check_token(s, afb_session_token(s)));
 
-       /* token can be renewed */
-       afb_session_new_token(s);
-       ck_assert(strcmp(afb_session_token(s), GOOD_UUID));
-       ck_assert(!afb_session_check_token(s, GOOD_UUID));
-       ck_assert(afb_session_check_token(s, afb_session_token(s)));
-
        /* query the session */
        uuid = strdup(afb_session_uuid(s));
        x = afb_session_search(uuid);