{"action":"created","issue":{"url":"https://api.github.com/repos/spring-projects/spring-security-oauth/issues/703","repository_url":"https://api.github.com/repos/spring-projects/spring-security-oauth","labels_url":"https://api.github.com/repos/spring-projects/spring-security-oauth/issues/703/labels{/name}","comments_url":"https://api.github.com/repos/spring-projects/spring-security-oauth/issues/703/comments","events_url":"https://api.github.com/repos/spring-projects/spring-security-oauth/issues/703/events","html_url":"https://github.com/spring-projects/spring-security-oauth/issues/703","id":137196426,"number":703,"title":"Using Spring Security with JDBC backend does not work","user":{"login":"tur-ing","id":15199933,"avatar_url":"https://avatars.githubusercontent.com/u/15199933?v=3","gravatar_id":"","url":"https://api.github.com/users/tur-ing","html_url":"https://github.com/tur-ing","followers_url":"https://api.github.com/users/tur-ing/followers","following_url":"https://api.github.com/users/tur-ing/following{/other_user}","gists_url":"https://api.github.com/users/tur-ing/gists{/gist_id}","starred_url":"https://api.github.com/users/tur-ing/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tur-ing/subscriptions","organizations_url":"https://api.github.com/users/tur-ing/orgs","repos_url":"https://api.github.com/users/tur-ing/repos","events_url":"https://api.github.com/users/tur-ing/events{/privacy}","received_events_url":"https://api.github.com/users/tur-ing/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/spring-projects/spring-security-oauth/labels/Question","name":"Question","color":"eb6420"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2016-02-29T09:19:01Z","updated_at":"2016-02-29T13:20:40Z","closed_at":null,"body":"I have followed the steps in this chapter of a Spring Security tutorial:\r\n\r\n[Go to tutorial on spring.io][1]\r\n\r\nI have built an app that works perfectly:\r\n\r\n[![enter image description here][2]][2]\r\n\r\n\r\nThen I wanted to implement a JDBC backend as described in this example:\r\n\r\n[Go to example on GitHub][3]\r\n\r\n\r\nI changed the initial project as shown in the example app on GitHub: \r\n\r\n[![enter image description here][4]][4]\r\n\r\nNow **it seems that the Resource Server is not able to check tokens** any more at the `/uaa/user` endpoint:\r\n\r\n**Executed commands:**\r\n\r\n[![enter image description here][5]][5]\r\n\r\n**Logs from the OAuth2 Authorization Server**\r\n\r\n    2016-02-28 12:35:08.762  INFO 1029 --- [nio-9999-exec-3] o.s.s.o.p.token.store.JdbcTokenStore     : Failed to find access token for token 41b1504d-b985-40e0-80a8-94c09992aafe\r\n    2016-02-28 12:37:58.604  INFO 1029 --- [nio-9999-exec-7] o.s.s.o.p.token.store.JdbcTokenStore     : Failed to find access token for token 41b1504d-b985-40e0-80a8-94c09992aafe\r\n    2016-02-28 12:44:06.845  INFO 1029 --- [nio-9999-exec-6] o.s.s.o.p.token.store.JdbcTokenStore     : Failed to find access token for token 41b1504d-b985-40e0-80a8-94c09992aafe\r\n\r\n\r\n**Logs from the Resource Server**\r\n\r\n    2016-02-28 12:37:42.149  INFO 1186 --- [0.1-8181-exec-3] o.s.b.a.s.o.r.UserInfoTokenServices      : Getting user info from: http://localhost:9999/uaa/user\r\n    2016-02-28 12:37:42.228  INFO 1186 --- [0.1-8181-exec-3] o.s.b.a.s.o.r.UserInfoTokenServices      : Could not fetch user details: class org.springframework.security.oauth2.client.resource.UserRedirectRequiredException, A redirect is required to get the users approval\r\n    2016-02-28 12:37:58.600  INFO 1186 --- [0.1-8181-exec-5] o.s.b.a.s.o.r.UserInfoTokenServices      : Getting user info from: http://localhost:9999/uaa/user\r\n    2016-02-28 12:37:58.623  INFO 1186 --- [0.1-8181-exec-5] o.s.b.a.s.o.r.UserInfoTokenServices      : Could not fetch user details: class java.lang.IllegalArgumentException, URI is not absolute\r\n    2016-02-28 12:44:06.839  INFO 1186 --- [0.1-8181-exec-7] o.s.b.a.s.o.r.UserInfoTokenServices      : Getting user info from: http://localhost:9999/uaa/user\r\n    2016-02-28 12:44:06.848  INFO 1186 --- [0.1-8181-exec-7] o.s.b.a.s.o.r.UserInfoTokenServices      : Could not fetch user details: class org.springframework.security.oauth2.common.exceptions.InvalidRequestException, Possible CSRF detected - state parameter was present but no state could be found\r\n\r\nHere are the important classes:\r\n\r\n**OAuth2 Authorization Server: SaAuthApplication.class**\r\n\r\n    @SpringBootApplication\r\n    @Configuration\r\n    @RestController\r\n    @EnableDiscoveryClient\r\n    @EnableResourceServer\r\n    @EnableAutoConfiguration\r\n    @EnableAuthorizationServer\r\n    public class SaAuthApplication {\r\n    \t\r\n    \t@Autowired\r\n    \tprivate DataSource dataSource;\r\n    \t\r\n    \t@RequestMapping(\"/user\")\r\n    \tpublic Principal user(Principal user) {\r\n    \t\treturn user;\r\n    \t}\r\n    \r\n    \tpublic static void main(String[] args) {\r\n    \t\tSpringApplication.run(SaAuthApplication.class, args);\r\n    \t}\r\n    \t\r\n    \t@Configuration\r\n    \t@EnableResourceServer\r\n    \tprotected static class ResourceServer extends ResourceServerConfigurerAdapter {\r\n    \r\n    \t\t@Autowired\r\n    \t\tprivate TokenStore tokenStore;\r\n    \r\n    \t\t@Override\r\n    \t\tpublic void configure(ResourceServerSecurityConfigurer resources)\r\n    \t\t\t\tthrows Exception {\r\n    \t\t\tresources.tokenStore(tokenStore);\r\n    \t\t}\r\n    \r\n    \t\t@Override\r\n    \t\tpublic void configure(HttpSecurity http) throws Exception {\r\n    \t\t\thttp.authorizeRequests().anyRequest().authenticated();\r\n    \t\t}\r\n    \r\n    \t}\r\n    \r\n    \t@Configuration\r\n    \t@EnableAuthorizationServer\r\n    \tprotected static class OAuth2Config extends AuthorizationServerConfigurerAdapter {\r\n    \r\n    \t\t@Autowired\r\n    \t\tprivate AuthenticationManager auth;\r\n    \r\n    \t\t@Autowired\r\n    \t\tprivate DataSource dataSource;\r\n    \r\n    \t\tprivate BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();\r\n    \r\n    \t\t@Bean\r\n    \t\tpublic JdbcTokenStore tokenStore() {\r\n    \t\t\treturn new JdbcTokenStore(dataSource);\r\n    \t\t}\r\n    \r\n    \t\t@Bean\r\n    \t\tprotected AuthorizationCodeServices authorizationCodeServices() {\r\n    \t\t\treturn new JdbcAuthorizationCodeServices(dataSource);\r\n    \t\t}\r\n    \r\n    \t\t@Override\r\n    \t\tpublic void configure(AuthorizationServerSecurityConfigurer security)\r\n    \t\t\t\tthrows Exception {\r\n    \t\t\tsecurity.passwordEncoder(passwordEncoder);\r\n    \t\t}\r\n    \r\n    \t\t@Override\r\n    \t\tpublic void configure(AuthorizationServerEndpointsConfigurer endpoints)\r\n    \t\t\t\tthrows Exception {\r\n    \t\t\tendpoints.authorizationCodeServices(authorizationCodeServices())\r\n    \t\t\t\t\t.authenticationManager(auth).tokenStore(tokenStore())\r\n    \t\t\t\t\t.approvalStoreDisabled();\r\n    \t\t}\r\n    \r\n    \t\t@Override\r\n    \t\tpublic void configure(ClientDetailsServiceConfigurer clients) throws Exception {\r\n    \t\t\t// @formatter:off\r\n    \t\t\tclients.jdbc(dataSource)\r\n    \t\t\t\t\t.passwordEncoder(passwordEncoder)\r\n    \t\t\t\t.withClient(\"my-trusted-client\")\r\n    \t\t\t\t\t.authorizedGrantTypes(\"password\", \"authorization_code\",\r\n    \t\t\t\t\t\t\t\"refresh_token\", \"implicit\")\r\n    \t\t\t\t\t.authorities(\"ROLE_CLIENT\", \"ROLE_TRUSTED_CLIENT\")\r\n    \t\t\t\t\t.scopes(\"read\", \"write\", \"trust\")\r\n    \t\t\t\t\t.resourceIds(\"oauth2-resource\")\r\n    \t\t\t\t\t.accessTokenValiditySeconds(60).and()\r\n    \t\t\t\t.withClient(\"my-client-with-registered-redirect\")\r\n    \t\t\t\t\t.authorizedGrantTypes(\"authorization_code\")\r\n    \t\t\t\t\t.authorities(\"ROLE_CLIENT\").scopes(\"read\", \"trust\")\r\n    \t\t\t\t\t.resourceIds(\"oauth2-resource\")\r\n    \t\t\t\t\t.redirectUris(\"http://anywhere?key=value\").and()\r\n    \t\t\t\t.withClient(\"my-client-with-secret\")\r\n    \t\t\t\t\t.authorizedGrantTypes(\"client_credentials\", \"password\")\r\n    \t\t\t\t\t.authorities(\"ROLE_CLIENT\").scopes(\"read\")\r\n    \t\t\t\t\t.resourceIds(\"oauth2-resource\").secret(\"secret\");\r\n    \t\t\t// @formatter:on\r\n    \t\t}\r\n    \r\n    \t}\r\n    \r\n    \t@Autowired\r\n    \tpublic void init(AuthenticationManagerBuilder auth) throws Exception {\r\n    \t\t// @formatter:off\r\n    \t\t\tauth.jdbcAuthentication().dataSource(dataSource).withUser(\"dave\")\r\n    \t\t\t\t\t.password(\"secret\").roles(\"USER\");\r\n    \t\t\t// @formatter:on\r\n    \t}\r\n    \r\n    }\r\n\r\n**Resource Server: application.yml**\r\n\r\n    security:\r\n      oauth2:\r\n        resource:\r\n          user-info-uri: http://localhost:9999/uaa/user\r\n\r\n**Resource Server: SaEmployeeApplication.class**\r\n\r\n    @SpringBootApplication\r\n    @EnableDiscoveryClient\r\n    @EnableResourceServer\r\n    public class SaEmployeeApplication {\r\n    \r\n    \tpublic static void main(String[] args) {\r\n    \t\tSpringApplication.run(SaEmployeeApplication.class, args);\r\n    \t}\r\n    \t\r\n    }\r\n\r\n\r\nEverything works fine at the **OAuth2 Authorization Server**. I can authorize clients and get tokens back. But the **Resource Server** seems to be unable to check the token at the `/uaa/user` endpoint.\r\n\r\n\r\n  [1]: https://spring.io/blog/2015/02/03/sso-with-oauth2-angular-js-and-spring-security-part-v\r\n  [2]: http://i.stack.imgur.com/YQeDm.png\r\n  [3]: https://github.com/spring-projects/spring-security-oauth/tree/master/tests/annotation/jdbc\r\n  [4]: http://i.stack.imgur.com/WUinY.png\r\n  [5]: http://i.stack.imgur.com/vMVHb.png"},"comment":{"url":"https://api.github.com/repos/spring-projects/spring-security-oauth/issues/comments/190209451","html_url":"https://github.com/spring-projects/spring-security-oauth/issues/703#issuecomment-190209451","issue_url":"https://api.github.com/repos/spring-projects/spring-security-oauth/issues/703","id":190209451,"user":{"login":"dsyer","id":124075,"avatar_url":"https://avatars.githubusercontent.com/u/124075?v=3","gravatar_id":"","url":"https://api.github.com/users/dsyer","html_url":"https://github.com/dsyer","followers_url":"https://api.github.com/users/dsyer/followers","following_url":"https://api.github.com/users/dsyer/following{/other_user}","gists_url":"https://api.github.com/users/dsyer/gists{/gist_id}","starred_url":"https://api.github.com/users/dsyer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dsyer/subscriptions","organizations_url":"https://api.github.com/users/dsyer/orgs","repos_url":"https://api.github.com/users/dsyer/repos","events_url":"https://api.github.com/users/dsyer/events{/privacy}","received_events_url":"https://api.github.com/users/dsyer/received_events","type":"User","site_admin":false},"created_at":"2016-02-29T13:20:40Z","updated_at":"2016-02-29T13:20:40Z","body":"Look in the database and check the expiry time?"}}