@@ -132,7 +132,6 @@ public class Start
132132 private ResourceDistributor resourceDistributor = new ResourceDistributor ();
133133 private String processId ;
134134 private HikariLoggingAppender appender ;
135- private static final String APP_ID_KEY_NAME = "app_id" ;
136135 private static final String ACCESS_TOKEN_SIGNING_KEY_NAME = "access_token_signing_key" ;
137136 private static final String REFRESH_TOKEN_KEY_NAME = "refresh_token_key" ;
138137 public static boolean isTesting = false ;
@@ -875,6 +874,8 @@ public void addInfoToNonAuthRecipesBasedOnUserId(TenantIdentifier tenantIdentifi
875874 }
876875 } else if (className .equals (JWTRecipeStorage .class .getName ())) {
877876 /* Since JWT recipe tables do not store userId we do not add any data to them */
877+ } else if (className .equals (OAuthStorage .class .getName ())) {
878+ /* Since OAuth recipe tables do not store userId we do not add any data to them */
878879 } else if (className .equals (ActiveUsersStorage .class .getName ())) {
879880 try {
880881 ActiveUsersQueries .updateUserLastActive (this , tenantIdentifier .toAppIdentifier (), userId );
@@ -3100,6 +3101,194 @@ public int countUsersThatHaveMoreThanOneLoginMethodOrTOTPEnabledAndActiveSince(A
31003101 }
31013102 }
31023103
3104+ @ Override
3105+ public boolean doesOAuthClientIdExist (AppIdentifier appIdentifier , String clientId )
3106+ throws StorageQueryException {
3107+ try {
3108+ return OAuthQueries .doesOAuthClientIdExist (this , clientId , appIdentifier );
3109+ } catch (SQLException e ) {
3110+ throw new StorageQueryException (e );
3111+ }
3112+ }
3113+
3114+ @ Override
3115+ public void addOrUpdateOauthClient (AppIdentifier appIdentifier , String clientId , boolean isClientCredentialsOnly )
3116+ throws StorageQueryException , TenantOrAppNotFoundException {
3117+ try {
3118+ OAuthQueries .addOrUpdateOauthClient (this , appIdentifier , clientId , isClientCredentialsOnly );
3119+ } catch (SQLException e ) {
3120+ PostgreSQLConfig config = Config .getConfig (this );
3121+ if (e instanceof PSQLException ) {
3122+ ServerErrorMessage serverMessage = ((PSQLException ) e ).getServerErrorMessage ();
3123+
3124+ if (isForeignKeyConstraintError (serverMessage , config .getOAuthClientsTable (), "app_id" )) {
3125+ throw new TenantOrAppNotFoundException (appIdentifier );
3126+ }
3127+ }
3128+ throw new StorageQueryException (e );
3129+ }
3130+ }
3131+
3132+ @ Override
3133+ public boolean deleteOAuthClient (AppIdentifier appIdentifier , String clientId ) throws StorageQueryException {
3134+ try {
3135+ return OAuthQueries .deleteOAuthClient (this , clientId , appIdentifier );
3136+ } catch (SQLException e ) {
3137+ throw new StorageQueryException (e );
3138+ }
3139+ }
3140+
3141+ @ Override
3142+ public List <String > listOAuthClients (AppIdentifier appIdentifier ) throws StorageQueryException {
3143+ try {
3144+ return OAuthQueries .listOAuthClients (this , appIdentifier );
3145+ } catch (SQLException e ) {
3146+ throw new StorageQueryException (e );
3147+ }
3148+ }
3149+
3150+ @ Override
3151+ public void revokeOAuthTokensBasedOnTargetFields (AppIdentifier appIdentifier , OAuthRevokeTargetType targetType , String targetValue , long exp )
3152+ throws StorageQueryException , TenantOrAppNotFoundException {
3153+ try {
3154+ OAuthQueries .revokeOAuthTokensBasedOnTargetFields (this , appIdentifier , targetType , targetValue , exp );
3155+ } catch (SQLException e ) {
3156+ PostgreSQLConfig config = Config .getConfig (this );
3157+ if (e instanceof PSQLException ) {
3158+ ServerErrorMessage serverMessage = ((PSQLException ) e ).getServerErrorMessage ();
3159+
3160+ if (isForeignKeyConstraintError (serverMessage , config .getOAuthRevokeTable (), "app_id" )) {
3161+ throw new TenantOrAppNotFoundException (appIdentifier );
3162+ }
3163+ }
3164+ throw new StorageQueryException (e );
3165+ }
3166+
3167+ }
3168+
3169+ @ Override
3170+ public boolean isOAuthTokenRevokedBasedOnTargetFields (AppIdentifier appIdentifier , OAuthRevokeTargetType [] targetTypes , String [] targetValues , long issuedAt )
3171+ throws StorageQueryException {
3172+ try {
3173+ return OAuthQueries .isOAuthTokenRevokedBasedOnTargetFields (this , appIdentifier , targetTypes , targetValues , issuedAt );
3174+ } catch (SQLException e ) {
3175+ throw new StorageQueryException (e );
3176+ }
3177+ }
3178+
3179+ @ Override
3180+ public void addOAuthM2MTokenForStats (AppIdentifier appIdentifier , String clientId , long iat , long exp )
3181+ throws StorageQueryException , OAuthClientNotFoundException {
3182+ try {
3183+ OAuthQueries .addOAuthM2MTokenForStats (this , appIdentifier , clientId , iat , exp );
3184+ } catch (SQLException e ) {
3185+ PostgreSQLConfig config = Config .getConfig (this );
3186+ if (e instanceof PSQLException ) {
3187+ ServerErrorMessage serverMessage = ((PSQLException ) e ).getServerErrorMessage ();
3188+
3189+ if (isForeignKeyConstraintError (serverMessage , config .getOAuthM2MTokensTable (), "client_id" )) {
3190+ throw new OAuthClientNotFoundException ();
3191+ }
3192+ }
3193+ throw new StorageQueryException (e );
3194+ }
3195+ }
3196+
3197+ @ Override
3198+ public void cleanUpExpiredAndRevokedOAuthTokensList () throws StorageQueryException {
3199+ try {
3200+ OAuthQueries .cleanUpExpiredAndRevokedOAuthTokensList (this );
3201+ } catch (SQLException e ) {
3202+ throw new StorageQueryException (e );
3203+ }
3204+ }
3205+
3206+ @ Override
3207+ public void addOAuthLogoutChallenge (AppIdentifier appIdentifier , String challenge , String clientId ,
3208+ String postLogoutRedirectionUri , String sessionHandle , String state , long timeCreated )
3209+ throws StorageQueryException , DuplicateOAuthLogoutChallengeException , OAuthClientNotFoundException {
3210+ try {
3211+ OAuthQueries .addOAuthLogoutChallenge (this , appIdentifier , challenge , clientId , postLogoutRedirectionUri , sessionHandle , state , timeCreated );
3212+ } catch (SQLException e ) {
3213+ PostgreSQLConfig config = Config .getConfig (this );
3214+ if (e instanceof PSQLException ) {
3215+ ServerErrorMessage serverMessage = ((PSQLException ) e ).getServerErrorMessage ();
3216+
3217+ if (isPrimaryKeyError (serverMessage , config .getOAuthLogoutChallengesTable ())) {
3218+ throw new DuplicateOAuthLogoutChallengeException ();
3219+ } else if (isForeignKeyConstraintError (serverMessage , config .getOAuthLogoutChallengesTable (), "client_id" )) {
3220+ throw new OAuthClientNotFoundException ();
3221+ }
3222+ }
3223+ throw new StorageQueryException (e );
3224+ }
3225+ }
3226+
3227+ @ Override
3228+ public OAuthLogoutChallenge getOAuthLogoutChallenge (AppIdentifier appIdentifier , String challenge ) throws StorageQueryException {
3229+ try {
3230+ return OAuthQueries .getOAuthLogoutChallenge (this , appIdentifier , challenge );
3231+ } catch (SQLException e ) {
3232+ throw new StorageQueryException (e );
3233+ }
3234+ }
3235+
3236+ @ Override
3237+ public void deleteOAuthLogoutChallenge (AppIdentifier appIdentifier , String challenge ) throws StorageQueryException {
3238+ try {
3239+ OAuthQueries .deleteOAuthLogoutChallenge (this , appIdentifier , challenge );
3240+ } catch (SQLException e ) {
3241+ throw new StorageQueryException (e );
3242+ }
3243+ }
3244+
3245+ @ Override
3246+ public void deleteOAuthLogoutChallengesBefore (long time ) throws StorageQueryException {
3247+ try {
3248+ OAuthQueries .deleteOAuthLogoutChallengesBefore (this , time );
3249+ } catch (SQLException e ) {
3250+ throw new StorageQueryException (e );
3251+ }
3252+ }
3253+
3254+ @ Override
3255+ public int countTotalNumberOfOAuthClients (AppIdentifier appIdentifier ) throws StorageQueryException {
3256+ try {
3257+ return OAuthQueries .countTotalNumberOfClients (this , appIdentifier , false );
3258+ } catch (SQLException e ) {
3259+ throw new StorageQueryException (e );
3260+ }
3261+ }
3262+
3263+ @ Override
3264+ public int countTotalNumberOfClientCredentialsOnlyOAuthClients (AppIdentifier appIdentifier )
3265+ throws StorageQueryException {
3266+ try {
3267+ return OAuthQueries .countTotalNumberOfClients (this , appIdentifier , true );
3268+ } catch (SQLException e ) {
3269+ throw new StorageQueryException (e );
3270+ }
3271+ }
3272+
3273+ @ Override
3274+ public int countTotalNumberOfOAuthM2MTokensCreatedSince (AppIdentifier appIdentifier , long since )
3275+ throws StorageQueryException {
3276+ try {
3277+ return OAuthQueries .countTotalNumberOfOAuthM2MTokensCreatedSince (this , appIdentifier , since );
3278+ } catch (SQLException e ) {
3279+ throw new StorageQueryException (e );
3280+ }
3281+ }
3282+
3283+ @ Override
3284+ public int countTotalNumberOfOAuthM2MTokensAlive (AppIdentifier appIdentifier ) throws StorageQueryException {
3285+ try {
3286+ return OAuthQueries .countTotalNumberOfOAuthM2MTokensAlive (this , appIdentifier );
3287+ } catch (SQLException e ) {
3288+ throw new StorageQueryException (e );
3289+ }
3290+ }
3291+
31033292 @ TestOnly
31043293 public int getDbActivityCount (String dbname ) throws SQLException , StorageQueryException {
31053294 String QUERY = "SELECT COUNT(*) as c FROM pg_stat_activity WHERE datname = ?;" ;
0 commit comments