Class AIConfigurationServiceImpl
- java.lang.Object
 - 
- com.composum.ai.backend.slingbase.impl.AIConfigurationServiceImpl
 
 
- 
- All Implemented Interfaces:
 AIConfigurationService
public class AIConfigurationServiceImpl extends Object implements AIConfigurationService
Collects the configurations fromAIConfigurationPlugins and aggregates them.The primary responsibility of this class is to determine which AI services are allowed based on various parameters such as:
- The user or user group making the request.
 - The content path being accessed or edited.
 - The URL of the editor in the browser.
 
The configurations are defined as OSGI configurations and can be dynamically modified at runtime. Each configuration specifies:
- Allowed and denied users or user groups.
 - Allowed and denied content paths.
 - Allowed and denied views (based on the URL).
 - The specific AI services that the configuration applies to.
 
When determining the allowed services, this implementation checks all the available configurations and aggregates the results. A service is considered allowed if it matches any of the "allowed" regular expressions and does not match any of the "denied" regular expressions.
- See Also:
 AIConfigurationPlugin,GPTPermissionConfiguration
 
- 
- 
Field Summary
Fields Modifier and Type Field Description protected com.composum.ai.backend.base.service.chat.GPTChatCompletionServicechatCompletionServiceprotected List<AIConfigurationPlugin>plugins 
- 
Constructor Summary
Constructors Constructor Description AIConfigurationServiceImpl() 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description GPTPermissionInfoallowedServices(org.apache.sling.api.SlingHttpServletRequest request, String contentPath, String editorUrl)Union of the plugin's results.protected booleanbasicCheck(GPTPermissionConfiguration config, org.apache.sling.api.SlingHttpServletRequest request, String contentPath, String editorUrl)Determines whether the configuration allows access wrt.com.composum.ai.backend.base.service.chat.GPTConfigurationgetGPTConfiguration(@NotNull org.apache.sling.api.resource.ResourceResolver resourceResolver, String contentPath)Reads the GPTConfiguration from sling context aware configurations.Map<String,String>getGPTConfigurationMap(@NotNull org.apache.sling.api.SlingHttpServletRequest request, String mapPath, String languageCode)Decodes the map from the given mapPath, as determined from the appropriate method ofAIConfigurationService.getGPTPromptLibraryPaths(SlingHttpServletRequest, String).GPTPromptLibrarygetGPTPromptLibraryPaths(@NotNull org.apache.sling.api.SlingHttpServletRequest request, String contentPath)Reads theGPTPromptLibraryfrom sling context aware configurations, falling back to OSGI configurations, falling back to default values.protected booleanpageAllowed(org.apache.sling.api.SlingHttpServletRequest request, String contentPath, GPTPermissionConfiguration config) 
 - 
 
- 
- 
Field Detail
- 
plugins
protected volatile List<AIConfigurationPlugin> plugins
 
- 
chatCompletionService
protected com.composum.ai.backend.base.service.chat.GPTChatCompletionService chatCompletionService
 
 - 
 
- 
Method Detail
- 
allowedServices
@Nullable public GPTPermissionInfo allowedServices(@Nonnull org.apache.sling.api.SlingHttpServletRequest request, @Nonnull String contentPath, @Nonnull String editorUrl)
Union of the plugin's results.- Specified by:
 allowedServicesin interfaceAIConfigurationService- Parameters:
 request- the SlingHttpServletRequestcontentPath- the content patheditorUrl- the editor URL- Returns:
 - information about allowed services
 
 
- 
basicCheck
protected boolean basicCheck(@Nonnull GPTPermissionConfiguration config, org.apache.sling.api.SlingHttpServletRequest request, @Nonnull String contentPath, @Nonnull String editorUrl)
Determines whether the configuration allows access wrt. user, page and view 
- 
pageAllowed
protected boolean pageAllowed(org.apache.sling.api.SlingHttpServletRequest request, String contentPath, GPTPermissionConfiguration config) 
- 
getGPTConfiguration
public com.composum.ai.backend.base.service.chat.GPTConfiguration getGPTConfiguration(@NotNull @NotNull org.apache.sling.api.resource.ResourceResolver resourceResolver, @Nullable String contentPath) throws IllegalArgumentExceptionDescription copied from interface:AIConfigurationServiceReads the GPTConfiguration from sling context aware configurations.- Specified by:
 getGPTConfigurationin interfaceAIConfigurationService- Parameters:
 resourceResolver- the resource resolvercontentPath- if that's given we read the configuration for this path, otherwise we take the requests path, as long as it starts with /content/- Throws:
 IllegalArgumentException- if none of the paths is a /content/ path.
 
- 
getGPTPromptLibraryPaths
@Nullable public GPTPromptLibrary getGPTPromptLibraryPaths(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, @Nullable String contentPath) throws IllegalArgumentException
Description copied from interface:AIConfigurationServiceReads theGPTPromptLibraryfrom sling context aware configurations, falling back to OSGI configurations, falling back to default values.- Specified by:
 getGPTPromptLibraryPathsin interfaceAIConfigurationService- Parameters:
 request- the requestcontentPath- if that's given we read the configuration for this path, otherwise we take the requests path, as long as it starts with /content/- Throws:
 IllegalArgumentException- if none of the paths is a /content/ path.
 
- 
getGPTConfigurationMap
@Nullable public Map<String,String> getGPTConfigurationMap(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, @Nullable String mapPath, @Nullable String languageCode)
Description copied from interface:AIConfigurationServiceDecodes the map from the given mapPath, as determined from the appropriate method ofAIConfigurationService.getGPTPromptLibraryPaths(SlingHttpServletRequest, String).- Specified by:
 getGPTConfigurationMapin interfaceAIConfigurationService
 
 - 
 
 -