Spring OAuth2 JDBCTokenStore 性能和数据库架构

2024-02-24

我使用 MySQL5.5 + REST(Jersey) + Spring Security + Spring OAuth2。现在我正在做性能测试并注意到

org.springframework.security.oauth2.provider.token.store.JdbcTokenStore.readAuthentication方法运行速度非常慢..特别是方法的这一部分:

authentication = jdbcTemplate.queryForObject(selectAccessTokenAuthenticationSql,
                    new RowMapper<OAuth2Authentication>() {
                        public OAuth2Authentication mapRow(ResultSet rs, int rowNum) throws SQLException {
                            return deserializeAuthentication(rs.getBytes(2));
                        }
                    }, extractTokenKey(token));

为了提高性能,我将向以下查询添加 MySQL 索引:

private static final String DEFAULT_ACCESS_TOKEN_AUTHENTICATION_SELECT_STATEMENT = "select token_id, authentication from oauth_access_token where token_id = ?";

on token_id领域,但主要问题是关于官方 oauth2 Spring 数据库架构,例如https://github.com/spring-projects/spring-security-oauth/blob/master/spring-security-oauth2/src/test/resources/schema.sql https://github.com/spring-projects/spring-security-oauth/blob/master/spring-security-oauth2/src/test/resources/schema.sql

create table oauth_access_token (
  token_id VARCHAR(256),
  token LONGVARBINARY,
  authentication_id VARCHAR(256) PRIMARY KEY,
  user_name VARCHAR(256),
  client_id VARCHAR(256),
  authentication LONGVARBINARY,
  refresh_token VARCHAR(256)
);

token_id is VARCHAR(256)由于 MySQL 错误或限制,我无法添加此索引(例如MySQL 指定的键太长 https://stackoverflow.com/questions/20908928/mysql-specified-key-was-too-long)..

所以我的问题是 - 是否必须拥有token_id as VARCHAR(256)或者我可以将其更改为VARCHAR(255) ?


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Spring OAuth2 JDBCTokenStore 性能和数据库架构 的相关文章

随机推荐