1515using EventStore . Core . Authentication . InternalAuthentication ;
1616using EventStore . Core . Authentication . PassthroughAuthentication ;
1717using EventStore . Core . Authorization ;
18- using EventStore . Core . Bus ;
1918using EventStore . Core . Certificates ;
2019using EventStore . Core . Hashing ;
2120using EventStore . Core . LogAbstraction ;
@@ -110,20 +109,20 @@ public ClusterVNodeHostedService(
110109 ? _options . Application . Config
111110 : _options . Auth . AuthenticationConfig ;
112111
113- ( _options , var policySelectorsFactory ) = ConfigurePolicySelectorsFactory ( ) ;
112+ ( _options , var authProviderFactory ) = GetAuthorizationProviderFactory ( ) ;
114113 if ( _options . Database . DbLogFormat == DbLogFormat . V2 )
115114 {
116115 var logFormatFactory = new LogV2FormatAbstractorFactory ( ) ;
117116 Node = ClusterVNode . Create ( _options , logFormatFactory , GetAuthenticationProviderFactory ( ) ,
118- GetAuthorizationProviderFactory ( policySelectorsFactory ) ,
117+ authProviderFactory ,
119118 GetPersistentSubscriptionConsumerStrategyFactories ( ) , certificateProvider ,
120119 configuration ) ;
121120 }
122121 else if ( _options . Database . DbLogFormat == DbLogFormat . ExperimentalV3 )
123122 {
124123 var logFormatFactory = new LogV3FormatAbstractorFactory ( ) ;
125124 Node = ClusterVNode . Create ( _options , logFormatFactory , GetAuthenticationProviderFactory ( ) ,
126- GetAuthorizationProviderFactory ( policySelectorsFactory ) ,
125+ authProviderFactory ,
127126 GetPersistentSubscriptionConsumerStrategyFactories ( ) , certificateProvider ,
128127 configuration ) ;
129128 }
@@ -139,81 +138,26 @@ public ClusterVNodeHostedService(
139138 RegisterWebControllers ( enabledNodeSubsystems ) ;
140139 return ;
141140
142- ( ClusterVNodeOptions , PolicySelectorsFactory ) ConfigurePolicySelectorsFactory ( )
141+ ( ClusterVNodeOptions , AuthorizationProviderFactory ) GetAuthorizationProviderFactory ( )
143142 {
144143 if ( _options . Application . Insecure )
145144 {
146- return ( _options , new PolicySelectorsFactory ( ) ) ;
145+ return ( _options , new AuthorizationProviderFactory ( _ => new PassthroughAuthorizationProviderFactory ( ) ) ) ;
147146 }
148147
149- var defaultPolicySelector = new LegacyPolicySelectorFactory (
150- _options . Application . AllowAnonymousEndpointAccess ,
151- _options . Application . AllowAnonymousStreamAccess ,
152- _options . Application . OverrideAnonymousEndpointAccessForGossip ) ;
153-
154- // Temporary: get the policy plugin configuration
155- // TODO: Allow specifying multiple policy selectors
156- var policyPluginType =
157- _options . ConfigurationRoot ! . GetValue < string > ( "EventStore:Plugins:Authorization:PolicyType" ) ??
158- string . Empty ;
159-
160- var policyPlugins = pluginLoader . Load < IPolicySelectorFactory > ( ) . ToArray ( ) ;
161- var policySelectors = new Dictionary < string , IPolicySelectorFactory > ( ) ;
162- foreach ( var policyPlugin in policyPlugins )
163- {
164- try
165- {
166- var commandLine = policyPlugin . Name . Replace ( "Plugin" , "" ) . ToLowerInvariant ( ) ;
167- Log . Information (
168- "Loaded authorization policy plugin: {plugin} version {version} (Command Line: {commandLine})" ,
169- policyPlugin . Name , policyPlugin . Version , commandLine ) ;
170- policySelectors . Add ( commandLine , policyPlugin ) ;
171- }
172- catch ( CompositionException ex )
173- {
174- Log . Error ( ex , "Error loading authorization policy plugin." ) ;
148+ var modifiedOptions = _options ;
149+ if ( _options . Auth . AuthorizationType . Equals ( "internal" , StringComparison . InvariantCultureIgnoreCase ) ) {
150+ var registryFactory = new AuthorizationPolicyRegistryFactory ( _options , configuration , pluginLoader ) ;
151+ foreach ( var authSubsystem in registryFactory . GetSubsystems ( ) ) {
152+ modifiedOptions = modifiedOptions . WithPlugableComponent ( authSubsystem ) ;
175153 }
176- }
177154
178- if ( policyPluginType == string . Empty )
179- {
180- Log . Information ( "Using default authorization policy" ) ;
181- return ( _options , new PolicySelectorsFactory ( defaultPolicySelector ) ) ;
155+ var internalFactory = new AuthorizationProviderFactory ( components =>
156+ new InternalAuthorizationProviderFactory ( registryFactory . Create ( components . MainQueue ) ) ) ;
157+ return ( modifiedOptions , internalFactory ) ;
182158 }
183- if ( ! policySelectors . TryGetValue ( policyPluginType , out var selectedPolicy ) )
184- {
185- throw new ApplicationInitializationException (
186- $ "The authorization policy plugin type { policyPluginType } is not recognised. If this is supposed " +
187- $ "to be provided by an authorization policy plugin, confirm the plugin DLL is located in { Locations . PluginsDirectory } ." +
188- Environment . NewLine +
189- $ "Valid options for authorization policies are: { string . Join ( ", " , policySelectors . Keys ) } .") ;
190- }
191-
192- Log . Information ( "Using authorization policy plugin: {plugin} version {version}" , selectedPolicy . Name ,
193- selectedPolicy . Version ) ;
194- // Policies will be applied in order, so the default should always be last
195- var factory = new PolicySelectorsFactory ( [ selectedPolicy , defaultPolicySelector ] ) ;
196159
197- if ( selectedPolicy is IPlugableComponent plugablePolicy )
198- {
199- return ( _options . WithPlugableComponent ( plugablePolicy ) , factory ) ;
200- }
201- return ( _options , factory ) ;
202- }
203-
204- AuthorizationProviderFactory GetAuthorizationProviderFactory ( PolicySelectorsFactory policySelectorsFactory )
205- {
206- if ( _options . Application . Insecure )
207- {
208- return new AuthorizationProviderFactory ( _ => new PassthroughAuthorizationProviderFactory ( ) ) ;
209- }
210- var authorizationTypeToPlugin = new Dictionary < string , AuthorizationProviderFactory > {
211- {
212- "internal" , new AuthorizationProviderFactory ( components =>
213- new InternalAuthorizationProviderFactory ( policySelectorsFactory . Create ( components ) )
214- )
215- }
216- } ;
160+ var authorizationTypeToPlugin = new Dictionary < string , AuthorizationProviderFactory > { } ;
217161
218162 foreach ( var potentialPlugin in pluginLoader . Load < IAuthorizationPlugin > ( ) )
219163 {
@@ -224,8 +168,9 @@ AuthorizationProviderFactory GetAuthorizationProviderFactory(PolicySelectorsFact
224168 "Loaded authorization plugin: {plugin} version {version} (Command Line: {commandLine})" ,
225169 potentialPlugin . Name , potentialPlugin . Version , commandLine ) ;
226170 authorizationTypeToPlugin . Add ( commandLine ,
227- new AuthorizationProviderFactory ( _ =>
228- potentialPlugin . GetAuthorizationProviderFactory ( authorizationConfig ) ) ) ;
171+ new AuthorizationProviderFactory (
172+ _ => potentialPlugin . GetAuthorizationProviderFactory ( authorizationConfig )
173+ ) ) ;
229174 }
230175 catch ( CompositionException ex )
231176 {
@@ -243,7 +188,7 @@ AuthorizationProviderFactory GetAuthorizationProviderFactory(PolicySelectorsFact
243188 $ "Valid options for authorization are: { string . Join ( ", " , authorizationTypeToPlugin . Keys ) } .") ;
244189 }
245190
246- return factory ;
191+ return ( modifiedOptions , factory ) ;
247192 }
248193
249194 static CompositionContainer FindPlugins ( )
0 commit comments