All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.formkiq.server.config.RaceConditionFixedJdbcTokenStore Maven / Gradle / Ivy

There is a newer version: 0.6.1
Show newest version
package com.formkiq.server.config;

import javax.sql.DataSource;

import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.store.JdbcTokenStore;

/**
 * Custom JDBCTokenStore to return a 403 when a Race Condition occurs in Spring
 * OAuth. It seems the Spring OAuth people are unable / unwilling to fix this so
 * a 403 is better than a 500 and can retry.
 *
 */
public class RaceConditionFixedJdbcTokenStore extends JdbcTokenStore {

    /**
     * constructor.
     * @param dataSource {@link DataSource}
     */
    public RaceConditionFixedJdbcTokenStore(final DataSource dataSource) {
        super(dataSource);
    }

    @Override
    public void storeAccessToken(final OAuth2AccessToken token,
            final OAuth2Authentication authentication) {

        try {
            super.storeAccessToken(token, authentication);
        } catch (RuntimeException e) {
            throw new AccessDeniedException(
                    "Server too busy. Please wait and try again");
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy