Skip to content

Commit

Permalink
MG-2456 - Refactor auth (absmach#2409)
Browse files Browse the repository at this point in the history
- Set/Unset parent Group for Things and Channels (absmach#2486)
- Move groups out of pkg (absmach#2493)
- Separate Things authn and Channels authz (absmach#2496)

Signed-off-by: Arvindh <[email protected]>

NOISSUE - Add Publish/Subscribe to channels (absmach#2497)

Signed-off-by: Arvindh <[email protected]>

MG-2457 - Update auth tests (absmach#2503)

Signed-off-by: Felix Gateru <[email protected]>

MG-2477 - Replace Things with Clients (absmach#2508)

Signed-off-by: Dusan Borovcanin <[email protected]>

NOISSUE - Rename Things to Clients

Signed-off-by: Felix Gateru <[email protected]>
Signed-off-by: Arvindh <[email protected]>
  • Loading branch information
arvindh123 authored and felixgateru committed Nov 27, 2024
1 parent c24a566 commit 321378a
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 5 deletions.
3 changes: 0 additions & 3 deletions clients/api/http/decode.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// Copyright (c) Abstract Machines
// SPDX-License-Identifier: Apache-2.0

package http

import (
Expand Down
2 changes: 1 addition & 1 deletion domains/roleactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const (
ChannelRead roles.Action = "channel_read"
ChannelDelete roles.Action = "channel_delete"
ChannelSetParentGroup roles.Action = "channel_set_parent_group"
ChannelConnectToClient roles.Action = "channel_connect_to_client"
ChannelConnectToClient roles.Action = "channel_connect_to_client"
ChannelPublish roles.Action = "channel_publish"
ChannelSubscribe roles.Action = "channel_subscribe"
ChannelManageRole roles.Action = "channel_manage_role"
Expand Down
171 changes: 171 additions & 0 deletions groups/roleactions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
package groups

import "github.com/absmach/magistrala/pkg/roles"

const (
Update = "update"
Read = "read"
Membership = "membership"
Delete = "delete"
SetChild = "set_child"
SetParent = "set_parent"

ManageRole = "manage_role"
AddRoleUsers = "add_role_users"
RemoveRoleUsers = "remove_role_users"
ViewRoleUsers = "view_role_users"

ClientCreate = "client_create"
ChannelCreate = "channel_create"
SubgroupCreate = "subgroup_create"
SubgroupClientCreate = "subgroup_client_create"
SubgroupChannelCreate = "subgroup_channel_create"

ClientUpdate = "client_update"
ClientRead = "client_read"
ClientDelete = "client_delete"
ClientSetParentGroup = "client_set_parent_group"
ClientConnectToChannel = "client_connect_to_channel"

ClientManageRole = "client_manage_role"
ClientAddRoleUsers = "client_add_role_users"
ClientRemoveRoleUsers = "client_remove_role_users"
ClientViewRoleUsers = "client_view_role_users"

ChannelUpdate = "channel_update"
ChannelRead = "channel_read"
ChannelDelete = "channel_delete"
ChannelSetParentGroup = "channel_set_parent_group"
ChannelConnectToClient = "channel_connect_to_client"
ChannelPublish = "channel_publish"
ChannelSubscribe = "channel_subscribe"

ChannelManageRole = "channel_manage_role"
ChannelAddRoleUsers = "channel_add_role_users"
ChannelRemoveRoleUsers = "channel_remove_role_users"
ChannelViewRoleUsers = "channel_view_role_users"

SubgroupUpdate = "subgroup_update"
SubgroupRead = "subgroup_read"
SubgroupMembership = "subgroup_membership"
SubgroupDelete = "subgroup_delete"
SubgroupSetChild = "subgroup_set_child"
SubgroupSetParent = "subgroup_set_parent"

SubgroupManageRole = "subgroup_manage_role"
SubgroupAddRoleUsers = "subgroup_add_role_users"
SubgroupRemoveRoleUsers = "subgroup_remove_role_users"
SubgroupViewRoleUsers = "subgroup_view_role_users"

SubgroupClientUpdate = "subgroup_client_update"
SubgroupClientRead = "subgroup_client_read"
SubgroupClientDelete = "subgroup_client_delete"
SubgroupClientSetParentGroup = "subgroup_client_set_parent_group"
SubgroupClientConnectToChannel = "subgroup_client_connect_to_channel"

SubgroupClientManageRole = "subgroup_client_manage_role"
SubgroupClientAddRoleUsers = "subgroup_client_add_role_users"
SubgroupClientRemoveRoleUsers = "subgroup_client_remove_role_users"
SubgroupClientViewRoleUsers = "subgroup_client_view_role_users"

SubgroupChannelUpdate = "subgroup_channel_update"
SubgroupChannelRead = "subgroup_channel_read"
SubgroupChannelDelete = "subgroup_channel_delete"
SubgroupChannelSetParentGroup = "subgroup_channel_set_parent_group"
SubgroupChannelConnectToClient = "subgroup_channel_connect_to_client"
SubgroupChannelPublish = "subgroup_channel_publish"
SubgroupChannelSubscribe = "subgroup_channel_subscribe"

SubgroupChannelManageRole = "subgroup_channel_manage_role"
SubgroupChannelAddRoleUsers = "subgroup_channel_add_role_users"
SubgroupChannelRemoveRoleUsers = "subgroup_channel_remove_role_users"
SubgroupChannelViewRoleUsers = "subgroup_channel_view_role_users"
)

const (
BuiltInRoleAdmin = "admin"
BuiltInRoleMembership = "membership"
)

func AvailableActions() []roles.Action {
return []roles.Action{
Update,
Read,
Membership,
Delete,
SetChild,
SetParent,
ManageRole,
AddRoleUsers,
RemoveRoleUsers,
ViewRoleUsers,
ClientCreate,
ChannelCreate,
SubgroupCreate,
SubgroupClientCreate,
SubgroupChannelCreate,
ClientUpdate,
ClientRead,
ClientDelete,
ClientSetParentGroup,
ClientConnectToChannel,
ClientManageRole,
ClientAddRoleUsers,
ClientRemoveRoleUsers,
ClientViewRoleUsers,
ChannelUpdate,
ChannelRead,
ChannelDelete,
ChannelSetParentGroup,
ChannelConnectToClient,
ChannelPublish,
ChannelSubscribe,
ChannelManageRole,
ChannelAddRoleUsers,
ChannelRemoveRoleUsers,
ChannelViewRoleUsers,
SubgroupUpdate,
SubgroupRead,
SubgroupMembership,
SubgroupDelete,
SubgroupSetChild,
SubgroupSetParent,
SubgroupManageRole,
SubgroupAddRoleUsers,
SubgroupRemoveRoleUsers,
SubgroupViewRoleUsers,
SubgroupClientUpdate,
SubgroupClientRead,
SubgroupClientDelete,
SubgroupClientSetParentGroup,
SubgroupClientConnectToChannel,
SubgroupClientManageRole,
SubgroupClientAddRoleUsers,
SubgroupClientRemoveRoleUsers,
SubgroupClientViewRoleUsers,
SubgroupChannelUpdate,
SubgroupChannelRead,
SubgroupChannelDelete,
SubgroupChannelSetParentGroup,
SubgroupChannelConnectToClient,
SubgroupChannelPublish,
SubgroupChannelSubscribe,
SubgroupChannelManageRole,
SubgroupChannelAddRoleUsers,
SubgroupChannelRemoveRoleUsers,
SubgroupChannelViewRoleUsers,
}
}

func membershipRoleActions() []roles.Action {
return []roles.Action{
Membership,
}
}

func BuiltInRoles() map[roles.BuiltInRoleName][]roles.Action {
return map[roles.BuiltInRoleName][]roles.Action{
BuiltInRoleAdmin: AvailableActions(),
BuiltInRoleMembership: membershipRoleActions(),
}
}
1 change: 0 additions & 1 deletion readers/api/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
climocks "github.com/absmach/magistrala/clients/mocks"
"github.com/absmach/magistrala/internal/testsutil"
"github.com/absmach/magistrala/pkg/apiutil"
mgauthn "github.com/absmach/magistrala/pkg/authn"
authnmocks "github.com/absmach/magistrala/pkg/authn/mocks"
svcerr "github.com/absmach/magistrala/pkg/errors/service"
"github.com/absmach/magistrala/pkg/transformers/senml"
Expand Down

0 comments on commit 321378a

Please sign in to comment.