Interface PermissionBackend
ru.tehkode.permissions.backends).
Implementations persist and load permission data (users, groups, world inheritance, and related
metadata). Concrete backend bodies live on AbstractPermissionBackend in
permissionsex-core; aliases and factory helpers stay on this interface for classpath-stable
static calls.
Each backend is constructed with a PermissionManager and a
PEXBackendConfiguration and is responsible for schema versioning, reload, and lifecycle
management.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final classInternal holder for backend alias-to-class mappings. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault backend alias used when no backend name is specified. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the backend and releases any held resources.Returns a short label describing this backend instance for diagnostics and logging.Returns world inheritance mappings for all worlds.static PermissionBackendgetBackend(String backendName, PermissionManager manager, PEXBackendConfiguration config) Instantiates a backend by name, falling back toDEFAULT_BACKENDon failure.static PermissionBackendgetBackend(String backendName, PermissionManager manager, PEXBackendConfiguration config, String fallBackBackend) Instantiates a backend by name with an explicit fallback backend.static StringgetBackendAlias(Class<? extends PermissionBackend> backendClass) Returns the registered alias for a backend class, or the class name if no alias is registered.static Class<? extends PermissionBackend> getBackendClass(String alias) Resolves a backend alias or class name to aPermissionBackendimplementation class.static StringgetBackendClassName(String alias) Resolves a backend alias to its fully qualified class name.getGroupData(String groupName) Returns mutable data for the group identified bygroupName.Returns all group names known to this backend.intReturns the latest schema version supported by this backend implementation.Returns the logger used by this backend for diagnostic output.Returns all registered backend aliases, sorted case-insensitively.intReturns the schema version currently stored by this backend.getUserData(String userName) Returns mutable data for the user identified byuserName.Returns all user identifiers known to this backend.Returns all user display names known to this backend.getWorldInheritance(String world) Returns the world inheritance chain for a specific world.booleanReturns whether a group record exists in this backend.booleanReturns whether a user record exists in this backend.voidloadFrom(PermissionBackend backend) Replaces this backend's in-memory contents with data copied from another backend.static voidregisterBackendAlias(String alias, Class<? extends PermissionBackend> backendClass) Registers a short alias for aPermissionBackendimplementation class.voidreload()Reloads all permission data from the underlying storage.voidReverts user identifiers from UUID form back to legacy name-based identifiers.voidsetPersistent(boolean persistent) Enables or disables automatic persistence of in-memory changes.voidsetWorldInheritance(String world, List<String> inheritance) Sets the world inheritance chain for a specific world.voidwriteContents(Writer writer) Writes a human-readable dump of backend contents to the given writer.
-
Field Details
-
DEFAULT_BACKEND
Default backend alias used when no backend name is specified.- See Also:
-
-
Method Details
-
getRegisteredBackendAliases
Returns all registered backend aliases, sorted case-insensitively.- Returns:
- an unmodifiable list of alias names; never
null
-
getBackendClassName
Resolves a backend alias to its fully qualified class name.If
aliasis a registered alias, returns the canonical name of the mapped class. Otherwise returnsaliasunchanged, treating it as a raw class name.- Parameters:
alias- backend alias or fully qualified class name- Returns:
- the resolved class name; never
null
-
getBackendClass
static Class<? extends PermissionBackend> getBackendClass(String alias) throws ClassNotFoundException Resolves a backend alias or class name to aPermissionBackendimplementation class.- Parameters:
alias- backend alias or fully qualified class name- Returns:
- the resolved backend class; never
null - Throws:
ClassNotFoundException- ifaliasis not registered and no class with that name existsIllegalArgumentException- if the resolved class does not extendPermissionBackend
-
registerBackendAlias
Registers a short alias for aPermissionBackendimplementation class.- Parameters:
alias- human-readable alias (for example"file"or"sql")backendClass- backend implementation class- Throws:
IllegalArgumentException- ifbackendClassis not a subclass ofPermissionBackend
-
getBackendAlias
Returns the registered alias for a backend class, or the class name if no alias is registered.- Parameters:
backendClass- backend implementation class- Returns:
- the alias associated with
backendClass, or its fully qualified name
-
getBackend
static PermissionBackend getBackend(String backendName, PermissionManager manager, PEXBackendConfiguration config) throws PermissionBackendException Instantiates a backend by name, falling back toDEFAULT_BACKENDon failure.- Parameters:
backendName- name or alias of the backend to initializemanager- permission manager that owns this backendconfig- backend-specific configuration- Returns:
- a new backend instance
- Throws:
PermissionBackendException- if the backend fails to initialize in a controlled mannerRuntimeException- if the backend class cannot be loaded or constructed
-
getBackend
static PermissionBackend getBackend(String backendName, PermissionManager manager, PEXBackendConfiguration config, String fallBackBackend) throws PermissionBackendException Instantiates a backend by name with an explicit fallback backend.If
backendNameisnullor empty,DEFAULT_BACKENDis used. When the primary backend class cannot be found,fallBackBackendis attempted once unless it resolves to the same class name.- Parameters:
backendName- name or alias of the backend to initialize; may benullor emptymanager- permission manager that owns this backendconfig- backend-specific configurationfallBackBackend- alias or class name to use when the primary backend is unknown; may benull- Returns:
- a new backend instance
- Throws:
PermissionBackendException- if the backend fails to initialize in a controlled mannerRuntimeException- if neither the primary nor fallback backend can be loaded or constructed
-
getSchemaVersion
int getSchemaVersion()Returns the schema version currently stored by this backend.- Returns:
- the persisted schema version number
-
getLatestSchemaVersion
int getLatestSchemaVersion()Returns the latest schema version supported by this backend implementation.- Returns:
- the highest schema version this backend can read and write
-
reload
Reloads all permission data from the underlying storage.- Throws:
PermissionBackendException- if the reload fails due to a storage or configuration error
-
getUserData
Returns mutable data for the user identified byuserName.- Parameters:
userName- user identifier (name or UUID string, depending on backend mode)- Returns:
- user data handle; never
nullfor known identifiers
-
getGroupData
Returns mutable data for the group identified bygroupName.- Parameters:
groupName- group name- Returns:
- group data handle; never
nullfor known group names
-
hasUser
Returns whether a user record exists in this backend.- Parameters:
userName- user identifier to check- Returns:
trueif the user exists in storage
-
hasGroup
Returns whether a group record exists in this backend.- Parameters:
group- group name to check- Returns:
trueif the group exists in storage
-
getUserIdentifiers
Collection<String> getUserIdentifiers()Returns all user identifiers known to this backend.- Returns:
- collection of user identifiers; never
null
-
getUserNames
Collection<String> getUserNames()Returns all user display names known to this backend.- Returns:
- collection of user names; never
null
-
getGroupNames
Collection<String> getGroupNames()Returns all group names known to this backend.- Returns:
- collection of group names; never
null
-
getWorldInheritance
Returns the world inheritance chain for a specific world.World inheritance defines which groups apply in a given world before user-specific permissions are evaluated.
- Parameters:
world- world name- Returns:
- ordered list of inherited group names; never
null
-
getAllWorldInheritance
Returns world inheritance mappings for all worlds.- Returns:
- map from world name to ordered inheritance group lists; never
null
-
setWorldInheritance
Sets the world inheritance chain for a specific world.- Parameters:
world- world nameinheritance- ordered list of group names to inherit in that world
-
close
Closes the backend and releases any held resources.- Throws:
PermissionBackendException- if shutdown or final persistence fails
-
getLogger
Logger getLogger()Returns the logger used by this backend for diagnostic output.- Returns:
- backend logger; never
null
-
loadFrom
Replaces this backend's in-memory contents with data copied from another backend.- Parameters:
backend- source backend whose data should be loaded into this instance
-
revertUUID
void revertUUID()Reverts user identifiers from UUID form back to legacy name-based identifiers.Used during migration or when switching away from UUID-backed storage.
-
setPersistent
void setPersistent(boolean persistent) Enables or disables automatic persistence of in-memory changes.- Parameters:
persistent-trueto write changes to storage immediately or on save;falseto hold changes in memory only
-
writeContents
Writes a human-readable dump of backend contents to the given writer.- Parameters:
writer- destination writer- Throws:
IOException- if writing fails
-
diagnosticLabel
String diagnosticLabel()Returns a short label describing this backend instance for diagnostics and logging.- Returns:
- diagnostic label (for example backend type and connection target)
-