mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-23 10:11:08 +00:00
auth: use defines when possible
This commit is contained in:
parent
3dc34af5aa
commit
1a307c707d
2 changed files with 19 additions and 16 deletions
|
@ -92,16 +92,16 @@ main (int argc, char *argv[])
|
|||
|
||||
/* allow user and admin to access this resource */
|
||||
gst_rtsp_media_factory_add_role (factory, "user",
|
||||
"media.factory.access", G_TYPE_BOOLEAN, TRUE,
|
||||
"media.factory.construct", G_TYPE_BOOLEAN, TRUE, NULL);
|
||||
GST_RTSP_PERM_MEDIA_FACTORY_ACCESS, G_TYPE_BOOLEAN, TRUE,
|
||||
GST_RTSP_PERM_MEDIA_FACTORY_CONSTRUCT, G_TYPE_BOOLEAN, TRUE, NULL);
|
||||
gst_rtsp_media_factory_add_role (factory, "admin",
|
||||
"media.factory.access", G_TYPE_BOOLEAN, TRUE,
|
||||
"media.factory.construct", G_TYPE_BOOLEAN, TRUE, NULL);
|
||||
GST_RTSP_PERM_MEDIA_FACTORY_ACCESS, G_TYPE_BOOLEAN, TRUE,
|
||||
GST_RTSP_PERM_MEDIA_FACTORY_CONSTRUCT, G_TYPE_BOOLEAN, TRUE, NULL);
|
||||
/* admin2 can look at the media but not construct so he gets a
|
||||
* 401 Unauthorized */
|
||||
gst_rtsp_media_factory_add_role (factory, "admin2",
|
||||
"media.factory.access", G_TYPE_BOOLEAN, TRUE,
|
||||
"media.factory.construct", G_TYPE_BOOLEAN, FALSE, NULL);
|
||||
GST_RTSP_PERM_MEDIA_FACTORY_ACCESS, G_TYPE_BOOLEAN, TRUE,
|
||||
GST_RTSP_PERM_MEDIA_FACTORY_CONSTRUCT, G_TYPE_BOOLEAN, FALSE, NULL);
|
||||
|
||||
/* make another factory */
|
||||
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
|
||||
* media and get a 404 Not Found */
|
||||
gst_rtsp_media_factory_add_role (factory, "admin2",
|
||||
"media.factory.access", G_TYPE_BOOLEAN, TRUE,
|
||||
"media.factory.construct", G_TYPE_BOOLEAN, TRUE, NULL);
|
||||
GST_RTSP_PERM_MEDIA_FACTORY_ACCESS, G_TYPE_BOOLEAN, TRUE,
|
||||
GST_RTSP_PERM_MEDIA_FACTORY_CONSTRUCT, G_TYPE_BOOLEAN, TRUE, NULL);
|
||||
|
||||
/* don't need the ref to the mapper anymore */
|
||||
g_object_unref (mounts);
|
||||
|
@ -125,24 +125,27 @@ main (int argc, char *argv[])
|
|||
auth = gst_rtsp_auth_new ();
|
||||
|
||||
/* make user token */
|
||||
token = gst_rtsp_token_new ("resources.class", G_TYPE_STRING, "user",
|
||||
"media.factory.role", G_TYPE_STRING, "user", NULL);
|
||||
token =
|
||||
gst_rtsp_token_new (GST_RTSP_TOKEN_MEDIA_FACTORY_ROLE, G_TYPE_STRING,
|
||||
"user", NULL);
|
||||
basic = gst_rtsp_auth_make_basic ("user", "password");
|
||||
gst_rtsp_auth_add_basic (auth, basic, token);
|
||||
g_free (basic);
|
||||
gst_rtsp_token_unref (token);
|
||||
|
||||
/* make admin token */
|
||||
token = gst_rtsp_token_new ("resources.class", G_TYPE_STRING, "admin",
|
||||
"media.factory.role", G_TYPE_STRING, "admin", NULL);
|
||||
token =
|
||||
gst_rtsp_token_new (GST_RTSP_TOKEN_MEDIA_FACTORY_ROLE, G_TYPE_STRING,
|
||||
"admin", NULL);
|
||||
basic = gst_rtsp_auth_make_basic ("admin", "power");
|
||||
gst_rtsp_auth_add_basic (auth, basic, token);
|
||||
g_free (basic);
|
||||
gst_rtsp_token_unref (token);
|
||||
|
||||
/* make admin2 token */
|
||||
token = gst_rtsp_token_new ("resources.class", G_TYPE_STRING, "admin",
|
||||
"media.factory.role", G_TYPE_STRING, "admin2", NULL);
|
||||
token =
|
||||
gst_rtsp_token_new (GST_RTSP_TOKEN_MEDIA_FACTORY_ROLE, G_TYPE_STRING,
|
||||
"admin2", NULL);
|
||||
basic = gst_rtsp_auth_make_basic ("admin2", "power2");
|
||||
gst_rtsp_auth_add_basic (auth, basic, token);
|
||||
g_free (basic);
|
||||
|
|
|
@ -422,11 +422,11 @@ check_factory (GstRTSPAuth * auth, GstRTSPClientState * state,
|
|||
if (!(perms = gst_rtsp_media_factory_get_permissions (state->factory)))
|
||||
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,
|
||||
GST_RTSP_PERM_MEDIA_FACTORY_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,
|
||||
GST_RTSP_PERM_MEDIA_FACTORY_CONSTRUCT))
|
||||
goto no_construct;
|
||||
|
|
Loading…
Reference in a new issue