@@ -94,24 +94,64 @@ public static async Task<bool> LoadPolicyAsync(this IModel model)
94
94
95
95
public static bool LoadFilteredPolicy ( this IModel model , IPolicyFilter filter )
96
96
{
97
+ if ( model . AdapterHolder . Adapter is null )
98
+ {
99
+ return false ;
100
+ }
101
+
97
102
if ( model . AdapterHolder . FilteredAdapter is null )
98
103
{
99
104
return false ;
100
105
}
101
106
107
+ DefaultPolicyStore policyStore = new ( ) ;
108
+ foreach ( KeyValuePair < string , PolicyAssertion > pair in model . Sections . GetPolicyAssertions ( ) )
109
+ {
110
+ policyStore . AddNode ( PermConstants . Section . PolicySection , pair . Key , pair . Value ) ;
111
+ }
112
+
113
+ if ( model . Sections . ContainsSection ( PermConstants . Section . RoleSection ) )
114
+ {
115
+ foreach ( KeyValuePair < string , RoleAssertion > pair in model . Sections . GetRoleAssertions ( ) )
116
+ {
117
+ policyStore . AddNode ( PermConstants . Section . RoleSection , pair . Key , pair . Value ) ;
118
+ }
119
+ }
120
+
102
121
model . AdapterHolder . FilteredAdapter . LoadFilteredPolicy ( model . PolicyStoreHolder . PolicyStore , filter ) ;
122
+ model . PolicyStoreHolder . PolicyStore = policyStore ;
103
123
return true ;
104
124
}
105
125
106
126
public static async Task < bool > LoadFilteredPolicyAsync ( this IModel model , IPolicyFilter filter )
107
127
{
128
+ if ( model . AdapterHolder . Adapter is null )
129
+ {
130
+ return false ;
131
+ }
132
+
108
133
if ( model . AdapterHolder . FilteredAdapter is null )
109
134
{
110
135
return false ;
111
136
}
112
137
138
+ DefaultPolicyStore policyStore = new ( ) ;
139
+ foreach ( KeyValuePair < string , PolicyAssertion > pair in model . Sections . GetPolicyAssertions ( ) )
140
+ {
141
+ policyStore . AddNode ( PermConstants . Section . PolicySection , pair . Key , pair . Value ) ;
142
+ }
143
+
144
+ if ( model . Sections . ContainsSection ( PermConstants . Section . RoleSection ) )
145
+ {
146
+ foreach ( KeyValuePair < string , RoleAssertion > pair in model . Sections . GetRoleAssertions ( ) )
147
+ {
148
+ policyStore . AddNode ( PermConstants . Section . RoleSection , pair . Key , pair . Value ) ;
149
+ }
150
+ }
151
+
113
152
await model . AdapterHolder . FilteredAdapter . LoadFilteredPolicyAsync ( model . PolicyStoreHolder . PolicyStore ,
114
153
filter ) ;
154
+ model . PolicyStoreHolder . PolicyStore = policyStore ;
115
155
return true ;
116
156
}
117
157
0 commit comments