Spring OAuth2 JDBCTokenStore性能和数据库架构

时间:2015-06-04 21:37:26

标签: mysql spring spring-security oauth-2.0 spring-security-oauth2

我使用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 = ?";

token_id字段上,但主要问题是关于官方oauth2 Spring数据库架构,例如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_idVARCHAR(256),由于MySQL的错误或限制,我无法添加此索引(例如MySQL Specified key was too long)..

所以我的问题是 - 将token_id作为VARCHAR(256)是强制性的,还是可以将其更改为VARCHAR(255)

0 个答案:

没有答案