Class AbstractSQLCoreProvider
- All Implemented Interfaces:
AutoCloseable, AuthSupportSudo, Reconfigurable
- Direct Known Subclasses:
MySQLCoreProvider, PostgresSQLCoreProvider, SQLCoreProvider
AuthCoreProvider.
Configuration fields (serialized)
- Core user columns –
uuidColumn,usernameColumn,accessTokenColumn,serverIDColumn,passwordColumn– andtableare required. - Permissions/roles columns are optional; their presence enables the respective query path automatically.
- Any
customQuery*/customUpdate*field overrides the corresponding generated SQL when non-null.
Adding an optional user-table column
OverrideregisterOptionalColumns() and call
registerColumnFeature(ColumnFeature) for each optional column.
The feature is automatically included in SELECT lists and ResultSet mapping
only when its column name is non-null — no other methods need to be touched.
// Example: totpSecret optional column in a subclass
public String totpSecretColumn; // null = feature disabled
@Override
protected void registerOptionalColumns() {
super.registerOptionalColumns();
registerColumnFeature(ColumnFeature.of(
totpSecretColumn,
(user, rs) -> ((MyUser) user).totpSecret = rs.getString(totpSecretColumn)
));
}
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classDescribes a single optional column in the user table.static classstatic classNested classes/interfaces inherited from class AuthCoreProvider
AuthCoreProvider.OAuthAccessTokenExpired, AuthCoreProvider.PasswordVerifyReportModifier and TypeClassDescriptionstatic classstatic class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final dev.samstevens.totp.code.CodeGeneratorlongSession / access-token lifetime in seconds (default: 1 hour).protected final org.apache.logging.log4j.Loggerprotected final dev.samstevens.totp.time.TimeProviderOptional TOTP secret column in the user table.protected final dev.samstevens.totp.code.CodeVerifierFields inherited from class AuthCoreProvider
pair, providers, serverModifier and TypeFieldDescriptionprotected AuthProviderPairstatic final pro.gravit.utils.ProviderMap<AuthCoreProvider> protected LaunchServer -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidApplies all registered optional columns touserfrom the current row ofset.authorize(String login, AuthResponse.AuthContext context, pro.gravit.launcher.base.request.auth.AuthRequest.AuthPasswordInterface password, boolean minecraftAccess) protected voidBuilds all transient SQL strings.checkServer(Client client, String username, String serverID) voidclose()protected AbstractSQLCoreProvider.SQLUserconstructUser(ResultSet set) Advancessetby one row and delegates toconstructUserFromRow(ResultSet), or returnsnullif the result set is empty.protected AbstractSQLCoreProvider.SQLUserConstructs aAbstractSQLCoreProvider.SQLUserfrom the current ResultSet row.protected AbstractSQLCoreProvider.SQLUserSessionprotected intexecuteSingleUpdate(String sql, String p1, String p2) Runs a two-parameter UPDATE and returns the affected-row count.List<pro.gravit.launcher.base.events.request.GetAvailabilityAuthRequestEvent.AuthAvailabilityDetails> getDetails(Client client) abstract SQLSourceConfiggetUserByLogin(String login) getUserByUsername(String username) getUserByUUID(UUID uuid) getUserSessionByOAuthAccessToken(String accessToken) voidinit(LaunchServer server, AuthProviderPair pair) booleanbooleanbooleanpro.gravit.launcher.base.ClientPermissionsloadPermissions(String uuid) protected StringReturns the comma-separated column list used in SELECT queries.refreshAccessToken(String refreshToken, AuthResponse.AuthContext context) protected final voidregisterColumnFeature(AbstractSQLCoreProvider.ColumnFeature<?, ?> feature) Registers one optional column.protected voidOverride to declare optional user-table columns.protected final AbstractSQLCoreProvider.SQLUsersafeQueryUser(String sql, String param) Executes a single-parameter SELECT and maps the result to aAbstractSQLCoreProvider.SQLUser(with permissions).protected voidupdateAuth(User user, String accessToken) protected booleanupdateServerID(User user, String serverID) protected voidverifyTotpCode(AbstractSQLCoreProvider.SQLUser user, String totpCode) Methods inherited from class AuthCoreProvider
authorize, getCommands, isSupport, registerProviders, verifyAuthModifier and TypeMethodDescriptionauthorize(User user, AuthResponse.AuthContext context, pro.gravit.launcher.base.request.auth.AuthRequest.AuthPasswordInterface password, boolean minecraftAccess) Gets a list of commands available for this object.<T> Tstatic voidvoidverifyAuth(AuthResponse.AuthContext context) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Reconfigurable
defaultCommandsMapModifier and TypeMethodDescription
-
Field Details
-
logger
protected final transient org.apache.logging.log4j.Logger logger -
expireSeconds
public long expireSecondsSession / access-token lifetime in seconds (default: 1 hour). -
table
-
uuidColumn
-
usernameColumn
-
accessTokenColumn
-
passwordColumn
-
serverIDColumn
-
totpSecretColumn
Optional TOTP secret column in the user table. Set to a non-null column name to enable TOTP support; leavenullto disable. When disabled the column is completely absent from all generated SQL. -
permissionsTable
-
permissionsPermissionColumn
-
permissionsUUIDColumn
-
rolesTable
-
rolesNameColumn
-
rolesUUIDColumn
-
passwordVerifier
-
customQueryByUUIDSQL
-
customQueryByUsernameSQL
-
customQueryByLoginSQL
-
customQueryPermissionsByUUIDSQL
-
customQueryRolesByUserUUID
-
customUpdateAuthSQL
-
customUpdateServerIdSQL
-
timeProvider
protected final transient dev.samstevens.totp.time.TimeProvider timeProvider -
codeGenerator
protected final transient dev.samstevens.totp.code.CodeGenerator codeGenerator -
verifier
protected final transient dev.samstevens.totp.code.CodeVerifier verifier
-
-
Constructor Details
-
AbstractSQLCoreProvider
public AbstractSQLCoreProvider()
-
-
Method Details
-
getSQLConfig
-
getUserByUsername
- Specified by:
getUserByUsernamein classAuthCoreProvider
-
getUserByUUID
- Specified by:
getUserByUUIDin classAuthCoreProvider
-
getUserByLogin
- Overrides:
getUserByLoginin classAuthCoreProvider
-
getDetails
public List<pro.gravit.launcher.base.events.request.GetAvailabilityAuthRequestEvent.AuthAvailabilityDetails> getDetails(Client client) - Overrides:
getDetailsin classAuthCoreProvider
-
getUserSessionByOAuthAccessToken
public UserSession getUserSessionByOAuthAccessToken(String accessToken) throws AuthCoreProvider.OAuthAccessTokenExpired - Specified by:
getUserSessionByOAuthAccessTokenin classAuthCoreProvider- Throws:
AuthCoreProvider.OAuthAccessTokenExpired
-
refreshAccessToken
public AuthManager.AuthReport refreshAccessToken(String refreshToken, AuthResponse.AuthContext context) - Specified by:
refreshAccessTokenin classAuthCoreProvider
-
authorize
public AuthManager.AuthReport authorize(String login, AuthResponse.AuthContext context, pro.gravit.launcher.base.request.auth.AuthRequest.AuthPasswordInterface password, boolean minecraftAccess) throws IOException - Specified by:
authorizein classAuthCoreProvider- Throws:
IOException
-
verifyTotpCode
protected void verifyTotpCode(AbstractSQLCoreProvider.SQLUser user, String totpCode) throws AuthException - Throws:
AuthException
-
sudo
- Specified by:
sudoin interfaceAuthSupportSudo- Throws:
IOException
-
checkServer
- Specified by:
checkServerin classAuthCoreProvider
-
joinServer
public boolean joinServer(Client client, String username, UUID uuid, String accessToken, String serverID) throws IOException - Specified by:
joinServerin classAuthCoreProvider- Throws:
IOException
-
init
- Overrides:
initin classAuthCoreProvider
-
registerOptionalColumns
protected void registerOptionalColumns()Override to declare optional user-table columns. Always callsuper.registerOptionalColumns()so the full hierarchy participates.Registering a feature with a
nullcolumn name is safe — it is silently ignored before any SQL is generated.See the class-level Javadoc for a usage example.
-
registerColumnFeature
Registers one optional column. Only valid to call fromregisterOptionalColumns(). -
buildPreparedQueries
protected void buildPreparedQueries()Builds all transient SQL strings. Called once perinit(LaunchServer, AuthProviderPair)after the optional-column registry is finalised.Subclasses that need additional SQL should override this and call
super.buildPreparedQueries()first. -
makeUserCols
Returns the comma-separated column list used in SELECT queries.The base implementation covers all required columns plus every enabled optional column registered via
registerOptionalColumns().Subclasses that add extra required (always-present) columns should override this and append to
super.makeUserCols(). Truly optional columns belong inregisterOptionalColumns()instead — they are appended here automatically. -
constructUserFromRow
Constructs aAbstractSQLCoreProvider.SQLUserfrom the current ResultSet row. AssumesResultSet.next()has already returnedtrue.Required columns are always read. Every enabled optional column is then applied via its
AbstractSQLCoreProvider.ColumnFeaturereader — no per-feature null checks needed.Subclasses that add their own required columns should override this, call
super.constructUserFromRow(set), cast the result to their SQLUser subtype, and populate the extra fields. Optional columns should useregisterOptionalColumns()instead.- Throws:
SQLException
-
constructUser
Advancessetby one row and delegates toconstructUserFromRow(ResultSet), or returnsnullif the result set is empty.- Throws:
SQLException
-
applyOptionalColumns
protected final void applyOptionalColumns(AbstractSQLCoreProvider.SQLUser user, ResultSet set) throws SQLException Applies all registered optional columns touserfrom the current row ofset.Subclasses that override
constructUserFromRow(ResultSet)to supply their own required columns should call this at the end of their override so optional columns are still applied:@Override protected SQLUser constructUserFromRow(ResultSet set) throws SQLException { MyUser user = new MyUser(..., set.getLong(myRequiredColumn)); applyOptionalColumns(user, set); return user; }- Throws:
SQLException
-
createSession
protected AbstractSQLCoreProvider.SQLUserSession createSession(AbstractSQLCoreProvider.SQLUser user) -
safeQueryUser
Executes a single-parameter SELECT and maps the result to aAbstractSQLCoreProvider.SQLUser(with permissions). Returnsnullon SQL errors. -
updateAuth
- Throws:
IOException
-
updateServerID
- Throws:
IOException
-
executeSingleUpdate
Runs a two-parameter UPDATE and returns the affected-row count. WrapsSQLExceptionasIOException.- Throws:
IOException
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein classAuthCoreProvider
-
isPermissionsEnabled
public boolean isPermissionsEnabled() -
isRolesEnabled
public boolean isRolesEnabled() -
loadPermissions
- Throws:
SQLException
-