简体   繁体   English

Oauth2 Spring-boot 只读连接错误

[英]Oauth2 Spring-boot read-only connection error

I am continuously getting below error , I did enable transaction with @EnableTransactionManagement , but still somehow transaction is not invoked in DefaultTokenServices .我不断遇到错误,我确实使用@EnableTransactionManagement启用了事务,但仍然没有在DefaultTokenServices 中调用事务。

Any help will be much appreciated任何帮助都感激不尽

Note: it was working with spring-boot 1.5 and recently I upgraded to 2.1注意:它与 spring-boot 1.5 一起工作,最近我升级到 2.1

2020-11-19 18:27:12.385 ERROR 49065 [tomcat-exec-2] - o.s.s.o.provider.endpoint.TokenEndpoint  : Handling error: TransientDataAccessResourceException, PreparedStatementCallback; SQL [insert into oauth_access_token (token_id, token, authentication_id, user_name, client_id, authentication, refresh_token) values (?, ?, ?, ?, ?, ?, ?)]; Connection is read-only. Queries leading to data modification are not allowed; nested exception is java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed

org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback; SQL [insert into oauth_access_token (token_id, token, authentication_id, user_name, client_id, authentication, refresh_token) values (?, ?, ?, ?, ?, ?, ?)]; Connection is read-only. Queries leading to data modification are not allowed; nested exception is java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed
    at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:110)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
  1. solution解决方案

I am able to fix with hack by manually attaching transaction to oauth jdbctokenservice.我可以通过手动将事务附加到 oauth jdbctokenservice 来修复 hack。

 private static final String AOP_POINTCUT_EXPRESSION = "execution (* org.springframework.security.oauth2.provider.token.store.JdbcTokenStore.*(..))";

    @Autowired
    public void txAdvice(TransactionInterceptor txAdvice) throws NoSuchMethodException {
        DefaultTransactionAttribute required = new DefaultTransactionAttribute();
        MethodMapTransactionAttributeSource source = new MethodMapTransactionAttributeSource();
        final Method method = JdbcTokenStore.class.getMethod("storeAccessToken", OAuth2AccessToken.class, OAuth2Authentication.class);
        source.addTransactionalMethod(method, required);
        txAdvice.setTransactionAttributeSource(source);
    }

    @Bean
    public Advisor txAdviceAdvisor(TransactionInterceptor txAdvice) {
        AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
        pointcut.setExpression(AOP_POINTCUT_EXPRESSION);
        return new DefaultPointcutAdvisor(pointcut, txAdvice);
    }

I also created issue with spring-security-oauth but seems it is not supposed to support spring-boot 2.x.我还创建了 spring-security-oauth 问题,但似乎它不应该支持 spring-boot 2.x。

Any Brilliant mind wanna help on why Transaction was not invoked in DefaultTokenServices.任何聪明的头脑都想帮助解释为什么没有在 DefaultTokenServices 中调用 Transaction。

  1. Solution解决方案

Create Bean for DefaultTokenServices and pass it to configurer为 DefaultTokenServices 创建 Bean 并将其传递给配置器

@Autowired
        private DefaultTokenServices tokenServices;

@Bean
        @Primary
        public DefaultTokenServices defaultTokenServices() {
            DefaultTokenServices defaultTokenServices = new DefaultTokenServices();
            defaultTokenServices.setTokenStore(tokenStore);
            return defaultTokenServices;
        }

        @Override
        public void configure(AuthorizationServerEndpointsConfigurer endpoints)
                throws Exception {
            endpoints.authorizationCodeServices(authorizationCodeServices())
                    .tokenStore(tokenStore)
                    .authenticationManager(auth)
                    .addInterceptor(handlerInterceptor)
                    .tokenServices(tokenServices)
                    .approvalStoreDisabled();
        }

link: https://github.com/spring-projects/spring-security-oauth/issues/1900链接: https : //github.com/spring-projects/spring-security-oauth/issues/1900

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Spring-Boot和OAuth2的JdbcTokenStore实现 - JdbcTokenStore implementation with Spring-Boot and OAuth2 使oauth2与spring-boot和rest一起使用 - Getting oauth2 to work with spring-boot and rest Spring-boot oauth2拆分授权服务器和资源服务器 - Spring-boot oauth2 splitting authorization server and resource server 如何限制到特定域以使用 Spring-Boot 和 OAuth2 登录 - How to restrict to a specific domain to login with Spring-Boot and OAuth2 Spring-Boot OAuth2 使用 Twitch 进行身份验证时的奇怪行为 - Spring-Boot OAuth2 Strange Behavior When Authenticating with Twitch 找不到UsernamePasswordAuthenticationToken的AuthenticationProvider - Spring-boot + Oauth2:Restful API - No AuthenticationProvider found for UsernamePasswordAuthenticationToken - Spring-boot + Oauth2: Restful API 使用OAuth2 SSO在spring-boot应用程序中禁用CSRF - Disable CSRF in spring-boot application with OAuth2 SSO 休眠和弹簧,本机选择上的连接是只读错误 - hibernate & spring, Connection is read-only error on native select spring-boot 1.3-M5 oauth2 SSO不能与spring-session一起使用吗? - spring-boot 1.3-M5 oauth2 SSO does not work with spring-session? 如何通过Spring-boot 1.3.0.RC1为oauth2提供自定义安全配置 - How to provide custom security configuration for oauth2 with spring-boot 1.3.0.RC1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM