-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Groupcast Access Control: EXPERIMENTAL #42066
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
rcasallas-silabs
wants to merge
1
commit into
project-chip:master
Choose a base branch
from
rcasallas-silabs:draft/groupcast_access_control
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,386
−1
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| #include "ExtendedAccessControlDelegate.h" | ||
| #include <access/AccessControl.h> | ||
| #include <access/AuthMode.h> | ||
| #include <lib/support/PersistentArray.h> | ||
| #include <lib/support/DefaultStorageKeyAllocator.h> | ||
| #include <lib/support/Pool.h> | ||
|
|
||
| // using namespace chip::Access; | ||
| // using Entry = AccessControl::Entry; | ||
| // using EntryIterator = AccessControl::EntryIterator; | ||
| // using Target = AccessControl::Entry::Target; | ||
|
|
||
| namespace chip { | ||
| namespace Access { | ||
|
|
||
| static constexpr size_t kIteratorsMax = 2; | ||
| static ObjectPool<EntryIteratorDelegate, kIteratorsMax> sEntryIterators; | ||
|
|
||
| void EntryIteratorDelegate::Release() { | ||
| if(mFirst) { | ||
| mFirst->Release(); | ||
| } | ||
| if(mSecond) { | ||
| mSecond->Release(); | ||
| } | ||
| sEntryIterators.ReleaseObject(this); | ||
| } | ||
|
|
||
| CHIP_ERROR EntryIteratorDelegate::Next(AccessControl::Entry & entry) { | ||
| VerifyOrReturnError(nullptr != mFirst, CHIP_ERROR_INCORRECT_STATE); | ||
| if(CHIP_NO_ERROR == mError) { | ||
| mError = mFirst->Next(entry); | ||
| } | ||
| if(mSecond && (CHIP_ERROR_SENTINEL == mError)) { | ||
| return mSecond->Next(entry); | ||
| } | ||
| return mError; | ||
| } | ||
|
|
||
|
|
||
| void ExtendedAccessControlDelegate::Release() {} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extended should be renamed to Auxiliary everywhere |
||
|
|
||
| CHIP_ERROR ExtendedAccessControlDelegate::Init(AccessControl::Delegate *primary, AccessControl::Delegate *secondary) | ||
| { | ||
| VerifyOrReturnError((nullptr != primary) && (nullptr != secondary), CHIP_ERROR_INCORRECT_STATE); | ||
| // Primary | ||
| mPrimary = primary; | ||
| ReturnErrorOnFailure(mPrimary->Init()); | ||
| // Secondary | ||
| mSecondary = secondary; | ||
| return mSecondary->Init(); | ||
| } | ||
|
|
||
| void ExtendedAccessControlDelegate::Finish() { | ||
| if(mPrimary) { | ||
| mPrimary->Finish(); | ||
| } | ||
| if(mSecondary) { | ||
| mSecondary->Finish(); | ||
| } | ||
| } | ||
|
|
||
| // Capabilities | ||
| CHIP_ERROR ExtendedAccessControlDelegate::GetMaxEntriesPerFabric(size_t & value) const | ||
| { | ||
| ChipLogDetail(DeviceLayer, "~~~ ExtendedAccessControlDelegate::GetMaxEntriesPerFabric: #%p/%p\n", mPrimary, mSecondary); | ||
| VerifyOrReturnError(nullptr != mPrimary, CHIP_ERROR_INCORRECT_STATE); | ||
| return mPrimary->GetMaxEntriesPerFabric(value); | ||
| } | ||
|
|
||
| CHIP_ERROR ExtendedAccessControlDelegate::GetMaxSubjectsPerEntry(size_t & value) const | ||
| { | ||
| VerifyOrReturnError(nullptr != mPrimary, CHIP_ERROR_INCORRECT_STATE); | ||
| return mPrimary->GetMaxSubjectsPerEntry(value); | ||
| } | ||
|
|
||
| CHIP_ERROR ExtendedAccessControlDelegate::GetMaxTargetsPerEntry(size_t & value) const | ||
| { | ||
| VerifyOrReturnError(nullptr != mPrimary, CHIP_ERROR_INCORRECT_STATE); | ||
| return mPrimary->GetMaxTargetsPerEntry(value); | ||
| } | ||
|
|
||
| CHIP_ERROR ExtendedAccessControlDelegate::GetMaxEntryCount(size_t & value) const | ||
| { | ||
| VerifyOrReturnError(nullptr != mPrimary, CHIP_ERROR_INCORRECT_STATE); | ||
| return mPrimary->GetMaxEntryCount(value); | ||
| } | ||
|
|
||
| // Actualities | ||
| CHIP_ERROR ExtendedAccessControlDelegate::GetEntryCount(FabricIndex fabric, size_t & value) const | ||
| { | ||
| VerifyOrReturnError(nullptr != mPrimary, CHIP_ERROR_INCORRECT_STATE); | ||
| return mPrimary->GetEntryCount(fabric, value); | ||
| } | ||
|
|
||
| CHIP_ERROR ExtendedAccessControlDelegate::GetEntryCount(size_t & value) const | ||
| { | ||
| VerifyOrReturnError(nullptr != mPrimary, CHIP_ERROR_INCORRECT_STATE); | ||
| return mPrimary->GetEntryCount(value); | ||
| } | ||
|
|
||
| // Preparation | ||
| CHIP_ERROR ExtendedAccessControlDelegate::PrepareEntry(AccessControl::Entry & entry) { | ||
| VerifyOrReturnError(nullptr != mPrimary, CHIP_ERROR_INCORRECT_STATE); | ||
| return mPrimary->PrepareEntry(entry); | ||
| } | ||
|
|
||
| // CRUD | ||
| CHIP_ERROR ExtendedAccessControlDelegate::CreateEntry(size_t * index, const AccessControl::Entry & entry, FabricIndex * fabricIndex) { | ||
| VerifyOrReturnError(nullptr != mPrimary, CHIP_ERROR_INCORRECT_STATE); | ||
| return mPrimary->CreateEntry(index, entry, fabricIndex); | ||
| } | ||
|
|
||
| CHIP_ERROR ExtendedAccessControlDelegate::ReadEntry(size_t index, AccessControl::Entry & entry, const FabricIndex * fabricIndex) const { | ||
| VerifyOrReturnError(nullptr != mPrimary, CHIP_ERROR_INCORRECT_STATE); | ||
| return mPrimary->ReadEntry(index, entry, fabricIndex); | ||
| } | ||
|
|
||
| CHIP_ERROR ExtendedAccessControlDelegate::UpdateEntry(size_t index, const AccessControl::Entry & entry, const FabricIndex * fabricIndex) { | ||
| VerifyOrReturnError(nullptr != mPrimary, CHIP_ERROR_INCORRECT_STATE); | ||
| return mPrimary->UpdateEntry(index, entry, fabricIndex); | ||
| } | ||
|
|
||
| CHIP_ERROR ExtendedAccessControlDelegate::DeleteEntry(size_t index, const FabricIndex * fabricIndex) { | ||
| VerifyOrReturnError(nullptr != mPrimary, CHIP_ERROR_INCORRECT_STATE); | ||
| return mPrimary->DeleteEntry(index, fabricIndex); | ||
| } | ||
|
|
||
| // Iteration | ||
| CHIP_ERROR ExtendedAccessControlDelegate::Entries(AccessControl::EntryIterator & iterator, const FabricIndex * fabricIndex) const { | ||
| VerifyOrReturnError(nullptr != mPrimary || nullptr != mSecondary, CHIP_ERROR_INCORRECT_STATE); | ||
| ChipLogDetail(DeviceLayer, "~~~ ExtendedAccessControlDelegate::Entries: #%p/%p\n", mPrimary, mSecondary); | ||
| // Primary | ||
| AccessControl::EntryIterator first; | ||
| ReturnErrorOnFailure(mPrimary->Entries(first, fabricIndex)); // TODO: OPTIONAL fabricIndex | ||
| AccessControl::EntryIterator::Delegate *it1 = &first.GetDelegate(); | ||
| // Secondary | ||
| AccessControl::EntryIterator second; | ||
| ReturnErrorOnFailure(mSecondary->Entries(second, fabricIndex)); | ||
| AccessControl::EntryIterator::Delegate *it2 = &second.GetDelegate(); | ||
|
Comment on lines
+134
to
+140
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What difference between primary and secondary? |
||
| // Delegate | ||
| AccessControl::EntryIterator::Delegate *delegate = sEntryIterators.CreateObject(it1, it2); | ||
| VerifyOrReturnError(delegate != nullptr, CHIP_ERROR_NO_MEMORY); | ||
| iterator.SetDelegate(*delegate); | ||
| return CHIP_NO_ERROR; | ||
| } | ||
|
|
||
| CHIP_ERROR ExtendedAccessControlDelegate::Check(const SubjectDescriptor & subjectDescriptor, const RequestPath & requestPath, Privilege requestPrivilege) { | ||
| return CHIP_ERROR_NOT_IMPLEMENTED; | ||
| } | ||
|
|
||
| } // namespace Access | ||
| } // namespace chip | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /* | ||
| * | ||
| * Copyright (c) 2021 Project CHIP Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| #pragma once | ||
|
|
||
| #include <access/AccessControl.h> | ||
|
|
||
| namespace chip { | ||
| namespace Access { | ||
|
|
||
| class EntryIteratorDelegate: public AccessControl::EntryIterator::Delegate | ||
| { | ||
| public: | ||
| EntryIteratorDelegate(AccessControl::EntryIterator::Delegate *first, AccessControl::EntryIterator::Delegate *second): | ||
| mFirst(first), mSecond(second) {} | ||
|
|
||
| EntryIteratorDelegate(const Delegate &) = delete; | ||
| EntryIteratorDelegate & operator=(const Delegate &) = delete; | ||
| virtual ~EntryIteratorDelegate() = default; | ||
|
|
||
| virtual void Release(); | ||
| virtual CHIP_ERROR Next(AccessControl::Entry & entry); | ||
|
|
||
| CHIP_ERROR mError = CHIP_NO_ERROR; | ||
| AccessControl::EntryIterator::Delegate *mFirst = nullptr; | ||
| AccessControl::EntryIterator::Delegate *mSecond = nullptr; | ||
| }; | ||
|
|
||
| class ExtendedAccessControlDelegate : public AccessControl::Delegate | ||
| { | ||
| public: | ||
| ExtendedAccessControlDelegate() = default; | ||
|
|
||
| ExtendedAccessControlDelegate(const Delegate &) = delete; | ||
| ExtendedAccessControlDelegate & operator=(const Delegate &) = delete; | ||
| virtual ~ExtendedAccessControlDelegate() = default; | ||
|
|
||
| void Release() override; | ||
| using AccessControl::Delegate::Init; | ||
| CHIP_ERROR Init(AccessControl::Delegate *primary, AccessControl::Delegate *seconday); | ||
| virtual CHIP_ERROR Init() override { return CHIP_ERROR_NOT_IMPLEMENTED; } | ||
| virtual void Finish() override; | ||
|
|
||
| // Capabilities | ||
| CHIP_ERROR GetMaxEntriesPerFabric(size_t & value) const override; | ||
| CHIP_ERROR GetMaxSubjectsPerEntry(size_t & value) const override; | ||
| CHIP_ERROR GetMaxTargetsPerEntry(size_t & value) const override; | ||
| CHIP_ERROR GetMaxEntryCount(size_t & value) const override; | ||
|
|
||
| // Actualities | ||
| CHIP_ERROR GetEntryCount(FabricIndex fabric, size_t & value) const override; | ||
| CHIP_ERROR GetEntryCount(size_t & value) const override; | ||
|
|
||
| // CRUD | ||
| CHIP_ERROR PrepareEntry(AccessControl::Entry & entry) override; | ||
| CHIP_ERROR CreateEntry(size_t * index, const AccessControl::Entry & entry, FabricIndex * fabricIndex) override; | ||
| CHIP_ERROR ReadEntry(size_t index, AccessControl::Entry & entry, const FabricIndex * fabricIndex) const override; | ||
| CHIP_ERROR UpdateEntry(size_t index, const AccessControl::Entry & entry, const FabricIndex * fabricIndex) override; | ||
| CHIP_ERROR DeleteEntry(size_t index, const FabricIndex * fabricIndex) override; | ||
|
|
||
| // Iteration | ||
| CHIP_ERROR Entries(AccessControl::EntryIterator & iterator, const FabricIndex * fabricIndex) const override; | ||
|
|
||
| CHIP_ERROR Check(const SubjectDescriptor & subjectDescriptor, const RequestPath & requestPath, Privilege requestPrivilege) override; | ||
|
|
||
| private: | ||
| AccessControl::Delegate *mPrimary = nullptr; | ||
| AccessControl::Delegate *mSecondary = nullptr; | ||
| }; | ||
|
|
||
| } // namespace Access | ||
| } // namespace chip |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Files are duplicated in both
src/access/examples/andsrc/access/directories. These duplicate files (ExtendedAccessControlDelegate.h/cpp) should be consolidated to a single location.