Open Rabindra1980 opened 7 years ago
Hi All, Can anybody guide me to resolve this issue.
Hi @dsyer , Could you please help me out to sort this issue.
Thanks, Rabindra
It's not really an issue specifically about this project. It's more of a usage question about Spring Boot. Your best option is to create a sample app and put the code in github, then ask your question on stack overflow. I recommend you learn how to format code snippets in markdown as well. Good luck.
Thanks for your early response. I will put the code in github.
any solution? already many guys have this problem, but still no response
I responded on Jun 19 (nearly 3 months ago). It's pretty hard to tell, but it seems like a usage issue to me (hence not really for discussion here), but we can leave this open until we get some more data.
userInfoUri must be wrong .
I corrected userInfoUri and it worked for me
objective of my application-Securing REST API with Oauth2 Technolgies used- spring boot 1.5.3 spring security spring oauth spring jdbc Mysql database List of important classes that i have implemented. Authorization serverconfig class
package com.rabindra.microservice.simpleDrCloudauthserverpartI.config;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.authentication.configurers.GlobalAuthenticationConfigurerAdapter; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer; import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer; import org.springframework.security.oauth2.provider.code.AuthorizationCodeServices; import org.springframework.security.oauth2.provider.code.JdbcAuthorizationCodeServices; import org.springframework.security.oauth2.provider.token.store.JdbcTokenStore;
@Configuration @EnableAuthorizationServer public class OAuth2Configuration extends AuthorizationServerConfigurerAdapter { @Autowired private AuthenticationManager auth;
}
Resource server configuration class package com.rabindra.microservice.simpleDrCloudauthserverpartI.config;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer; import org.springframework.security.oauth2.provider.token.store.JdbcTokenStore;
import org.springframework.security.oauth2.provider.token.TokenStore; @Configuration @EnableResourceServer
public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter{
/ @Override public void configure(ResourceServerSecurityConfigurer resources) throws Exception { resources.resourceId("apis"); }/ } Note these two class are in one spring boot application Api controller package com.rabindra.microservice.simpleDrCloudauthserverpartI.api;
import java.security.Principal;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;
@RestController @RequestMapping("/") public class AuthUserController {
} application .yml for authorization server server: port: 9090 contextPath: /authserv #The auth server will run on this port and with auth contextpath like http://localhost:9090/auth .you can give ny name for the contextpath
spring: datasource: url: jdbc:mysql://localhost:3306/auth username: root password: root driver-class-name: com.mysql.jdbc.Driver
jpa:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
another spring boot application where i have one resource which has to be accessd. Please find the class as below for this application
controller- package com.rabindra.microservice.simpleDrCloudpartI.api.controller;
import java.time.LocalTime; import java.time.format.DateTimeFormatter;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;
@RestController public class TimeRestController { // Only users with the role ROLE_ADMIN or ROLE_EXTERNAL_USER are allowed to retrieve the time @RequestMapping(value = "/time")
}
security config class
package com.rabindra.microservice.simpleDrCloudpartI.config;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso; @Configuration @EnableWebSecurity @EnableOAuth2Sso public class SecurityConfiguration extends WebSecurityConfigurerAdapter { @Autowired private DataSource dataSource;
}
application.yml
we commented it as we set the credential in adapter class using inmmemory
security:
user:
password: test123
spring: datasource: url: jdbc:mysql://localhost:3306/auth username: root password: root driver-class-name: com.mysql.jdbc.Driver
jpa:
Configure the Authorization Server and User Info Resource Server details
security: oauth2: client: accessTokenUri: http://localhost:9090/authserv/oauth/token userAuthorizationUri: http://localhost:9090/authserv/oauth/authorize clientId: myauthserver clientSecret: secret scope: read,write auto-approve-scopes: '.*'
pom.xml for this application
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
while running the url , http://localhost:8080/time, in chrome it is giving as below error 2017-06-17 11:16:21.336 INFO 7668 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet' 2017-06-17 11:16:21.336 INFO 7668 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started 2017-06-17 11:16:21.378 INFO 7668 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 42 ms 2017-06-17 11:17:02.834 WARN 7668 --- [nio-8080-exec-5] o.s.b.a.s.o.r.UserInfoTokenServices : Could not fetch user details: class org.springframework.web.client.HttpClientErrorException, 401 null 2017-06-17 11:17:03.142 WARN 7668 --- [nio-8080-exec-6] o.s.b.a.s.o.r.UserInfoTokenServices : Could not fetch user details: class org.springframework.web.client.HttpClientErrorException, 401 null 2017-06-17 11:21:22.462 WARN 7668 --- [nio-8080-exec-3] o.s.b.a.s.o.r.UserInfoTokenServices : Could not fetch user details: class org.springframework.web.client.HttpClientErrorException, 401 null 2017-06-17 11:21:22.518 WARN 7668 --- [nio-8080-exec-4] o.s.b.a.s.o.r.UserInfoTokenServices : Could not fetch user details: class org.springframework.web.client.HttpClientErrorException, 401 null 2017-06-17 11:21:29.564 WARN 7668 --- [nio-8080-exec-8] o.s.b.a.s.o.r.UserInfoTokenServices : Could not fetch user details: class org.springframework.web.client.HttpClientErrorException, 401 null 2017-06-17 11:21:29.670 WARN 7668 --- [io-8080-exec-10] o.s.b.a.s.o.r.UserInfoTokenServices : Could not fetch user details: class org.springframework.web.client.HttpClientErrorException, 401 null 2017-06-17 11:21:36.450 WARN 7668 --- [nio-8080-exec-3] o.s.b.a.s.o.r.UserInfoTokenServices : Could not fetch user details: class org.springframework.web.client.HttpClientErrorException, 401 null
--- I have created table in mysql table ,schema as auth create table users ( username varchar(256), password varchar(256), enabled boolean );
create table authorities ( username varchar(256), authority varchar(256) );
create table oauth_client_details ( client_id VARCHAR(256) PRIMARY KEY, resource_ids VARCHAR(256), client_secret VARCHAR(256), scope VARCHAR(256), authorized_grant_types VARCHAR(256), web_server_redirect_uri VARCHAR(256), authorities VARCHAR(256), access_token_validity INTEGER, refresh_token_validity INTEGER, additional_information VARCHAR(4096), autoapprove VARCHAR(256) );
create table oauth_client_token ( token_id VARCHAR(256), token LONGVARBINARY, authentication_id VARCHAR(256), user_name VARCHAR(256), client_id VARCHAR(256) );
create table oauth_access_token ( token_id VARCHAR(256), token LONGVARBINARY, authentication_id VARCHAR(256), user_name VARCHAR(256), client_id VARCHAR(256), authentication LONGVARBINARY, refresh_token VARCHAR(256) );
create table oauth_refresh_token ( token_id VARCHAR(256), token LONGVARBINARY, authentication LONGVARBINARY );
create table oauth_code ( code VARCHAR(256), authentication LONGVARBINARY );
There is no data in oauth_refresh_token table.
Could you please help me to resolve this issue. Is ther anything missed to implement.
Regards, Rabindra