auth: use defines when possible

This commit is contained in:
Wim Taymans 2013-07-18 11:44:50 +02:00
parent 3dc34af5aa
commit 1a307c707d
2 changed files with 19 additions and 16 deletions

View file

@ -92,16 +92,16 @@ main (int argc, char *argv[])
/* allow user and admin to access this resource */ /* allow user and admin to access this resource */
gst_rtsp_media_factory_add_role (factory, "user", gst_rtsp_media_factory_add_role (factory, "user",
"media.factory.access", G_TYPE_BOOLEAN, TRUE, GST_RTSP_PERM_MEDIA_FACTORY_ACCESS, G_TYPE_BOOLEAN, TRUE,
"media.factory.construct", G_TYPE_BOOLEAN, TRUE, NULL); GST_RTSP_PERM_MEDIA_FACTORY_CONSTRUCT, G_TYPE_BOOLEAN, TRUE, NULL);
gst_rtsp_media_factory_add_role (factory, "admin", gst_rtsp_media_factory_add_role (factory, "admin",
"media.factory.access", G_TYPE_BOOLEAN, TRUE, GST_RTSP_PERM_MEDIA_FACTORY_ACCESS, G_TYPE_BOOLEAN, TRUE,
"media.factory.construct", G_TYPE_BOOLEAN, TRUE, NULL); GST_RTSP_PERM_MEDIA_FACTORY_CONSTRUCT, G_TYPE_BOOLEAN, TRUE, NULL);
/* admin2 can look at the media but not construct so he gets a /* admin2 can look at the media but not construct so he gets a
* 401 Unauthorized */ * 401 Unauthorized */
gst_rtsp_media_factory_add_role (factory, "admin2", gst_rtsp_media_factory_add_role (factory, "admin2",
"media.factory.access", G_TYPE_BOOLEAN, TRUE, GST_RTSP_PERM_MEDIA_FACTORY_ACCESS, G_TYPE_BOOLEAN, TRUE,
"media.factory.construct", G_TYPE_BOOLEAN, FALSE, NULL); GST_RTSP_PERM_MEDIA_FACTORY_CONSTRUCT, G_TYPE_BOOLEAN, FALSE, NULL);
/* make another factory */ /* make another factory */
factory = gst_rtsp_media_factory_new (); factory = gst_rtsp_media_factory_new ();
@ -115,8 +115,8 @@ main (int argc, char *argv[])
/* user and admin have no permissions so they can't even see the /* user and admin have no permissions so they can't even see the
* media and get a 404 Not Found */ * media and get a 404 Not Found */
gst_rtsp_media_factory_add_role (factory, "admin2", gst_rtsp_media_factory_add_role (factory, "admin2",
"media.factory.access", G_TYPE_BOOLEAN, TRUE, GST_RTSP_PERM_MEDIA_FACTORY_ACCESS, G_TYPE_BOOLEAN, TRUE,
"media.factory.construct", G_TYPE_BOOLEAN, TRUE, NULL); GST_RTSP_PERM_MEDIA_FACTORY_CONSTRUCT, G_TYPE_BOOLEAN, TRUE, NULL);
/* don't need the ref to the mapper anymore */ /* don't need the ref to the mapper anymore */
g_object_unref (mounts); g_object_unref (mounts);
@ -125,24 +125,27 @@ main (int argc, char *argv[])
auth = gst_rtsp_auth_new (); auth = gst_rtsp_auth_new ();
/* make user token */ /* make user token */
token = gst_rtsp_token_new ("resources.class", G_TYPE_STRING, "user", token =
"media.factory.role", G_TYPE_STRING, "user", NULL); gst_rtsp_token_new (GST_RTSP_TOKEN_MEDIA_FACTORY_ROLE, G_TYPE_STRING,
"user", NULL);
basic = gst_rtsp_auth_make_basic ("user", "password"); basic = gst_rtsp_auth_make_basic ("user", "password");
gst_rtsp_auth_add_basic (auth, basic, token); gst_rtsp_auth_add_basic (auth, basic, token);
g_free (basic); g_free (basic);
gst_rtsp_token_unref (token); gst_rtsp_token_unref (token);
/* make admin token */ /* make admin token */
token = gst_rtsp_token_new ("resources.class", G_TYPE_STRING, "admin", token =
"media.factory.role", G_TYPE_STRING, "admin", NULL); gst_rtsp_token_new (GST_RTSP_TOKEN_MEDIA_FACTORY_ROLE, G_TYPE_STRING,
"admin", NULL);
basic = gst_rtsp_auth_make_basic ("admin", "power"); basic = gst_rtsp_auth_make_basic ("admin", "power");
gst_rtsp_auth_add_basic (auth, basic, token); gst_rtsp_auth_add_basic (auth, basic, token);
g_free (basic); g_free (basic);
gst_rtsp_token_unref (token); gst_rtsp_token_unref (token);
/* make admin2 token */ /* make admin2 token */
token = gst_rtsp_token_new ("resources.class", G_TYPE_STRING, "admin", token =
"media.factory.role", G_TYPE_STRING, "admin2", NULL); gst_rtsp_token_new (GST_RTSP_TOKEN_MEDIA_FACTORY_ROLE, G_TYPE_STRING,
"admin2", NULL);
basic = gst_rtsp_auth_make_basic ("admin2", "power2"); basic = gst_rtsp_auth_make_basic ("admin2", "power2");
gst_rtsp_auth_add_basic (auth, basic, token); gst_rtsp_auth_add_basic (auth, basic, token);
g_free (basic); g_free (basic);

View file

@ -422,11 +422,11 @@ check_factory (GstRTSPAuth * auth, GstRTSPClientState * state,
if (!(perms = gst_rtsp_media_factory_get_permissions (state->factory))) if (!(perms = gst_rtsp_media_factory_get_permissions (state->factory)))
goto no_permissions; goto no_permissions;
if (g_str_equal (check, "auth.check.media.factory.access")) { if (g_str_equal (check, GST_RTSP_AUTH_CHECK_MEDIA_FACTORY_ACCESS)) {
if (!gst_rtsp_permissions_is_allowed (perms, role, if (!gst_rtsp_permissions_is_allowed (perms, role,
GST_RTSP_PERM_MEDIA_FACTORY_ACCESS)) GST_RTSP_PERM_MEDIA_FACTORY_ACCESS))
goto no_access; goto no_access;
} else if (g_str_equal (check, "auth.check.media.factory.construct")) { } else if (g_str_equal (check, GST_RTSP_AUTH_CHECK_MEDIA_FACTORY_CONSTRUCT)) {
if (!gst_rtsp_permissions_is_allowed (perms, role, if (!gst_rtsp_permissions_is_allowed (perms, role,
GST_RTSP_PERM_MEDIA_FACTORY_CONSTRUCT)) GST_RTSP_PERM_MEDIA_FACTORY_CONSTRUCT))
goto no_construct; goto no_construct;