public class ScopeInfo
extends sirius.kernel.di.transformers.Composable
The scope is determined using the installed ScopeDetector
(Any class
implementing the interface and wearing a Register
annotation will do.)
The current scope is used to determine which UserManager
is used. Therefore
a system consisting of a backend and frontend can use distinct scopes and a different user manager for each.
Modifier and Type | Field and Description |
---|---|
static ScopeInfo |
DEFAULT_SCOPE
If no distinct scope is recognized by the current ScopeDetector or if no detector is installed,
this scope is used.
|
Constructor and Description |
---|
ScopeInfo(String scopeId,
String scopeType,
String scopeName,
String lang,
Function<ScopeInfo,com.typesafe.config.Config> configSupplier,
Function<ScopeInfo,Object> scopeSupplier)
Creates a new ScopeInfo with the given parameters.
|
Modifier and Type | Method and Description |
---|---|
static String |
getDefaulScopeConfigContents(String name)
Returns the original contents of the given default config file.
|
static List<String> |
getDefaultScopeConfigFiles()
Lists the names of all loaded default config files.
|
<T> T |
getHelper(Class<T> clazz)
Retrieves the helper of the given type.
|
<T> T |
getHelper(String name)
Retrieves the helper of the given name.
|
String |
getLang()
Returns the two letter language code of this scope as understood by
NLS.setDefaultLanguage(String) . |
static com.typesafe.config.Config |
getScopeDefaultConfig()
Returns the default config for all scopes.
|
String |
getScopeId()
Returns the unique ID of the scope
|
String |
getScopeName()
Returns the representative name of the scope
|
<T> T |
getScopeObject(Class<T> clazz)
Returns the associated scope object.
|
String |
getScopeType()
Returns the type of the scope.
|
UserSettings |
getSettings()
Returns the scope specific configuration.
|
UserManager |
getUserManager()
Returns the
UserManager responsible for this scope. |
boolean |
is(Class<?> type) |
<A> Optional<A> |
tryAs(Class<A> adapterType) |
public static final ScopeInfo DEFAULT_SCOPE
public ScopeInfo(@Nonnull String scopeId, @Nonnull String scopeType, @Nonnull String scopeName, @Nullable String lang, @Nullable Function<ScopeInfo,com.typesafe.config.Config> configSupplier, @Nullable Function<ScopeInfo,Object> scopeSupplier)
scopeId
- the unique id of the scopescopeType
- the type of the scope (like "backend" or "frontend"). This is used to retrieve the
associated UserManager
from the system config.scopeName
- the representative name of the scopelang
- the language used by the scope or null for the default languageconfigSupplier
- used to fetch the scope specific configurationscopeSupplier
- used to fetch the associated scope object. This can be a database entity or the like
associated with the scope@Nonnull public String getScopeId()
@Nonnull public String getScopeType()
This is used to determine the associated UserManager
from the system config
using the key security.scopes.[type].manager.
@Nonnull public String getScopeName()
@Nullable public String getLang()
NLS.setDefaultLanguage(String)
.public <T> T getScopeObject(Class<T> clazz)
Can be used to fetch the data object or database entity which represents this scope.
T
- determines the type of the expected scope objectclazz
- the expected type of the scope objectpublic boolean is(@Nonnull Class<?> type)
is
in interface sirius.kernel.di.transformers.Transformable
is
in class sirius.kernel.di.transformers.Composable
public <A> Optional<A> tryAs(@Nonnull Class<A> adapterType)
tryAs
in interface sirius.kernel.di.transformers.Transformable
tryAs
in class sirius.kernel.di.transformers.Composable
public <T> T getHelper(Class<T> clazz)
Helpers are utility classes which are kept per ScopeInfo and created by HelperFactory
instances.
T
- the generic type of the helperclazz
- the type of the helper to fetchpublic <T> T getHelper(String name)
Helpers are utility classes which are kept per ScopeInfo and created by HelperFactory
instances.
When using helpers in templates, it is better to refer to them via name than via class, as this stays constant when renaming or moving classes.
T
- the generic type of the helpername
- the name of the helper to fetchpublic static List<String> getDefaultScopeConfigFiles()
This and getDefaulScopeConfigContents(String)
can be used to output the default configuration for
users which customizes the scope configuration.
public static String getDefaulScopeConfigContents(String name)
Can be used to display the default config (with explaining comments) to the user which customizes the scope configuration.
name
- the name of the config file to showpublic static com.typesafe.config.Config getScopeDefaultConfig()
This is built by loading all scope-*.conf files. Additionaly the scope-settings.conf for all active customizations are used as well (if present).
public UserSettings getSettings()
Applications should consider using UserInfo.getSettings()
or UserContext.getSettings()
as this
also includes user specific settings.
public UserManager getUserManager()
UserManager
responsible for this scope.Copyright © 2018. All rights reserved.